Add reliable Android BLE ride recorder
This commit is contained in:
+37
-16
@@ -28,7 +28,7 @@
|
||||
#define TRIKKE_I2C_FREQ_HZ 400000
|
||||
#define TRIKKE_SAMPLE_RATE_HZ 100
|
||||
#define TRIKKE_SAMPLE_TICKS pdMS_TO_TICKS(1000 / TRIKKE_SAMPLE_RATE_HZ)
|
||||
#define TRIKKE_SAMPLE_QUEUE_DEPTH 1024
|
||||
#define TRIKKE_SAMPLE_QUEUE_DEPTH 3072
|
||||
#define TRIKKE_METADATA_INTERVAL_PACKETS 64
|
||||
#define TRIKKE_STATUS_INTERVAL_PACKETS 64
|
||||
#define TRIKKE_TRANSPORT_RETRY_DELAY_MS 10
|
||||
@@ -59,9 +59,14 @@ typedef struct {
|
||||
adxl345_t accelerometer;
|
||||
l3g4200d_t gyroscope;
|
||||
QueueHandle_t sample_queue;
|
||||
StaticQueue_t sample_queue_control;
|
||||
uint8_t sample_queue_storage[
|
||||
TRIKKE_SAMPLE_QUEUE_DEPTH * sizeof(trikke_wire_sample_t)];
|
||||
atomic_uint_least32_t sensor_read_failure_count;
|
||||
atomic_uint_least32_t queue_overflow_count;
|
||||
atomic_uint_least32_t loop_overrun_count;
|
||||
TaskHandle_t output_task_handle;
|
||||
TaskHandle_t acquisition_task_handle;
|
||||
trikke_transport_t transport;
|
||||
#if CONFIG_TRIKKE_TRANSPORT_BLE
|
||||
trikke_ble_transport_t ble_transport;
|
||||
@@ -147,6 +152,18 @@ static trikke_wire_status_t status_snapshot(
|
||||
return status;
|
||||
}
|
||||
|
||||
#if CONFIG_TRIKKE_TRANSPORT_BLE
|
||||
static void session_ready(void *argument)
|
||||
{
|
||||
trikke_context_t *context = argument;
|
||||
if (context == NULL) {
|
||||
return;
|
||||
}
|
||||
xTaskNotifyGive(context->output_task_handle);
|
||||
xTaskNotifyGive(context->acquisition_task_handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void acquisition_task(void *argument)
|
||||
{
|
||||
trikke_context_t *context = argument;
|
||||
@@ -407,8 +424,11 @@ void app_main(void)
|
||||
usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_LF);
|
||||
#endif
|
||||
|
||||
s_context.sample_queue =
|
||||
xQueueCreate(TRIKKE_SAMPLE_QUEUE_DEPTH, sizeof(trikke_wire_sample_t));
|
||||
s_context.sample_queue = xQueueCreateStatic(
|
||||
TRIKKE_SAMPLE_QUEUE_DEPTH,
|
||||
sizeof(trikke_wire_sample_t),
|
||||
s_context.sample_queue_storage,
|
||||
&s_context.sample_queue_control);
|
||||
if (s_context.sample_queue == NULL) {
|
||||
ESP_LOGE(TAG, "sample queue allocation failed");
|
||||
l3g4200d_deinit(&s_context.gyroscope);
|
||||
@@ -417,17 +437,15 @@ void app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
TaskHandle_t output_task_handle = NULL;
|
||||
TaskHandle_t acquisition_task_handle = NULL;
|
||||
if (xTaskCreate(output_task, "trikke_output", 4096, &s_context, 5,
|
||||
&output_task_handle) != pdPASS ||
|
||||
&s_context.output_task_handle) != pdPASS ||
|
||||
xTaskCreate(acquisition_task, "trikke_acquire", 4096, &s_context, 10,
|
||||
&acquisition_task_handle) != pdPASS) {
|
||||
if (output_task_handle != NULL) {
|
||||
vTaskDelete(output_task_handle);
|
||||
&s_context.acquisition_task_handle) != pdPASS) {
|
||||
if (s_context.output_task_handle != NULL) {
|
||||
vTaskDelete(s_context.output_task_handle);
|
||||
}
|
||||
if (acquisition_task_handle != NULL) {
|
||||
vTaskDelete(acquisition_task_handle);
|
||||
if (s_context.acquisition_task_handle != NULL) {
|
||||
vTaskDelete(s_context.acquisition_task_handle);
|
||||
}
|
||||
vQueueDelete(s_context.sample_queue);
|
||||
ESP_LOGE(TAG, "telemetry task creation failed");
|
||||
@@ -439,14 +457,15 @@ void app_main(void)
|
||||
|
||||
#if CONFIG_TRIKKE_TRANSPORT_BLE
|
||||
err = trikke_ble_transport_init(
|
||||
&s_context.ble_transport, &s_context.transport);
|
||||
&s_context.ble_transport, &s_context.transport,
|
||||
session_ready, &s_context);
|
||||
#else
|
||||
err = trikke_usb_transport_init(
|
||||
&s_context.usb_transport, &s_context.transport);
|
||||
#endif
|
||||
if (err != ESP_OK) {
|
||||
vTaskDelete(output_task_handle);
|
||||
vTaskDelete(acquisition_task_handle);
|
||||
vTaskDelete(s_context.output_task_handle);
|
||||
vTaskDelete(s_context.acquisition_task_handle);
|
||||
vQueueDelete(s_context.sample_queue);
|
||||
#if CONFIG_TRIKKE_TRANSPORT_BLE
|
||||
ESP_LOGE(TAG, "BLE transport initialization failed: %s",
|
||||
@@ -463,6 +482,8 @@ void app_main(void)
|
||||
|
||||
// No text may share the byte stream once framed binary output begins.
|
||||
esp_log_level_set("*", ESP_LOG_NONE);
|
||||
xTaskNotifyGive(output_task_handle);
|
||||
xTaskNotifyGive(acquisition_task_handle);
|
||||
#if !CONFIG_TRIKKE_TRANSPORT_BLE
|
||||
xTaskNotifyGive(s_context.output_task_handle);
|
||||
xTaskNotifyGive(s_context.acquisition_task_handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user