Skip to content

Commit

Permalink
protocol in working condition with occasional misshaps
Browse files Browse the repository at this point in the history
  • Loading branch information
abiri committed Oct 19, 2018
1 parent 31dc08f commit 83abd6a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
10 changes: 7 additions & 3 deletions software/module/firmware/app_standard_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,15 @@ uint64_t standard_get_rxdelay_from_ranging_response_channel (uint8_t channel_ind
// TX / RX functions
/******************************************************************************/

void debug_print_tx(uint32_t length) {
/*debug_msg("Tx -> length ");
debug_msg_uint(length);
debug_msg("\n");*/
}

static void common_txcallback(const dwt_cb_data_t *txd) {

/*debug_msg("Tx -> length: ");
debug_msg_uint(txd->datalength);
debug_msg("\n");*/
//debug_msg("Tx -> done\n"); // datalength is NOT valid for Tx callbacks

// Handle GLOSSY
if (glossy_process_txcallback()) {
Expand Down
2 changes: 2 additions & 0 deletions software/module/firmware/app_standard_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct pp_anc_final {
struct ieee154_footer footer;
} __attribute__ ((__packed__));

#define MSG_PP_ANC_FINAL_PAYLOAD_DEFAULT_LENGTH 11 // 3 * uint8_t + 1 * uint64_t

/******************************************************************************/
// State objects for the standard application
Expand Down Expand Up @@ -186,6 +187,7 @@ void resp_txcallback (const dwt_cb_data_t *txd);
void resp_rxcallback (const dwt_cb_data_t *rxd, uint8_t * buf, uint64_t dw_rx_timestamp);

// Helper functions
void debug_print_tx(uint32_t length);
void helper_print_EUI(uint8_t * address);

#endif
1 change: 1 addition & 0 deletions software/module/firmware/app_standard_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ static void send_poll () {

// Tell the DW1000 about the packet
dwt_writetxfctrl(tx_len, 0, MSG_TYPE_RANGING);
debug_print_tx(tx_len);

// Setup the time the packet will go out at, and save that timestamp
uint32_t delay_time = dwt_readsystimestamphi32() + DW_DELAY_FROM_PKT_LEN(tx_len);
Expand Down
31 changes: 17 additions & 14 deletions software/module/firmware/app_standard_resp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ dw1000_err_e standard_resp_start () {
// Chip did not seem to wakeup. This is not good, so we have
// to reset the application.
return err;
} else {
// Did not go to sleep

// Clear state
memset(sr_scratch->resp_antenna_recv_num, 0, sizeof(sr_scratch->resp_antenna_recv_num));
}
}

// Also we start over in case the anchor was doing anything before
sr_scratch->state = RSTATE_IDLE;
Expand Down Expand Up @@ -149,6 +144,9 @@ static void ranging_broadcast_subsequence_task () {
// Stop iterating through timing channels
timer_stop(sr_scratch->resp_timer);

// Prepare for next initiators
sr_scratch->pp_anc_final_pkt.init_response_length++;

// Now, we either wait for the next initiator or will start responding with our packet when its our turn
standard_resp_start();

Expand Down Expand Up @@ -211,6 +209,7 @@ void standard_resp_send_response () {

const uint16_t frame_len = get_anc_final_packet_length(&sr_scratch->pp_anc_final_pkt);
dwt_writetxfctrl(frame_len, 0, MSG_TYPE_RANGING);
debug_print_tx(frame_len);

// Leave enough time to copy packet
// TODO: Verify that frames are not too long and have sufficient time to be transmitted and copied
Expand All @@ -237,6 +236,10 @@ void standard_resp_send_response () {
// Done with our response; Go back to IDLE
sr_scratch->state = RSTATE_IDLE;

// Clear state for next round
sr_scratch->pp_anc_final_pkt.init_response_length = 0;
memset(sr_scratch->resp_antenna_recv_num, 0, sizeof(sr_scratch->resp_antenna_recv_num));

}


Expand Down Expand Up @@ -274,9 +277,9 @@ void resp_rxcallback (const dwt_cb_data_t *rxd, uint8_t * buf, uint64_t dw_rx_ti
/*debug_msg("Received Poll message ");
debug_msg_int(rx_poll_pkt->subsequence);
debug_msg(": ");
debug_msg_int((uint32_t)(dw_rx_timestamp >> 32));
debug_msg_uint((uint32_t)(dw_rx_timestamp >> 32));
debug_msg(" ");
debug_msg_int((uint32_t)(dw_rx_timestamp & 0xFFFFFFFF));
debug_msg_uint((uint32_t)(dw_rx_timestamp & 0xFFFFFFFF));
debug_msg("\n");*/

// Decide what to do with this packet
Expand Down Expand Up @@ -400,24 +403,24 @@ void resp_rxcallback (const dwt_cb_data_t *rxd, uint8_t * buf, uint64_t dw_rx_ti
// Helper functions ----------------------------------------------------------------------------------------------------


static void write_anc_final_to_buffer() {
static void write_anc_final_to_buffer() {

uint8_t * dest = sr_scratch->pp_anc_final_pkt_buffer;

// Clear buffer
memset(dest, 0, sizeof(sr_scratch->pp_anc_final_pkt_buffer));

// Fill buffer:
uint8_t offset = 0;
uint16_t offset = 0;

// Header + Constant part
uint8_t header_length = sizeof(struct ieee154_header_broadcast) + 4;
uint16_t header_length = sizeof(struct ieee154_header_broadcast) + MSG_PP_ANC_FINAL_PAYLOAD_DEFAULT_LENGTH;

memcpy(dest + offset, &sr_scratch->pp_anc_final_pkt, header_length);
offset += header_length;

// Responses
uint8_t responses_length = sr_scratch->pp_anc_final_pkt.init_response_length * sizeof(struct pp_anc_final_init_response);
uint16_t responses_length = sr_scratch->pp_anc_final_pkt.init_response_length * sizeof(struct pp_anc_final_init_response);

memcpy(dest + offset, sr_scratch->pp_anc_final_pkt.init_responses, responses_length);
offset += responses_length;
Expand All @@ -428,8 +431,8 @@ static void write_anc_final_to_buffer() {

static uint16_t get_anc_final_packet_length(struct pp_anc_final * packet) {

uint16_t packet_length = sizeof(struct ieee154_header_broadcast) + 4 + sizeof(struct ieee154_footer);
packet_length += packet->init_response_length * sizeof(struct pp_anc_final_init_response);
uint16_t packet_length = sizeof(struct ieee154_header_broadcast) + MSG_PP_ANC_FINAL_PAYLOAD_DEFAULT_LENGTH + sizeof(struct ieee154_footer);
packet_length += packet->init_response_length * sizeof(struct pp_anc_final_init_response);

/*debug_msg("Anchor response packet size: ");
debug_msg_uint(packet_length);
Expand Down
9 changes: 6 additions & 3 deletions software/module/firmware/glossy.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ static void glossy_lwb_round_task() {

uint16_t frame_len = sizeof(struct pp_signal_flood);
dwt_writetxfctrl(frame_len, 0, MSG_TYPE_CONTROL);
debug_print_tx(frame_len);

// Send out a signalling packet during this contention slot
// Pick a random time offset to avoid colliding with others
Expand Down Expand Up @@ -485,7 +486,7 @@ static void glossy_lwb_round_task() {

if (_lwb_scheduled_resp) {
// Enable responders
standard_set_resp_active(TRUE);
standard_resp_start();
} else {
// Turn transceiver off (save energy) - initiators will wake up in their own slot
dwt_forcetrxoff();
Expand Down Expand Up @@ -611,6 +612,7 @@ bool glossy_process_txcallback(){
void lwb_send_sync(uint32_t delay_time){
uint16_t frame_len = get_sync_packet_length(&_sync_pkt);
dwt_writetxfctrl(frame_len, 0, MSG_TYPE_CONTROL);
debug_print_tx(frame_len);

_last_delay_time = delay_time;

Expand Down Expand Up @@ -752,6 +754,7 @@ void glossy_process_rxcallback(uint64_t dw_timestamp, uint8_t *buf){

uint16_t frame_len = sizeof(struct pp_signal_flood);
dwt_writetxfctrl(frame_len, 0, MSG_TYPE_CONTROL);
debug_print_tx(frame_len);

// Flood out as soon as possible
uint32_t delay_time = (dw_timestamp >> 8) + (DW_DELAY_FROM_US(GLOSSY_FLOOD_TIMESLOT_US) & 0xFFFFFFFE);
Expand Down Expand Up @@ -1097,7 +1100,7 @@ static void increment_sched_timeout(){
}

static uint8_t get_sync_packet_length(struct pp_sched_flood * packet) {
uint8_t packet_size = sizeof(struct ieee154_header_broadcast) + 4 + sizeof(struct ieee154_footer);
uint8_t packet_size = sizeof(struct ieee154_header_broadcast) + MSG_PP_SCHED_FLOOD_PAYLOAD_DEFAULT_LENGTH + sizeof(struct ieee154_footer);
packet_size += (packet->init_schedule_length + packet->resp_schedule_length) * PROTOCOL_EUI_LEN;

/*debug_msg("Schedule packet size: ");
Expand Down Expand Up @@ -1183,7 +1186,7 @@ static void write_sync_to_packet_buffer() {
uint8_t offset = 0;

// Header + Constant part
uint8_t header_length = sizeof(struct ieee154_header_broadcast) + 4;
uint8_t header_length = sizeof(struct ieee154_header_broadcast) + MSG_PP_SCHED_FLOOD_PAYLOAD_DEFAULT_LENGTH;

memcpy(_sync_pkt_buffer + offset, &_sync_pkt, header_length);
offset += header_length;
Expand Down
2 changes: 2 additions & 0 deletions software/module/firmware/glossy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct pp_sched_flood {
struct ieee154_footer footer;
} __attribute__ ((__packed__));

#define MSG_PP_SCHED_FLOOD_PAYLOAD_DEFAULT_LENGTH 4 // 4 * uint8_t

struct pp_signal_flood {
struct ieee154_header_broadcast header;
uint8_t message_type;
Expand Down

0 comments on commit 83abd6a

Please sign in to comment.