From cc00bc472eb4dc4fedc2db12da8bdcdb8efffe0c Mon Sep 17 00:00:00 2001
From: David <stierint@hotmail.com>
Date: Tue, 4 Feb 2020 17:23:17 -0600
Subject: [PATCH] multi-tag multi-anchor now working

---
 DecaRanging.coproj                | 454 ++++++++++-----------
 src/application/dw_main.c         |  64 ++-
 src/application/instance.c        | 631 ++++++++++++++++++++++++------
 src/application/instance.h        |  40 +-
 src/application/instance_common.c | 487 ++++++++++++++++++++---
 src/decadriver/deca_device_api.h  |  10 +-
 6 files changed, 1276 insertions(+), 410 deletions(-)

diff --git a/DecaRanging.coproj b/DecaRanging.coproj
index c5d3ae4..93b3496 100644
--- a/DecaRanging.coproj
+++ b/DecaRanging.coproj
@@ -1,228 +1,228 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<Project version="2G - 1.7.5" name="DecaRanging">
-  <Target name="EVK1000" isCurrent="1">
-    <Device manufacturerId="9" manufacturerName="ST" chipId="334" chipName="STM32F105RC" boardId="" boardName=""/>
-    <BuildOption>
-      <Compile>
-        <Option name="OptimizationLevel" value="0"/>
-        <Option name="UseFPU" value="0"/>
-        <Option name="UserEditCompiler" value="-ffunction-sections; -fdata-sections; -c; -fmessage-length=0;"/>
-        <Includepaths>
-          <Includepath path="."/>
-          <Includepath path="Libraries/CMSIS/CM3/CoreSupport"/>
-          <Includepath path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x"/>
-          <Includepath path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup"/>
-          <Includepath path="src/application"/>
-          <Includepath path="src/compiler"/>
-          <Includepath path="src/decadriver"/>
-          <Includepath path="src/sys"/>
-          <Includepath path="src/usb"/>
-          <Includepath path="Libraries/STM32F10x_StdPeriph_Driver/inc"/>
-          <Includepath path="Libraries/STM32F10x_StdPeriph_Driver/src"/>
-          <Includepath path="Libraries/STM32_USB_Device_Library/Core/inc"/>
-          <Includepath path="Libraries/STM32_USB_OTG_Driver/inc"/>
-          <Includepath path="Libraries/STM32_USB_Device_Library/Class/cdc/inc"/>
-          <Includepath path="Libraries/STM32_USB_Device_Library/Class/msc/inc"/>
-          <Includepath path="src/platform"/>
-        </Includepaths>
-        <DefinedSymbols>
-          <Define name="STM32F105RC"/>
-          <Define name="STM32F10X_CL"/>
-          <Define name="USE_STDPERIPH_DRIVER"/>
-          <Define name="__ASSEMBLY__"/>
-        </DefinedSymbols>
-      </Compile>
-      <Link useDefault="0">
-        <Option name="DiscardUnusedSection" value="0"/>
-        <Option name="UserEditLinkder" value=""/>
-        <Option name="UseMemoryLayout" value="0"/>
-        <Option name="LTO" value="0"/>
-        <Option name="IsNewStartupCode" value="1"/>
-        <Option name="Library" value="Use base C Library"/>
-        <Option name="nostartfiles" value="0"/>
-        <Option name="UserEditLinker" value=""/>
-        <LinkedLibraries>
-          <Libset dir="" libs="rdimon"/>
-        </LinkedLibraries>
-        <MemoryAreas debugInFlashNotRAM="1">
-          <Memory name="IROM1" type="ReadOnly" size="0x00040000" startValue="0x08000000"/>
-          <Memory name="IRAM1" type="ReadWrite" size="0x00010000" startValue="0x20000000"/>
-          <Memory name="IROM2" type="ReadOnly" size="" startValue=""/>
-          <Memory name="IRAM2" type="ReadWrite" size="" startValue=""/>
-        </MemoryAreas>
-        <LocateLinkFile path="linkers/stm32_flash_256k_ram_64k.ld" type="0"/>
-      </Link>
-      <Output>
-        <Option name="OutputFileType" value="0"/>
-        <Option name="Path" value="./"/>
-        <Option name="Name" value="EVK1000"/>
-        <Option name="HEX" value="1"/>
-        <Option name="BIN" value="1"/>
-      </Output>
-      <User>
-        <UserRun name="Run#1" type="Before" checked="0" value=""/>
-        <UserRun name="Run#1" type="After" checked="0" value="arm-none-eabi-objdump -h -S &quot;${project.bin}/${output.name}.elf&quot; &gt; &quot;${project.bin}/${output.name}.lst&quot;"/>
-        <UserRun name="Run#2" type="After" checked="0" value="arm-none-eabi-size --format=berkeley &quot;${project.bin}/${output.name}.elf&quot;"/>
-      </User>
-    </BuildOption>
-    <DebugOption>
-      <Option name="org.coocox.codebugger.gdbjtag.core.adapter" value="ST-Link"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.debugMode" value="SWD"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.clockDiv" value="1M"/>
-      <Option name="org.coocox.codebugger.gdbjtag.corerunToMain" value="1"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.jlinkgdbserver" value=""/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.userDefineGDBScript" value=""/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.targetEndianess" value="0"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.jlinkResetMode" value="Type 0: Normal"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.resetMode" value="SYSRESETREQ"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.ifSemihost" value="0"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.ifCacheRom" value="1"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.ipAddress" value="127.0.0.1"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.portNumber" value="2009"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.autoDownload" value="1"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.verify" value="1"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.downloadFuction" value="Erase Effected"/>
-      <Option name="org.coocox.codebugger.gdbjtag.core.defaultAlgorithm" value="STM32F10x_CL_256.elf"/>
-    </DebugOption>
-    <ExcludeFile/>
-  </Target>
-  <Components path="./"/>
-  <Files>
-    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_ioreq.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_ioreq.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_usr.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_usr.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Core" path="" type="2"/>
-    <File name="src/usb/usbd_desc.c" path="src/usb/usbd_desc.c" type="1"/>
-    <File name="src" path="" type="2"/>
-    <File name="Libraries/STM32_USB_Device_Library/Class/cdc" path="" type="2"/>
-    <File name="Libraries/CMSIS" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dac.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dac.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd_int.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd_int.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Class/cdc/src" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_flash.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_flash.h" type="1"/>
-    <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="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"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c" type="1"/>
-    <File name="src/application/instance.c" path="src/application/instance.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c" type="1"/>
-    <File name="src/decadriver/deca_device_api.h" path="src/decadriver/deca_device_api.h" type="1"/>
-    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h" type="1"/>
-    <File name="src/compiler/compiler.h" path="src/compiler/compiler.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver" path="" type="2"/>
-    <File name="src/platform/deca_mutex.c" path="src/platform/deca_mutex.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c" type="1"/>
-    <File name="src/platform/port.h" path="src/platform/port.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dma.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dma.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rcc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rcc.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_sdio.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_sdio.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c" type="1"/>
-    <File name="src/platform/port.c" path="src/platform/port.c" type="1"/>
-    <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="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.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/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c" 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_fsmc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c" 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"/>
-    <File name="src/usb/deca_usb.c" path="src/usb/deca_usb.c" type="1"/>
-    <File name="src/platform/deca_range_tables.c" path="src/platform/deca_range_tables.c" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/src" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_pwr.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_pwr.c" type="1"/>
-    <File name="src/application/instance_common.c" path="src/application/instance_common.c" type="1"/>
-    <File name="src/decadriver/deca_params_init.c" path="src/decadriver/deca_params_init.c" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Core/inc" path="" type="2"/>
-    <File name="src/application" path="" type="2"/>
-    <File name="src/application/instance_calib.c" path="src/application/instance_calib.c" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_core.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_core.c" type="1"/>
-    <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/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="src/decadriver/deca_param_types.h" path="src/decadriver/deca_param_types.h" 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/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/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"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c" type="1"/>
-    <File name="src/platform/stm32f10x_it.h" path="src/platform/stm32f10x_it.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_can.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_can.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c" path="Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library" path="" type="2"/>
-    <File name="Libraries/STM32_USB_Device_Library/Class" path="" type="2"/>
-    <File name="Libraries/CMSIS/CM3/CoreSupport/core_cm3.c" path="Libraries/CMSIS/CM3/CoreSupport/core_cm3.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_cec.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_cec.c" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd.h" type="1"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc" path="" type="2"/>
-    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h" type="1"/>
-    <File name="Libraries/CMSIS/CM3/DeviceSupport" path="" type="2"/>
-    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dac.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dac.c" type="1"/>
-    <File name="Libraries/CMSIS/CM3/CoreSupport/core_cm3.h" path="Libraries/CMSIS/CM3/CoreSupport/core_cm3.h" type="1"/>
-    <File name="src/decadriver" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_usart.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_usart.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_tim.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_tim.h" type="1"/>
-    <File name="Libraries/STM32_USB_Device_Library/Class/cdc/inc" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/misc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/misc.h" type="1"/>
-    <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="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"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src" path="" type="2"/>
-    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h" path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h" type="1"/>
-    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST" path="" type="2"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c" type="1"/>
-    <File name="src/decadriver/deca_regs.h" path="src/decadriver/deca_regs.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h" type="1"/>
-    <File name="src/usb/usbd_usr.c" path="src/usb/usbd_usr.c" type="1"/>
-    <File name="src/application/instance.h" path="src/application/instance.h" type="1"/>
-    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_gpio.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_gpio.h" type="1"/>
-  </Files>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Project version="2G - 1.7.5" name="DecaRanging">
+  <Target name="EVK1000" isCurrent="1">
+    <Device manufacturerId="9" manufacturerName="ST" chipId="334" chipName="STM32F105RC" boardId="" boardName=""/>
+    <BuildOption>
+      <Compile>
+        <Option name="OptimizationLevel" value="0"/>
+        <Option name="UseFPU" value="0"/>
+        <Option name="UserEditCompiler" value="-ffunction-sections; -fdata-sections; -c; -fmessage-length=0;"/>
+        <Includepaths>
+          <Includepath path="."/>
+          <Includepath path="Libraries/CMSIS/CM3/CoreSupport"/>
+          <Includepath path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x"/>
+          <Includepath path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup"/>
+          <Includepath path="src/application"/>
+          <Includepath path="src/compiler"/>
+          <Includepath path="src/decadriver"/>
+          <Includepath path="src/sys"/>
+          <Includepath path="src/usb"/>
+          <Includepath path="Libraries/STM32F10x_StdPeriph_Driver/inc"/>
+          <Includepath path="Libraries/STM32F10x_StdPeriph_Driver/src"/>
+          <Includepath path="Libraries/STM32_USB_Device_Library/Core/inc"/>
+          <Includepath path="Libraries/STM32_USB_OTG_Driver/inc"/>
+          <Includepath path="Libraries/STM32_USB_Device_Library/Class/cdc/inc"/>
+          <Includepath path="Libraries/STM32_USB_Device_Library/Class/msc/inc"/>
+          <Includepath path="src/platform"/>
+        </Includepaths>
+        <DefinedSymbols>
+          <Define name="STM32F105RC"/>
+          <Define name="STM32F10X_CL"/>
+          <Define name="USE_STDPERIPH_DRIVER"/>
+          <Define name="__ASSEMBLY__"/>
+        </DefinedSymbols>
+      </Compile>
+      <Link useDefault="0">
+        <Option name="DiscardUnusedSection" value="0"/>
+        <Option name="UserEditLinkder" value=""/>
+        <Option name="UseMemoryLayout" value="0"/>
+        <Option name="LTO" value="0"/>
+        <Option name="IsNewStartupCode" value="1"/>
+        <Option name="Library" value="Use base C Library"/>
+        <Option name="nostartfiles" value="0"/>
+        <Option name="UserEditLinker" value=""/>
+        <LinkedLibraries>
+          <Libset dir="" libs="rdimon"/>
+        </LinkedLibraries>
+        <MemoryAreas debugInFlashNotRAM="1">
+          <Memory name="IROM1" type="ReadOnly" size="0x00040000" startValue="0x08000000"/>
+          <Memory name="IRAM1" type="ReadWrite" size="0x00010000" startValue="0x20000000"/>
+          <Memory name="IROM2" type="ReadOnly" size="" startValue=""/>
+          <Memory name="IRAM2" type="ReadWrite" size="" startValue=""/>
+        </MemoryAreas>
+        <LocateLinkFile path="linkers/stm32_flash_256k_ram_64k.ld" type="0"/>
+      </Link>
+      <Output>
+        <Option name="OutputFileType" value="0"/>
+        <Option name="Path" value="./"/>
+        <Option name="Name" value="EVK1000"/>
+        <Option name="HEX" value="1"/>
+        <Option name="BIN" value="1"/>
+      </Output>
+      <User>
+        <UserRun name="Run#1" type="Before" checked="0" value=""/>
+        <UserRun name="Run#1" type="After" checked="0" value="arm-none-eabi-objdump -h -S &quot;${project.bin}/${output.name}.elf&quot; &gt; &quot;${project.bin}/${output.name}.lst&quot;"/>
+        <UserRun name="Run#2" type="After" checked="0" value="arm-none-eabi-size --format=berkeley &quot;${project.bin}/${output.name}.elf&quot;"/>
+      </User>
+    </BuildOption>
+    <DebugOption>
+      <Option name="org.coocox.codebugger.gdbjtag.core.adapter" value="ST-Link"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.debugMode" value="SWD"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.clockDiv" value="1M"/>
+      <Option name="org.coocox.codebugger.gdbjtag.corerunToMain" value="1"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.jlinkgdbserver" value=""/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.userDefineGDBScript" value=""/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.targetEndianess" value="0"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.jlinkResetMode" value="Type 0: Normal"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.resetMode" value="SYSRESETREQ"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.ifSemihost" value="0"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.ifCacheRom" value="1"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.ipAddress" value="127.0.0.1"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.portNumber" value="2009"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.autoDownload" value="1"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.verify" value="1"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.downloadFuction" value="Erase Effected"/>
+      <Option name="org.coocox.codebugger.gdbjtag.core.defaultAlgorithm" value="STM32F10x_CL_256.elf"/>
+    </DebugOption>
+    <ExcludeFile/>
+  </Target>
+  <Components path="./"/>
+  <Files>
+    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_ioreq.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_ioreq.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_usr.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_usr.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Core" path="" type="2"/>
+    <File name="src/usb/usbd_desc.c" path="src/usb/usbd_desc.c" type="1"/>
+    <File name="src" path="" type="2"/>
+    <File name="Libraries/STM32_USB_Device_Library/Class/cdc" path="" type="2"/>
+    <File name="Libraries/CMSIS" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dac.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dac.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd_int.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd_int.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Class/cdc/src" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_flash.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_flash.h" type="1"/>
+    <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/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"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c" type="1"/>
+    <File name="src/application/instance.c" path="src/application/instance.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h" type="1"/>
+    <File name="src/decadriver/deca_device_api.h" path="src/decadriver/deca_device_api.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c" type="1"/>
+    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c" type="1"/>
+    <File name="src/compiler/compiler.h" path="src/compiler/compiler.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver" path="" type="2"/>
+    <File name="src/platform/deca_mutex.c" path="src/platform/deca_mutex.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c" type="1"/>
+    <File name="src/platform/port.h" path="src/platform/port.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dma.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dma.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rcc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rcc.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_sdio.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_sdio.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c" type="1"/>
+    <File name="src/platform/port.c" path="src/platform/port.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h" type="1"/>
+    <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/STM32F10x_StdPeriph_Driver/inc/stm32f10x_adc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_adc.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/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_fsmc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c" 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"/>
+    <File name="src/usb/deca_usb.c" path="src/usb/deca_usb.c" type="1"/>
+    <File name="src/platform/deca_range_tables.c" path="src/platform/deca_range_tables.c" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/src" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_pwr.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_pwr.c" type="1"/>
+    <File name="src/application/instance_common.c" path="src/application/instance_common.c" type="1"/>
+    <File name="src/decadriver/deca_params_init.c" path="src/decadriver/deca_params_init.c" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Core/inc" path="" type="2"/>
+    <File name="src/application" path="" type="2"/>
+    <File name="src/application/instance_calib.c" path="src/application/instance_calib.c" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_core.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_core.c" type="1"/>
+    <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/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="src/decadriver/deca_param_types.h" path="src/decadriver/deca_param_types.h" 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="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/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"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c" path="Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c" type="1"/>
+    <File name="src/platform/stm32f10x_it.h" path="src/platform/stm32f10x_it.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_can.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_can.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c" path="Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library" path="" type="2"/>
+    <File name="Libraries/STM32_USB_Device_Library/Class" path="" type="2"/>
+    <File name="Libraries/CMSIS/CM3/CoreSupport/core_cm3.c" path="Libraries/CMSIS/CM3/CoreSupport/core_cm3.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_cec.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_cec.c" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_hcd.h" type="1"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc" path="" type="2"/>
+    <File name="Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h" path="Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h" type="1"/>
+    <File name="Libraries/CMSIS/CM3/DeviceSupport" path="" type="2"/>
+    <File name="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" path="Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dac.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dac.c" type="1"/>
+    <File name="Libraries/CMSIS/CM3/CoreSupport/core_cm3.h" path="Libraries/CMSIS/CM3/CoreSupport/core_cm3.h" type="1"/>
+    <File name="src/decadriver" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_usart.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_usart.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_tim.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_tim.h" type="1"/>
+    <File name="Libraries/STM32_USB_Device_Library/Class/cdc/inc" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/misc.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/misc.h" type="1"/>
+    <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/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"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src" path="" type="2"/>
+    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h" path="Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h" type="1"/>
+    <File name="Libraries/CMSIS/CM3/DeviceSupport/ST" path="" type="2"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c" path="Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c" type="1"/>
+    <File name="src/decadriver/deca_regs.h" path="src/decadriver/deca_regs.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h" type="1"/>
+    <File name="src/usb/usbd_usr.c" path="src/usb/usbd_usr.c" type="1"/>
+    <File name="src/application/instance.h" path="src/application/instance.h" type="1"/>
+    <File name="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_gpio.h" path="Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_gpio.h" type="1"/>
+  </Files>
 </Project>
