Skip to content

Commit

Permalink
rename REQUESTQUEUE to RQ + misc
Browse files Browse the repository at this point in the history
  • Loading branch information
LowPowerLab committed May 29, 2020
1 parent f28c65f commit f77011b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 40 deletions.
40 changes: 25 additions & 15 deletions Examples/MightyHat/MightyHat.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
#define DEBUGln(input)
#endif

#define PRINT_UPTIME Serial<< F("UPTIME:") << millis() << endl;
#define PRINT_FREQUENCY Serial << F("SYSFREQ:") << radio.getFrequency() << endl;

#define LED_HIGH digitalWrite(LED_BUILTIN, HIGH)
#define LED_LOW digitalWrite(LED_BUILTIN, LOW)

Expand Down Expand Up @@ -648,6 +651,8 @@ void setup() {
Beep(20, false);delay(50);Beep(20, false);delay(50);Beep(20, false);
setupPowerControl();
Serial.begin(SERIAL_BAUD);
pinMode(LED_BUILTIN, OUTPUT);
LED_HIGH;

radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef ENCRYPTKEY
Expand All @@ -656,9 +661,10 @@ void setup() {
#ifdef IS_RFM69HW_HCW
radio.setHighPower();
#endif
Pbuff="SYSFREQ:";
Pbuff << radio.getFrequency();
DEBUGln(buff);
Serial << endl << "GATEWAYSTART" << endl;
PRINT_FREQUENCY;
PRINT_UPTIME;

if (!flash.initialize()) DEBUGln(F("DEBUG:SPI_Flash_Init_FAIL"));

#ifdef FREQUENCY_EXACT
Expand All @@ -678,6 +684,7 @@ void setup() {
refreshLCD();
delay(1000);
#endif
LED_LOW;
}

boolean newPacketReceived;
Expand Down Expand Up @@ -769,11 +776,11 @@ boolean insert(uint16_t new_id, char new_data[]) {
//processCommand - parse the command and send it to target
//if target is non-responsive it(sleeppy node?) then queue command to send when target wakes and asks for an ACK
//SPECIAL COMMANDS FROM HOST:
// - REQUESTQUEUE:123:MESSAGE - send or (upon fail) queue message
// - RQ:123:MESSAGE - send or (upon fail) queue message
// - 123:VOID - removes all queued commands for node 123
// - 123:VOID:command - removes 'command' from queue (if found)
// - REQUESTQUEUE - prints the queued list of nodes on serial port, to host (Pi?)
// - REQUESTQUEUE:VOID - flush entire queue
// - RQ - prints the queued list of nodes on serial port, to host (Pi?)
// - RQ:VOID - flush entire queue
// - FREERAM - returns # of unallocated bytes at end of heap
// - SYSFREQ - returns operating frequency in Hz
// - UPTIME - returns millis()
Expand All @@ -787,16 +794,16 @@ void processCommand(char data[], boolean allowDuplicate=false) {

if (strcmp(data, "FREERAM")==0)
Serial << F("FREERAM:") << freeRAM() << ':' << RAMSIZE << endl;
if (strcmp(data, "REQUESTQUEUE")==0)
if (strcmp(data, "RQ")==0)
{
ptr = strtok(NULL, ":"); //move to next :
if (ptr == NULL) printQueue(queue);
else isQueueRequest = true;
}
if (strcmp(data, "SYSFREQ")==0)
Serial << F("SYSFREQ:") << radio.getFrequency() << endl;
PRINT_FREQUENCY;
if (strcmp(data, "UPTIME")==0)
Serial << F("UPTIME:") << millis() << endl;
PRINT_UPTIME;
if (strcmp(data, "NETWORKID")==0)
Serial << F("NETWORKID:") << NETWORKID << endl;
if (strcmp(data, "BEEP")==0) Beep(5, false);
Expand All @@ -811,7 +818,7 @@ void processCommand(char data[], boolean allowDuplicate=false) {
if(ptr != NULL) { // delimiter found, valid command
sprintf(dataPart, "%s", ptr);

//if "REQUESTQUEUE:VOID" then flush entire requst queue
//if "RQ:VOID" then flush entire requst queue
if (isQueueRequest && strcmp(dataPart, "VOID")==0) {
REQUEST* aux = queue;
byte removed=0;
Expand Down Expand Up @@ -846,8 +853,7 @@ void processCommand(char data[], boolean allowDuplicate=false) {
if (strlen(dataPart) == 0) return;

//check target nodeID is valid
if (targetId > 0 && targetId != NODEID && targetId<=1023)
{
if (targetId > 0 && targetId != NODEID && targetId<=1023) {
REQUEST* aux;
byte removed=0;

Expand Down Expand Up @@ -944,24 +950,28 @@ void processCommand(char data[], boolean allowDuplicate=false) {
//DEBUGln(dataPart);
size_of_queue++;
}
else
else
{
DEBUGln(F("DEBUG:INSERT_FAIL:MEM_FULL"));
Serial << F("[") << targetId << F("] ") << dataPart << F(":MEMFULL") << endl;
}
}
else {
//DEBUG(F("DEBUG:INSERT_FAIL - INVALID nodeId:")); DEBUGln(targetId);
Serial<< '[' << targetId <<"] " << dataPart << F(":INV:ID-OUT-OF-RANGE") << endl;
}
}
}

void printQueue(REQUEST* p) {
if (!size_of_queue) {
Serial << F("REQUESTQUEUE:EMPTY") << endl;
Serial << F("RQ:EMPTY") << endl;
return;
}

REQUEST* aux=p;
while (aux!=NULL) {
Serial << F("REQUESTQUEUE:") << aux->nodeId << ':' << aux->data << endl;
Serial << F("RQ:") << aux->nodeId << ':' << aux->data << endl;
aux=aux->next;
}
}
Expand Down
55 changes: 30 additions & 25 deletions Examples/PiGateway/PiGateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#define DEBUGln(input)
#endif

#define PRINT_UPTIME Serial<< F("UPTIME:") << millis() << endl;
#define PRINT_FREQUENCY Serial << F("SYSFREQ:") << radio.getFrequency() << endl;

#define LED_HIGH digitalWrite(LED_BUILTIN, HIGH)
#define LED_LOW digitalWrite(LED_BUILTIN, LOW)

Expand Down Expand Up @@ -84,6 +87,9 @@ void setup() {
#endif

Serial.begin(SERIAL_BAUD);
pinMode(LED_BUILTIN, OUTPUT);
LED_HIGH;

delay(100);

radio.initialize(FREQUENCY,NODEID,NETWORKID);
Expand All @@ -92,24 +98,20 @@ void setup() {
#endif
radio.encrypt(ENCRYPTKEY);

if (flash.initialize()) {
DEBUGln(F("DEBUG:SPI Flash Init OK!"));
flash.sleep();
}
else DEBUGln(F("DEBUG:SPI Flash MEM FAIL!"));

#ifdef FREQUENCY_EXACT
radio.setFrequency(FREQUENCY_EXACT); //set frequency to some custom frequency
#endif

Pbuff = F("DEBUG:Listening @ ");
Pbuff.print(radio.getFrequency());
Pbuff.print(F("Hz..."));
DEBUGln(buff);
Serial << endl << "GATEWAYSTART" << endl;
PRINT_FREQUENCY;
PRINT_UPTIME;

pinMode(LED_BUILTIN, OUTPUT);
DEBUG(F("DEBUG:Size of REQUEST* struct = "));DEBUGln(sizeof(REQUEST));
Serial << endl << "GATEWAYSTART SYSFREQ:" << radio.getFrequency() << endl;
if (flash.initialize()) {
DEBUGln(F("DEBUG:SPI Flash Init OK!"));
flash.sleep();
}
else DEBUGln(F("DEBUG:SPI Flash MEM FAIL!"));
LED_LOW;
}

void loop() {
Expand Down Expand Up @@ -180,11 +182,11 @@ boolean insert(uint16_t new_id, char new_data[]) {
//processCommand - parse the command and send it to target
//if target is non-responsive it(sleeppy node?) then queue command to send when target wakes and asks for an ACK
//SPECIAL COMMANDS FROM HOST:
// - REQUESTQUEUE:123:MESSAGE - send or (upon fail) queue message
// - RQ:123:MESSAGE - send or (upon fail) queue message
// - 123:VOID - removes all queued commands for node 123
// - 123:VOID:command - removes 'command' from queue (if found)
// - REQUESTQUEUE - prints the queued list of nodes on serial port, to host (Pi?)
// - REQUESTQUEUE:VOID - flush entire queue
// - RQ - prints the queued list of nodes on serial port, to host (Pi?)
// - RQ:VOID - flush entire queue
// - FREERAM - returns # of unallocated bytes at end of heap
// - SYSFREQ - returns operating frequency in Hz
// - UPTIME - returns millis()
Expand All @@ -198,16 +200,16 @@ void processCommand(char data[], boolean allowDuplicate=false) {

if (strcmp(data, "FREERAM")==0)
Serial << F("FREERAM:") << freeRAM() << ':' << RAMSIZE << endl;
if (strcmp(data, "REQUESTQUEUE")==0)
if (strcmp(data, "RQ")==0)
{
ptr = strtok(NULL, ":"); //move to next :
if (ptr == NULL) printQueue(queue);
else isQueueRequest = true;
}
if (strcmp(data, "SYSFREQ")==0)
Serial << F("SYSFREQ:") << radio.getFrequency() << endl;
PRINT_FREQUENCY;
if (strcmp(data, "UPTIME")==0)
Serial << F("UPTIME:") << millis() << endl;
PRINT_UPTIME;
if (strcmp(data, "NETWORKID")==0)
Serial << F("NETWORKID:") << NETWORKID << endl;
if (strcmp(data, "ENCRYPTKEY")==0)
Expand All @@ -220,7 +222,7 @@ void processCommand(char data[], boolean allowDuplicate=false) {
if(ptr != NULL) { // delimiter found, valid command
sprintf(dataPart, "%s", ptr);

//if "REQUESTQUEUE:VOID" then flush entire requst queue
//if "RQ:VOID" then flush entire requst queue
if (isQueueRequest && strcmp(dataPart, "VOID")==0) {
REQUEST* aux = queue;
byte removed=0;
Expand Down Expand Up @@ -255,8 +257,7 @@ void processCommand(char data[], boolean allowDuplicate=false) {
if (strlen(dataPart) == 0) return;

//check target nodeID is valid
if (targetId > 0 && targetId != NODEID && targetId<=1023)
{
if (targetId > 0 && targetId != NODEID && targetId<=1023) {
REQUEST* aux;
byte removed=0;

Expand Down Expand Up @@ -353,24 +354,28 @@ void processCommand(char data[], boolean allowDuplicate=false) {
//DEBUGln(dataPart);
size_of_queue++;
}
else
else
{
DEBUGln(F("DEBUG:INSERT_FAIL:MEM_FULL"));
Serial << F("[") << targetId << F("] ") << dataPart << F(":MEMFULL") << endl;
}
}
else {
//DEBUG(F("DEBUG:INSERT_FAIL - INVALID nodeId:")); DEBUGln(targetId);
Serial<< '[' << targetId <<"] " << dataPart << F(":INV:ID-OUT-OF-RANGE") << endl;
}
}
}

void printQueue(REQUEST* p) {
if (!size_of_queue) {
Serial << F("REQUESTQUEUE:VOID") << endl;
Serial << F("RQ:EMPTY") << endl;
return;
}

REQUEST* aux=p;
while (aux!=NULL) {
Serial << F("REQUESTQUEUE:") << aux->nodeId << ':' << aux->data << endl;
Serial << F("RQ:") << aux->nodeId << ':' << aux->data << endl;
aux=aux->next;
}
}
Expand Down

0 comments on commit f77011b

Please sign in to comment.