Skip to content

Commit 5c76a0c

Browse files
authored
Merge pull request #539 from LeeLeahy2/ati11-runtime
Add ATI11 to display the radio runtime in milliseconds
2 parents 9671c34 + cd1e90a commit 5c76a0c

File tree

5 files changed

+98
-11
lines changed

5 files changed

+98
-11
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ bool commandAT(const char * commandString)
224224
systemPrintln(" ATI8 - Display system unique ID");
225225
systemPrintln(" ATI9 - Display the maximum datagram size");
226226
systemPrintln(" ATI10 - Display radio metrics");
227+
systemPrintln(" ATI11 - Display the system runtime");
227228

228229
//Virtual circuit information commands
229230
systemPrintln(" ATI30 - Return myVc value");
@@ -601,6 +602,32 @@ bool commandAT(const char * commandString)
601602
systemPrintln(" State History");
602603
displayRadioStateHistory();
603604
return true;
605+
606+
case ('1'): //ATI11 - Display the system runtime
607+
systemPrint("Runtime: ");
608+
systemPrintU64(runtime.u64);
609+
systemPrint(", Programmed: ");
610+
systemPrintU64(programmed);
611+
systemPrintln();
612+
if (settings.operatingMode == MODE_VIRTUAL_CIRCUIT)
613+
{
614+
VC_RUNTIME_MESSAGE msg;
615+
uint8_t * data;
616+
617+
//Build the runtime message
618+
memcpy(&msg.runtime, &runtime.u64, sizeof(msg.runtime));
619+
memcpy(&msg.programmed, &programmed, sizeof(msg.programmed));
620+
621+
//Send the message
622+
systemWrite(START_OF_VC_SERIAL); //Start byte
623+
systemWrite(3 + sizeof(VC_RUNTIME_MESSAGE)); //Length
624+
systemWrite(PC_RUNTIME); //Destination
625+
systemWrite(myVc); //Source
626+
data = (uint8_t *)&msg;
627+
for (int index = 0; index < sizeof(msg); index++)
628+
systemWrite(*data++);
629+
}
630+
return true;
604631
}
605632
}
606633
if ((commandString[2] == 'I') && (commandString[3] == '3') && (commandLength == 5))

Firmware/LoRaSerial/LoRaSerial.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ Settings tempSettings; //Temporary settings used for command processing
521521
Settings trainingSettings; //Settings used for training other radios
522522

523523
char platformPrefix[25]; //Used for printing platform specific device name, ie "SAMD21 1W 915MHz"
524+
union {
525+
uint32_t u32[2];
526+
uint64_t u64;
527+
} runtime; //Amount of time the system has been running in milliseconds
528+
uint64_t programmed; //Time the system was programmed in milliseconds
529+
524530
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
525531