\ No newline at end of file
diff --git a/src/application/dw_main.c b/src/application/dw_main.c
index ef04600..e1305eb 100644
--- a/src/application/dw_main.c
+++ b/src/application/dw_main.c
@@ -361,7 +361,7 @@ int dw_main(void)
         // Do nothing in foreground -- allow USB application to run, I guess on the basis of USB interrupts?
         while (1)       // loop forever
         {
-            usb_run();
+            //usb_run();
         }
 #endif
         return 1;
@@ -458,8 +458,9 @@ int dw_main(void)
     // main loop
     while(1)
     {
+        
 		instance_data_t* inst = instance_get_local_structure_ptr(0);
-		canSleep = instance_run();
+		canSleep = instance_run(); //run the state machine!!!
 
         //if delayed TX scheduled but did not happen after expected time then it has failed... (has to be < slot period)
         //if anchor just go into RX and wait for next message from tags/anchors
@@ -521,14 +522,40 @@ int dw_main(void)
                 //n = sprintf((char*)&dataseq[0], "ia%04x t%04x %04x %04x %04x %04x %04x %02x %02x a", aaddr, taddr, rng, rng_raw, l, txa, rxa, txl, rxl);
             	//n = sprintf((char*)&dataseq[0], "ia%04x t%04x %08x %08x %04x %04x %04x %2.2f a", aaddr, taddr, rng, rng_raw, l, txa, rxa, instance_data[0].clockOffset);
             	n = sprintf((char*)&dataseq[0], "ia%04x t%04x %08x %08x %04x %04x %04x a", aaddr, taddr, rng, rng_raw, l, txa, rxa);
+                //n = sprintf((char*)&dataseq[0], "TEST");
             }
+
+            
+//            ranging = 0;
+//            resetinstanceanchorwaiting();
+//            dataseq[0] = 0x2 ;  //return cursor home
+//            writetoLCD( 1, 0,  dataseq);
+//
+//            memcpy(&dataseq[0], (const uint8 *) "     RESET      ", 16);
+//           writetoLCD( 40, 1, dataseq); //send some data
+//            memcpy(&dataseq[0], (const uint8 *) "     RANGING    ", 16);
+//            writetoLCD( 16, 1, dataseq); //send some data
+
+
 #ifdef USB_SUPPORT //this is set in the port.h file
             send_usbmessage(&dataseq[0], n);
+            // n = sprintf((char*)&dataseq[0], "This is a test");
+            // send_usbmessage(&dataseq[0], n);
 #endif
         }
 
-        if(ranging == 0)
+
+        if(ranging == 0) //discovery/initialization mode for anchor and tag
         {
+            
+            // dataseq[0] = 0x2 ;  //return cursor home
+            // writetoLCD( 1, 0,  dataseq);
+            // memcpy(&dataseq[0], (const uint8 *) "     RANGING    ", 16);
+            // writetoLCD( 40, 1, dataseq); //send some data
+            // memcpy(&dataseq[0], (const uint8 *) "      == 0      ", 16);
+            // writetoLCD( 16, 1, dataseq); //send some data
+            //Sleep(1000);
+
             if(instance_mode != ANCHOR)
             {
                 if(instancesleeping())
@@ -567,8 +594,27 @@ int dw_main(void)
             }
             else //if(instance_mode == ANCHOR)
             {
+                // dataseq[0] = 0x2 ;  //return cursor home
+                // writetoLCD( 1, 0,  dataseq);
+                // memcpy(&dataseq[0], (const uint8 *) "   AM AN        ", 16);
+                // writetoLCD( 40, 1, dataseq); //send some data
+                // memcpy(&dataseq[0], (const uint8 *) "    ANCHOR      ", 16);
+                // writetoLCD( 16, 1, dataseq); //send some data
+                //Sleep(1000);
+
                 if(instanceanchorwaiting())
                 {
+
+                    // dataseq[0] = 0x2 ;  //return cursor home
+                    // writetoLCD( 1, 0,  dataseq);
+                    // memcpy(&dataseq[0], (const uint8 *) " ANCHOR WAITING ", 16);
+                    // writetoLCD( 40, 1, dataseq); //send some data
+                    // memcpy(&dataseq[0], (const uint8 *) "      == 1      ", 16);
+                    // writetoLCD( 16, 1, dataseq); //send some data
+                    //Sleep(1000);
+
+
+
                     toggle+=2;
 
                     if(toggle > 300000)
@@ -591,21 +637,33 @@ int dw_main(void)
                             sprintf((char*)&dataseq[0], "%llX", instance_get_addr());
                             writetoLCD( 16, 1, dataseq); //send some data
                         }
+                    // Sleep(1000);
                     }
 
                 }
                 else if(instanceanchorwaiting() == 2)
                 {
+                    // dataseq[0] = 0x2 ;  //return cursor home
+                    // writetoLCD( 1, 0,  dataseq);
+                    // memcpy(&dataseq[0], (const uint8 *) " ANCHOR WAITING ", 16);
+                    // writetoLCD( 40, 1, dataseq); //send some data
+                    // memcpy(&dataseq[0], (const uint8 *) "      == 2      ", 16);
+                    // writetoLCD( 16, 1, dataseq); //send some data
+                    //Sleep(1000);
+
                     dataseq[0] = 0x2 ;  //return cursor home
                     writetoLCD( 1, 0,  dataseq);
                     memcpy(&dataseq[0], (const uint8 *) "    RANGING WITH", 16);
                     writetoLCD( 40, 1, dataseq); //send some data
                     sprintf((char*)&dataseq[0], "%llX", instance_get_tagaddr());
                     writetoLCD( 16, 1, dataseq); //send some data
+                    //Sleep(1000);
                 }
             }
         }
 #ifdef USB_SUPPORT //this is set in the port.h file
+        // int n = sprintf((char*)&dataseq[0], "Main Loop");
+        // send_usbmessage(&dataseq[0], n);
         usb_run();
 #endif
 
diff --git a/src/application/instance.c b/src/application/instance.c
index 302a291..46bafdd 100644
--- a/src/application/instance.c
+++ b/src/application/instance.c
@@ -16,10 +16,27 @@
 #include "deca_spi.h"
 #include "deca_regs.h"
 
-#include "lib.h"
 
+#include "lib.h"
 #include "instance.h"
 
+// #include "deca_usb.h"
+
+//NOTE: my added USB debug values/functions
+#define USB_DEBUG_BUFF_LEN (100)
+uint8 usbdebugdata[USB_DEBUG_BUFF_LEN]; //data to be sent over usb for debug purposes
+int usbdebugdata_size = 0;     
+uint8 usbdebugdataprev[USB_DEBUG_BUFF_LEN]; //previous message sent
+int usbdebugdataprev_size = 0;
+uint8 usbrxdebugdata[USB_DEBUG_BUFF_LEN];
+int usbrxdebugdata_size = 0;
+uint8 usbrxdebugdataprev[USB_DEBUG_BUFF_LEN];
+int usbrxdebugdataprev_size = 0;        
+uint8 usbtxdebugdata[USB_DEBUG_BUFF_LEN];
+int usbtxdebugdata_size = 0;
+uint8 usbtxdebugdataprev[USB_DEBUG_BUFF_LEN];
+int usbtxdebugdataprev_size = 0;        
+ 
 // -------------------------------------------------------------------------------------------------------------------
 
 // -------------------------------------------------------------------------------------------------------------------
@@ -43,16 +60,16 @@
 //
 void instanceconfigframeheader(instance_data_t *inst)
 {
-    inst->msg.panID[0] = (inst->panID) & 0xff;
-    inst->msg.panID[1] = inst->panID >> 8;
+    inst->msg[inst->tagToRangeWith].panID[0] = (inst->panID) & 0xff;
+    inst->msg[inst->tagToRangeWith].panID[1] = inst->panID >> 8;
 
     //set frame type (0-2), SEC (3), Pending (4), ACK (5), PanIDcomp(6)
-    inst->msg.frameCtrl[0] = 0x1 /*frame type 0x1 == data*/ | 0x40 /*PID comp*/;
+    inst->msg[inst->tagToRangeWith].frameCtrl[0] = 0x1 /*frame type 0x1 == data*/ | 0x40 /*PID comp*/;
 #if (USING_64BIT_ADDR==1)
     //source/dest addressing modes and frame version
-    inst->msg.frameCtrl[1] = 0xC /*dest extended address (64bits)*/ | 0xC0 /*src extended address (64bits)*/;
+    inst->msg[inst->tagToRangeWith].frameCtrl[1] = 0xC /*dest extended address (64bits)*/ | 0xC0 /*src extended address (64bits)*/;
 #else
-    inst->msg.frameCtrl[1] = 0x8 /*dest short address (16bits)*/ | 0x80 /*src short address (16bits)*/;
+    inst->msg[inst->tagToRangeWith].frameCtrl[1] = 0x8 /*dest short address (16bits)*/ | 0x80 /*src short address (16bits)*/;
 #endif
 }
 
@@ -95,6 +112,126 @@ int instancesendpacket(uint16 length, uint8 txmode, uint32 dtime)
 
 }
 
