Skip to content

Commit

Permalink
Log data to flash
Browse files Browse the repository at this point in the history
* Define flash storage area in linker
  • Loading branch information
ojousima authored Aug 25, 2020
1 parent 5908be6 commit afeda5b
Show file tree
Hide file tree
Showing 32 changed files with 2,483 additions and 71 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ Document is generated with Doxygen. Run `make doxygen` to generate the docs loca
browse to [Travis built docs](ruuvi.github.io/ruuvi.firmware.c)

# Changelog
## 3.29.0
- Refactor, move tasks under drivers.
- Refactor, store log data to flash.
- Improve GATT power consumption.
- Improve GATT data rate.

## 3.28.12
- Fix leds not blinking

## 3.28.12
- Automatically release a tag

Expand Down
17 changes: 17 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
:extension:
:executable: .out

:tools:
# Ceedling defaults to using gcc for compiling, linking, etc.
# As [:tools] is blank, gcc will be used (so long as it's in your system path)
# See documentation to configure a given toolchain for use
:test_linker:
:executable: gcc #absolute file path
:name: 'gcc linker'
:arguments:
- ${1} #list of object files to link (Ruby method call param list sub)
- -lm #link with math header
- -o ${2} #executable file output (Ruby method call param list sub)

:tools_gcov_linker:
:arguments:
- -lm

:paths:
:test:
- +:test/**
Expand Down Expand Up @@ -63,6 +79,7 @@
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :ignore_arg
- :callback
- :return_thru_ptr
- :array
Expand Down
83 changes: 80 additions & 3 deletions src/app_comms.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include "app_config.h"
#include "app_comms.h"
#include "app_heartbeat.h"
#include "app_sensor.h"
#include "ruuvi_boards.h"
#include "ruuvi_endpoints.h"
#include "ruuvi_interface_communication.h"
#include "ruuvi_interface_communication_radio.h"
#include "ruuvi_interface_scheduler.h"
#include "ruuvi_task_advertisement.h"
#include "ruuvi_task_communication.h"
#include "ruuvi_task_gatt.h"
Expand All @@ -24,8 +29,66 @@
* TODO
* @endcode
*/

#if APP_GATT_ENABLED

static void handle_comms (const ri_comm_xfer_fp_t reply_fp, void * p_data,
size_t data_len)
{
rd_status_t err_code = RD_SUCCESS;

if (NULL == p_data)
{
err_code |= RD_ERROR_NULL;
}
else if (data_len < RE_STANDARD_MESSAGE_LENGTH)
{
err_code |= RD_ERROR_INVALID_PARAM;
}
else
{
// Stop heartbeat processing.
err_code |= app_heartbeat_stop();
// Parse message type
const uint8_t * const raw_message = (uint8_t *) p_data;
re_type_t type = raw_message[RE_STANDARD_DESTINATION_INDEX];

// Route message to proper handler
switch (type)
{
case RE_ACC_XYZ:
case RE_ACC_X:
case RE_ACC_Y:
case RE_ACC_Z:
case RE_GYR_XYZ:
case RE_GYR_X:
case RE_GYR_Y:
case RE_GYR_Z:
case RE_ENV_ALL:
case RE_ENV_TEMP:
case RE_ENV_HUMI:
case RE_ENV_PRES:
err_code |= app_sensor_handle (reply_fp, raw_message, data_len);
break;

default:
break;
}

// Resume heartbeat processing.
err_code |= app_heartbeat_start();
}

RD_ERROR_CHECK (err_code, ~RD_ERROR_FATAL);
}

#ifndef CEEDLING
static
#endif
void handle_gatt (void * p_data, uint16_t data_len)
{
handle_comms (&rt_gatt_send_asynchronous, p_data, data_len);
}

/** @brief Callback when GATT is connected" */
#ifndef CEEDLING
static
Expand All @@ -45,7 +108,21 @@ void on_gatt_disconnected_isr (void * p_data, size_t data_len)
// Start advertising for GATT
rt_gatt_enable();
}
// TODO: On data received

/**
* @brief Callback when data is received via GATT
*
* Schedule handling incoming message and replying back via given function pointer.
*/
#ifndef CEEDLING
static
#endif
void on_gatt_data_isr (void * p_data, size_t data_len)
{
rd_status_t err_code = RD_SUCCESS;
err_code |= ri_scheduler_event_put (p_data, (uint16_t) data_len, &handle_gatt);
RD_ERROR_CHECK (err_code, ~RD_ERROR_FATAL);
}

