From 31e40280527e85c4eefd8b3a68047ffbaac50821 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sat, 1 Apr 2023 15:13:42 -1000 Subject: [PATCH 1/5] Add ATI13, ATI14 and ATI15 commands to display seed and channel table --- Firmware/LoRaSerial/Commands.ino | 66 ++++++++++++++++++++++++++++++ Firmware/LoRaSerial/LoRaSerial.ino | 3 ++ Firmware/LoRaSerial/Radio.ino | 3 -- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index 596104f6..4fbe5e01 100644 --- a/Firmware/LoRaSerial/Commands.ino +++ b/Firmware/LoRaSerial/Commands.ino @@ -226,6 +226,9 @@ bool commandAT(const char * commandString) systemPrintln(" ATI10 - Display radio metrics"); systemPrintln(" ATI11 - Display the system runtime"); systemPrintln(" ATI12 - Set programming complete"); + systemPrintln(" ATI13 - Display the random seed"); + systemPrintln(" ATI14 - Display the channel table by channel"); + systemPrintln(" ATI15 - Display the channel table by frequency"); //Virtual circuit information commands systemPrintln(" ATI30 - Return myVc value"); @@ -637,6 +640,69 @@ bool commandAT(const char * commandString) systemWrite(*data++); } return true; + + case ('3'): //ATI13 - Display the random seed + systemPrint("myRandSeed: "); + systemPrintln(myRandSeed); + return true; + + case ('4'): //ATI14 - Display the channel table by channel + systemPrintln("Channel Table"); + if (!channels) + systemPrintln(" Channel table not allocated!"); + else + { + for (int index = 0; index < settings.numberOfChannels; index++) + { + systemPrint(" Channel "); + if ((index <= 9) && (settings.numberOfChannels >= 10)) + systemPrint(" "); + systemPrint(index); + systemPrint(": "); + systemPrint(channels[index],3); + systemPrintln(" MHz"); + } + } + return true; + + case ('5'): //ATI14 - Display the channel table by frequency + systemPrintln("Channel Table by Frequency"); + if (!channels) + systemPrintln(" Channel table not allocated!"); + else + { + //Initialize the channel array + uint8_t chanIndex[settings.numberOfChannels]; + for (int index = 0; index < settings.numberOfChannels; index++) + chanIndex[index] = index; + + //Sort the channel numbers by frequency + for (int index = 0; index < (settings.numberOfChannels - 1); index++) + { + for (int x = index + 1; x < settings.numberOfChannels; x++) + { + if (channels[chanIndex[index]] > channels[chanIndex[x]]) + { + uint8_t f = chanIndex[index]; + chanIndex[index] = chanIndex[x]; + chanIndex[x] = f; + } + } + } + + //Display the frequencies + for (int index = 0; index < settings.numberOfChannels; index++) + { + systemPrint(" Channel "); + if ((chanIndex[index] <= 9) && (settings.numberOfChannels >= 10)) + systemPrint(" "); + systemPrint(chanIndex[index]); + systemPrint(": "); + systemPrint(channels[chanIndex[index]],3); + systemPrintln(" MHz"); + } + } + return true; } } if ((commandString[2] == 'I') && (commandString[3] == '3') && (commandLength == 5)) diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index 82561953..4f688231 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -152,6 +152,9 @@ float *channels; uint8_t channelNumber = 0; uint32_t airSpeed; +uint16_t myRandSeed; +bool myRandBit; + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //Encryption diff --git a/Firmware/LoRaSerial/Radio.ino b/Firmware/LoRaSerial/Radio.ino index 39ac2f80..7b24cb57 100644 --- a/Firmware/LoRaSerial/Radio.ino +++ b/Firmware/LoRaSerial/Radio.ino @@ -482,9 +482,6 @@ uint16_t calcMaxThroughput() return (mostBytesPerSecond); } -uint16_t myRandSeed; -bool myRandBit; - //Generate unique hop table based on radio settings void generateHopTable() { From 62699e7726589043d2afbef56828ee7294be4654 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sat, 1 Apr 2023 15:23:26 -1000 Subject: [PATCH 2/5] VCT: Validate the srcVC before indexing the virtualCircuitList --- Firmware/Tools/VcServerTest.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Firmware/Tools/VcServerTest.c b/Firmware/Tools/VcServerTest.c index b0c62a30..4c93f5df 100644 --- a/Firmware/Tools/VcServerTest.c +++ b/Firmware/Tools/VcServerTest.c @@ -686,8 +686,27 @@ void radioCommandComplete(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uin //The command processor is still running commandProcessorRunning = STALL_CHECK_COUNT; - //Done with this command + //Validate the srcVc srcVc = header->radio.srcVc; + if (srcVc >= PC_REMOTE_COMMAND) + { + if (srcVc < (uint8_t)VC_RSVD_SPECIAL_VCS) + srcVc &= VCAB_NUMBER_MASK; + else + switch(srcVc) + { + default: + fprintf(stderr, "ERROR: Unknown VC: %d (0x%02x)\n", srcVc, srcVc); + exit(-2); + break; + + //Ignore this command + case (uint8_t)VC_UNASSIGNED: + return; + } + } + + //Done with this command if (srcVc == myVc) { if (pcActiveCommand < CMD_LIST_SIZE) From a807ee4dc9fd2e871d7bb96db5118365fcbec192 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sun, 2 Apr 2023 08:31:05 -1000 Subject: [PATCH 3/5] Enable updates to settings.rtsOnBytes to enable RTS --- Firmware/LoRaSerial/Serial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/LoRaSerial/Serial.ino b/Firmware/LoRaSerial/Serial.ino index 7b1f7e55..ef5392e5 100644 --- a/Firmware/LoRaSerial/Serial.ino +++ b/Firmware/LoRaSerial/Serial.ino @@ -302,7 +302,7 @@ void updateSerial() //Assert RTS when there is enough space in the receive buffer if ((!rtsAsserted) && (availableRXBytes() < (sizeof(serialReceiveBuffer) / 2)) - && (availableTXBytes() <= RTS_ON_BYTES)) + && (availableTXBytes() <= settings.rtsOnBytes)) updateRTS(true); //We're ready for more data //Attempt to empty the serialTransmitBuffer From 93fb71f8bd5187b1ea56a091abc25f62a59cfdb2 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sun, 2 Apr 2023 10:18:50 -1000 Subject: [PATCH 4/5] VC: Add ATI33 command to display the VC states --- Firmware/LoRaSerial/Commands.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index 4fbe5e01..80495997 100644 --- a/Firmware/LoRaSerial/Commands.ino +++ b/Firmware/LoRaSerial/Commands.ino @@ -234,6 +234,7 @@ bool commandAT(const char * commandString) systemPrintln(" ATI30 - Return myVc value"); systemPrintln(" ATI31 - Display the VC details"); systemPrintln(" ATI32 - Dump the NVM unique ID table"); + systemPrintln(" ATI33 - Display the VC states"); return true; case ('0'): //ATI0 - Show user settable parameters @@ -835,6 +836,17 @@ bool commandAT(const char * commandString) systemPrintln("Empty"); } return true; + + case ('3'): //ATI33 - Display the VC states + for (int vcIndex = 0; vcIndex < MAX_VC; vcIndex++) + { + systemPrint("VC "); + systemPrint(vcIndex); + systemPrint(": "); + systemPrintln(vcStateNames[virtualCircuitList[vcIndex].vcState]); + } + return true; + } } if ((commandString[2] == 'I') && (commandString[3] == '5') && (commandLength == 5)) From 24b95714cb225137fef07b9d440ca82de7cede27 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Sun, 2 Apr 2023 11:44:22 -1000 Subject: [PATCH 5/5] VCT: Add DEBUG_CMD_ISSUE to display issued commands --- Firmware/Tools/VcServerTest.c | 61 +++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/Firmware/Tools/VcServerTest.c b/Firmware/Tools/VcServerTest.c index 4c93f5df..7467c575 100644 --- a/Firmware/Tools/VcServerTest.c +++ b/Firmware/Tools/VcServerTest.c @@ -30,6 +30,7 @@ #define SET_PROGRAM_COMPLETE "ati12" #define START_3_WAY_HANDSHAKE "atc" +#define DEBUG_CMD_ISSUE 0 #define DEBUG_LOCAL_COMMANDS 0 #define DEBUG_PC_CMD_ISSUE 0 #define DEBUG_PC_TO_RADIO 0 @@ -64,28 +65,54 @@ { \ if (COMMAND_PENDING(queue, active)) \ { \ + if (DEBUG_CMD_ISSUE) \ + { \ + if (queue == pcCommandQueue) \ + printf("PC %s done\n", commandName[active]); \ + else \ + { \ + int vc = (&queue[0] - &virtualCircuitList[0].commandQueue[0]) \ + * sizeof(QUEUE_T) / sizeof(virtualCircuitList[0]); \ + printf("VC %d %s done\n", vc, commandName[active]); \ + } \ + } \ queue[active / QUEUE_T_BITS] &= ~(1 << (active & QUEUE_T_MASK)); \ active = CMD_LIST_SIZE; \ } \ } -#define COMMAND_ISSUE(queue, pollCount, cmd) \ -{ \ - /* Place the command in the queue */ \ - queue[cmd / QUEUE_T_BITS] |= 1 << (cmd & QUEUE_T_MASK); \ - \ - /* Timeout the command processor */ \ - if (!commandProcessorRunning) \ - commandProcessorRunning = STALL_CHECK_COUNT; \ - \ - /* Remember when this command was issued */ \ - if (!pollCount) \ - { \ - if (timeoutCount) \ - pollCount = timeoutCount; \ - else \ - pollCount = 1; \ - } \ +#define COMMAND_ISSUE(queue, pollCount, cmd) \ +{ \ + if (DEBUG_CMD_ISSUE) \ + { \ + if (!COMMAND_PENDING(queue, cmd)) \ + { \ + if (queue == pcCommandQueue) \ + printf("PC %s issued\n", commandName[cmd]); \ + else \ + { \ + int vc = (&queue[0] - &virtualCircuitList[0].commandQueue[0]) \ + * sizeof(QUEUE_T) / sizeof(virtualCircuitList[0]); \ + printf("VC %d %s issued\n", vc, commandName[cmd]); \ + } \ + } \ + } \ + \ + /* Place the command in the queue */ \ + queue[cmd / QUEUE_T_BITS] |= 1 << (cmd & QUEUE_T_MASK); \ + \ + /* Timeout the command processor */ \ + if (!commandProcessorRunning) \ + commandProcessorRunning = STALL_CHECK_COUNT; \ + \ + /* Remember when this command was issued */ \ + if (!pollCount) \ + { \ + if (timeoutCount) \ + pollCount = timeoutCount; \ + else \ + pollCount = 1; \ + } \ } #define COMMAND_PENDING(queue,cmd) ((queue[cmd / QUEUE_T_BITS] >> (cmd & QUEUE_T_MASK)) & 1)