+//debug helper function to print the testAppState
+const char* get_inst_states_string(enum inst_states state)
+{
+    switch (state)
+    {
+        case TA_INIT : return "TA_INIT";
+        case TA_TXE_WAIT : return "TA_TXE_WAIT";       
+        case TA_TXPOLL_WAIT_SEND : return "TA_TXPOLL_WAIT_SEND";       
+        case TA_TXFINAL_WAIT_SEND : return "TA_TXFINAL_WAIT_SEND";  
+        case TA_TXRESPONSE_WAIT_SEND : return "TA_TXRESPONSE_WAIT_SEND";
+        case TA_TX_WAIT_CONF : return "TA_TX_WAIT_CONF";
+        case TA_RXE_WAIT : return "TA_RXE_WAIT";
+        case TA_RX_WAIT_DATA : return "TA_RX_WAIT_DATA";
+        case TA_SLEEP_DONE : return "TA_SLEEP_DONE";
+        case TA_TXBLINK_WAIT_SEND : return "TA_TXBLINK_WAIT_SEND";
+        case TA_TXRANGINGINIT_WAIT_SEND : return "TA_TXRANGINGINIT_WAIT_SEND";
+        case TA_TX_SELECT : return "TA_TX_SELECT";
+        default: return "NONE";
+    }
+}
+
+//debug helper function to print the mode
+const char* get_instanceModes_string(enum instanceModes mode)
+{
+    switch (mode)
+    {
+        case LISTENER : return "LISTENER";
+        case TAG : return "TAG";       
+        case ANCHOR : return "ANCHOR";       
+        case TAG_TDOA : return "TAG_TDOA";  
+        case NUM_MODES : return "NUM_MODES";
+        default: return "NONE";
+    }
+}
+
+char* get_msg_fcode_string(int fcode)
+{
+    if (fcode == (int)RTLS_DEMO_MSG_RNG_INIT)
+    {
+        return "RTLS_DEMO_MSG_RNG_INIT";
+    }
+    else if(fcode == (int)RTLS_DEMO_MSG_TAG_POLL)
+    {
+        return "RTLS_DEMO_MSG_TAG_POLL";
+    }
+    else if(fcode == (int)RTLS_DEMO_MSG_ANCH_RESP)
+    {
+        return "RTLS_DEMO_MSG_ANCH_RESP";
+    }
+    else if(fcode == (int)RTLS_DEMO_MSG_TAG_FINAL)
+    {
+        return "RTLS_DEMO_MSG_TAG_FINAL";
+    }
+    else
+    {
+        return "NONE";
+    }
+}
+
+void send_statetousb(instance_data_t *inst)
+{
+    // usbrxdebugdata[0] = 0x2 ;  //return cursor home
+    int usbdebugdata_size = sprintf((char*)&usbdebugdata[0], "%s , %s , %s , %s", get_inst_states_string(inst->testAppState), get_inst_states_string(inst->previousState), get_inst_states_string(inst->nextState), get_instanceModes_string(inst->mode));
+     
+    memcpy(usbdebugdata, usbdebugdata, usbdebugdata_size);
+    if (strncmp(usbdebugdataprev, usbdebugdata, usbdebugdata_size) != 0 || usbdebugdata_size != usbdebugdataprev_size)
+    {
+        
+        // send_usbmessage("start", 5);
+        // usb_run();
+        send_usbmessage(&usbdebugdata[0], usbdebugdata_size);
+        usb_run();
+        // send_usbmessage(&usbdebugdataprev[0], usbdebugdataprev_size);
+        // usb_run();
+
+        // usbrxdebugdataprev[0] = 0x2 ;  //return cursor home
+        usbdebugdataprev_size = usbdebugdata_size;
+        memcpy(usbdebugdataprev, usbdebugdata, usbdebugdata_size);
+    }
+}
+
+void send_rxmsgtousb(char *data)
+{
+    // usbrxdebugdata[0] = 0x2 ;  //return cursor home
+    int usbrxdebugdata_size = sprintf((char*)&usbrxdebugdata[0], "%s", data);
+     
+    memcpy(usbrxdebugdata, usbrxdebugdata, usbrxdebugdata_size);
+    if (strncmp(usbrxdebugdataprev, usbrxdebugdata, usbrxdebugdata_size) != 0 || usbrxdebugdata_size != usbrxdebugdataprev_size)
+    {
+        // n = sprintf((char*)&usbtmpmsg[0], "prev: %s curr: %s", (char*)&usbrxdebugdata, (char*)&usbrxdebugdataprev);
+        // send_usbmessage(&usbtmpmsg[0], n);
+
+        // send_usbmessage("start", 5);
+        // usb_run();
+        send_usbmessage(&usbrxdebugdata[0], usbrxdebugdata_size);
+        usb_run();
+        // send_usbmessage(&usbrxdebugdataprev[0], usbrxdebugdataprev_size);
+        // usb_run();
+
+        // usbrxdebugdataprev[0] = 0x2 ;  //return cursor home
+        usbrxdebugdataprev_size = usbrxdebugdata_size;
+        memcpy(usbrxdebugdataprev, usbrxdebugdata, usbrxdebugdata_size);
+    }
+}
+
+void send_txmsgtousb(char *data)
+{
+    int usbtxdebugdata_size = sprintf((char*)&usbtxdebugdata[0], "TX message: %s", data);
+     
+    // memcpy(usbtxdebugdata, usbtxdebugdata, usbtxdebugdata_size);
+    // if (strncmp(usbtxdebugdataprev, usbtxdebugdata, usbtxdebugdata_size) != 0 || usbtxdebugdata_size != usbtxdebugdataprev_size)
+    // {
+        send_usbmessage(&usbtxdebugdata[0], usbtxdebugdata_size);
+        usb_run();
+
+    //     usbtxdebugdataprev_size = usbtxdebugdata_size;
+    //     memcpy(usbtxdebugdataprev, usbtxdebugdata, usbtxdebugdata_size);
+    // }
+}
+
 // -------------------------------------------------------------------------------------------------------------------
 //
 // the main instance state machine (all the instance modes Tag, Anchor or Listener use the same statemachine....)
