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

Commit

Permalink
Merge branch 'master' into resetReceiver-refact
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonic0 committed Dec 7, 2018
2 parents cfda86a + 0a7d32c commit dada9f8
Show file tree
Hide file tree
Showing 13 changed files with 630 additions and 720 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The main reason for this fork is because the development there is really slow (d
We also wanted to change how the ranging logic works.<br/>
Rather than providing a ranging loop, we wanted to provide functions to send the different Two way ranging flow frames, giving the user more control over the program. <br />
The base driver was also re-written in a lot of places, to make every API function more independent from each other.
We also plan to make very high-level abstractions to hack projects fast.

Features
------------
Expand Down
7 changes: 7 additions & 0 deletions examples/BasicConnectivityTest/BasicConnectivityTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@
#include <DW1000Ng.hpp>

// connection pins
#if defined(ESP8266)
const uint8_t PIN_RST = 5; // reset pin
const uint8_t PIN_IRQ = 4; // irq pin
const uint8_t PIN_SS = 15; // spi select pin
#else
const uint8_t PIN_RST = 9; // reset pin
const uint8_t PIN_IRQ = 2; // irq pin
const uint8_t PIN_SS = SS; // spi select pin
#endif


void setup() {
// DEBUG monitoring
Expand Down
72 changes: 23 additions & 49 deletions examples/BasicReceiver/BasicReceiver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@
#include <SPI.h>
#include <DW1000Ng.hpp>

// connection pins
const uint8_t PIN_RST = 9; // reset pin
const uint8_t PIN_IRQ = 2; // irq pin
#if defined(ESP8266)
//const uint8_t PIN_RST = 5; // reset pin
//const uint8_t PIN_IRQ = 4; // irq pin
const uint8_t PIN_SS = 15; // spi select pin
#else
//const uint8_t PIN_RST = 9; // reset pin
//const uint8_t PIN_IRQ = 2; // irq pin
const uint8_t PIN_SS = SS; // spi select pin
#endif

// DEBUG packet sent status and count
volatile boolean received = false;
volatile boolean error = false;
volatile int16_t numReceived = 0; // todo check int type
int16_t numReceived = 0; // todo check int type
String message;

device_configuration_t DEFAULT_CONFIG = {
Expand All @@ -75,24 +77,15 @@ device_configuration_t DEFAULT_CONFIG = {
PreambleCode::CODE_3
};

interrupt_configuration_t DEFAULT_INTERRUPT_CONFIG = {
true,
true,
true,
false,
true
};

void setup() {
// DEBUG monitoring
Serial.begin(9600);
Serial.println(F("### DW1000Ng-arduino-receiver-test ###"));
// initialize the driver
DW1000Ng::initialize(PIN_SS, PIN_IRQ, PIN_RST);
DW1000Ng::initializeNoInterrupt(PIN_SS);
Serial.println(F("DW1000Ng initialized ..."));

DW1000Ng::applyConfiguration(DEFAULT_CONFIG);
DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);

DW1000Ng::setDeviceAddress(6);
DW1000Ng::setNetworkId(10);
Expand All @@ -109,40 +102,21 @@ void setup() {
Serial.print("Network ID & Device Address: "); Serial.println(msg);
DW1000Ng::getPrintableDeviceMode(msg);
Serial.print("Device mode: "); Serial.println(msg);
// attach callback for (successfully) received messages
DW1000Ng::attachReceivedHandler(handleReceived);
DW1000Ng::attachReceiveFailedHandler(handleError);
DW1000Ng::attachErrorHandler(handleError);
// start reception
DW1000Ng::startReceive();
}

void handleReceived() {
// status change on reception success
received = true;
}

void handleError() {
error = true;
}

void loop() {
// enter on confirmation of ISR status change (successfully received)
if (received) {
received = false;
numReceived++;
// get data as string
DW1000Ng::getReceivedData(message);
Serial.print("Received message ... #"); Serial.println(numReceived);
Serial.print("Data is ... "); Serial.println(message);
Serial.print("RX power is [dBm] ... "); Serial.println(DW1000Ng::getReceivePower());
Serial.print("Signal quality is ... "); Serial.println(DW1000Ng::getReceiveQuality());
DW1000Ng::startReceive();
}
if (error) {
error = false;
Serial.println("Error receiving a message");
DW1000Ng::getReceivedData(message);
Serial.print("Error data is ... "); Serial.println(message);
DW1000Ng::startReceive();
while(!DW1000Ng::isReceiveDone()) {
#if defined(ESP8266)
yield();
#endif
}
DW1000Ng::clearReceiveStatus();
numReceived++;
// get data as string
DW1000Ng::getReceivedData(message);
Serial.print("Received message ... #"); Serial.println(numReceived);
Serial.print("Data is ... "); Serial.println(message);
Serial.print("RX power is [dBm] ... "); Serial.println(DW1000Ng::getReceivePower());
Serial.print("Signal quality is ... "); Serial.println(DW1000Ng::getReceiveQuality());
}
45 changes: 21 additions & 24 deletions examples/BasicSender/BasicSender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@
#include <SPI.h>
#include <DW1000Ng.hpp>

// connection pins
const uint8_t PIN_RST = 9; // reset pin
const uint8_t PIN_IRQ = 2; // irq pin
#if defined(ESP8266)
//const uint8_t PIN_RST = 5; // reset pin
//const uint8_t PIN_IRQ = 4; // irq pin
const uint8_t PIN_SS = 15; // spi select pin
#else
//const uint8_t PIN_RST = 9; // reset pin
//const uint8_t PIN_IRQ = 2; // irq pin
const uint8_t PIN_SS = SS; // spi select pin
#endif

// DEBUG packet sent status and count
boolean sent = false;
volatile boolean sentAck = false;
volatile unsigned long delaySent = 0;
int16_t sentNum = 0; // todo check int type

Expand All @@ -74,24 +77,16 @@ device_configuration_t DEFAULT_CONFIG = {
PreambleCode::CODE_3
};

interrupt_configuration_t DEFAULT_INTERRUPT_CONFIG = {
true,
true,
true,
false,
true
};

void setup() {
// DEBUG monitoring
Serial.begin(9600);
Serial.println(F("### DW1000Ng-arduino-sender-test ###"));
// initialize the driver
DW1000Ng::initialize(PIN_SS, PIN_IRQ, PIN_RST);
DW1000Ng::initializeNoInterrupt(PIN_SS);
Serial.println(F("DW1000Ng initialized ..."));

DW1000Ng::applyConfiguration(DEFAULT_CONFIG);
DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);
//DW1000Ng::applyInterruptConfiguration(DEFAULT_INTERRUPT_CONFIG);

DW1000Ng::setDeviceAddress(5);
DW1000Ng::setNetworkId(10);
Expand All @@ -109,15 +104,17 @@ void setup() {
DW1000Ng::getPrintableDeviceMode(msg);
Serial.print("Device mode: "); Serial.println(msg);
// attach callback for (successfully) sent messages
DW1000Ng::attachSentHandler(handleSent);
//DW1000Ng::attachSentHandler(handleSent);
// start a transmission
transmit();
}

/*
void handleSent() {
// status change on sent success
sentAck = true;
}
*/

void transmit() {
// transmit some data
Expand All @@ -128,19 +125,19 @@ void transmit() {
delay(1000);
DW1000Ng::startTransmit(TransmitMode::IMMEDIATE);
delaySent = millis();
while(!DW1000Ng::isTransmitDone()) {
#if defined(ESP8266)
yield();
#endif
}
sentNum++;
DW1000Ng::clearTransmitStatus();
}

void loop() {
if (sentAck) {
// continue on success confirmation
// (we are here after the given amount of send delay time has passed)
sentAck = false;
transmit();
// update and print some information about the sent message
Serial.print("ARDUINO delay sent [ms] ... "); Serial.println(millis() - delaySent);
uint64_t newSentTime = DW1000Ng::getTransmitTimestamp();
Serial.print("Processed packet ... #"); Serial.println(sentNum);
sentNum++;
// again, transmit some data
transmit();
}
}
Loading

0 comments on commit dada9f8

Please sign in to comment.