Commit bcc56e94 authored by Oscar Saldias Calcerrada's avatar Oscar Saldias Calcerrada
Browse files

Mejoras en DW1000Ranging.cpp:

- Se cambia _data a tamaño LEN_UWB_FRAMES en lugar de LEN_DATA
- Mejoras en nombres de variables
- Se agrega variable de clase _rangingRound para agrupar las estimaciones de los distintos dispositivos involucrados en una iteración de ranging
- Se agrega el rangingRound a la firma del callback handler de _handleNewRange
- _replyDelayTimeUS pasa a ser _transmitDelayTimeUs y el tipo pasa de uint16_t a uint32_t para evitar overflow
parent ed27fe18
......@@ -33,20 +33,21 @@
DW1000RangingClass DW1000Ranging;
static byte BROADCAST_SHORT_ADDRESS[] = {0xFF, 0xFF};
static const byte BROADCAST_SHORT_ADDRESS[] = {0xFF, 0xFF};
//other devices we are going to communicate with which are on our network:
DW1000Device DW1000RangingClass::_networkDevices[MAX_DEVICES];
volatile uint8_t DW1000RangingClass::_networkDevicesNumber = 0; // TODO short, 8bit?
volatile uint8_t DW1000RangingClass::_networkDevicesNumber = 0;
// Anchors which replied POLL (POLL_ACK)
DW1000Device* DW1000RangingClass::_networkDevicesForRanging[MAX_DEVICES];
volatile uint8_t DW1000RangingClass::_networkDevicesNumberForRanging = 0;
volatile uint32_t DW1000RangingClass::_rangingRound = 0;
byte DW1000RangingClass::_selfAddress[8];
byte DW1000RangingClass::_selfShortAddress[2];
byte DW1000RangingClass::_lastSentToShortAddress[2];
uint8_t DW1000RangingClass::_lastDistantDevice = 0; // TODO short, 8bit?
uint8_t DW1000RangingClass::_lastDistantDevice = 0;
DW1000Mac DW1000RangingClass::_globalMac;
//module type (anchor or tag)
......@@ -76,22 +77,23 @@ int8_t DW1000RangingClass::_countdownForBlink = 0;
char DW1000RangingClass::_logBuffer[LEN_LOG_BUFFER];
// data buffer
byte DW1000RangingClass::_data[LEN_DATA];
//byte DW1000RangingClass::_data[LEN_DATA];
byte DW1000RangingClass::_data[LEN_UWB_FRAMES];
// reset line to the chip
uint8_t DW1000RangingClass::_RST;
uint8_t DW1000RangingClass::_SS;
// watchdog and reset period
uint32_t DW1000RangingClass::_lastActivity;
uint32_t DW1000RangingClass::_resetPeriod;
uint32_t DW1000RangingClass::_resetPeriodMs;
// reply times (same on both sides for symm. ranging)
uint16_t DW1000RangingClass::_replyDelayTimeUS;
uint32_t DW1000RangingClass::_transmitDelayTimeUs;
//timer delay
uint16_t DW1000RangingClass::_timerDelay;
uint16_t DW1000RangingClass::_timerDelayMs;
// ranging counter (per second)
uint16_t DW1000RangingClass::_successRangingCount = 0;
uint32_t DW1000RangingClass::_rangingCountPeriod = 0;
//Here our handlers
void (* DW1000RangingClass::_handleNewRange)(DW1000Device*) = 0;
void (* DW1000RangingClass::_handleNewRange)(DW1000Device*, uint32_t) = 0;
void (* DW1000RangingClass::_handleBlinkDevice)(DW1000Device*) = 0;
void (* DW1000RangingClass::_handleNewDevice)(DW1000Device*) = 0;
void (* DW1000RangingClass::_handleInactiveDevice)(DW1000Device*) = 0;
......@@ -106,11 +108,11 @@ void DW1000RangingClass::initCommunication(uint8_t myRST, uint8_t mySS, uint8_t
// reset line to the chip
_RST = myRST;
_SS = mySS;
_resetPeriod = DEFAULT_RESET_PERIOD;
_resetPeriodMs = DEFAULT_RESET_PERIOD_MS;
// reply times (same on both sides for symm. ranging)
_replyDelayTimeUS = DEFAULT_REPLY_DELAY_TIME;
_transmitDelayTimeUs = DEFAULT_TRANSMIT_DELAY_TIME_US;
//we set our timer delay
_timerDelay = DEFAULT_TIMER_DELAY;
_timerDelayMs = DEFAULT_TIMER_DELAY_MS;
DW1000.begin(myIRQ, myRST);
......@@ -135,7 +137,6 @@ void DW1000RangingClass::generalStart() {
DW1000.attachReceivedHandler(handleReceived);
// anchor starts in receiving mode, awaiting a ranging poll message
if(DEBUG) {
// DEBUG monitoring
// Serial.println("DW1000-arduino");
......
......@@ -43,31 +43,35 @@
//#define BLINK 4
//#define RANGING_INIT 5
#define LEN_DATA 90
//#define LEN_DATA 90
// if LEN_DATA > (127-2) (LEN_UWB_FRAMES=127) then must be enabled extended frame length
#define LEN_DATA SHORT_MAC_LEN+2+MAX_DEVICES*(2+DW1000Time::LEN_TIMESTAMP*3)
// for debugging
#define LEN_LOG_BUFFER 100
#define LEN_LOG_BUFFER 100
//Max devices we put in the networkDevices array ! Each DW1000Device is 74 Bytes in SRAM memory for now.
#define MAX_DEVICES 10
#define MAX_DEVICES 10
//#define MAX_DEVICES 6 // OS: 2020-11-03
//Default Pin for module:
#define DEFAULT_RST_PIN 9
#define DEFAULT_SPI_SS_PIN 10
#define DEFAULT_RST_PIN 9
#define DEFAULT_SPI_SS_PIN 10
//Default value
//in ms
#define DEFAULT_RESET_PERIOD 200
#define DEFAULT_RESET_PERIOD_MS 200
//in us
//#define DEFAULT_REPLY_DELAY_TIME 7000
#define DEFAULT_REPLY_DELAY_TIME 3000 // OS: 2020-10-24
#define DEFAULT_TRANSMIT_DELAY_TIME_US 7000
//#define DEFAULT_REPLY_DELAY_TIME_US 5000 // OS: 2020-10-24
//sketch type (anchor or tag)
#define TAG 0
#define ANCHOR 1
#define TAG 0
#define ANCHOR 1
//default timer delay
#define DEFAULT_TIMER_DELAY 80
#define DEFAULT_TIMER_DELAY_MS 80
//#define DEFAULT_TIMER_DELAY_MS 100 // OS: 2020-10-28
//debug mode
#ifndef DEBUG
......@@ -88,7 +92,8 @@ class DW1000RangingClass {
public:
//variables
// data buffer
static byte _data[LEN_DATA];
//static byte _data[LEN_DATA];
static byte _data[LEN_UWB_FRAMES];
//initialisation
static void initCommunication(uint8_t myRST = DEFAULT_RST_PIN, uint8_t mySS = DEFAULT_SPI_SS_PIN, uint8_t myIRQ = 2);
......@@ -101,7 +106,7 @@ public:
static void removeNetworkDevice(uint8_t index);
//setters
static void setReplyTime(uint16_t replyDelayTimeUs);
static void setTransmitDelayTimeUs(uint32_t transmitDelayTimeUs);
static void setResetPeriod(uint32_t resetPeriod);
//getters
......@@ -119,7 +124,7 @@ public:
static void setRangeFilterValue(uint16_t newValue);
//Handlers:
static void attachNewRange(void (* handleNewRange)(DW1000Device*)) { _handleNewRange = handleNewRange; };
static void attachNewRange(void (* handleNewRange)(DW1000Device*, uint32_t)) { _handleNewRange = handleNewRange; };
static void attachBlinkDevice(void (* handleBlinkDevice)(DW1000Device*)) { _handleBlinkDevice = handleBlinkDevice; };
......@@ -149,6 +154,7 @@ private:
static DW1000Device* _networkDevicesForRanging[MAX_DEVICES];
static volatile uint8_t _networkDevicesNumberForRanging;
static volatile uint32_t _rangingRound;
static uint8_t _lastDistantDevice;
static byte _selfAddress[8];
......@@ -159,7 +165,7 @@ private:
static int8_t _countdownForBlink;
//Handlers:
static void (* _handleNewRange)(DW1000Device*);
static void (* _handleNewRange)(DW1000Device*, uint32_t);
static void (* _handleBlinkDevice)(DW1000Device*);
static void (* _handleNewDevice)(DW1000Device*);
static void (* _handleInactiveDevice)(DW1000Device*);
......@@ -182,15 +188,15 @@ private:
static uint8_t _RST;
static uint8_t _SS;
// watchdog and reset period
static uint32_t _lastActivity;
static uint32_t _resetPeriod;
static uint32_t _lastActivity;
static uint32_t _resetPeriodMs;
// reply times (same on both sides for symm. ranging)
static uint16_t _replyDelayTimeUS;
static uint32_t _transmitDelayTimeUs;
//timer Tick delay
static uint16_t _timerDelay;
static uint16_t _timerDelayMs;
// ranging counter (per second)
static uint16_t _successRangingCount;
static uint32_t _rangingCountPeriod;
static uint16_t _successRangingCount;
static uint32_t _rangingCountPeriod;
//ranging filter
static volatile boolean _useRangeFilter;
static uint16_t _rangeFilterValue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment