Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 47dee55

Browse files
anacromaniacSonic0
andauthored
Implemented polling abstraction of TWR algorithm (#136)
Co-authored-by: Sonic0 <[email protected]>
1 parent 4ae4c26 commit 47dee55

File tree

11 files changed

+483
-609
lines changed

11 files changed

+483
-609
lines changed

examples/BasicConnectivityTest/BasicConnectivityTest.ino

+7
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@
5151
#include <DW1000Ng.hpp>
5252

5353
// connection pins
54+
#if defined(ESP8266)
55+
const uint8_t PIN_RST = 5; // reset pin
56+
const uint8_t PIN_IRQ = 4; // irq pin
57+
const uint8_t PIN_SS = 15; // spi select pin
58+
#else
5459
const uint8_t PIN_RST = 9; // reset pin
5560
const uint8_t PIN_IRQ = 2; // irq pin
5661
const uint8_t PIN_SS = SS; // spi select pin
62+
#endif
63+
5764

5865
void setup() {
5966
// DEBUG monitoring

examples/BasicReceiver/BasicReceiver.ino

+23-49
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@
5050
#include <SPI.h>
5151
#include <DW1000Ng.hpp>
5252

53-
// connection pins
54-
const uint8_t PIN_RST = 9; // reset pin
55-
const uint8_t PIN_IRQ = 2; // irq pin
53+
#if defined(ESP8266)
54+
//const uint8_t PIN_RST = 5; // reset pin
55+
//const uint8_t PIN_IRQ = 4; // irq pin
56+
const uint8_t PIN_SS = 15; // spi select pin
57+
#else
58+
//const uint8_t PIN_RST = 9; // reset pin
59+
//const uint8_t PIN_IRQ = 2; // irq pin
5660
const uint8_t PIN_SS = SS; // spi select pin
61+
#endif
5762

58-
// DEBUG packet sent status and count
59-
volatile boolean received = false;
60-
volatile boolean error = false;
61-
volatile int16_t numReceived = 0; // todo check int type
63+
int16_t numReceived = 0; // todo check int type
6264
String message;
6365

6466
device_configuration_t DEFAULT_CONFIG = {
@@ -75,24 +77,15 @@ device_configuration_t DEFAULT_CONFIG = {
7577
PreambleCode::CODE_3
7678
};
7779

78-
interrupt_configuration_t DEFAULT_INTERRUPT_CONFIG = {
79-
true,
80-
true,
81-
true,
82-
false,
83-
true
84-
};
85-
8680
void setup() {
8781
// DEBUG monitoring
8882
Serial.begin(9600);
8983
Serial.println(F("### DW1000Ng-arduino-receiver-test ###"));
9084
// initialize the driver
91-
DW1000Ng::initialize(PIN_SS, PIN_IRQ, PIN_RST);
85+
DW1000Ng::initializeNoInterrupt(PIN_SS);
9286
Serial.println(F("DW1000Ng initialized ..."));
9387

9488
DW1000Ng::applyConfiguration(DEFAULT_CONFIG);
95-
DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);
9689

9790
DW1000Ng::setDeviceAddress(6);
9891
DW1000Ng::setNetworkId(10);
@@ -109,40 +102,21 @@ void setup() {
109102
Serial.print("Network ID & Device Address: "); Serial.println(msg);
110103
DW1000Ng::getPrintableDeviceMode(msg);
111104
Serial.print("Device mode: "); Serial.println(msg);
112-
// attach callback for (successfully) received messages
113-
DW1000Ng::attachReceivedHandler(handleReceived);
114-
DW1000Ng::attachReceiveFailedHandler(handleError);
115-
DW1000Ng::attachErrorHandler(handleError);
116-
// start reception
117-
DW1000Ng::startReceive();
118-
}
119-
120-
void handleReceived() {
121-
// status change on reception success
122-
received = true;
123-
}
124-
125-
void handleError() {
126-
error = true;
127105
}
128106

129107
void loop() {
130-
// enter on confirmation of ISR status change (successfully received)
131-
if (received) {
132-
received = false;
133-
numReceived++;
134-
// get data as string
135-
DW1000Ng::getReceivedData(message);
136-
Serial.print("Received message ... #"); Serial.println(numReceived);
137-
Serial.print("Data is ... "); Serial.println(message);
138-
Serial.print("RX power is [dBm] ... "); Serial.println(DW1000Ng::getReceivePower());
139-
Serial.print("Signal quality is ... "); Serial.println(DW1000Ng::getReceiveQuality());
140-
DW1000Ng::startReceive();
141-
}
142-
if (error) {
143-
error = false;
144-
Serial.println("Error receiving a message");
145-
DW1000Ng::getReceivedData(message);
146-
Serial.print("Error data is ... "); Serial.println(message);
108+
DW1000Ng::startReceive();
109+
while(!DW1000Ng::isReceiveDone()) {
110+
#if defined(ESP8266)
111+
yield();
112+
#endif
147113
}
114+
DW1000Ng::clearReceiveStatus();
115+
numReceived++;
116+
// get data as string
117+
DW1000Ng::getReceivedData(message);
118+
Serial.print("Received message ... #"); Serial.println(numReceived);
119+
Serial.print("Data is ... "); Serial.println(message);
120+
Serial.print("RX power is [dBm] ... "); Serial.println(DW1000Ng::getReceivePower());
121+
Serial.print("Signal quality is ... "); Serial.println(DW1000Ng::getReceiveQuality());
148122
}

examples/BasicSender/BasicSender.ino

+21-24
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@
4949
#include <SPI.h>
5050
#include <DW1000Ng.hpp>
5151

52-
// connection pins
53-
const uint8_t PIN_RST = 9; // reset pin
54-
const uint8_t PIN_IRQ = 2; // irq pin
52+
#if defined(ESP8266)
53+
//const uint8_t PIN_RST = 5; // reset pin
54+
//const uint8_t PIN_IRQ = 4; // irq pin
55+
const uint8_t PIN_SS = 15; // spi select pin
56+
#else
57+
//const uint8_t PIN_RST = 9; // reset pin
58+
//const uint8_t PIN_IRQ = 2; // irq pin
5559
const uint8_t PIN_SS = SS; // spi select pin
60+
#endif
5661

5762
// DEBUG packet sent status and count
58-
boolean sent = false;
59-
volatile boolean sentAck = false;
6063
volatile unsigned long delaySent = 0;
6164
int16_t sentNum = 0; // todo check int type
6265

@@ -74,24 +77,16 @@ device_configuration_t DEFAULT_CONFIG = {
7477
PreambleCode::CODE_3
7578
};
7679

77-
interrupt_configuration_t DEFAULT_INTERRUPT_CONFIG = {
78-
true,
79-
true,
80-
true,
81-
false,
82-
true
83-
};
84-
8580
void setup() {
8681
// DEBUG monitoring
8782
Serial.begin(9600);
8883
Serial.println(F("### DW1000Ng-arduino-sender-test ###"));
8984
// initialize the driver
90-
DW1000Ng::initialize(PIN_SS, PIN_IRQ, PIN_RST);
85+
DW1000Ng::initializeNoInterrupt(PIN_SS);
9186
Serial.println(F("DW1000Ng initialized ..."));
9287

9388
DW1000Ng::applyConfiguration(DEFAULT_CONFIG);
94-
DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);
89+
//DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);
9590

9691
DW1000Ng::setDeviceAddress(5);
9792
DW1000Ng::setNetworkId(10);
@@ -109,15 +104,17 @@ void setup() {
109104
DW1000Ng::getPrintableDeviceMode(msg);
110105
Serial.print("Device mode: "); Serial.println(msg);
111106
// attach callback for (successfully) sent messages
112-
DW1000Ng::attachSentHandler(handleSent);
107+
//DW1000Ng::attachSentHandler(handleSent);
113108
// start a transmission
114109
transmit();
115110
}
116111

112+
/*
117113
void handleSent() {
118114
// status change on sent success
119115
sentAck = true;
120116
}
117+
*/
121118

122119
void transmit() {
123120
// transmit some data
@@ -128,19 +125,19 @@ void transmit() {
128125
delay(1000);
129126
DW1000Ng::startTransmit(TransmitMode::IMMEDIATE);
130127
delaySent = millis();
128+
while(!DW1000Ng::isTransmitDone()) {
129+
#if defined(ESP8266)
130+
yield();
131+
#endif
132+
}
133+
sentNum++;
134+
DW1000Ng::clearTransmitStatus();
131135
}
132136

133137
void loop() {
134-
if (sentAck) {
135-
// continue on success confirmation
136-
// (we are here after the given amount of send delay time has passed)
137-
sentAck = false;
138+
transmit();
138139
// update and print some information about the sent message
139140
Serial.print("ARDUINO delay sent [ms] ... "); Serial.println(millis() - delaySent);
140141
uint64_t newSentTime = DW1000Ng::getTransmitTimestamp();
141142
Serial.print("Processed packet ... #"); Serial.println(sentNum);
142-
sentNum++;
143-
// again, transmit some data
144-
transmit();
145-
}
146143
}

0 commit comments

Comments
 (0)