Skip to content

Commit

Permalink
DotBots#292 LH_LOC: send processed LH2 data from the DotBot
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidAlvarado committed Mar 7, 2024
1 parent 32aec39 commit 247bf68
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
5 changes: 4 additions & 1 deletion bsp/lh2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions bsp/nrf/lh2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//*********************************************************************************//
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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 ==========================================
Expand Down
7 changes: 3 additions & 4 deletions drv/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===========================================
Expand Down
22 changes: 15 additions & 7 deletions projects/03app_dotbot/03app_dotbot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ========================================
Expand Down Expand Up @@ -206,23 +208,29 @@ 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
if (_dotbot_vars.lh2.data_ready[0][0] == DB_LH2_PROCESSED_DATA_AVAILABLE && _dotbot_vars.lh2.data_ready[1][0] == DB_LH2_PROCESSED_DATA_AVAILABLE) {

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();
Expand Down

0 comments on commit 247bf68

Please sign in to comment.