@@ -105,14 +242,29 @@ int testapprun(instance_data_t *inst, int message)
 {
     int done = INST_NOT_DONE_YET;
 
+    // uint8 debug_msg[100];
+    // int n = sprintf((char*)&debug_msg[0], "Test app run");
+    // send_usbmessage(&debug_msg[0], n);
+    // usb_run();
+
+    // uint8 debug_msg2[100];
+    // int n = sprintf((char*)&debug_msg2[0], "TTRW %i", inst->tagToRangeWith);
+    // send_usbmessage(&debug_msg2[0], n);
+    // usb_run();
+
     switch (inst->testAppState)
     {
         case TA_INIT :
+            // if (inst->mode == ANCHOR)
+            // {
+                send_statetousb(inst);
+            // }
             // printf("TA_INIT") ;
             switch (inst->mode)
             {
                 case TAG:
                 {
+                    Sleep(5000);
                     int mode = 0;
 
                     dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN); //allow data, ACK frames;
@@ -123,11 +275,14 @@ int testapprun(instance_data_t *inst, int message)
                     //the short address is assigned by the anchor
 #else
                     //set source address into the message structure
-                    memcpy(&inst->msg.sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_L);
+                    for(int i=0; i<TAG_LIST_SIZE; i++)
+                    {
+                        memcpy(&inst->msg[i].sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_L);
+                    }
 #endif
 
                     //change to next state - send a Poll message to 1st anchor in the list
-                    inst->mode = TAG_TDOA ;
+                    //inst->mode = TAG_TDOA ;
                     inst->testAppState = TA_TXBLINK_WAIT_SEND;
                     memcpy(inst->blinkmsg.tagID, inst->eui64, ADDR_BYTE_SIZE_L);
 
@@ -158,13 +313,19 @@ int testapprun(instance_data_t *inst, int message)
                         uint16 addr = inst->eui64[0] + (inst->eui64[1] << 8);
                         dwt_setaddress16(addr);
                         //set source address into the message structure
-                        memcpy(&inst->msg.sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_S);
+                        for(int i=0; i<TAG_LIST_SIZE; i++)
+                        {
+                            memcpy(&inst->msg[i].sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_S);
+                        }
                         //set source address into the message structure
                         memcpy(&inst->rng_initmsg.sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_S);
                     }
 #else
                     //set source address into the message structure
-                    memcpy(&inst->msg.sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_L);
+                    for(int i=0; i<TAG_LIST_SIZE; i++)
+                    {
+                        memcpy(&inst->msg[i].sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_L);
+                    }
                     //set source address into the message structure
                     memcpy(&inst->rng_initmsg.sourceAddr[0], inst->eui64, ADDR_BYTE_SIZE_L);
 #endif
@@ -196,8 +357,47 @@ int testapprun(instance_data_t *inst, int message)
             }
             break; // end case TA_INIT
 
+        case TA_TX_SELECT:
+            {
+            // uint8 debug_msg[100];
+            // int n = sprintf((char*)&debug_msg[0], "TA_TX_SELECT");
+            // send_usbmessage(&debug_msg[0], n);
+            // usb_run();
+            uint8 debug_msg[100];
+            int n = sprintf((char*)&debug_msg[0], "TA_TX_SELECT: inst->tagListLen: %i, inst->tagToRangeWith: %i", inst->tagListLen, inst->tagToRangeWith);
+            send_usbmessage(&debug_msg[0], n);
+            usb_run();
+            // select whether to blink or send out a range poll message.
+            // select a tag from the list if sending out a range poll message
+            if(inst->tagListLen == 0) //no known anchors yet, send out blink
+            {
+                inst->testAppState = TA_TXBLINK_WAIT_SEND;
+                inst->tagToRangeWith = 255;
+            }
+            else
+            {
+                //for now, blink after attempting to poll each tag in the list
+                if((inst->tagToRangeWith >= inst->tagListLen) || (inst->tagTimeout[inst->tagToRangeWith] == 1))
+                {
+                    inst->testAppState = TA_TXBLINK_WAIT_SEND;
+                    inst->tagToRangeWith = 255;
+                }
+                else
+                {
+                    // inst->tagToRangeWith = inst->tagToRangeWith + 1;
+                    inst->testAppState = TA_TXPOLL_WAIT_SEND;
+                }
+            }
+
+            send_statetousb(inst);
+            break; // end case TA_TX_SELECT
+            }
         case TA_SLEEP_DONE :
         {
+            // if (inst->mode == ANCHOR)
+            // {
+                send_statetousb(inst);
+            // }
             event_data_t* dw_event = instance_getevent(10); //clear the event from the queue
             // waiting for timout from application to wakup IC
             if (dw_event->type != DWT_SIG_RX_TIMEOUT)
@@ -235,10 +435,14 @@ int testapprun(instance_data_t *inst, int message)
             break;
 
         case TA_TXE_WAIT : //either go to sleep or proceed to TX a message
+            // if (inst->mode == ANCHOR)
+            // {
+                send_statetousb(inst);
+            // }
             // printf("TA_TXE_WAIT") ;
             //if we are scheduled to go to sleep before next sending then sleep first.
             if(((inst->nextState == TA_TXPOLL_WAIT_SEND)
-                || (inst->nextState == TA_TXBLINK_WAIT_SEND))
+                || (inst->nextState == TA_TXBLINK_WAIT_SEND) || (inst->nextState == TA_TX_SELECT)) //add TA_TX_SELECT???
                     && (inst->goToSleep)  //go to sleep before sending the next poll
                     )
             {
@@ -247,10 +451,10 @@ int testapprun(instance_data_t *inst, int message)
                 done = INST_DONE_WAIT_FOR_NEXT_EVENT_TO; //don't sleep here but kick off the TagTimeoutTimer (instancetimer)
                 inst->testAppState = TA_SLEEP_DONE;
 
-                if(inst->mode == TAG_TDOA) //once we start ranging we want to display the new range
-                {
-                    inst->canPrintInfo = 1;
-                }
+                // if(inst->mode == TAG_TDOA) //once we start ranging we want to display the new range
+                // {
+                inst->canPrintInfo = 1;
+                // }
 
 #if (DEEP_SLEEP == 1)
                 if (inst->sleepingEabled)
@@ -279,6 +483,12 @@ int testapprun(instance_data_t *inst, int message)
 
         case TA_TXBLINK_WAIT_SEND :
             {
+                // if (inst->mode == ANCHOR)
+                // {
+                    send_statetousb(inst);
+                // }
+                //send_txmsgtousb("BLINK");
+
                 int flength = (BLINK_FRAME_CRTL_AND_ADDRESS + FRAME_CRC);
 
                 //blink frames with IEEE EUI-64 tag ID
@@ -287,8 +497,7 @@ int testapprun(instance_data_t *inst, int message)
 
                 dwt_writetxdata(flength, (uint8 *)  (&inst->blinkmsg), 0) ; // write the frame data
                 dwt_writetxfctrl(flength, 0, 1);
-
-
+                
                 //using wait for response to do delayed receive
                 inst->wait4ack = DWT_RESPONSE_EXPECTED;
 
@@ -308,6 +517,14 @@ int testapprun(instance_data_t *inst, int message)
 
         case TA_TXRANGINGINIT_WAIT_SEND :
                 {
+                if (inst->mode == ANCHOR)
+                {
+                    send_statetousb(inst);
+                }
+                send_txmsgtousb("RTLS_DEMO_MSG_RNG_INIT");
+
+                // TODO should only send RTLS_DEMO_MSG_RNG_INIT if handshake not already complete 
+                
                 uint16 resp_dly_us, resp_dly;
 
                 int psduLength = RANGINGINIT_MSG_LEN;
@@ -351,6 +568,8 @@ int testapprun(instance_data_t *inst, int message)
 
                 dwt_writetxdata(psduLength, (uint8 *)  &inst->rng_initmsg, 0) ; // write the frame data
 
+
+
                 //anchor - we don't use timeout, just wait for next frame
                 if(instancesendpacket(psduLength, DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED, inst->delayedReplyTime))
                 {
@@ -367,19 +586,20 @@ int testapprun(instance_data_t *inst, int message)
 
                     //CONFIGURE FIXED PARTS OF RESPONSE MESSAGE FRAME (these won't change)
                     //program option octet and parameters (not used currently)
-                    inst->msg.messageData[RES_R1] = 0x2; // "activity"
-                    inst->msg.messageData[RES_R2] = 0x0; //
-                    inst->msg.messageData[RES_R3] = 0x0;
+                    inst->msg[inst->tagToRangeWith].messageData[RES_R1] = 0x2; // "activity"
+                    inst->msg[inst->tagToRangeWith].messageData[RES_R2] = 0x0; //
+                    inst->msg[inst->tagToRangeWith].messageData[RES_R3] = 0x0;
                     //set the destination address in the TWR response message
 #if 0
 #if (USING_64BIT_ADDR == 1)
-                    memcpy(&inst->msg.destAddr[0], &inst->rng_initmsg.destAddr[0], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
+                    memcpy(&inst->msg[inst->tagToRangeWith].destAddr[0], &inst->rng_initmsg.destAddr[0], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
 #else
-                    memcpy(&inst->msg.destAddr[0], &inst->tagShortAdd, ADDR_BYTE_SIZE_S); //remember who to send the reply to (set destination address)
+                    memcpy(&inst->msg[inst->tagToRangeWith].destAddr[0], &inst->tagShortAdd, ADDR_BYTE_SIZE_S); //remember who to send the reply to (set destination address)
 #endif
 #endif
 
-                    inst->msg.messageData[FCODE] = RTLS_DEMO_MSG_ANCH_RESP; //message function code (specifies if message is a poll, response or other...)
+                   
+                    inst->msg[inst->tagToRangeWith].messageData[FCODE] = RTLS_DEMO_MSG_ANCH_RESP; //message function code (specifies if message is a poll, response or other...)
 
                     instanceconfigframeheader(inst);
                     //inst->timeofTx = portGetTickCnt();
@@ -391,12 +611,14 @@ int testapprun(instance_data_t *inst, int message)
 
         case TA_TXPOLL_WAIT_SEND :
             {
+                send_statetousb(inst);
+                // send_txmsgtousb("RTLS_DEMO_MSG_TAG_POLL");
                 int psduLength = 0;
                 //NOTE the anchor address is set after receiving the ranging initialisation message
                 inst->goToSleep = 1; //go to Sleep after this poll
 
-                inst->msg.seqNum = inst->frameSN++;
-                inst->msg.messageData[FCODE] = RTLS_DEMO_MSG_TAG_POLL; //message function code (specifies if message is a poll, response or other...)
+                inst->msg[inst->tagToRangeWith].seqNum = inst->frameSN++;
+                inst->msg[inst->tagToRangeWith].messageData[FCODE] = RTLS_DEMO_MSG_TAG_POLL; //message function code (specifies if message is a poll, response or other...)
 
                 instanceconfigframeheader(inst);
 #if (USING_64BIT_ADDR==1)
@@ -409,7 +631,7 @@ int testapprun(instance_data_t *inst, int message)
                 dwt_setrxaftertxdelay(inst->txToRxDelayTag_sy);
                 dwt_setrxtimeout((uint16)inst->fwtoTime_sy);
 
-                dwt_writetxdata(psduLength, (uint8 *)  &inst->msg, 0) ; // write the frame data
+                dwt_writetxdata(psduLength, (uint8 *)  &inst->msg[inst->tagToRangeWith], 0) ; // write the frame data
 
                 //response is expected
                 inst->wait4ack = DWT_RESPONSE_EXPECTED;
@@ -426,6 +648,7 @@ int testapprun(instance_data_t *inst, int message)
 
         case TA_TXRESPONSE_WAIT_SEND : //the frame is loaded and sent from the RX callback
             {
+                send_statetousb(inst);
                //printf("TA_TXRESPONSE\n") ;
                 inst->testAppState = TA_TX_WAIT_CONF;                                               // wait confirmation
                 inst->previousState = TA_TXRESPONSE_WAIT_SEND ;
@@ -434,12 +657,14 @@ int testapprun(instance_data_t *inst, int message)
 
         case TA_TXFINAL_WAIT_SEND :
             {
+                send_statetousb(inst);
+                // send_txmsgtousb("RTLS_DEMO_MSG_TAG_FINAL");
                 int psduLength = 0;
                 // Embbed into Final message:40-bit respRxTime
                 // Write Response RX time field of Final message
-                memcpy(&(inst->msg.messageData[RRXT]), (uint8 *)&inst->anchorRespRxTime, 5);
+                memcpy(&(inst->msg[inst->tagToRangeWith].messageData[RRXT]), (uint8 *)&inst->anchorRespRxTime, 5);
 
-                inst->msg.messageData[FCODE] = RTLS_DEMO_MSG_TAG_FINAL; //message function code (specifies if message is a poll, response or other...)
+                inst->msg[inst->tagToRangeWith].messageData[FCODE] = RTLS_DEMO_MSG_TAG_FINAL; //message function code (specifies if message is a poll, response or other...)
 
                 instanceconfigframeheader(inst);
 #if (USING_64BIT_ADDR==1)
@@ -448,14 +673,14 @@ int testapprun(instance_data_t *inst, int message)
                 psduLength = TAG_FINAL_MSG_LEN + FRAME_CRTL_AND_ADDRESS_S + FRAME_CRC;
 #endif
 
-                dwt_writetxdata(psduLength, (uint8 *)  &inst->msg, 0) ; // write the frame data
+                dwt_writetxdata(psduLength, (uint8 *)  &inst->msg[inst->tagToRangeWith], 0) ; // write the frame data
 
                 if(instancesendpacket(psduLength, DWT_START_TX_DELAYED, inst->delayedReplyTime))
                 {
                     // initiate the re-transmission
                     inst->testAppState = TA_TXE_WAIT ;
                     inst->nextState = TA_TXPOLL_WAIT_SEND ;
-
+                    
                     inst->wait4ack = 0; //clear the flag as the TX has failed the TRX is off
                     inst->lateTX++;
 
@@ -463,12 +688,14 @@ int testapprun(instance_data_t *inst, int message)
                 }
                 else
                 {
+                    
                     inst->testAppState = TA_TX_WAIT_CONF;                                               // wait confirmation
                     inst->previousState = TA_TXFINAL_WAIT_SEND;
                     done = INST_DONE_WAIT_FOR_NEXT_EVENT; //will use RX FWTO to time out  (set below)
-                    //inst->responseTimeouts = 0; //reset response timeout count
+                    // inst->responseTimeouts = 0; //reset response timeout count
                     inst->timeofTx = portGetTickCnt();
                     inst->monitor = 1;
+                    send_txmsgtousb("RTLS_DEMO_MSG_TAG_FINAL");
                 }
             }
             break;
@@ -476,7 +703,11 @@ int testapprun(instance_data_t *inst, int message)
         case TA_TX_WAIT_CONF :
            //printf("TA_TX_WAIT_CONF %d m%d states %08x %08x\n", inst->previousState, message, dwt_read32bitreg(0x19), dwt_read32bitreg(0x0f)) ;
 
-                {
+            {
+                // if (inst->mode == ANCHOR)
+                // {
+                    send_statetousb(inst);
+                // }
                 event_data_t* dw_event = instance_getevent(11); //get and clear this event
 
                 //NOTE: Can get the ACK before the TX confirm event for the frame requesting the ACK
@@ -486,37 +717,46 @@ int testapprun(instance_data_t *inst, int message)
                 {
                     if(dw_event->type == DWT_SIG_RX_TIMEOUT) //got RX timeout - i.e. did not get the response (e.g. ACK)
                     {
-                        //printf("RX timeout in TA_TX_WAIT_CONF (%d)\n", inst->previousState);
+                        // printf("RX timeout in TA_TX_WAIT_CONF (%d)\n", inst->previousState);
                         //we need to wait for SIG_TX_DONE and then process the timeout and re-send the frame if needed
                         inst->gotTO = 1;
                     }
 
                     done = INST_DONE_WAIT_FOR_NEXT_EVENT;
-                        break;
+                    send_rxmsgtousb("RX process: (1st) got TO in TA_TX_WAIT_CONF");
+                    break;
 
                 }
 
                 done = INST_NOT_DONE_YET;
 
-                if(inst->previousState == TA_TXFINAL_WAIT_SEND)
+
+
+                if(inst->previousState == TA_TXFINAL_WAIT_SEND) //TAG operations
                 {
                     inst->testAppState = TA_TXE_WAIT ;
-                    inst->nextState = TA_TXPOLL_WAIT_SEND ;
+                    //inst->nextState = TA_TXPOLL_WAIT_SEND ; 
+                    //inst->nextState = TA_TXBLINK_WAIT_SEND ;
+                    inst->nextState = TA_TX_SELECT;
+                    uint8 idx = inst->tagToRangeWith + 1;
+                    inst->tagToRangeWith = instfindfirstawaketaginlist(inst, idx);
+                    
                     break;
                 }
                 else if (inst->gotTO) //timeout
                 {
                     //printf("got TO in TA_TX_WAIT_CONF\n");
+                    send_rxmsgtousb("RX process: (2nd) got TO in TA_TX_WAIT_CONF");
                     inst_processrxtimeout(inst);
                     inst->gotTO = 0;
                     inst->wait4ack = 0 ; //clear this
                     break;
                 }
-                else
+                else 
                 {
                     inst->txu.txTimeStamp = dw_event->timeStamp;
 
-                    if(inst->previousState == TA_TXPOLL_WAIT_SEND)
+                    if(inst->previousState == TA_TXPOLL_WAIT_SEND) //TAG operations
                     {
                         uint64 tagCalculatedFinalTxTime ;
                         // Embed into Final message: 40-bit pollTXTime,  40-bit respRxTime,  40-bit finalTxTime
@@ -532,9 +772,9 @@ int testapprun(instance_data_t *inst, int message)
                         tagCalculatedFinalTxTime &= MASK_40BIT;
 
                         // Write Calculated TX time field of Final message
-                        memcpy(&(inst->msg.messageData[FTXT]), (uint8 *)&tagCalculatedFinalTxTime, 5);
+                        memcpy(&(inst->msg[inst->tagToRangeWith].messageData[FTXT]), (uint8 *)&tagCalculatedFinalTxTime, 5);
                         // Write Poll TX time field of Final message
-                        memcpy(&(inst->msg.messageData[PTXT]), (uint8 *)&inst->txu.tagPollTxTime, 5);
+                        memcpy(&(inst->msg[inst->tagToRangeWith].messageData[PTXT]), (uint8 *)&inst->txu.tagPollTxTime, 5);
                     }
 
                     inst->testAppState = TA_RXE_WAIT ;                      // After sending, tag expects response/report, anchor waits to receive a final/new poll
@@ -550,7 +790,11 @@ int testapprun(instance_data_t *inst, int message)
         case TA_RXE_WAIT :
         // printf("TA_RXE_WAIT") ;
         {
-
+            if (inst->mode == ANCHOR)
+            {
+                send_statetousb(inst);
+            }
+            
             if(inst->wait4ack == 0) //if this is set the RX will turn on automatically after TX
             {
                 //turn RX on
@@ -573,45 +817,75 @@ int testapprun(instance_data_t *inst, int message)
             if(message == 0) break;
         }
 
-        case TA_RX_WAIT_DATA :                                                                     // Wait RX data
+        case TA_RX_WAIT_DATA :     
+            if (inst->mode == ANCHOR)
+            {
+                send_statetousb(inst);
+            }
+            // Wait RX data
            //printf("TA_RX_WAIT_DATA %d", message) ;
 
             switch (message)
             {
                 case DWT_SIG_RX_BLINK :
                 {
+                    send_rxmsgtousb("RX process: DWT_SIG_RX_BLINK ");
                     event_data_t* dw_event = instance_getevent(12); //get and clear this event
                     //printf("we got blink message from %08X\n", ( tagaddr& 0xFFFF));
                     if((inst->mode == LISTENER) || (inst->mode == ANCHOR))
                     {
                         inst->canPrintInfo = 1;
 
-                        //add this Tag to the list of Tags we know about
-                        instaddtagtolist(inst, &(dw_event->msgu.rxblinkmsg.tagID[0]));
-
-                        //initiate ranging message
-                        if(inst->tagToRangeWith < TAG_LIST_SIZE)
+                        // if(inst->tagToRangeWith == 255)
+                        // {
+                        //     instaddtagtolist(inst, &(dw_event->msgu.rxblinkmsg.tagID[0]));
+                        //     // int n = sprintf((char*)&debug_msg[0], "BLINK!!! tagToRangeWith after %i", inst->tagToRangeWith);
+                        //     // send_usbmessage(&debug_msg[0], n);
+                        //     // usb_run();
+                        //     //initiate ranging message this is a Blink from the Tag we would like to range to
+                        //     //NOTE not sure if this check is needed... but leave it for now
+                        //     if(memcmp(&inst->tagList[inst->tagToRangeWith][0],  &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS) == 0)
+                        //     {
+                        //         inst->tagShortAdd = (dwt_getpartid() & 0xFF);
+                        //         inst->tagShortAdd =  (inst->tagShortAdd << 8) + dw_event->msgu.rxblinkmsg.tagID[0] ; //TODO need to figure this out...
+
+                        //         //if using longer reply delay time (e.g. if interworking with a PC application)
+                        //         inst->delayedReplyTime = (dw_event->timeStamp + inst->rnginitReplyDelay) >> 8 ;  // time we should send the blink response
+                                
+                        //         //set destination address
+                        //         memcpy(&inst->rng_initmsg.destAddr[0], &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS); //remember who to send the reply to
+
+                        //         inst->testAppState = TA_TXE_WAIT;
+                        //         inst->nextState = TA_TXRANGINGINIT_WAIT_SEND ;
+
+                        //         break;
+                        //     }
+
+                        //     //else stay in RX
+                        // }
+
+                        uint8 debug_msg[100];
+                        int n = sprintf((char*)&debug_msg[0], "memcmp tagList & tagID: %i   %i", inst->tagList[inst->tagToRangeWith][0], dw_event->msgu.rxblinkmsg.tagID[0]);
+                        send_usbmessage(&debug_msg[0], n);
+                        usb_run();
+                        
+                        if(memcmp(&inst->tagList[inst->tagToRangeWith][0],  &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS) == 0)
                         {
-                            //initiate ranging message this is a Blink from the Tag we would like to range to
-                            if(memcmp(&inst->tagList[inst->tagToRangeWith][0],  &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS) == 0)
-                            {
-                                inst->tagShortAdd = (dwt_getpartid() & 0xFF);
-                                inst->tagShortAdd =  (inst->tagShortAdd << 8) + dw_event->msgu.rxblinkmsg.tagID[0] ;
+                            inst->tagShortAdd = (dwt_getpartid() & 0xFF);
+                            inst->tagShortAdd =  (inst->tagShortAdd << 8) + dw_event->msgu.rxblinkmsg.tagID[0] ; //TODO need to figure this out...
 
-                                //if using longer reply delay time (e.g. if interworking with a PC application)
-                                inst->delayedReplyTime = (dw_event->timeStamp + inst->rnginitReplyDelay) >> 8 ;  // time we should send the blink response
+                            //if using longer reply delay time (e.g. if interworking with a PC application)
+                            inst->delayedReplyTime = (dw_event->timeStamp + inst->rnginitReplyDelay) >> 8 ;  // time we should send the blink response
+                            
+                            //set destination address
+                            memcpy(&inst->rng_initmsg.destAddr[0], &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS); //remember who to send the reply to
 
-                                //set destination address
-                                memcpy(&inst->rng_initmsg.destAddr[0], &(dw_event->msgu.rxblinkmsg.tagID[0]), BLINK_FRAME_SOURCE_ADDRESS); //remember who to send the reply to
+                            inst->testAppState = TA_TXE_WAIT;
+                            inst->nextState = TA_TXRANGINGINIT_WAIT_SEND ;
 
-                                inst->testAppState = TA_TXE_WAIT;
-                                inst->nextState = TA_TXRANGINGINIT_WAIT_SEND ;
-
-                                break;
-                            }
-
-                            //else stay in RX
+                            break;
                         }
+                        //else stay in RX
                     }
                     //else //not initiating ranging - continue to receive
                     {
@@ -625,6 +899,7 @@ int testapprun(instance_data_t *inst, int message)
                 //if we have received a DWT_SIG_RX_OKAY event - this means that the message is IEEE data type - need to check frame control to know which addressing mode is used
                 case DWT_SIG_RX_OKAY :
                 {
+
                     event_data_t* dw_event = instance_getevent(15); //get and clear this event
                     uint8  srcAddr[8] = {0,0,0,0,0,0,0,0};
                     int fcode = 0;
@@ -660,6 +935,7 @@ int testapprun(instance_data_t *inst, int message)
                         if(inst->mode == ANCHOR)
                         {
 #if (USING_64BIT_ADDR==1)
+                            
                             if(memcmp(&inst->tagList[inst->tagToRangeWith][0], &srcAddr[0], BLINK_FRAME_SOURCE_ADDRESS) == 0) //if the Tag's address does not match (ignore the message)
 #else
                             //if using 16-bit addresses the ranging messages from tag are using the short address tag was given in the ranging init message
@@ -669,6 +945,23 @@ int testapprun(instance_data_t *inst, int message)
                             {
                                 fcode = fn_code;
                             }
+// #if (USING_64BIT_ADDR==1)
+//                             if(instchecktaginlist(&inst, &srcAddr[0]) != 255) //if the Tag's address does not match (ignore the message)
+// #else
+//                             //if using 16-bit addresses the ranging messages from tag are using the short address tag was given in the ranging init message
+//                             if(inst->tagShortAdd == (srcAddr[0] + (srcAddr[1] << 8)))
+// #endif
+//                             //only process messages from an associated tag
+//                             {
+//                                 fcode = fn_code;
+//                             }
+//                             else
+//                             {
+//                                 uint8 debug_msg[100];
+//                                 int n = sprintf((char*)&debug_msg[0], "Tag not in list, RX message not processed");
+//                                 send_usbmessage(&debug_msg[0], n);
+//                                 usb_run();
+//                             }
                         }
                         else // LISTENER or TAG
                         {
@@ -677,64 +970,128 @@ int testapprun(instance_data_t *inst, int message)
 
                         switch(fcode)
                         {
-                            case RTLS_DEMO_MSG_RNG_INIT:
+                            case RTLS_DEMO_MSG_RNG_INIT: //TAG operations
                             {
-                                if(inst->mode == TAG_TDOA) //only start ranging with someone if not ranging already
+                                send_rxmsgtousb("RX process: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_RNG_INIT");
+                                // send_rxmsgtousb("RX message fcode: RTLS_DEMO_MSG_RNG_INIT");
+                                
+                                //shouldn't use different tag modes. should only accept if not in list already
+                                //NOTE this is the poll message sent by the tag to initiate the handshake
+
+                                uint32 final_reply_delay_us;
+                                uint32 resp_dly[RESP_DLY_NB];
+                                int i;
+
+                                inst->testAppState = TA_TXE_WAIT;
+                                inst->nextState = TA_TXPOLL_WAIT_SEND ; // send next poll
+
+                                inst->tagShortAdd = messageData[RNG_INIT_TAG_SHORT_ADDR_LO]
+                                                    + (messageData[RNG_INIT_TAG_SHORT_ADDR_HI] << 8) ;
+
+                                // Get response delays from message and update internal timings accordingly
+                                resp_dly[RESP_DLY_ANC] =  messageData[RNG_INIT_ANC_RESP_DLY_LO]
+                                                            + (messageData[RNG_INIT_ANC_RESP_DLY_HI] << 8);
+                                resp_dly[RESP_DLY_TAG] =  messageData[RNG_INIT_TAG_RESP_DLY_LO]
+                                                            + (messageData[RNG_INIT_TAG_RESP_DLY_HI] << 8);
+                                for (i = 0; i < RESP_DLY_NB; i++)
                                 {
-                                    uint32 final_reply_delay_us;
-                                    uint32 resp_dly[RESP_DLY_NB];
-                                    int i;
-
-                                    inst->testAppState = TA_TXE_WAIT;
-                                    inst->nextState = TA_TXPOLL_WAIT_SEND ; // send next poll
-
-                                    inst->tagShortAdd = messageData[RNG_INIT_TAG_SHORT_ADDR_LO]
-                                                        + (messageData[RNG_INIT_TAG_SHORT_ADDR_HI] << 8) ;
-
-                                    // Get response delays from message and update internal timings accordingly
-                                    resp_dly[RESP_DLY_ANC] =  messageData[RNG_INIT_ANC_RESP_DLY_LO]
-                                                              + (messageData[RNG_INIT_ANC_RESP_DLY_HI] << 8);
-                                    resp_dly[RESP_DLY_TAG] =  messageData[RNG_INIT_TAG_RESP_DLY_LO]
-                                                              + (messageData[RNG_INIT_TAG_RESP_DLY_HI] << 8);
-                                    for (i = 0; i < RESP_DLY_NB; i++)
+                                    if (((resp_dly[i] & RESP_DLY_UNIT_MASK) >> RESP_DLY_UNIT_SHIFT) == RESP_DLY_UNIT_MS)
                                     {
-                                        if (((resp_dly[i] & RESP_DLY_UNIT_MASK) >> RESP_DLY_UNIT_SHIFT) == RESP_DLY_UNIT_MS)
-                                        {
-                                            // Remove unit bit and convert to microseconds.
-                                            resp_dly[i] &= ~RESP_DLY_UNIT_MASK;
-                                            resp_dly[i] *= 1000;
-                                        }
-                                    }
-                                    // Update delay between poll transmission and response reception.
-                                    // Use uint64 for resp_dly here to avoid overflows if it is more than 400 ms.
-                                    inst->txToRxDelayTag_sy = US_TO_SY_INT((uint64)resp_dly[RESP_DLY_ANC] - inst->frameLengths_us[POLL]) - RX_START_UP_SY;
-                                    // Update delay between poll transmission and final transmission.
-                                    final_reply_delay_us = resp_dly[RESP_DLY_ANC] + resp_dly[RESP_DLY_TAG];
-                                    inst->finalReplyDelay = convertmicrosectodevicetimeu(final_reply_delay_us);
-                                    inst->finalReplyDelay_ms = CEIL_DIV(final_reply_delay_us, 1000);
-                                    // If we are using long response delays, deactivate sleep.
-                                    if (resp_dly[RESP_DLY_ANC] >= LONG_RESP_DLY_LIMIT_US
-                                        || resp_dly[RESP_DLY_TAG] >= LONG_RESP_DLY_LIMIT_US)
-                                    {
-                                        inst->sleepingEabled = 0;
+                                        // Remove unit bit and convert to microseconds.
+                                        resp_dly[i] &= ~RESP_DLY_UNIT_MASK;
+                                        resp_dly[i] *= 1000;
                                     }
+                                }
+                                // Update delay between poll transmission and response reception.
+                                // Use uint64 for resp_dly here to avoid overflows if it is more than 400 ms.
+                                inst->txToRxDelayTag_sy = US_TO_SY_INT((uint64)resp_dly[RESP_DLY_ANC] - inst->frameLengths_us[POLL]) - RX_START_UP_SY;
+                                // Update delay between poll transmission and final transmission.
+                                final_reply_delay_us = resp_dly[RESP_DLY_ANC] + resp_dly[RESP_DLY_TAG];
+                                inst->finalReplyDelay = convertmicrosectodevicetimeu(final_reply_delay_us);
+                                inst->finalReplyDelay_ms = CEIL_DIV(final_reply_delay_us, 1000);
+                                // If we are using long response delays, deactivate sleep.
+                                if (resp_dly[RESP_DLY_ANC] >= LONG_RESP_DLY_LIMIT_US
+                                    || resp_dly[RESP_DLY_TAG] >= LONG_RESP_DLY_LIMIT_US)
+                                {
+                                    inst->sleepingEabled = 0;
+                                }
 
 #if (USING_64BIT_ADDR == 1)
-                                    memcpy(&inst->msg.destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //set the anchor address for the reply (set destination address)
+                                memcpy(&inst->msg[inst->tagToRangeWith].destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //set the anchor address for the reply (set destination address)
 #else
-                                    memcpy(&inst->msg.destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_S); //set anchor address for the reply (set destination address)
-                                    inst->msg.sourceAddr[0] =  messageData[RES_R1]; //set tag short address
-                                    inst->msg.sourceAddr[1] =  messageData[RES_R2];
-                                    dwt_setaddress16(inst->tagShortAdd);
+                                memcpy(&inst->msg[inst->tagToRangeWith].destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_S); //set anchor address for the reply (set destination address)
+                                inst->msg[inst->tagToRangeWith].sourceAddr[0] =  messageData[RES_R1]; //set tag short address
+                                inst->msg[inst->tagToRangeWith].sourceAddr[1] =  messageData[RES_R2];
+                                dwt_setaddress16(inst->tagShortAdd); //NOTE tagShortAdd might need to be reworked for TAG...
 #endif
 
-                                    memcpy(&inst->relpyAddress[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
-
-                                    inst->mode = TAG ;
-                                    //inst->responseTimeouts = 0; //reset timeout count
-                                    inst->goToSleep = 0; //don't go to sleep - start ranging instead and then sleep after 1 range is done or poll times out
-                                    inst->instanceTimerTimeSaved = inst->instanceTimerTime = portGetTickCnt(); //set timer base
-                                }
+                                //NOTE this might be a problem...
+                                memcpy(&inst->relpyAddress[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
+
+                                inst->mode = TAG ;
+                                //inst->responseTimeouts = 0; //reset timeout count
+                                inst->goToSleep = 0; //don't go to sleep - start ranging instead and then sleep after 1 range is done or poll times out
+                                inst->instanceTimerTimeSaved = inst->instanceTimerTime = portGetTickCnt(); //set timer base
+
+
+
+//                                 //NOTE this is the poll message sent by the tag to initiate the handshake
+//                                 if(inst->mode == TAG_TDOA) //only start ranging with someone if not ranging already
+//                                 {
+//                                     uint32 final_reply_delay_us;
+//                                     uint32 resp_dly[RESP_DLY_NB];
+//                                     int i;
+
+//                                     inst->testAppState = TA_TXE_WAIT;
+//                                     inst->nextState = TA_TXPOLL_WAIT_SEND ; // send next poll
+
+//                                     inst->tagShortAdd = messageData[RNG_INIT_TAG_SHORT_ADDR_LO]
+//                                                         + (messageData[RNG_INIT_TAG_SHORT_ADDR_HI] << 8) ;
+
+//                                     // Get response delays from message and update internal timings accordingly
+//                                     resp_dly[RESP_DLY_ANC] =  messageData[RNG_INIT_ANC_RESP_DLY_LO]
+//                                                               + (messageData[RNG_INIT_ANC_RESP_DLY_HI] << 8);
+//                                     resp_dly[RESP_DLY_TAG] =  messageData[RNG_INIT_TAG_RESP_DLY_LO]
+//                                                               + (messageData[RNG_INIT_TAG_RESP_DLY_HI] << 8);
+//                                     for (i = 0; i < RESP_DLY_NB; i++)
+//                                     {
+//                                         if (((resp_dly[i] & RESP_DLY_UNIT_MASK) >> RESP_DLY_UNIT_SHIFT) == RESP_DLY_UNIT_MS)
+//                                         {
+//                                             // Remove unit bit and convert to microseconds.
+//                                             resp_dly[i] &= ~RESP_DLY_UNIT_MASK;
+//                                             resp_dly[i] *= 1000;
+//                                         }
+//                                     }
+//                                     // Update delay between poll transmission and response reception.
+//                                     // Use uint64 for resp_dly here to avoid overflows if it is more than 400 ms.
+//                                     inst->txToRxDelayTag_sy = US_TO_SY_INT((uint64)resp_dly[RESP_DLY_ANC] - inst->frameLengths_us[POLL]) - RX_START_UP_SY;
+//                                     // Update delay between poll transmission and final transmission.
+//                                     final_reply_delay_us = resp_dly[RESP_DLY_ANC] + resp_dly[RESP_DLY_TAG];
+//                                     inst->finalReplyDelay = convertmicrosectodevicetimeu(final_reply_delay_us);
+//                                     inst->finalReplyDelay_ms = CEIL_DIV(final_reply_delay_us, 1000);
+//                                     // If we are using long response delays, deactivate sleep.
+//                                     if (resp_dly[RESP_DLY_ANC] >= LONG_RESP_DLY_LIMIT_US
+//                                         || resp_dly[RESP_DLY_TAG] >= LONG_RESP_DLY_LIMIT_US)
+//                                     {
+//                                         inst->sleepingEabled = 0;
+//                                     }
+
+// #if (USING_64BIT_ADDR == 1)
+//                                     memcpy(&inst->msg.destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //set the anchor address for the reply (set destination address)
+// #else
+//                                     memcpy(&inst->msg.destAddr[0], &srcAddr[0], ADDR_BYTE_SIZE_S); //set anchor address for the reply (set destination address)
+//                                     inst->msg.sourceAddr[0] =  messageData[RES_R1]; //set tag short address
+//                                     inst->msg.sourceAddr[1] =  messageData[RES_R2];
+//                                     dwt_setaddress16(inst->tagShortAdd);
+// #endif
+
+//                                     memcpy(&inst->relpyAddress[0], &srcAddr[0], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
+
+//                                     inst->mode = TAG ;
+//                                     //inst->responseTimeouts = 0; //reset timeout count
+//                                     inst->goToSleep = 0; //don't go to sleep - start ranging instead and then sleep after 1 range is done or poll times out
+//                                     inst->instanceTimerTimeSaved = inst->instanceTimerTime = portGetTickCnt(); //set timer base
+//                                 }
                                 //printf("GOT RTLS_DEMO_MSG_RNG_INIT - start ranging - \n");
                                 //else we ignore this message if already associated... (not TAG_TDOA)
                             }
@@ -742,6 +1099,8 @@ int testapprun(instance_data_t *inst, int message)
 
                             case RTLS_DEMO_MSG_TAG_POLL:
                             {
+                                // send_rxmsgtousb("RX process: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_TAG_POLL ");
+                                // send_rxmsgtousb("RX message fcode: RTLS_DEMO_MSG_TAG_POLL");
                                 if(inst->mode == LISTENER) //don't process any ranging messages when in Listener mode
                                 {
                                     //only enable receiver when not using double buffering
@@ -749,10 +1108,12 @@ int testapprun(instance_data_t *inst, int message)
                                     break;
                                 }
 
-                                if (!inst->frameFilteringEnabled)
+
+                                if (!inst->frameFilteringEnabled) //NOTE this might cause problems... might need to move somewhere else
                                 {
                                     // if we missed the ACK to the ranging init message we may not have turned frame filtering on
                                     dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN); //we are starting ranging - enable the filter....
+                                    
                                     inst->frameFilteringEnabled = 1 ;
                                 }
 
@@ -772,6 +1133,8 @@ int testapprun(instance_data_t *inst, int message)
 
                             case RTLS_DEMO_MSG_ANCH_RESP:
                             {
+                                // send_rxmsgtousb("RX process: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_ANCH_RESP ");
+                                // send_rxmsgtousb("RX message fcode: RTLS_DEMO_MSG_ANCH_RESP");
                                 if(inst->mode == LISTENER) //don't process any ranging messages when in Listener mode
                                 {
                                     inst->testAppState = TA_RXE_WAIT ;              // wait for next frame
@@ -795,6 +1158,7 @@ int testapprun(instance_data_t *inst, int message)
 
                             case RTLS_DEMO_MSG_TAG_FINAL:
                             {
+                                send_rxmsgtousb("RX process: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_TAG_FINAL ");
                                 int64 Rb, Da, Ra, Db ;
                                 uint64 tagFinalTxTime  = 0;
                                 uint64 tagFinalRxTime  = 0;
@@ -850,7 +1214,20 @@ int testapprun(instance_data_t *inst, int message)
                                 inst->newRangeAncAddress = inst->eui64[0] + ((uint16) inst->eui64[1] << 8);
                                 //inst->lastReportTime = time_ms;
 
-                                inst->testAppState = TA_RXE_WAIT ;              // wait for next frame
+                                // inst->testAppState = TA_RXE_WAIT ;              // wait for next frame
+                                // ranging complete with one of the tags, lets go back to listening for blinks/polls!
+                                
+                                //keep track of when the tag was last ranged to
+                                // inst->finalTimeStamp[inst->tagToRangeWith] = tagFinalRxTime;
+                                
+                                inst->testAppState = TA_RXE_WAIT ;
+                                inst->previousState = TA_INIT;
+                                inst->nextState = TA_INIT;
+                                inst->prevTagToRangeWith = inst->tagToRangeWith;
+                                inst->tagToRangeWith = 255;
+                                inst->frameFilteringEnabled = 0;
+                                dwt_enableframefilter(DWT_FF_NOTYPE_EN);
+                                
                                 dwt_setrxaftertxdelay(0);
 
                                 instancesetantennadelays(); //this will update the antenna delay if it has changed
@@ -861,9 +1238,14 @@ int testapprun(instance_data_t *inst, int message)
 
                             default:
                             {
+                                if(inst->mode == ANCHOR)
+                                {
+                                    send_rxmsgtousb("RX process: DWT_SIG_RX_OKAY-default ");
+                                }
+                                //send_rxmsgtousb("RX message fcode: default");
                                 inst->testAppState = TA_RXE_WAIT ;              // wait for next frame
                                 dwt_setrxaftertxdelay(0);
-
+                                
                             }
                             break;
                         } //end switch (fcode)
@@ -882,6 +1264,10 @@ int testapprun(instance_data_t *inst, int message)
                 break ; //end of DWT_SIG_RX_OKAY
 
                 case DWT_SIG_RX_TIMEOUT :
+                    if(inst->mode == ANCHOR)
+                    {
+                        send_rxmsgtousb("RX process: DWT_SIG_RX_TIMEOUT ");
+                    }
                     instance_getevent(17); //get and clear this event
                     //printf("PD_DATA_TIMEOUT %d\n", inst->previousState) ;
                     inst_processrxtimeout(inst);
@@ -892,14 +1278,23 @@ int testapprun(instance_data_t *inst, int message)
                 case 0:
                 default :
                 {
+                    if(inst->mode == ANCHOR)
+                    {   
+                        send_rxmsgtousb("RX process: default ");
+                    }
                     //if(DWT_SIG_TX_AA_DONE == message) printf("Got SIG_TX_AA_DONE in RX wait - ignore\n");
                     if(done == INST_NOT_DONE_YET) done = INST_DONE_WAIT_FOR_NEXT_EVENT;
+                    // inst->testAppState = TA_RXE_WAIT;
                 }
                 break;
 
             }
             break ; // end case TA_RX_WAIT_DATA
-            default:
+        default:
+            if (inst->mode == ANCHOR)
+            {
+                send_statetousb(inst);
+            }
                 //printf("\nERROR - invalid state %d - what is going on??\n", inst->testAppState) ;
             break;
     } // end switch on testAppState
@@ -934,7 +1329,9 @@ int instance_init_s(int mode)
 
     dwt_setcallbacks(instance_txcallback, instance_rxgoodcallback, instance_rxtimeoutcallback, instance_rxerrorcallback);
 
-    inst->anchorListIndex = 0 ;
+    //inst->anchorListIndex = 0 ;
+    inst->tagToRangeWith = 255;
+    inst->prevTagToRangeWith = 255;
 
     return 0 ;
 }
diff --git a/src/application/instance.h b/src/application/instance.h
index 0574209..47c71cb 100644
--- a/src/application/instance.h
+++ b/src/application/instance.h
@@ -21,6 +21,9 @@ extern "C" {
 #include "deca_types.h"
 #include "deca_device_api.h"
 
+
+
+
 /******************************************************************************************************************
 ********************* NOTES on Decaranging EVK1000 application features/options ***********************************************************
 *******************************************************************************************************************/
@@ -131,11 +134,12 @@ enum
 #define BLINK_FRAME_CRTL_AND_ADDRESS    (BLINK_FRAME_SOURCE_ADDRESS + BLINK_FRAME_CTRLP) //10 bytes
 #define BLINK_FRAME_LEN_BYTES           (BLINK_FRAME_CRTL_AND_ADDRESS + BLINK_FRAME_CRC)
 
-#define TAG_LIST_SIZE				(1)	//anchor will range with 1st Tag it gets blink from
+#define TAG_LIST_SIZE				    (10)	//anchor will range with 1st Tag it gets blink from
+#define TAG_COMM_TIMEOUT                3000    //ms
 
-#define BLINK_SLEEP_DELAY					1000 //ms
-#define POLL_SLEEP_DELAY					500 //ms
-//#define POLL_SLEEP_DELAY					50 //ms	//NOTE 200 gives 5 Hz range period
+#define BLINK_SLEEP_DELAY					1000    //ms
+#define POLL_SLEEP_DELAY					500     //ms
+//#define POLL_SLEEP_DELAY					50      //ms	//NOTE 200 gives 5 Hz range period
 
 
 #define IMMEDIATE_RESPONSE (1)
@@ -243,7 +247,7 @@ typedef enum instanceModes{LISTENER, TAG, ANCHOR, TAG_TDOA, NUM_MODES} INST_MODE
 
 typedef enum inst_states
 {
-    TA_INIT, //0
+    TA_INIT,                    //0
 
     TA_TXE_WAIT,                //1
     TA_TXPOLL_WAIT_SEND,        //2
@@ -256,7 +260,8 @@ typedef enum inst_states
 
     TA_SLEEP_DONE,              //9
     TA_TXBLINK_WAIT_SEND,       //10
-    TA_TXRANGINGINIT_WAIT_SEND  //11
+    TA_TXRANGINGINIT_WAIT_SEND, //11
+    TA_TX_SELECT                //12
 } INST_STATES;
 
 
@@ -419,10 +424,10 @@ typedef struct
 	//message structures used for transmitted messages
 #if (USING_64BIT_ADDR == 1)
 	srd_msg_dlsl rng_initmsg ;	// ranging init message (destination long, source long)
-    srd_msg_dlsl msg ;			// simple 802.15.4 frame structure (used for tx message) - using long addresses
+    srd_msg_dlsl msg[TAG_LIST_SIZE] ; // simple 802.15.4 frame structure (used for tx message) - using long addresses
 #else
 	srd_msg_dlss rng_initmsg ;  // ranging init message (destination long, source short)
-    srd_msg_dsss msg ;			// simple 802.15.4 frame structure (used for tx message) - using short addresses
+    srd_msg_dsss msg[TAG_LIST_SIZE] ; // simple 802.15.4 frame structure (used for tx message) - using short addresses
 #endif
 	iso_IEEE_EUI64_blink_msg blinkmsg ; // frame structure (used for tx blink message)
 
@@ -454,6 +459,8 @@ typedef struct
 
 
     //diagnostic counters/data, results and logging
+    
+
     int32 tof32 ;
     int64 tof ;
     double clockOffset ;
@@ -483,8 +490,12 @@ typedef struct
 
 	uint8 tagToRangeWith;	//it is the index of the tagList array which contains the address of the Tag we are ranging with
     uint8 tagListLen ;
-    uint8 anchorListIndex ;
+    uint8 prevTagToRangeWith ;
 	uint8 tagList[TAG_LIST_SIZE][8];
+    
+    // keep track of when final messages so we can drop tags that we havent communicated with in a while
+    uint32 lastCommTimeStamp[TAG_LIST_SIZE] ;
+    uint8 tagTimeout[TAG_LIST_SIZE] ;    
 
 
 	//event queue - used to store DW1000 events as they are processed by the dw_isr/callback functions
@@ -510,7 +521,9 @@ int reportTOF(instance_data_t *inst);
 void instanceclearcounts(void) ;
 void instcleartaglist(void);
 void instsettagtorangewith(int tagID);
-int instaddtagtolist(instance_data_t *inst, uint8 *tagAddr);
+int instaddwaketagilist(instance_data_t *inst, uint8 *tagAddr);
+int instcheckawaketaginlist(instance_data_t *inst, uint8 *tagAddr);
+int instfindfirstawaketaginlist(instance_data_t *inst, uint8 startindex);
 
 void instance_readaccumulatordata(void);
 //-------------------------------------------------------------------------------------------------------------
@@ -607,6 +620,13 @@ int instance_starttxtest(int framePeriod);
 
 instance_data_t* instance_get_local_structure_ptr(unsigned int x);
 
+
+void send_statetousb(instance_data_t *inst);
+void send_rxmsgtousb(char *data);
+void send_txmsgtousb(char *data);
+char* get_msg_fcode_string(int fcode);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/application/instance_common.c b/src/application/instance_common.c
index 3bf6bac..70daa09 100644
--- a/src/application/instance_common.c
+++ b/src/application/instance_common.c
@@ -194,8 +194,9 @@ int reportTOF(instance_data_t *inst)
 // function to select the destination address (e.g. the address of the next anchor to poll)
 //
 // -------------------------------------------------------------------------------------------------------------------
-//
-int instaddtagtolist(instance_data_t *inst, uint8 *tagAddr)
+// return 1 if tag added to list or already in list but woke up from timeout status 
+// return 0 if tag not added list or woke up from timeout status
+int instaddwaketagilist(instance_data_t *inst, uint8 *tagAddr)
 {
     uint8 i;
     uint8 blank[8] = {0, 0, 0, 0, 0, 0, 0, 0};
@@ -209,18 +210,93 @@ int instaddtagtolist(instance_data_t *inst, uint8 *tagAddr)
             {
                 memcpy(&inst->tagList[i][0], &tagAddr[0], 8) ;
                 inst->tagListLen = i + 1 ;
-                break;
+				inst->tagToRangeWith = i;
+				inst->tagTimeout[i] = 0;
+				return 1;
+                // break;
             }
         }
         else
         {
-            break; //we already have this Tag in the list
+			if(inst->tagTimeout[i])
+			{
+				//tag has timed out, wake it up
+				inst->tagToRangeWith = i;
+				inst->tagTimeout[i] = 0;
+				return 1;
+			}
+			else
+			{
+				//we already have this Tag in the list and it has not timed out
+				break; 
+			}
         }
     }
 
     return 0;
 }
 
+// -------------------------------------------------------------------------------------------------------------------
+//
+// function to check if a tag is already in our list and not in a timeout status
+//
+// -------------------------------------------------------------------------------------------------------------------
+// return index if tag in list and not timed out
+// return 255 if tag not in list or is but has timed out
+int instcheckawaketaginlist(instance_data_t *inst, uint8 *tagAddr)
+{
+    uint8 i;
+    uint8 blank[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+
+    //add the new Tag to the list, if not already there and there is space
+    for(i=0; i<TAG_LIST_SIZE; i++)
+    {
+        if(memcmp(&inst->tagList[i][0], &tagAddr[0], 8) == 0)
+        {
+			if(inst->tagTimeout[i])
+			{
+				//tag in list, but timed out 
+				break;	
+			}
+			else
+			{
+				return i; //we already have this Tag in the list
+			}
+        }
+        else
+        {
+			if(memcmp(&inst->tagList[i][0], &blank[0], 8) == 0) //blank entry
+            {
+                break;
+            }
+        }
+    }
+
+    return 255;
+}
+
+// -------------------------------------------------------------------------------------------------------------------
+//
+// function to find the first tag in our list that is not in a timeout status, starting with the given index
+//
+// -------------------------------------------------------------------------------------------------------------------
+// return index for first tag in list that is not timed out
+// return 255 if all tags in list (from the starting index) are timed out
+int instfindfirstawaketaginlist(instance_data_t *inst, uint8 startindex)
+{
+    uint8 i;
+    
+    for(i=startindex; i<inst->tagListLen; i++)
+    {
+		if(!inst->tagTimeout[i])
+		{
+			return i;
+		}
+    }
+
+    return 255;
+}
+
 
 // -------------------------------------------------------------------------------------------------------------------
 #if (NUM_INST != 1)
@@ -233,7 +309,14 @@ void instcleartaglist(void)
     uint8 blank[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 
     instance_data[instance].tagListLen = 0 ;
-    instance_data[instance].tagToRangeWith = 0;
+    instance_data[instance].tagToRangeWith = 255;
+	instance_data[instance].prevTagToRangeWith = 255;
+	for(int i=0; i<TAG_LIST_SIZE; i++)
+	{
+		instance_data[instance].lastCommTimeStamp[i] = 0;
+		instance_data[instance].tagTimeout[i] = 0;
+	}
+	
 
     memcpy(&instance_data[instance].tagList[0][0], &blank[0], 8);
 }
@@ -272,6 +355,12 @@ int instanceanchorwaiting(void)
 	return instance_data[0].canPrintInfo;
 }
 
+//NOTE quick hack by me
+void resetinstanceanchorwaiting(void)
+{
+	return instance_data[0].canPrintInfo;
+}
+
 int instancesleeping(void)
 {
 	if(instance_data[0].canPrintInfo == 1)
@@ -663,6 +752,12 @@ double instance_get_adist(void) //get average range
 
 void inst_processrxtimeout(instance_data_t *inst)
 {
+	send_statetousb(inst);
+	uint8 debug_msg[100];
+	int n = sprintf((char*)&debug_msg[0], "inst_processrxtimeout(), tagToRangeWith: %i, taglistlen: %i", inst->tagToRangeWith, inst->tagListLen);
+	send_usbmessage(&debug_msg[0], n);
+	usb_run();
+	
     if(inst->mode == ANCHOR) //we did not receive the final/ACK - wait for next poll
     {
 		//only enable receiver when not using double buffering
@@ -672,17 +767,39 @@ void inst_processrxtimeout(instance_data_t *inst)
 	else //if(inst->mode == TAG)
     {
 		// initiate the re-transmission of the poll that was not responded to
-		inst->testAppState = TA_TXE_WAIT ;
-
-		if(inst->mode == TAG)
+		inst->testAppState = TA_TX_SELECT ;
+		if(inst->previousState == TA_TXBLINK_WAIT_SEND)
 		{
-			inst->nextState = TA_TXPOLL_WAIT_SEND ;
+			inst->tagToRangeWith = instfindfirstawaketaginlist(inst, 0);
+			// inst->tagToRangeWith = 0;
 		}
-		else //TAG_TDOA
+		else if(inst->previousState == TA_TXPOLL_WAIT_SEND)
 		{
-			inst->nextState = TA_TXBLINK_WAIT_SEND ;
+			uint8 idx = inst->tagToRangeWith + 1;
+			inst->tagToRangeWith = instfindfirstawaketaginlist(inst, idx);
+			// inst->tagToRangeWith = inst->tagToRangeWith + 1;
 		}
 
+
+		// inst->testAppState = TA_TXE_WAIT ;
+
+		// if(inst->previousState == TA_TXBLINK_WAIT_SEND)
+		// {
+		// 	inst->nextState = TA_TXBLINK_WAIT_SEND ;
+		// }
+		// else
+		// {
+		// 	inst->nextState = TA_TXPOLL_WAIT_SEND ;
+		// }
+		// if(inst->mode == TAG)
+		// {
+		// 	inst->nextState = TA_TXPOLL_WAIT_SEND ;
+		// }
+		// else //TAG_TDOA
+		// {
+		// 	inst->nextState = TA_TXBLINK_WAIT_SEND ;
+		// }
+
     }
 
     //timeout - disable the radio (if using SW timeout the rx will not be off)
@@ -735,7 +852,8 @@ void instance_rxerrorcallback(const dwt_cb_data_t *rxd)
 	event_data_t dw_event;
 	//re-enable the receiver
 	//for ranging application rx error frame is same as TO - as we are not going to get the expected frame
-	if((instance_data[instance].mode == TAG) || (instance_data[instance].mode == TAG_TDOA))
+	// if((instance_data[instance].mode == TAG) || (instance_data[instance].mode == TAG_TDOA))
+	if(instance_data[instance].mode == TAG)
 	{
 		dw_event.type = DWT_SIG_RX_TIMEOUT;
 		dw_event.typeSave = 0x40 | DWT_SIG_RX_TIMEOUT;
@@ -752,6 +870,11 @@ void instance_rxerrorcallback(const dwt_cb_data_t *rxd)
 
 void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 {
+	uint8 debug_msg[100];
+    // int n = sprintf((char*)&debug_msg[0], "RX CALLBACK");
+    // send_usbmessage(&debug_msg[0], n);
+	// usb_run();
+
 	int instance = 0;
 	uint8 rxTimeStamp[5]  = {0, 0, 0, 0, 0};
 	uint8 srcAddr_index = 0;
@@ -773,6 +896,9 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 			if(rxd->datalength == 12)
 			{
 				rxd_event = DWT_SIG_RX_BLINK;
+				int n = sprintf((char*)&debug_msg[0], "RX CALLBACK: DWT_SIG_RX_BLINK");
+				send_usbmessage(&debug_msg[0], n);
+				usb_run();
 			}
 			else
 				rxd_event = SIG_RX_UNKNOWN;
@@ -842,16 +968,123 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 	//TWR - here we check if we need to respond to a TWR Poll or Response Messages
 	//----------------------------------------------------------------------------------------------
 
-	//Process good frames
-	if(rxd_event == DWT_SIG_RX_OKAY)
+	
+	//TODO need some way to drop tags from list after a certain period of time
+
+	int tag_index = 255;
+	if(rxd_event == DWT_SIG_RX_BLINK)
+	{
+		int n = sprintf((char*)&debug_msg[0], "RX CALLBACK RECEIVED: BLINK");
+		send_usbmessage(&debug_msg[0], n);
+		usb_run();
+
+		tag_index = instcheckawaketaginlist(&instance_data[instance], &dw_event.msgu.rxblinkmsg.tagID[0]);
+	}
+	else
 	{
-		//check if this is a TWR message (and also which one)
-		if(instance_data[instance].tagListLen > 0)
+		int n = sprintf((char*)&debug_msg[0], "RX CALLBACK RECEIVED: DWT_SIG_RX_OKAY-%s", get_msg_fcode_string(dw_event.msgu.frame[fcode_index]));
+		send_usbmessage(&debug_msg[0], n);
+		usb_run();
+
+		tag_index = instcheckawaketaginlist(&instance_data[instance], &dw_event.msgu.frame[srcAddr_index]);
+	}
+	// instcheckawaketaginlist(&instance_data[instance], &dw_event.msgu.frame[srcAddr_index]);
+	// int n = sprintf((char*)&debug_msg[0], "RX callback: tag_index: %i, tagToRangeWith: %i", tag_index, instance_data[instance].tagToRangeWith);
+    // send_usbmessage(&debug_msg[0], n);
+	// usb_run();
+
+	// select a tag to range with if certain messages are received when not currently ranging with another tag
+	if (instance_data[instance].tagToRangeWith == 255)
+	{
+		// if(instance_data[instance].mode == ANCHOR)
+		// {
+		// 	if(rxd_event == DWT_SIG_RX_BLINK)
+		// 	{
+
+		// 	}
+		// 	else if(dw_event.msgu.frame[fcode_index] == RTLS_DEMO_MSG_TAG_POLL)
+		// 	{
+
+		// 	}
+		// }
+		// else if(instance_data[instance].mode == TAG)
+		// {
+		// 	if(dw_event.msgu.frame[fcode_index] == RTLS_DEMO_MSG_RNG_INIT)
+		// 	{
+		// 		if(instaddwaketagilist(&instance_data[instance], &dw_event.msgu.frame[srcAddr_index]))
+		// 		{
+		// 			tag_index = instance_data[instance].tagToRangeWith;
+		// 		}
+		// 		else
+		// 		{
+		// 			tag_index = 255;
+		// 			instance_data[instance].tagToRangeWith == 255;
+		// 		}
+		// 	}
+		// }
+		
+
+		if(tag_index == 255) //tag not yet in list, or timed out
+		{
+			if(dw_event.msgu.frame[fcode_index] == RTLS_DEMO_MSG_RNG_INIT && instance_data[instance].mode == TAG)
+			{	
+				//only process range init from anchors not already in our list, or those that have timed out
+				if(instaddwaketagilist(&instance_data[instance], &dw_event.msgu.frame[srcAddr_index]))
+				{
+					tag_index = instance_data[instance].tagToRangeWith;
+				}
+				else
+				{
+					tag_index = 255;
+					instance_data[instance].tagToRangeWith == 255;
+				}
+			}
+			else if(rxd_event == DWT_SIG_RX_BLINK && instance_data[instance].mode == ANCHOR)
+			{
+				//only process blinks from tags not already in our list, or those that have timed out
+				if(instaddwaketagilist(&instance_data[instance], &dw_event.msgu.rxblinkmsg.tagID[0]))
+				{
+					tag_index = instance_data[instance].tagToRangeWith;
+				}
+				else
+				{
+					tag_index = 255;
+					instance_data[instance].tagToRangeWith == 255;
+				}
+			}
+		}
+		else //tag_index != 255 tag already in list and not timed out
 		{
-			switch(dw_event.msgu.frame[fcode_index])
+			if (dw_event.msgu.frame[fcode_index] == RTLS_DEMO_MSG_TAG_POLL && instance_data[instance].mode == ANCHOR) 
 			{
+				instance_data[instance].tagToRangeWith = tag_index; 
+			}	
+		}
+	}
+	
+	int n = sprintf((char*)&debug_msg[0], "RX callback: tag_index: %i, tagToRangeWith: %i", tag_index, instance_data[instance].tagToRangeWith);
+    send_usbmessage(&debug_msg[0], n);
+	usb_run();
+
+	
+	
 
-				case RTLS_DEMO_MSG_TAG_POLL:
+	int event_placed = 0; 
+	if(tag_index != 255 && instance_data[instance].tagToRangeWith == tag_index)
+	{
+		//update the timestamp for the most recent communication
+		instance_data[instance].lastCommTimeStamp[tag_index] = portGetTickCnt();
+		
+		if(rxd_event == DWT_SIG_RX_OKAY)
+		{
+			// int n = sprintf((char*)&debug_msg[0], "RX CALLBACK ACCEPTED: DWT_SIG_RX_OKAY-%s", get_msg_fcode_string(dw_event.msgu.frame[fcode_index]));
+			// send_usbmessage(&debug_msg[0], n);
+			// usb_run();
+
+			if(instance_data[instance].tagListLen > 0) //NOTE shouldn't need this check if here.
+			{	
+				//process RTLS_DEMO_MSG_TAG_POLL immediately.
+				if(dw_event.msgu.frame[fcode_index] == RTLS_DEMO_MSG_TAG_POLL)
 				{
 					uint16 frameLength = 0;
 
@@ -865,17 +1098,18 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 
 #if (USING_64BIT_ADDR == 1)
 					frameLength = ANCH_RESPONSE_MSG_LEN + FRAME_CRTL_AND_ADDRESS_L + FRAME_CRC;
-					memcpy(&instance_data[instance].msg.destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
+					memcpy(&instance_data[instance].msg[tag_index].destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
 #else
 					frameLength = ANCH_RESPONSE_MSG_LEN + FRAME_CRTL_AND_ADDRESS_S + FRAME_CRC;
-					memcpy(&instance_data[instance].msg.destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_S); //remember who to send the reply to (set destination address)
+					memcpy(&instance_data[instance].msg[tag_index].destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_S); //remember who to send the reply to (set destination address)
 #endif
 					// Write calculated TOF into response message
-					memcpy(&(instance_data[instance].msg.messageData[TOFR]), &instance_data[instance].tof, 5);
+					memcpy(&(instance_data[instance].msg[tag_index].messageData[TOFR]), &instance_data[instance].tof, 5);
 
 					instance_data[instance].tof = 0; //clear ToF ..
 
-					instance_data[instance].msg.seqNum = instance_data[instance].frameSN++;
+
+					instance_data[instance].msg[tag_index].seqNum = instance_data[instance].frameSN++;
 
 					//set the delayed rx on time (the final message will be sent after this delay)
 					dwt_setrxaftertxdelay((uint32)instance_data[instance].txToRxDelayAnc_sy);  //units are 1.0256us - wait for wait4respTIM before RX on (delay RX)
@@ -884,7 +1118,12 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 					instance_data[instance].wait4ack = DWT_RESPONSE_EXPECTED;
 
 					dwt_writetxfctrl(frameLength, 0, 1);
-					dwt_writetxdata(frameLength, (uint8 *)  &instance_data[instance].msg, 0) ;	// write the frame data
+					dwt_writetxdata(frameLength, (uint8 *)  &instance_data[instance].msg[tag_index], 0) ;	// write the frame data
+
+					//report out which message is being sent!
+					// send_rxmsgtousb("RX message: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_TAG_POLL ");
+					send_txmsgtousb(get_msg_fcode_string((int)instance_data[instance].msg[tag_index].messageData[FCODE]));
+					
 
 #if (IMMEDIATE_RESPONSE == 1)
 					dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);
@@ -903,36 +1142,149 @@ void instance_rxgoodcallback(const dwt_cb_data_t *rxd)
 						dw_event.typePend = DWT_SIG_TX_PENDING ; // exit this interrupt and notify the application/instance that TX is in progress.
 					}
 				}
-				break;
-
-				case RTLS_DEMO_MSG_ANCH_RESP:
-				default: //process rx frame in the application state machine
-				break;
 			}
-		}
 
-		instance_putevent(dw_event);
+			instance_putevent(dw_event);
+			event_placed = 1;
 
 #if (DEEP_SLEEP == 1)
-		if (instance_data[instance].sleepingEabled)
-			instance_data[instance].rxmsgcount++;
+			if (instance_data[instance].sleepingEabled)
+				instance_data[instance].rxmsgcount++;
 #endif
-	}
-	else if (rxd_event == DWT_SIG_RX_BLINK)
-	{
-		instance_putevent(dw_event);
+		}
+		else if (rxd_event == DWT_SIG_RX_BLINK)
+		{
+			int n = sprintf((char*)&debug_msg[0], "RX CALLBACK ACCEPTED: BLINK");
+			send_usbmessage(&debug_msg[0], n);
+			usb_run();
+			instance_putevent(dw_event);
+			event_placed = 1;
 
 #if (DEEP_SLEEP == 1)
-		if (instance_data[instance].sleepingEabled)
-			instance_data[instance].rxmsgcount++;
+			if (instance_data[instance].sleepingEabled)
+				instance_data[instance].rxmsgcount++;
 #endif
+		}
 	}
-	else
-	//if (rxd_event == SIG_RX_UNKNOWN) //need to re-enable the rx
+
+	//NOTE maybe don't want to do this. maybe just process actual error signals... or dont process errors at all.
+	//treat as error
+	if(!event_placed)
 	{
-		instance_rxerrorcallback(rxd);
+		// instance_rxerrorcallback(rxd);
+		instancerxon(&instance_data[instance], 0, 0); //immediate enable 
 	}
 
+	
+// 	//Process good frames
+// 	// only process DWT_SIG_RX_OKAY events for the selected tag in our list
+// 	if(rxd_event == DWT_SIG_RX_OKAY & tag_index != 255 & instance_data[instance].tagToRangeWith == tag_index)
+// 	// if(rxd_event == DWT_SIG_RX_OKAY)
+// 	{
+// 		int n = sprintf((char*)&debug_msg[0], "RX CALLBACK: DWT_SIG_RX_OKAY-%s", get_msg_fcode_string(dw_event.msgu.frame[fcode_index]));
+// 		send_usbmessage(&debug_msg[0], n);
+// 		usb_run();
+
+// 		//check if this is a TWR message (and also which one)
+// 		if(instance_data[instance].tagListLen > 0)
+// 		{
+// 			switch(dw_event.msgu.frame[fcode_index])
+// 			{
+
+// 				case RTLS_DEMO_MSG_TAG_POLL:
+// 				{
+// 					// if(tag_index != 255 & tag_index == instance_data[instance].tagToRangeWith)
+// 					// {
+// 						uint16 frameLength = 0;
+
+// 						instance_data[instance].tagPollRxTime = dw_event.timeStamp ; //Poll's Rx time
+
+// #if (IMMEDIATE_RESPONSE == 0)
+// 						instance_data[instance].delayedReplyTime = (instance_data[instance].tagPollRxTime + instance_data[instance].responseReplyDelay) >> 8 ;  // time we should send the response
+// #else
+// 						instance_data[instance].delayedReplyTime = 0;
+// #endif
+
+// #if (USING_64BIT_ADDR == 1)
+// 						frameLength = ANCH_RESPONSE_MSG_LEN + FRAME_CRTL_AND_ADDRESS_L + FRAME_CRC;
+// 						memcpy(&instance_data[instance].msg.destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_L); //remember who to send the reply to (set destination address)
+// #else
+// 						frameLength = ANCH_RESPONSE_MSG_LEN + FRAME_CRTL_AND_ADDRESS_S + FRAME_CRC;
+// 						memcpy(&instance_data[instance].msg.destAddr[0], &dw_event.msgu.frame[srcAddr_index], ADDR_BYTE_SIZE_S); //remember who to send the reply to (set destination address)
+// #endif
+// 						// Write calculated TOF into response message
+// 						memcpy(&(instance_data[instance].msg.messageData[TOFR]), &instance_data[instance].tof, 5);
+
+// 						instance_data[instance].tof = 0; //clear ToF ..
+
+// 						instance_data[instance].msg.seqNum = instance_data[instance].frameSN++;
+
+// 						//set the delayed rx on time (the final message will be sent after this delay)
+// 						dwt_setrxaftertxdelay((uint32)instance_data[instance].txToRxDelayAnc_sy);  //units are 1.0256us - wait for wait4respTIM before RX on (delay RX)
+
+// 						//response is expected
+// 						instance_data[instance].wait4ack = DWT_RESPONSE_EXPECTED;
+
+// 						dwt_writetxfctrl(frameLength, 0, 1);
+// 						dwt_writetxdata(frameLength, (uint8 *)  &instance_data[instance].msg, 0) ;	// write the frame data
+
+// 						//report out which message is being sent!
+// 						send_rxmsgtousb("RX message: DWT_SIG_RX_OKAY-RTLS_DEMO_MSG_TAG_POLL ");
+// 						send_txmsgtousb(get_msg_fcode_string((int)instance_data[instance].msg.messageData[FCODE]));
+						
+
+
+// #if (IMMEDIATE_RESPONSE == 1)
+// 						dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);
+// #else
+// 						if(instancesendpacket(frameLength, DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED, instance_data[instance].delayedReplyTime))
+// 						{
+// 							dw_event.typePend = DWT_SIG_TX_ERROR ;
+// 							dwt_setrxaftertxdelay(0);
+// 							instance_data[instance].wait4ack = 0; //clear the flag as the TX has failed the TRX is off
+// 							instance_data[instance].lateTX++;
+
+// 						}
+// 						else
+// #endif
+// 						{
+// 							dw_event.typePend = DWT_SIG_TX_PENDING ; // exit this interrupt and notify the application/instance that TX is in progress.
+// 						}
+// 					// }
+// 				}
+// 				break;
+
+// 				case RTLS_DEMO_MSG_ANCH_RESP:
+// 				default: //process rx frame in the application state machine
+// 				break;
+// 			}
+// 		}
+
+// 		instance_putevent(dw_event);
+
+// #if (DEEP_SLEEP == 1)
+// 		if (instance_data[instance].sleepingEabled)
+// 			instance_data[instance].rxmsgcount++;
+// #endif
+// 	}
+// 	else if (rxd_event == DWT_SIG_RX_BLINK)// & tag_index == 255) //only accept blinks from tags that aren't already in our taglist
+// 	{
+		
+// 		instance_putevent(dw_event);
+
+// #if (DEEP_SLEEP == 1)
+// 		if (instance_data[instance].sleepingEabled)
+// 			instance_data[instance].rxmsgcount++;
+// #endif
+// 	}
+// 	else
+// 	//if (rxd_event == SIG_RX_UNKNOWN) //need to re-enable the rx
+// 	{
+// 		instance_rxerrorcallback(rxd);
+// 	}
+
+
+
 }
 
 
@@ -1034,17 +1386,56 @@ int instance_run(void)
 		message = 0;
 	}
 
+	//check if lastCommTimeStamp has expired for any of the tags in our list
+	for(int i=0; i < instance_data[instance].tagListLen; i++)
+	{
+		if(instance_data[instance].lastCommTimeStamp[i] + TAG_COMM_TIMEOUT < portGetTickCnt())
+		{
+			if(instance_data[instance].tagTimeout[i] == 0)
+			{
+				instance_data[instance].tagTimeout[i] = 1;
+				
+				uint8 debug_msg[100];
+				int n = sprintf((char*)&debug_msg[0], "TIMEOUT: tag %i", i);
+				send_usbmessage(&debug_msg[0], n);
+				usb_run();	
+			}
+			if(instance_data[instance].tagToRangeWith == i)
+			{	
+				instance_data[instance].tagToRangeWith = 255;	
+				//NOTE this might need to be changed for TAG operations
+				if(instance_data[instance].mode == ANCHOR)
+				{
+					instance_data[instance].testAppState = TA_RXE_WAIT;
+					instance_data[instance].frameFilteringEnabled = 0;
+					dwt_enableframefilter(DWT_FF_NOTYPE_EN);
+				}
+				else
+				{
+					instance_data[instance].testAppState = TA_TX_SELECT;
+				}
+			}
+		}
+		
+	}
+
+	
+
+
     if(done == INST_DONE_WAIT_FOR_NEXT_EVENT_TO) //we are in RX and need to timeout (Tag needs to send another poll if no Rx frame)
     {
         if(instance_data[instance].mode == TAG) //Tag (is either in RX or sleeping)
         {
-            instance_data[instance].instanceTimerTime = instance_data[instance].instanceTimerTimeSaved + instance_data[instance].tagSleepTime_ms; //set timeout time
-            instance_data[instance].instanceTimerEnabled = 1; //start timer
-        }
-        if(instance_data[instance].mode == TAG_TDOA)
-        {
-            instance_data[instance].instanceTimerTime += instance_data[instance].tagBlinkSleepTime_ms; //set timeout time
-            instance_data[instance].instanceTimerEnabled = 1; //start timer
+			if(instance_data[instance].previousState == TA_TXBLINK_WAIT_SEND)
+			{
+				instance_data[instance].instanceTimerTime += instance_data[instance].tagBlinkSleepTime_ms; //set timeout time
+            	instance_data[instance].instanceTimerEnabled = 1; //start timer
+			}
+			else
+			{
+				instance_data[instance].instanceTimerTime = instance_data[instance].instanceTimerTimeSaved + instance_data[instance].tagSleepTime_ms; //set timeout time
+            	instance_data[instance].instanceTimerEnabled = 1; //start timer
+			}
         }
     }
 
diff --git a/src/decadriver/deca_device_api.h b/src/decadriver/deca_device_api.h
index 6d79f6a..d4de677 100644
--- a/src/decadriver/deca_device_api.h
+++ b/src/decadriver/deca_device_api.h
@@ -512,8 +512,8 @@ void dwt_setsmarttxpower(int enable);
  *                         standard PHR mode allows up to 127 bytes
  *                         if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
  *                         see dwt_configure function
- * @param txFrameBytes   - Pointer to the user’s buffer containing the data to send.
- * @param txBufferOffset - This specifies an offset in the DW1000’s TX Buffer at which to start writing data.
+ * @param txFrameBytes   - Pointer to the user�s buffer containing the data to send.
+ * @param txBufferOffset - This specifies an offset in the DW1000�s TX Buffer at which to start writing data.
  *
  * output parameters
  *
@@ -741,7 +741,7 @@ int dwt_rxenable(int mode);
  * @param enable - 1 to enable SNIFF mode, 0 to disable. When 0, all other parameters are not taken into account.
  * @param timeOn - duration of receiver ON phase, expressed in multiples of PAC size. The counter automatically adds 1 PAC
  *                 size to the value set. Min value that can be set is 1 (i.e. an ON time of 2 PAC size), max value is 15.
- * @param timeOff - duration of receiver OFF phase, expressed in multiples of 128/125 µs (~1 µs). Max value is 255.
+ * @param timeOff - duration of receiver OFF phase, expressed in multiples of 128/125 �s (~1 �s). Max value is 255.
  *
  * output parameters
  *
@@ -787,9 +787,9 @@ void dwt_setlowpowerlistening(int enable);
  * @brief Set duration of "short sleep" phase when in low-power listening mode.
  *
  * input parameters:
- * @param snooze_time - "short sleep" phase duration, expressed in multiples of 512/19.2 µs (~26.7 µs). The counter
+ * @param snooze_time - "short sleep" phase duration, expressed in multiples of 512/19.2 �s (~26.7 �s). The counter
  *                      automatically adds 1 to the value set. The smallest working value that should be set is 1,
- *                      i.e. giving a snooze time of 2 units (or ~53 µs).
+ *                      i.e. giving a snooze time of 2 units (or ~53 �s).
  *
  * output parameters
  *
-- 
GitLab