526532
/*
@@ -660,6 +666,12 @@ void loop()
660666
{
661667
petWDT();
662668

669+
//Update the runtime
670+
uint32_t currentMillis = millis();
671+
if (currentMillis < runtime.u32[0])
672+
runtime.u32[1] += 1;
673+
runtime.u32[0] = currentMillis;
674+
663675
updateButton(); //Check if train button is pressed
664676

665677
updateSerial(); //Store incoming and print outgoing

Firmware/LoRaSerial/System.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ void systemPrint(int value)
2323
systemPrint(temp);
2424
}
2525

26+
//Print an integer value
27+
void systemPrintU64(uint64_t value)
28+
{
29+
char temp[20 + 1];
30+
sprintf(temp, "%ld", value);
31+
systemPrint(temp);
32+
}
33+
2634
//Print an integer value as HEX or decimal
2735
void systemPrint(int value, uint8_t printType)
2836
{

Firmware/LoRaSerial/Virtual_Circuit_Protocol.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@
3131
//Address space 7 is reserved for the following special addresses:
3232

3333
#define VC_RSVD_SPECIAL_VCS ((int8_t)(VCAB_CHANNEL_MASK << VCAB_NUMBER_BITS))
34-
#define VC_BROADCAST ((int8_t)(VC_RSVD_SPECIAL_VCS | VCAB_NUMBER_MASK))
35-
#define VC_COMMAND (VC_BROADCAST - 1) //Command input and command response
36-
#define VC_UNASSIGNED (VC_COMMAND - 1)
37-
#define VC_IGNORE_TX (VC_UNASSIGNED - 1)
34+
#define VC_BROADCAST ((int8_t)(VC_RSVD_SPECIAL_VCS | VCAB_NUMBER_MASK)) //0xff
35+
#define VC_COMMAND (VC_BROADCAST - 1) //0xfe: Command input and command response
36+
#define VC_UNASSIGNED (VC_COMMAND - 1) //0xfd
37+
#define VC_IGNORE_TX (VC_UNASSIGNED - 1) //0xfc
3838

3939
//Source and destinations reserved for the local host
40-
#define PC_COMMAND VC_RSVD_SPECIAL_VCS //Command input and command response
41-
#define PC_LINK_STATUS (PC_COMMAND + 1) //Asynchronous link status output
42-
#define PC_DATA_ACK (PC_LINK_STATUS + 1)//Indicate data delivery success
43-
#define PC_DATA_NACK (PC_DATA_ACK + 1) //Indicate data delivery failure
44-
#define PC_SERIAL_RECONNECT (PC_DATA_NACK + 1) //Disconnect/reconnect the serial port over LoRaSerial CPU reset
45-
#define PC_COMMAND_COMPLETE (PC_SERIAL_RECONNECT + 1)//Command complete
40+
#define PC_COMMAND VC_RSVD_SPECIAL_VCS //0xe0: Command input and command response
41+
#define PC_LINK_STATUS (PC_COMMAND + 1) //0xe1: Asynchronous link status output
42+
#define PC_DATA_ACK (PC_LINK_STATUS + 1)//0xe2: Indicate data delivery success
43+
#define PC_DATA_NACK (PC_DATA_ACK + 1) //0xe3: Indicate data delivery failure
44+
#define PC_SERIAL_RECONNECT (PC_DATA_NACK + 1) //0xe4: Disconnect/reconnect the serial port over LoRaSerial CPU reset
45+
#define PC_COMMAND_COMPLETE (PC_SERIAL_RECONNECT + 1) //0xe5: Command complete
46+
#define PC_RUNTIME (PC_COMMAND_COMPLETE + 1) //0xe6: Radio uptime
4647

4748
//Address space 1 and 6 are reserved for the host PC interface to support remote
4849
//command processing. The radio removes these bits and converts them to the
@@ -177,6 +178,12 @@ typedef struct _VC_COMMAND_COMPLETE_MESSAGE
177178
uint8_t cmdStatus; //Command status
178179
} VC_COMMAND_COMPLETE_MESSAGE;
179180

181+
typedef struct _VC_RUNTIME_MESSAGE
182+
{
183+
uint64_t runtime; //Time the system has been running in milliseconds
184+
uint64_t programmed; //Time the system was programmed in milliseconds
185+
} VC_RUNTIME_MESSAGE;
186+
180187
//------------------------------------------------------------------------------
181188
// Macros
182189
//------------------------------------------------------------------------------

Firmware/Tools/VcServerTest.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define BREAK_LINKS_COMMAND "atb"
2222
#define GET_DEVICE_INFO "ati"
2323
#define GET_MY_VC_ADDRESS "ati30"
24+
#define GET_RUNTIME "ati11"
2425
#define GET_UNIQUE_ID "ati8"
2526
#define GET_VC_STATE "ati31"
2627
#define GET_VC_STATUS "ata"
@@ -36,6 +37,7 @@
3637
#define DISPLAY_DATA_ACK 0
3738
#define DISPLAY_DATA_NACK 1
3839
#define DISPLAY_RESOURCE_USAGE 0
40+
#define DISPLAY_RUNTIME 0
3941
#define DISPLAY_STATE_TRANSITION 0
4042
#define DISPLAY_UNKNOWN_COMMANDS 0
4143
#define DISPLAY_VC_STATE 0
@@ -106,6 +108,7 @@ typedef enum
106108
CMD_ATI31, //Get the VC state
107109
CMD_ATI_2, //Get the device type
108110
CMD_ATI8_2, //Get the radio's unique ID
111+
CMD_ATI11, //Get the runtime
109112

110113
//Last in the list
111114
CMD_LIST_SIZE
@@ -115,7 +118,7 @@ const char * const commandName[] =
115118
{
116119
"ATI30", "ATIB", "ATI", "ATI8", "ATA", "AT-CMDVC", "ATC",
117120
"WAIT_CONNECT",
118-
"AT-CMDVC_2", "ATI31", "ATI_2", "ATI8_2",
121+
"AT-CMDVC_2", "ATI31", "ATI_2", "ATI8_2", "ATI11",
119122
};
120123

121124
typedef struct _VIRTUAL_CIRCUIT
@@ -124,6 +127,8 @@ typedef struct _VIRTUAL_CIRCUIT
124127
uint32_t activeCommand;
125128
QUEUE_T commandQueue[COMMAND_QUEUE_SIZE];
126129
uint32_t commandTimer;
130+
uint64_t programmed;
131+
uint64_t runtime;
127132
uint8_t uniqueId[UNIQUE_ID_BYTES];
128133
bool valid;
129134
} VIRTUAL_CIRCUIT;
@@ -594,6 +599,9 @@ void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint
594599
COMMAND_ISSUE(virtualCircuitList[srcVc].commandQueue,
595600
virtualCircuitList[srcVc].commandTimer,
596601
CMD_ATI8_2);
602+
COMMAND_ISSUE(virtualCircuitList[srcVc].commandQueue,
603+
virtualCircuitList[srcVc].commandTimer,
604+
CMD_ATI11);
597605
}
598606
break;
599607
}
@@ -639,6 +647,23 @@ void radioDataNack(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t le
639647
virtualCircuitList[vcIndex].vcState = VC_STATE_LINK_DOWN;
640648
}
641649

650+
void radioRuntime(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
651+
{
652+
int index;
653+
int vcIndex;
654+
VC_RUNTIME_MESSAGE * vcMsg;
655+
656+
vcMsg = (VC_RUNTIME_MESSAGE *)data;
657+
vcIndex = header->radio.srcVc & VCAB_NUMBER_MASK;
658+
if (DISPLAY_RUNTIME)
659+
printf("VC %d runtime: %lld, programmed: %lld\n",
660+
vcIndex, (long long)vcMsg->runtime, (long long)vcMsg->programmed);
661+
662+
//Set the time values
663+
memcpy(&virtualCircuitList[vcIndex].runtime, &vcMsg->runtime, sizeof(vcMsg->runtime));
664+
memcpy(&virtualCircuitList[vcIndex].programmed, &vcMsg->programmed, sizeof(vcMsg->programmed));
665+
}
666+
642667
void radioCommandComplete(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
643668
{
644669
VC_COMMAND_COMPLETE_MESSAGE * vcMsg;
@@ -800,6 +825,10 @@ int radioToHost()
800825
else if (header->radio.destVc == PC_DATA_NACK)
801826
radioDataNack(header, data, length);
802827

828+
//Display radio runtime
829+
else if (header->radio.destVc == PC_RUNTIME)
830+
radioRuntime(header, data, length);
831+
803832
//Display received messages
804833
else if ((header->radio.destVc == myVc) || (header->radio.destVc == VC_BROADCAST))
805834
{
@@ -1082,6 +1111,10 @@ bool issueVcCommands(int vcIndex)
10821111
case CMD_ATI8_2:
10831112
sendVcCommand(GET_UNIQUE_ID, vcIndex);
10841113
return true;
1114+
1115+
case CMD_ATI11:
1116+
sendVcCommand(GET_RUNTIME, vcIndex);
1117+
return true;
10851118
}
10861119
}
10871120
}

0 commit comments

Comments
 (0)