Main project file that contain core program handling and initialization. More...
Macros | |
#define | DEVICE_NAME "Buoyancy" |
Name of device. More... | |
#define | MANUFACTURER_NAME "NTNU" |
Manufacturer. More... | |
#define | APP_ADV_INTERVAL 64 |
The advertising interval (in units of 0.625 ms. More... | |
#define | NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN |
UUID type for the Nordic UART Service (vendor specific). More... | |
#define | APP_ADV_DURATION 18000 |
The advertising duration (180 seconds) in units of 10 milliseconds. More... | |
#define | APP_BLE_OBSERVER_PRIO 3 |
Application's BLE observer priority. More... | |
#define | APP_BLE_CONN_CFG_TAG 1 |
A tag identifying the SoftDevice BLE configuration. More... | |
#define | MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) |
Minimum acceptable connection interval (7.5 ms). More... | |
#define | MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) |
Maximum acceptable connection interval (75 second). More... | |
#define | SLAVE_LATENCY 0 |
Slave latency. More... | |
#define | CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) |
Connection supervisory timeout (4 seconds). More... | |
#define | FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). More... | |
#define | NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) |
Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). More... | |
#define | MAX_CONN_PARAMS_UPDATE_COUNT 6 |
Number of attempts before giving up the connection parameter negotiation. More... | |
#define | SEC_PARAM_BOND 1 |
Perform bonding. More... | |
#define | SEC_PARAM_MITM 0 |
Man In The Middle protection not required. More... | |
#define | SEC_PARAM_LESC 0 |
LE Secure Connections not enabled. More... | |
#define | SEC_PARAM_KEYPRESS 0 |
Keypress notifications not enabled. More... | |
#define | SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE |
No I/O capabilities. More... | |
#define | SEC_PARAM_OOB 0 |
Out Of Band data not available. More... | |
#define | SEC_PARAM_MIN_KEY_SIZE 7 |
Minimum encryption key size. More... | |
#define | SEC_PARAM_MAX_KEY_SIZE 16 |
Maximum encryption key size. More... | |
#define | DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind. More... | |
#define | UART_TX_BUF_SIZE 256 |
UART TX buffer size. More... | |
#define | UART_RX_BUF_SIZE 256 |
UART RX buffer size. More... | |
#define | TXD_PIN (6UL) |
White wire. More... | |
#define | RXD_PIN (8UL) |
Gray/brown wire. More... | |
#define | MOTION_INT 13UL |
ICM motion sensor interrupt. More... | |
#define | TMP_ALERT 15UL |
TMP117 temperature sensor interrupt. More... | |
#define | HALLEFFECT_INT 17UL |
Hall Effect sensor interrupt. More... | |
#define | TOP_LIMIT 29UL |
Top Limit switch - Max Depth. More... | |
#define | BOTTOM_LIMIT 28UL |
Bottom Limit switch - Water Surface. More... | |
#define | PRESSURE_SWITCH 20UL |
Signal to switch on or off pressure sensor power. More... | |
#define | LOW_POWER_THRESHOLD 8700 |
SAADC value at 12.8 V - Go to LOWPOWER state. More... | |
Functions | |
BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT) | |
BLE NUS service instance. More... | |
NRF_BLE_GATT_DEF (m_gatt) | |
GATT module instance. More... | |
NRF_BLE_QWR_DEF (m_qwr) | |
Context for the Queued Write module. More... | |
BLE_ADVERTISING_DEF (m_advertising) | |
Advertising module instance. More... | |
void | hallEffectInterrupt_handler (void) |
Hall Effect button Interrupt handler. More... | |
void | limitSwitchBottom_handler (void) |
Bottom limit switch Interrupt handler. More... | |
void | limitSwitchTop_handler (void) |
Upper limit switch Interrupt handler. More... | |
void | TMP_temp_Alert_Interrupt_handler (void) |
TMP117 Temperature Alert Interrupt handler. More... | |
void | motionSensorInterrupt_handler (void) |
ICM20948 Motion Sensor Interrupt handler. More... | |
void | assert_nrf_callback (uint16_t line_num, const uint8_t *p_file_name) |
Callback function for asserts in the SoftDevice. More... | |
void | pm_evt_handler (pm_evt_t const *p_evt) |
Function for handling Peer Manager events. More... | |
void | gatt_evt_handler (nrf_ble_gatt_t *p_gatt, nrf_ble_gatt_evt_t const *p_evt) |
Function for handling events from the GATT library. More... | |
void | uart_event_handle (app_uart_evt_t *p_event) |
Function for handling app_uart events. More... | |
void | idle_state_handle (void) |
More... | |
void | gatt_init (void) |
Function for initializing the GATT library. More... | |
void | enablePressureSensor () |
Function to enable pressure sensor. More... | |
void | disablePressureSensor () |
Function to disable pressure sensor. More... | |
void | sleep_mode_enter (void) |
Function for putting the chip into sleep mode. More... | |
void | nus_send (uint8_t data[], uint16_t length) |
Send data over BLE Nordic UART Service (NUS) More... | |
void | advertising_start (bool erase_bonds) |
Function for starting advertising. More... | |
void | HFCLKstart () |
Start HFCLK from crystal oscillator, this will give the PWM and SAADC higher accuracy. More... | |
void | BLEdisconnect () |
Disconnect BLE connection. More... | |
void | disableAdvOnDisconnect (void) |
disable restarted advertising upon disconnection. More... | |
void | enableAdvOnDisconnect (void) |
enable restarted advertising upon disconnection. More... | |
bool | BLEconnected () |
Check if connected to client. More... | |
void | stopAdvertising () |
stop advertising More... | |
void | readTMP117 (uint8_t *tempMSB, uint8_t *tempLSB) |
Read TMP117 16 bit temperature register. More... | |
int | main (void) |
Function for application main entry. More... | |
void | nus_send (uint8_t *, uint16_t) |
void | printLine (uint8_t data[], uint16_t) |
void | anotherPrint (void) |
void | handleRXdata (ble_evt_t const *) |
void | uart_error_handle (app_uart_evt_t *) |
void | advLEDoff (void) |
Variables | |
bool | getValue = false |
Menu is waiting for value from BLE application. More... | |
bool | transferDataFlag = false |
Menu is in the process of transfering data to BLE application. More... | |
bool | updateFSM = true |
Init to true in order to access state machine. More... | |
bool | sendNUS = false |
Flag to signal Nordic UART Service to send data. More... | |
bool | motorStopped = false |
Flag to signal if motor is stopped or need to be stopped. More... | |
bool | isAdvertising = false |
Flag to signal if advertising or not. More... | |
bool | bottomLimit = false |
Flag to signal when bottom limit switch is reached. More... | |
mission_t | mission |
Create mission struct instance. More... | |
FSM_t | fsm |
Create Finite State Machine struct instance. More... | |
enum menu | currentMenu |
Create menu enumeration instance to keep track of menu operations. More... | |
Main project file that contain core program handling and initialization.
#define APP_ADV_DURATION 18000 |
The advertising duration (180 seconds) in units of 10 milliseconds.
#define APP_ADV_INTERVAL 64 |
The advertising interval (in units of 0.625 ms.
This value corresponds to 40 ms).
#define APP_BLE_CONN_CFG_TAG 1 |
A tag identifying the SoftDevice BLE configuration.
#define APP_BLE_OBSERVER_PRIO 3 |
Application's BLE observer priority.
You shouldn't need to modify this value.
#define BOTTOM_LIMIT 28UL |
Bottom Limit switch - Water Surface.
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) |
Connection supervisory timeout (4 seconds).
#define DEAD_BEEF 0xDEADBEEF |
Value used as error code on stack dump, can be used to identify stack location on stack unwind.
UART FIFO BUFFER SIZE
#define DEVICE_NAME "Buoyancy" |
Name of device.
Will be included in the advertising data.
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) |
Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds).
#define HALLEFFECT_INT 17UL |
Hall Effect sensor interrupt.
#define LOW_POWER_THRESHOLD 8700 |
SAADC value at 12.8 V - Go to LOWPOWER state.
#define MANUFACTURER_NAME "NTNU" |
Manufacturer.
Will be passed to Device Information Service.
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) |
Maximum acceptable connection interval (75 second).
#define MAX_CONN_PARAMS_UPDATE_COUNT 6 |
Number of attempts before giving up the connection parameter negotiation.
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) |
Minimum acceptable connection interval (7.5 ms).
#define MOTION_INT 13UL |
ICM motion sensor interrupt.
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) |
Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds).
#define NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN |
UUID type for the Nordic UART Service (vendor specific).
#define PRESSURE_SWITCH 20UL |
Signal to switch on or off pressure sensor power.
#define RXD_PIN (8UL) |
Gray/brown wire.
GPIOTE input Interrupt
#define SEC_PARAM_BOND 1 |
Perform bonding.
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE |
No I/O capabilities.
#define SEC_PARAM_KEYPRESS 0 |
Keypress notifications not enabled.
#define SEC_PARAM_LESC 0 |
LE Secure Connections not enabled.
#define SEC_PARAM_MAX_KEY_SIZE 16 |
Maximum encryption key size.
#define SEC_PARAM_MIN_KEY_SIZE 7 |
Minimum encryption key size.
#define SEC_PARAM_MITM 0 |
Man In The Middle protection not required.
#define SEC_PARAM_OOB 0 |
Out Of Band data not available.
#define SLAVE_LATENCY 0 |
Slave latency.
#define TMP_ALERT 15UL |
TMP117 temperature sensor interrupt.
#define TOP_LIMIT 29UL |
Top Limit switch - Max Depth.
#define TXD_PIN (6UL) |
White wire.
#define UART_RX_BUF_SIZE 256 |
UART RX buffer size.
UART
#define UART_TX_BUF_SIZE 256 |
UART TX buffer size.
void advertising_start | ( | bool | erase_bonds | ) |
Function for starting advertising.
void advLEDoff | ( | void | ) |
void anotherPrint | ( | void | ) |
Callback function for asserts in the SoftDevice.
This function will be called in case of an assert in the SoftDevice, FAILUREstate is called to float buoyancy vehicle to surface and change LED to PINK.
[in] | line_num | Line number of the failing ASSERT call. |
[in] | file_name | File name of the failing ASSERT call. |
BLE_ADVERTISING_DEF | ( | m_advertising | ) |
Advertising module instance.
BLE_NUS_DEF | ( | m_nus | , |
NRF_SDH_BLE_TOTAL_LINK_COUNT | |||
) |
BLE NUS service instance.
bool BLEconnected | ( | ) |
Check if connected to client.
void BLEdisconnect | ( | ) |
Disconnect BLE connection.
void disableAdvOnDisconnect | ( | void | ) |
disable restarted advertising upon disconnection.
void disablePressureSensor | ( | ) |
Function to disable pressure sensor.
void enableAdvOnDisconnect | ( | void | ) |
enable restarted advertising upon disconnection.
void enablePressureSensor | ( | ) |
Function to enable pressure sensor.
void gatt_evt_handler | ( | nrf_ble_gatt_t * | p_gatt, |
nrf_ble_gatt_evt_t const * | p_evt | ||
) |
Function for handling events from the GATT library.
void gatt_init | ( | void | ) |
Function for initializing the GATT library.
This function sets up all the necessary GAP (Generic Access Profile) parameters of the device.
void hallEffectInterrupt_handler | ( | void | ) |
Hall Effect button Interrupt handler.
< Notify FSM that hall effect interrupt has occured
void handleRXdata | ( | ble_evt_t const * | ) |
void HFCLKstart | ( | ) |
Start HFCLK from crystal oscillator, this will give the PWM and SAADC higher accuracy.
void idle_state_handle | ( | void | ) |
Function for handling the idle state (main loop).
If there is no pending log operation, then sleep until next the next event occurs.
void limitSwitchBottom_handler | ( | void | ) |
Bottom limit switch Interrupt handler.
< Debounce delay.
void limitSwitchTop_handler | ( | void | ) |
Upper limit switch Interrupt handler.
int main | ( | void | ) |
Function for application main entry.
< Initialize PWM before anything else to avoid the LED on full strength when uninitialized.
< variable to measure motor speed while returning to lower limit switch
< Enable limit switches as soon as possible to make sure they are enabled when motor is running
< Call NUS data transmission by setting flag: sendNUS
void motionSensorInterrupt_handler | ( | void | ) |
ICM20948 Motion Sensor Interrupt handler.
NRF_BLE_GATT_DEF | ( | m_gatt | ) |
GATT module instance.
NRF_BLE_QWR_DEF | ( | m_qwr | ) |
Context for the Queued Write module.
Send data over BLE Nordic UART Service (NUS)
[in] | data | string array to be sent over NUS |
[in] | length | Length of string array |
void pm_evt_handler | ( | pm_evt_t const * | p_evt | ) |
Function for handling Peer Manager events.
[in] | p_evt | Peer Manager event. |
Read TMP117 16 bit temperature register.
[out] | tempMSB | 8 most significant bits representing temperature |
[out] | tempLSB | 8 least significant bits representing temperature |
<Temperature register within TMP117
void sleep_mode_enter | ( | void | ) |
Function for putting the chip into sleep mode.
void stopAdvertising | ( | ) |
stop advertising
void TMP_temp_Alert_Interrupt_handler | ( | void | ) |
TMP117 Temperature Alert Interrupt handler.
void uart_error_handle | ( | app_uart_evt_t * | ) |
void uart_event_handle | ( | app_uart_evt_t * | p_event | ) |
Function for handling app_uart events.
This function will receive the reply message from motor controller interface, through the app_uart module, and append it to a data buffer array. The data buffer will be summed to verify correct checksum and sent to receiveReply().
[in] | p_event | UART event |
< UART Rx - Receive reply from motor controller.
< Go to FAILUREstate() to change LED to PINK and float to surface
< Go to FAILUREstate() to change LED to PINK and float to surface
bool bottomLimit = false |
Flag to signal when bottom limit switch is reached.
enum menu currentMenu |
Create menu enumeration instance to keep track of menu operations.
FSM_t fsm |
Create Finite State Machine struct instance.
bool getValue = false |
Menu is waiting for value from BLE application.
bool isAdvertising = false |
Flag to signal if advertising or not.
mission_t mission |
Create mission struct instance.
mission structure instance
bool motorStopped = false |
Flag to signal if motor is stopped or need to be stopped.
Flag to signal motor stopped.
bool sendNUS = false |
Flag to signal Nordic UART Service to send data.
bool transferDataFlag = false |
Menu is in the process of transfering data to BLE application.
bool updateFSM = true |
Init to true in order to access state machine.