static rd_status_t ble_name_string_create (char * const name_str, const size_t name_len)
{
Expand Down Expand Up @@ -92,7 +169,6 @@ rd_status_t app_comms_init (void)
{
rd_status_t err_code = RD_SUCCESS;
ri_comm_dis_init_t dis = {0};
// Allow switchover to extended / 2 MBPS comms.
err_code |= ri_radio_init (APP_MODULATION);

if (RD_SUCCESS == err_code)
Expand All @@ -113,6 +189,7 @@ rd_status_t app_comms_init (void)
err_code |= rt_gatt_nus_init();
rt_gatt_set_on_connected_isr (&on_gatt_connected_isr);
rt_gatt_set_on_disconn_isr (&on_gatt_disconnected_isr);
rt_gatt_set_on_received_isr (&on_gatt_data_isr);
err_code |= rt_gatt_enable();
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions src/app_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ rd_status_t app_comms_init (void);
/** Handles for unit test framework */
void on_gatt_connected_isr (void * p_data, size_t data_len);
void on_gatt_disconnected_isr (void * p_data, size_t data_len);
void on_gatt_data_isr (void * p_data, size_t data_len);
void handle_gatt (void * p_data, uint16_t data_len);
#endif


Expand Down
35 changes: 35 additions & 0 deletions src/app_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "app_config.h"
#include "app_comms.h"
#include "app_heartbeat.h"
#include "app_log.h"
#include "app_sensor.h"
#include "ruuvi_driver_error.h"
#include "ruuvi_driver_sensor.h"
Expand All @@ -23,6 +24,7 @@
#include "ruuvi_task_nfc.h"

static ri_timer_id_t heart_timer; //!< Timer for updating data.

#ifndef CEEDLING
static
#endif
Expand Down Expand Up @@ -110,6 +112,9 @@ void heartbeat (void * p_event, uint16_t event_size)
{
ri_watchdog_feed();
}

err_code = app_log_process (&data);
RD_ERROR_CHECK (err_code, ~RD_ERROR_FATAL);
}

/**
Expand Down Expand Up @@ -147,7 +152,37 @@ rd_status_t app_heartbeat_init (void)
return err_code;
}

rd_status_t app_heartbeat_start (void)
{
rd_status_t err_code = RD_SUCCESS;

if (NULL == heart_timer)
{
err_code |= RD_ERROR_INVALID_STATE;
}
else
{
err_code |= ri_timer_start (heart_timer, APP_HEARTBEAT_INTERVAL_MS, NULL);
}

return err_code;
}

rd_status_t app_heartbeat_stop (void)
{
rd_status_t err_code = RD_SUCCESS;

if (NULL == heart_timer)
{
err_code |= RD_ERROR_INVALID_STATE;
}
else
{
err_code |= ri_timer_stop (heart_timer);
}

return err_code;
}

#ifdef CEEDLING
// Give CEEDLING a handle to state of module.
Expand Down
27 changes: 27 additions & 0 deletions src/app_heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,39 @@
* The heartbeat interval should be at most as logging rate to make sure
* that application will log fresh data.
*
* The heartbeat data is passed on to logging module which then decides
* if sample should be logged.
*
* @retval RD_SUCCESS on success
* @retval RD_ERROR_INVALID_STATE if timers or scheduler is not initialized.
* @retval RD_ERROR_RESOURCES if a timer cannot be allocated.
*/
rd_status_t app_heartbeat_init (void);

/**
* @brief (Re)starts app heartbeats.
*
* Calling this while heartbeats are ongoing has no effect.
*
* @retval RD_SUCCESS on success
* @retval RD_ERROR_INVALID_STATE if heartbeat is not initialized.
*/
rd_status_t app_heartbeat_start (void);

/**
* @brief Stops app heartbeats.
*
* This should be called to reduce the number of interrupts during heavier processing,
* e.g. stop while replaying sensor logs to attached device.
* Calling this has no effect if heartbeats are already stopped.
*
* @note Remember to restart the heartbeat, othewise app watchdog will trigger.
*
* @retval RD_SUCCESS on success.
* @retval RD_ERROR_INVALID_STATE if heartbeat is not initialized.
*/
rd_status_t app_heartbeat_stop (void);

#ifdef CEEDLING
#include "ruuvi_interface_timer.h"
ri_timer_id_t * get_heart_timer (void);
Expand Down
Loading

0 comments on commit afeda5b

Please sign in to comment.