Skip to content
Snippets Groups Projects
Commit 7d1032a3 authored by David's avatar David
Browse files

consolidated uwbList TDMA variables

parent c8015334
No related branches found
No related tags found
No related merge requests found
......@@ -105,8 +105,8 @@
<File name="src/platform/deca_spi.h" path="src/platform/deca_spi.h" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Core/src/usbd_ioreq.c" path="Libraries/STM32_USB_Device_Library/Core/src/usbd_ioreq.c" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c" path="Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c" type="1"/>
<File name="src/usb/usbd_desc.h" path="src/usb/usbd_desc.h" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h" path="Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h" type="1"/>
<File name="src/usb/usbd_desc.h" path="src/usb/usbd_desc.h" type="1"/>
<File name="src/platform/deca_spi.c" path="src/platform/deca_spi.c" type="1"/>
<File name="src/usb" path="" type="2"/>
<File name="src/decadriver/deca_version.h" path="src/decadriver/deca_version.h" type="1"/>
......@@ -137,12 +137,12 @@
<File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h" path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h" type="1"/>
<File name="src/decadriver/deca_device.c" path="src/decadriver/deca_device.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_req.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_req.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_adc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_adc.h" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_req.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_req.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c" type="1"/>
<File name="src/usb/usb_conf.h" path="src/usb/usb_conf.h" type="1"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_otg.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_otg.h" type="1"/>
<File name="src/usb/usb_conf.h" path="src/usb/usb_conf.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c" path="Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c" type="1"/>
<File name="src/usb/usbd_conf.h" path="src/usb/usbd_conf.h" type="1"/>
......@@ -163,26 +163,26 @@
<File name="Libraries/STM32_USB_Device_Library/Core/src" path="" type="2"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/misc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/misc.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h" type="1"/>
<File name="Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h" type="1"/>
<File name="src/application/main.c" path="src/main.c" type="1"/>
<File name="src/platform/deca_sleep.c" path="src/platform/deca_sleep.c" type="1"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h" type="1"/>
<File name="Libraries/CMSIS/CM3/CoreSupport" path="" type="2"/>
<File name="Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c" type="1"/>
<File name="src/compiler" path="" type="2"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h" type="1"/>
<File name="src/decadriver/deca_param_types.h" path="src/decadriver/deca_param_types.h" type="1"/>
<File name="src/compiler" path="" type="2"/>
<File name="Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c" type="1"/>
<File name="src/usb/deca_usb_bsp_evk1000.c" path="src/usb/deca_usb_bsp_evk1000.c" type="1"/>
<File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/startup_stm32f10x_cl.S" path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/startup_stm32f10x_cl.S" type="1"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" type="1"/>
<File name="src/platform/stm32f10x_conf.h" path="src/platform/stm32f10x_conf.h" type="1"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" type="1"/>
<File name="Libraries/CMSIS/CM3" path="" type="2"/>
<File name="Libraries" path="" type="2"/>
<File name="src/decadriver/deca_types.h" path="src/decadriver/deca_types.h" type="1"/>
<File name="src/usb/deca_usb.h" path="src/usb/deca_usb.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc" path="" type="2"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_spi.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_spi.h" type="1"/>
<File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_def.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_def.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_spi.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_spi.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h" type="1"/>
<File name="src/platform/stm32f10x_it.c" path="src/platform/stm32f10x_it.c" type="1"/>
<File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c" path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c" type="1"/>
......@@ -216,8 +216,8 @@
<File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup" path="" type="2"/>
<File name="Libraries/STM32_USB_OTG_Driver/inc/usb_core.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_core.h" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_bkp.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_bkp.c" type="1"/>
<File name="src/application/dw_main.c" path="src/application/dw_main.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c" type="1"/>
<File name="src/application/dw_main.c" path="src/application/dw_main.c" type="1"/>
<File name="src/platform" path="" type="2"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_tim.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_tim.c" type="1"/>
<File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_i2c.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_i2c.h" type="1"/>
......
......@@ -529,7 +529,8 @@ int testapprun(instance_data_t *inst, struct TDMAHandler *tdma_handler, int mess
memcpy(&inst->uwbList[0][0], &inst->eui64, inst->addrByteSize);
#endif
inst->uwbListLen = 1;
inst->uwbListType[0] = UWB_LIST_SELF;
// inst->uwbListType[0] = UWB_LIST_SELF;
tdma_handler->uwbListTDMAInfo[0].connectionType = UWB_LIST_SELF;
mode = (DWT_PRESRV_SLEEP|DWT_CONFIG|DWT_TANDV);
......@@ -1783,7 +1784,9 @@ int testapprun(instance_data_t *inst, struct TDMAHandler *tdma_handler, int mess
}
}
inst->lastRangeTimeStamp[inst->uwbToRangeWith] = portGetTickCnt();
// inst->lastRangeTimeStamp[inst->uwbToRangeWith] = portGetTickCnt();
tdma_handler->uwbListTDMAInfo[inst->uwbToRangeWith].lastRange = portGetTickCnt();
inst->newRangeTagAddress = instance_get_uwbaddr(inst->uwbToRangeWith);
inst->newRangeAncAddress = instance_get_addr();
......@@ -1845,7 +1848,8 @@ int testapprun(instance_data_t *inst, struct TDMAHandler *tdma_handler, int mess
}
}
inst->lastRangeTimeStamp[inst->uwbToRangeWith] = portGetTickCnt();
// inst->lastRangeTimeStamp[inst->uwbToRangeWith] = portGetTickCnt();
tdma_handler->uwbListTDMAInfo[inst->uwbToRangeWith].lastRange = portGetTickCnt();
uint8 debug_msg[100];
// int n = sprintf((char *)&debug_msg, "POLL_COMPLETE,%llX,%llX", inst->newRangeTagAddress, inst->newRangeAncAddress);
......
......@@ -151,19 +151,19 @@ typedef struct
uint8 uwbListLen ;
uint8 uwbList[UWB_LIST_SIZE][8]; //index 0 reserved for self, rest for other tracked uwbs
uint8 uwbListType[UWB_LIST_SIZE]; //UWB_LIST_SELF, UWB_LIST_NEIGHBOR, UWB_LIST_HIDDEN, UWB_LIST_INACTIVE
// uint8 uwbListType[UWB_LIST_SIZE]; //UWB_LIST_SELF, UWB_LIST_NEIGHBOR, UWB_LIST_HIDDEN, UWB_LIST_INACTIVE
uint8 uwbNumActive[UWB_LIST_SIZE]; //number of TAGs each tracked ANCHOR is actively ranging with. //TODO remove?
// uint8 uwbNumActive[UWB_LIST_SIZE]; //number of TAGs each tracked ANCHOR is actively ranging with. //TODO remove?
// keep track of when final messages so we can drop uwbs that we haven't communicated with in a while
uint32 lastCommTimeStamp[UWB_LIST_SIZE]; //TODO move into tdma_handler?
uint32 lastHiddenTimeStamp[UWB_LIST_SIZE];
uint32 lastTwiceHiddenTimeStamp[UWB_LIST_SIZE];
uint8 uwbTimeout[UWB_LIST_SIZE] ;
uint8 uwbTimeout[UWB_LIST_SIZE] ; //TODO remove and use list type instead
uint32 lastRangeTimeStamp[UWB_LIST_SIZE];
// uint32 lastRangeTimeStamp[UWB_LIST_SIZE];
uint8 time_till_next_reported[UWB_LIST_SIZE]; //used to keep track of whether we reported the RX_ACCEPT node. 0 if no, 1 if yes.
// uint8 time_till_next_reported[UWB_LIST_SIZE]; //used to keep track of whether we reported the RX_ACCEPT node. 0 if no, 1 if yes.
uint32 blink_start;
uint32 range_start;
......
......@@ -216,6 +216,7 @@ int instgetuwblistindex(instance_data_t *inst, uint8 *uwbAddr, uint8 addrByteSiz
char uwbChar[2];
memcpy(&uwbChar[0], &uwbAddr[0], 2);
//TODO remove the following!
bool match = FALSE;
char test_addr[2] = {0x95, 0x15};
if(memcmp(&uwbChar[0], &test_addr[0], 2) == 0)
......@@ -449,7 +450,8 @@ int instfindnumactiveneighbors(instance_data_t *inst)
for(int i=1; i<inst->uwbListLen; i++)// 0 reserved for self, cant be neighbor
{
if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
// if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
if(tdma_handler.uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR)
{
num++;
}
......@@ -469,8 +471,10 @@ int instfindnumactivehidden(instance_data_t *inst)
for(int i=1; i<inst->uwbListLen; i++)//0 reserved for self, cannot be hidden
{
if(inst->uwbListType[i] == UWB_LIST_HIDDEN)
// if(inst->uwbListType[i] == UWB_LIST_HIDDEN)
if(tdma_handler.uwbListTDMAInfo[i].connectionType == UWB_LIST_HIDDEN)
{
num++;
}
}
......@@ -496,12 +500,14 @@ void instclearuwbList(void)
for(int i=0; i<UWB_LIST_SIZE; i++)
{
instance_data[instance].lastCommTimeStamp[i] = 0;
instance_data[instance].lastRangeTimeStamp[i] = 0;
// instance_data[instance].lastRangeTimeStamp[i] = 0;
tdma_handler.uwbListTDMAInfo[i].lastRange = 0;
instance_data[instance].uwbTimeout[i] = 0;
instance_data[instance].time_till_next_reported[i] = 0;
// instance_data[instance].time_till_next_reported[i] = 0;
memcpy(&instance_data[instance].uwbList[i][0], &blank[0], 8);
instance_data[instance].uwbListType[i] = UWB_LIST_INACTIVE;
// instance_data[instance].uwbListType[i] = UWB_LIST_INACTIVE;
tdma_handler.uwbListTDMAInfo[i].connectionType = UWB_LIST_INACTIVE;
}
}
......@@ -1329,7 +1335,8 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
uwb_index = instgetuwblistindex(&instance_data[instance], &dw_event.msgu.frame[srcAddr_index], instance_data[instance].addrByteSize);
//TODO maybe do this somewhere else...
instance_data[instance].uwbListType[uwb_index] = UWB_LIST_NEIGHBOR;
// instance_data[instance].uwbListType[uwb_index] = UWB_LIST_NEIGHBOR;
tdma_handler.uwbListTDMAInfo[uwb_index].connectionType = UWB_LIST_NEIGHBOR;
instance_data[instance].lastCommTimeStamp[uwb_index] = time_now;
instance_data[instance].uwbTimeout[uwb_index] = 0;
......@@ -1839,13 +1846,13 @@ int instance_run(void)
uint32 time_now = portGetTickCnt();
uint32 delta_t = get_dt32(instance_data[instance].lastCommTimeStamp[i], time_now);
// if(instance_data[instance].lastCommTimeStamp[i] + UWB_COMM_TIMEOUT < portGetTickCnt()) //TODO handle number wrapping
if(delta_t > UWB_COMM_TIMEOUT) //TODO handle number wrapping
{
// if(instance_data[instance].uwbTimeout[i] == 0)
if(instance_data[instance].uwbListType[i] == UWB_LIST_NEIGHBOR) //what about hidden?
// if(instance_data[instance].uwbListType[i] == UWB_LIST_NEIGHBOR) //what about hidden?
if(tdma_handler.uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR) //what about hidden?
{
instance_data[instance].uwbListType[i] = UWB_LIST_INACTIVE; //TODO release TDMA slots as well
// instance_data[instance].uwbListType[i] = UWB_LIST_INACTIVE; //TODO release TDMA slots as well
tdma_handler.uwbListTDMAInfo[i].connectionType = UWB_LIST_INACTIVE; //TODO release TDMA slots as well
instance_data[instance].uwbTimeout[i] = 1;
//NEW
......
......@@ -28,7 +28,8 @@ static bool slot_transition(struct TDMAHandler *this)
//we have transitioned into the next slot.
//get the slot number and set the start time appropriately
uint64 timeSinceFrameStart64 = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
// uint64 timeSinceFrameStart64 = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
uint64 timeSinceFrameStart64 = get_dt64(this->uwbListTDMAInfo[0].frameStartTime, time_now_us);
uint64 frameDuration64 = this->slotDuration_us*this->uwbListTDMAInfo[0].framelength;
if(timeSinceFrameStart64 >= frameDuration64)
......@@ -48,14 +49,17 @@ static bool slot_transition(struct TDMAHandler *this)
while(timeSinceFrameStart64 >= frameDuration64)
{
this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], frameDuration64);
// this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], frameDuration64);
this->uwbListTDMAInfo[0].frameStartTime = timestamp_add64(this->uwbListTDMAInfo[0].frameStartTime, frameDuration64);
timeSinceFrameStart64 -= frameDuration64;
}
this->lastFST = this->uwbFrameStartTimes64[0];
// this->lastFST = this->uwbFrameStartTimes64[0];
this->lastFST = this->uwbListTDMAInfo[0].frameStartTime;
uint8 slot = timeSinceFrameStart64/(this->slotDuration_us); //integer division rounded down
this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)(this->slotDuration_us*slot);
// this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)(this->slotDuration_us*slot);
this->lastSlotStartTime64 = this->uwbListTDMAInfo[0].frameStartTime + (uint64)(this->slotDuration_us*slot);
// uint8 debug_msg[100];
......@@ -152,13 +156,16 @@ static void frame_sync(struct TDMAHandler *this, event_data_t *dw_event, uint8 f
uint64 txrx_delay = (uint64)(convertdevicetimetosec(tx_antenna_delay + rxfs_process_delay)*1000000.0) + inst->storePreLen_us;
uint64 hisTimeSinceFrameStart_us = timeSinceFrameStart_us + txrx_delay;
this->uwbFrameStartTimes64[srcIndex] = timestamp_subtract64(time_now_us, hisTimeSinceFrameStart_us); //TODO consider applying the diff!
// this->uwbFrameStartTimes64[srcIndex] = timestamp_subtract64(time_now_us, hisTimeSinceFrameStart_us); //TODO consider applying the diff!
this->uwbListTDMAInfo[srcIndex].frameStartTime = timestamp_subtract64(time_now_us, hisTimeSinceFrameStart_us); //TODO consider applying the diff!
if(mode == FS_ADOPT) //TODO this might not be right! incoming framelength not always the same as ours!
{
this->uwbFrameStartTimes64[0] = this->uwbFrameStartTimes64[srcIndex];
// this->uwbFrameStartTimes64[0] = this->uwbFrameStartTimes64[srcIndex];
this->uwbListTDMAInfo[0].frameStartTime = this->uwbListTDMAInfo[srcIndex].frameStartTime;
uint8 slot = hisTimeSinceFrameStart_us/this->slotDuration_us; //integer division rounded down
this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)((this->slotDuration_us)*slot);
// this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)((this->slotDuration_us)*slot);
this->lastSlotStartTime64 = this->uwbListTDMAInfo[0].frameStartTime + (uint64)((this->slotDuration_us)*slot);
}
else if(mode == FS_COLLECT)
{
......@@ -167,7 +174,8 @@ static void frame_sync(struct TDMAHandler *this, event_data_t *dw_event, uint8 f
else// if(mode == FS_AVERAGE || mode == FS_EVAL) //TODO consider using a weighted average. perhaps use threshholds to determine if instead we should just use the ADOPT logic
{
// uint64 myFramelengthDuration_us = this->uwbListTDMAInfo[0].framelength*this->slotDuration_us;
uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
// uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbListTDMAInfo[0].frameStartTime, time_now_us);
////OLD WAY
......@@ -300,7 +308,8 @@ static void frame_sync(struct TDMAHandler *this, event_data_t *dw_event, uint8 f
// send_usbmessage(&debug_msg[0], n);
// usb_run();
this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], diff_us/div);
// this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], diff_us/div);
this->uwbListTDMAInfo[0].frameStartTime = timestamp_add64(this->uwbListTDMAInfo[0].frameStartTime, diff_us/div);
this->lastSlotStartTime64 = timestamp_add64(this->lastSlotStartTime64, diff_us/div);
}
else
......@@ -309,7 +318,8 @@ static void frame_sync(struct TDMAHandler *this, event_data_t *dw_event, uint8 f
// int n = sprintf((char*)&debug_msg[0], "subtract %llu", diff_us);
// send_usbmessage(&debug_msg[0], n);
// usb_run();
this->uwbFrameStartTimes64[0] = timestamp_subtract64(this->uwbFrameStartTimes64[0], diff_us/div);
// this->uwbFrameStartTimes64[0] = timestamp_subtract64(this->uwbFrameStartTimes64[0], diff_us/div);
this->uwbListTDMAInfo[0].frameStartTime = timestamp_subtract64(this->uwbListTDMAInfo[0].frameStartTime, diff_us/div);
this->lastSlotStartTime64 = timestamp_subtract64(this->lastSlotStartTime64, diff_us/div);
}
......@@ -323,7 +333,8 @@ static bool tx_sync_msg(struct TDMAHandler *this)
{
instance_data_t *inst = instance_get_local_structure_ptr(0);
uint64 time_now_us = portGetTickCntMicro();
uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
// uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
uint64 myTimeSinceFrameStart_us = get_dt64(this->uwbListTDMAInfo[0].frameStartTime, time_now_us);
memcpy(&inst->sync_msg.messageData[SYNC_FRAMELENGTH], &this->uwbListTDMAInfo[0].framelength, sizeof(uint8));
memcpy(&inst->sync_msg.messageData[SYNC_TSFS], &myTimeSinceFrameStart_us, 6);
int psduLength = 0;
......@@ -667,9 +678,11 @@ static bool tx_select(struct TDMAHandler *this) //TODO handle unsuccessful add
uint32 timeSinceOldestRange = 0;
for(int i = 1; i < inst->uwbListLen; i++)//0 reserved for self
{
if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
// if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
if(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR)
{
uint32 timeSinceRange = get_dt32(inst->lastRangeTimeStamp[i], time_now);
// uint32 timeSinceRange = get_dt32(inst->lastRangeTimeStamp[i], time_now);
uint32 timeSinceRange = get_dt32(this->uwbListTDMAInfo[i].lastRange, time_now);
if(timeSinceRange > timeSinceOldestRange)
{
timeSinceOldestRange = timeSinceRange;
......@@ -842,7 +855,8 @@ static void populate_inf_msg(struct TDMAHandler *this, uint8 inf_msg_type)
//neighbor address, framelength, number of slots, and slot assignments
for(int i = 1; i < inst->uwbListLen; i++) //slot 0 reserved for self
{
if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
// if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR)
if(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR)
{
struct TDMAInfo *info = &this->uwbListTDMAInfo[i];
......@@ -870,7 +884,8 @@ static void populate_inf_msg(struct TDMAHandler *this, uint8 inf_msg_type)
//hidden address, framelength, number of slots, and slot assignments
for(int i = 1; i < inst->uwbListLen; i++) //slot 0 reserved for self
{
if(inst->uwbListType[i] == UWB_LIST_HIDDEN)
// if(inst->uwbListType[i] == UWB_LIST_HIDDEN)
if(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_HIDDEN)
{
struct TDMAInfo *info = &this->uwbListTDMAInfo[i];
......@@ -912,11 +927,13 @@ static void update_inf_tsfs(struct TDMAHandler *this)
instance_data_t *inst = instance_get_local_structure_ptr(0);
uint64 time_now_us = portGetTickCntMicro();
int msgDataIndex = TDMA_TSFS;
uint64 timeSinceFrameStart64 = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
// uint64 timeSinceFrameStart64 = get_dt64(this->uwbFrameStartTimes64[0], time_now_us);
uint64 timeSinceFrameStart64 = get_dt64(this->uwbListTDMAInfo[0].frameStartTime, time_now_us);
uint64 frameDuration = this->slotDuration_us*this->uwbListTDMAInfo[0].framelength;
while(timeSinceFrameStart64 > frameDuration)
{
this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], frameDuration);
// this->uwbFrameStartTimes64[0] = timestamp_add64(this->uwbFrameStartTimes64[0], frameDuration);
this->uwbListTDMAInfo[0].frameStartTime = timestamp_add64(this->uwbListTDMAInfo[0].frameStartTime, frameDuration);
timeSinceFrameStart64 -= frameDuration;
}
......@@ -995,7 +1012,8 @@ static bool process_inf_msg(struct TDMAHandler *this, uint8 *messageData, uint8
}
instance_data_t *inst = instance_get_local_structure_ptr(0);
inst->uwbListType[srcIndex] = UWB_LIST_NEIGHBOR;
// inst->uwbListType[srcIndex] = UWB_LIST_NEIGHBOR;
this->uwbListTDMAInfo[srcIndex].connectionType = UWB_LIST_NEIGHBOR;
uint8 numNeighbors;
uint8 numHidden;
......@@ -1090,9 +1108,11 @@ static bool process_inf_msg(struct TDMAHandler *this, uint8 *messageData, uint8
uint8 uwb_index = instgetuwblistindex(inst, &address[0], inst->addrByteSize);
if(uwb_index != 0)
{
if(inst->uwbListType[uwb_index] == UWB_LIST_INACTIVE || inst->uwbListType[uwb_index] == UWB_LIST_TWICE_HIDDEN)
// if(inst->uwbListType[uwb_index] == UWB_LIST_INACTIVE || inst->uwbListType[uwb_index] == UWB_LIST_TWICE_HIDDEN)
if(this->uwbListTDMAInfo[uwb_index].connectionType == UWB_LIST_INACTIVE || this->uwbListTDMAInfo[uwb_index].connectionType == UWB_LIST_TWICE_HIDDEN)
{
inst->uwbListType[uwb_index] = UWB_LIST_HIDDEN;
// inst->uwbListType[uwb_index] = UWB_LIST_HIDDEN;
this->uwbListTDMAInfo[uwb_index].connectionType = UWB_LIST_HIDDEN;
}
inst->lastHiddenTimeStamp[uwb_index] = time_now;
......@@ -1165,9 +1185,11 @@ static bool process_inf_msg(struct TDMAHandler *this, uint8 *messageData, uint8
uint8 uwb_index = instgetuwblistindex(inst, &address[0], inst->addrByteSize);
if(uwb_index != 0)//0 reserved for self
{
if(inst->uwbListType[uwb_index] == UWB_LIST_INACTIVE)
// if(inst->uwbListType[uwb_index] == UWB_LIST_INACTIVE)
if(this->uwbListTDMAInfo[uwb_index].connectionType == UWB_LIST_INACTIVE)
{
inst->uwbListType[uwb_index] = UWB_LIST_TWICE_HIDDEN;
// inst->uwbListType[uwb_index] = UWB_LIST_TWICE_HIDDEN;
this->uwbListTDMAInfo[uwb_index].connectionType = UWB_LIST_TWICE_HIDDEN;
}
inst->lastTwiceHiddenTimeStamp[uwb_index] = time_now;
......@@ -1240,10 +1262,14 @@ static bool process_inf_msg(struct TDMAHandler *this, uint8 *messageData, uint8
if((uwbListInMsg[i] == FALSE && uwbListInMsg[j] == TRUE) || (uwbListInMsg[i] == TRUE && uwbListInMsg[j] == FALSE))
{
if((inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_NEIGHBOR) ||
(inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_HIDDEN) ||
(inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_NEIGHBOR) ||
(inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_HIDDEN))
// if((inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_NEIGHBOR) ||
// (inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_HIDDEN) ||
// (inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_NEIGHBOR) ||
// (inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_HIDDEN))
if((this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[j].connectionType == UWB_LIST_NEIGHBOR) ||
(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[j].connectionType == UWB_LIST_HIDDEN) ||
(this->uwbListTDMAInfo[j].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR) ||
(this->uwbListTDMAInfo[j].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[i].connectionType == UWB_LIST_HIDDEN))
{
//TODO make sure this is okay. will i need to ensure the assignments from the message are maintained?
if(this->deconflict_uwb_pair(this, &this->uwbListTDMAInfo[i], &this->uwbListTDMAInfo[j]) == TRUE)
......@@ -2082,7 +2108,8 @@ static void build_new_network(struct TDMAHandler *this)
// this->lastSlotStartTime_stm32 = time_now;
//build the initial TDMA
this->uwbFrameStartTimes64[0] = timestamp_subtract64(time_now_us, this->slotDuration_us);
// this->uwbFrameStartTimes64[0] = timestamp_subtract64(time_now_us, this->slotDuration_us);
this->uwbListTDMAInfo[0].frameStartTime = timestamp_subtract64(time_now_us, this->slotDuration_us);
this->lastSlotStartTime64 = time_now_us;
......@@ -2106,17 +2133,23 @@ static bool deconflict_slot_assignments(struct TDMAHandler *this)
//first deconflict slots in neighbor, hidden, and twice hidden
for(int i = 1; i < inst->uwbListLen; i++)//0 reserved for self
{
if(inst->uwbListType[i] != UWB_LIST_INACTIVE)
// if(inst->uwbListType[i] != UWB_LIST_INACTIVE)
if(this->uwbListTDMAInfo[i].connectionType != UWB_LIST_INACTIVE)
{
for(int j = i+1; j < inst->uwbListLen; j++)
{
if(inst->uwbListType[j] != UWB_LIST_INACTIVE && j != i)
// if(inst->uwbListType[j] != UWB_LIST_INACTIVE && j != i)
if(this->uwbListTDMAInfo[j].connectionType != UWB_LIST_INACTIVE && j != i)
{
//first check if their list type requires deconflicting
if((inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_TWICE_HIDDEN) ||
(inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_TWICE_HIDDEN) ||
(inst->uwbListType[i] == UWB_LIST_TWICE_HIDDEN && inst->uwbListType[j] == UWB_LIST_TWICE_HIDDEN) ||
(inst->uwbListType[i] == UWB_LIST_HIDDEN && inst->uwbListType[j] == UWB_LIST_HIDDEN))
// if((inst->uwbListType[i] == UWB_LIST_NEIGHBOR && inst->uwbListType[j] == UWB_LIST_TWICE_HIDDEN) ||
// (inst->uwbListType[j] == UWB_LIST_NEIGHBOR && inst->uwbListType[i] == UWB_LIST_TWICE_HIDDEN) ||
// (inst->uwbListType[i] == UWB_LIST_TWICE_HIDDEN && inst->uwbListType[j] == UWB_LIST_TWICE_HIDDEN) ||
// (inst->uwbListType[i] == UWB_LIST_HIDDEN && inst->uwbListType[j] == UWB_LIST_HIDDEN))
if((this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[j].connectionType == UWB_LIST_TWICE_HIDDEN) ||
(this->uwbListTDMAInfo[j].connectionType == UWB_LIST_NEIGHBOR && this->uwbListTDMAInfo[i].connectionType == UWB_LIST_TWICE_HIDDEN) ||
(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_TWICE_HIDDEN && this->uwbListTDMAInfo[j].connectionType == UWB_LIST_TWICE_HIDDEN) ||
(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_HIDDEN && this->uwbListTDMAInfo[j].connectionType == UWB_LIST_HIDDEN))
{
continue;
}
......@@ -2146,7 +2179,8 @@ static bool deconflict_slot_assignments(struct TDMAHandler *this)
//next deconflict slots between self and neighbor, hidden, and twice hidden
for(int i = 1; i < inst->uwbListLen; i++)//0 reserved for self
{
if(inst->uwbListType[i] != UWB_LIST_INACTIVE)
// if(inst->uwbListType[i] != UWB_LIST_INACTIVE)
if(this->uwbListTDMAInfo[i].connectionType != UWB_LIST_INACTIVE)
{
if(this->deconflict_uwb_pair(this, &this->uwbListTDMAInfo[0], &this->uwbListTDMAInfo[i]))
{
......@@ -2420,9 +2454,12 @@ static bool self_conflict(struct TDMAHandler *this)
for(int b = 1; b < inst->uwbListLen; b++)
{
if(inst->uwbListType[b] == UWB_LIST_NEIGHBOR ||
inst->uwbListType[b] == UWB_LIST_HIDDEN ||
inst->uwbListType[b] == UWB_LIST_TWICE_HIDDEN)
// if(inst->uwbListType[b] == UWB_LIST_NEIGHBOR ||
// inst->uwbListType[b] == UWB_LIST_HIDDEN ||
// inst->uwbListType[b] == UWB_LIST_TWICE_HIDDEN)
if(this->uwbListTDMAInfo[b].connectionType == UWB_LIST_NEIGHBOR ||
this->uwbListTDMAInfo[b].connectionType == UWB_LIST_HIDDEN ||
this->uwbListTDMAInfo[b].connectionType == UWB_LIST_TWICE_HIDDEN)
{
struct TDMAInfo *info_b = &this->uwbListTDMAInfo[b];
......@@ -2646,14 +2683,16 @@ static void set_discovery_mode(struct TDMAHandler *this, DISCOVERY_MODE discover
for(int i=1; i < inst->uwbListLen; i++) //zero reserved for self
{
if(inst->uwbListType[i] != UWB_LIST_NEIGHBOR)
// if(inst->uwbListType[i] != UWB_LIST_NEIGHBOR)
if(this->uwbListTDMAInfo[i].connectionType != UWB_LIST_NEIGHBOR)
{
continue; //TODO consider a way to accoutn for hidden and twice hidden to determine which netowrk is larger
}
struct TDMAInfo *info_i = &this->uwbListTDMAInfo[i];
// uint64 framelengthDuration_us = info_i->framelength*this->slotDuration_us;
uint64 timeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[i], time_now_us);
// uint64 timeSinceFrameStart_us = get_dt64(this->uwbFrameStartTimes64[i], time_now_us);
uint64 timeSinceFrameStart_us = get_dt64(this->uwbListTDMAInfo[i].frameStartTime, time_now_us);
//if tsfs > framelengthDuration_us, reduce it by framelengthDuration_us
......@@ -2738,7 +2777,8 @@ static void set_discovery_mode(struct TDMAHandler *this, DISCOVERY_MODE discover
//reached the last listed sub_netowrk, list a new subnetwork.
sub_network_members[num_sub_networks] = 1;
sub_network_base_framelength[num_sub_networks] = this->uwbListTDMAInfo[i].framelength;
sub_network_tsfs[num_sub_networks] = get_dt64(this->uwbFrameStartTimes64[i], time_now_us);
// sub_network_tsfs[num_sub_networks] = get_dt64(this->uwbFrameStartTimes64[i], time_now_us);
sub_network_tsfs[num_sub_networks] = get_dt64(this->uwbListTDMAInfo[i].frameStartTime, time_now_us);
sub_network_membership[num_sub_networks] = num_sub_networks;
num_sub_networks++;
break;
......@@ -2780,10 +2820,12 @@ static void set_discovery_mode(struct TDMAHandler *this, DISCOVERY_MODE discover
for(int i = 1; i < inst->uwbListLen; i++)//0 reserved for self
{
if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR && sub_network_membership[i] == sub_network_selected)
// if(inst->uwbListType[i] == UWB_LIST_NEIGHBOR && sub_network_membership[i] == sub_network_selected)
if(this->uwbListTDMAInfo[i].connectionType == UWB_LIST_NEIGHBOR && sub_network_membership[i] == sub_network_selected)
{
neighborIndices[nidx] = i;
tnext[nidx] = this->uwbFrameStartTimes64[i];
// tnext[nidx] = this->uwbFrameStartTimes64[i];
tnext[nidx] = this->uwbListTDMAInfo[i].frameStartTime;
while(time_now_us > tnext[nidx]) //TODO handle number wrapping...
{
tnext[nidx] += this->uwbListTDMAInfo[i].framelength*slotDuration_us;
......@@ -2853,15 +2895,20 @@ static void set_discovery_mode(struct TDMAHandler *this, DISCOVERY_MODE discover
//back-track the frame start time so we can inform the need to rebase
//and keep in sync with the subnetwork we initially chose to sync with
this->uwbFrameStartTimes64[0] = latest_tnext;
// this->uwbFrameStartTimes64[0] = latest_tnext;
this->uwbListTDMAInfo[0].frameStartTime = latest_tnext;
//TODO handle number wrapping
uint64 myFrameDuration = this->uwbListTDMAInfo[0].framelength*this->slotDuration_us;
while(this->uwbFrameStartTimes64[0] > time_now_us)
// while(this->uwbFrameStartTimes64[0] > time_now_us)
while(this->uwbListTDMAInfo[0].frameStartTime > time_now_us)
{
this->uwbFrameStartTimes64[0] -= myFrameDuration;
// this->uwbFrameStartTimes64[0] -= myFrameDuration;
this->uwbListTDMAInfo[0].frameStartTime -= myFrameDuration;
}
uint8 slot = this->uwbFrameStartTimes64[0]/this->slotDuration_us; //integer division rounded down
this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)(this->slotDuration_us*slot);
// uint8 slot = this->uwbFrameStartTimes64[0]/this->slotDuration_us; //integer division rounded down
uint8 slot = this->uwbListTDMAInfo[0].frameStartTime/this->slotDuration_us; //integer division rounded down
// this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0] + (uint64)(this->slotDuration_us*slot);
this->lastSlotStartTime64 = this->uwbListTDMAInfo[0].frameStartTime + (uint64)(this->slotDuration_us*slot);
// this->lastSlotStartTime64 = this->uwbFrameStartTimes64[0];
......@@ -3078,9 +3125,12 @@ static struct TDMAHandler new(){
ret.uwbListTDMAInfo[i].framelength = (uint8)MIN_FRAMELENGTH;
ret.uwbListTDMAInfo[i].slots = NULL;
ret.uwbListTDMAInfo[i].slotsLength = 0;
ret.uwbListTDMAInfo[i].frameStartTime = time_now_us;
ret.uwbListTDMAInfo[i].connectionType = UWB_LIST_INACTIVE;
}
ret.uwbListTDMAInfo[0].connectionType = UWB_LIST_SELF;
ret.uwbFrameStartTimes64[0] = time_now_us;
// ret.uwbFrameStartTimes64[0] = time_now_us;
ret.lastFST = time_now_us;
ret.lastSlotStartTime64 = time_now_us;
ret.infSentThisSlot = FALSE;
......
......@@ -7,6 +7,12 @@
struct TDMAInfo
{
//lastCommNeighbor
//lastCommHidden
//lastComm2Hidden
uint64 frameStartTime;
uint32 lastRange;
uint8 connectionType; //UWB_LIST_SELF, UWB_LIST_NEIGHBOR, UWB_LIST_HIDDEN, UWB_LIST_INACTIVE
uint8 uwbIndex; //TODO remove if unused
uint8 framelength;
uint8 slotsLength;
......@@ -45,7 +51,7 @@ struct TDMAHandler
uint64 lastINFrx;
uint64 uwbFrameStartTimes64[UWB_LIST_SIZE];
// uint64 uwbFrameStartTimes64[UWB_LIST_SIZE];
uint64 lastFST;
uint64 lastSlotStartTime64;
uint32 slotDuration_ms; //TODO make variable in duration based on UWB_LIST_SIZE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment