From 247bf681a5de98ddeb66e9c9377106c50a32382e Mon Sep 17 00:00:00 2001 From: Said Alvarado Date: Thu, 7 Mar 2024 15:34:38 +0100 Subject: [PATCH] #292 LH_LOC: send processed LH2 data from the DotBot --- bsp/lh2.h | 5 ++++- bsp/nrf/lh2.c | 18 +++++++++++++----- drv/protocol.h | 7 +++---- projects/03app_dotbot/03app_dotbot.c | 22 +++++++++++++++------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/bsp/lh2.h b/bsp/lh2.h index 13ac15cb0..6158fe0f9 100644 --- a/bsp/lh2.h +++ b/bsp/lh2.h @@ -79,8 +79,11 @@ void db_lh2_process_raw_data(db_lh2_t *lh2); * @brief Compute the location based on raw data coming from the lighthouse * * @param[in] lh2 pointer to the lh2 instance + * @param[out] out_sweep which sweep was processed. Only valid if return == True + * @param[out] out_basestation which basestation was processed. Only valid if return == True + * @return True if a sweep was processed, False if no processed occured */ -void db_lh2_process_location(db_lh2_t *lh2); +bool db_lh2_process_location(db_lh2_t *lh2, uint8_t *out_sweep, uint8_t *out_basestation); /** * @brief Start the LH2 frame acquisition diff --git a/bsp/nrf/lh2.c b/bsp/nrf/lh2.c index 3cd6eaf28..5cd214b27 100644 --- a/bsp/nrf/lh2.c +++ b/bsp/nrf/lh2.c @@ -903,9 +903,9 @@ void db_lh2_process_raw_data(db_lh2_t *lh2) { lh2->data_ready[sweep][temp_selected_polynomial >> 1] = DB_LH2_RAW_DATA_AVAILABLE; } -void db_lh2_process_location(db_lh2_t *lh2) { +bool db_lh2_process_location(db_lh2_t *lh2, uint8_t *out_sweep, uint8_t *out_basestation) { if (_lh2_vars.data.count == 0) { - return; + return false; } //*********************************************************************************// @@ -921,7 +921,7 @@ void db_lh2_process_location(db_lh2_t *lh2) { // stop the interruptions while you're reading the data. uint32_t temp_timestamp = 0; // default timestamp if (!_get_from_spi_ring_buffer(&_lh2_vars.data, temp_spi_bits, &temp_timestamp)) { - return; + return false; } // perform the demodulation + poly search on the received packets // convert the SPI reading to bits via zero-crossing counter demodulation and differential/biphasic manchester decoding @@ -933,7 +933,7 @@ void db_lh2_process_location(db_lh2_t *lh2) { // If there was an error with the polynomial, leave without updating anything if (temp_selected_polynomial == LH2_POLYNOMIAL_ERROR_INDICATOR) { - return; + return false; } // Figure in which of the two sweep slots we should save the new data. @@ -951,7 +951,7 @@ void db_lh2_process_location(db_lh2_t *lh2) { if ((temp_bits_sweep >> (47 - temp_bit_offset)) == 0x000000) { // Mark the data as wrong and keep going lh2->data_ready[sweep][basestation] = DB_LH2_NO_NEW_DATA; - return; + return false; } // Compute and save the lsfr location. @@ -974,6 +974,14 @@ void db_lh2_process_location(db_lh2_t *lh2) { lh2->locations[sweep][basestation].selected_polynomial = temp_selected_polynomial; // Mark the data point as processed lh2->data_ready[sweep][basestation] = DB_LH2_PROCESSED_DATA_AVAILABLE; + + //====================================================================================// + // Return Status // + //====================================================================================// + + *out_basestation = basestation; + *out_sweep = sweep; + return true; } //=========================== private ========================================== diff --git a/drv/protocol.h b/drv/protocol.h index d25f5899c..4acbcaf7d 100644 --- a/drv/protocol.h +++ b/drv/protocol.h @@ -104,10 +104,9 @@ typedef struct __attribute__((packed)) { } protocol_gps_waypoints_t; /// LH2 process data compressed for sending over radio. -typedef struct __attribute__((packed)) { - uint8_t selected_polynomial; ///< selected poly is the polyomial # (between 0 and 31) that the demodulation code thinks the demodulated bits are a part of, initialize to error state - uint32_t lfsr_location; ///< LFSR location is the position in a given polynomial's LFSR that the decoded data is, initialize to error state - uint32_t delay_us; ///< How many microseconds passed since the sample was taken +typedef struct __attribute__((packed)) { + uint8_t polynomial[2]; ///< selected poly is the polyomial # (between 0 and 31) that the demodulation code thinks the demodulated bits are a part of, initialize to error state + uint32_t lfsr_location[2]; ///< LFSR location is the position in a given polynomial's LFSR that the decoded data is, initialize to error state } protocol_lh2_processed_packet_t; //=========================== public =========================================== diff --git a/projects/03app_dotbot/03app_dotbot.c b/projects/03app_dotbot/03app_dotbot.c index a562733e1..01bdb8c80 100644 --- a/projects/03app_dotbot/03app_dotbot.c +++ b/projects/03app_dotbot/03app_dotbot.c @@ -68,6 +68,8 @@ typedef struct { uint8_t lh2_update_counter; ///< Counter used to track when lh2 data were received and to determine if an advertizement packet is needed uint64_t device_id; ///< Device ID of the DotBot db_log_dotbot_data_t log_data; + uint8_t out_sweep; + uint8_t out_basestation; } dotbot_vars_t; //=========================== variables ======================================== @@ -206,7 +208,8 @@ int main(void) { bool need_advertize = false; // Process available lighthouse data - db_lh2_process_location(&_dotbot_vars.lh2); + + db_lh2_process_location(&_dotbot_vars.lh2, &_dotbot_vars.out_sweep, &_dotbot_vars.out_basestation); if (_dotbot_vars.update_lh2) { // Check if data is ready to send @@ -214,15 +217,20 @@ int main(void) { db_lh2_stop(); // Prepare the radio buffer - db_protocol_header_to_buffer(_dotbot_vars.radio_buffer, DB_BROADCAST_ADDRESS, DotBot, DB_PROTOCOL_DOTBOT_DATA); - memcpy(_dotbot_vars.radio_buffer + sizeof(protocol_header_t), &_dotbot_vars.direction, sizeof(int16_t)); - // Add the LH2 sweep + db_protocol_header_to_buffer(_dotbot_vars.radio_buffer, DB_BROADCAST_ADDRESS, DotBot, DB_PROTOCOL_LH2_PROCESSED_DATA); + // Add the LH2 sweeps + protocol_lh2_processed_packet_t lh2_processed_packet; for (uint8_t lh2_sweep_index = 0; lh2_sweep_index < LH2_SWEEP_COUNT; lh2_sweep_index++) { - memcpy(_dotbot_vars.radio_buffer + sizeof(protocol_header_t) + sizeof(int16_t) + lh2_sweep_index * sizeof(db_lh2_raw_data_t), &_dotbot_vars.lh2.raw_data[lh2_sweep_index][0], sizeof(db_lh2_raw_data_t)); + // Copy data into the packet + lh2_processed_packet.polynomial[lh2_sweep_index] = _dotbot_vars.lh2.locations[lh2_sweep_index][0].selected_polynomial; + lh2_processed_packet.lfsr_location[lh2_sweep_index] = _dotbot_vars.lh2.locations[lh2_sweep_index][0].lfsr_location; // Mark the data as already sent - _dotbot_vars.lh2.data_ready[lh2_sweep_index][0] = DB_LH2_NO_NEW_DATA; + _dotbot_vars.lh2.data_ready[lh2_sweep_index][0] = DB_LH2_NO_NEW_DATA; } - size_t length = sizeof(protocol_header_t) + sizeof(int16_t) + sizeof(db_lh2_raw_data_t) * LH2_SWEEP_COUNT; + + // Copy packet into the radio buffer + memcpy(_dotbot_vars.radio_buffer + sizeof(protocol_header_t), &lh2_processed_packet, sizeof(protocol_lh2_processed_packet_t)); + size_t length = sizeof(protocol_header_t) + sizeof(protocol_lh2_processed_packet_t); // Send the radio packet db_radio_disable();