Skip to content
Merged
27 changes: 27 additions & 0 deletions Firmware/LoRaSerial/Commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ bool commandAT(const char * commandString)
systemPrintln(" ATI8 - Display system unique ID");
systemPrintln(" ATI9 - Display the maximum datagram size");
systemPrintln(" ATI10 - Display radio metrics");
systemPrintln(" ATI11 - Display the system runtime");

//Virtual circuit information commands
systemPrintln(" ATI30 - Return myVc value");
Expand Down Expand Up @@ -601,6 +602,32 @@ bool commandAT(const char * commandString)
systemPrintln(" State History");
displayRadioStateHistory();
return true;

case ('1'): //ATI11 - Display the system runtime
systemPrint("Runtime: ");
systemPrintU64(runtime.u64);
systemPrint(", Programmed: ");
systemPrintU64(programmed);
systemPrintln();
if (settings.operatingMode == MODE_VIRTUAL_CIRCUIT)
{
VC_RUNTIME_MESSAGE msg;
uint8_t * data;

//Build the runtime message
memcpy(&msg.runtime, &runtime.u64, sizeof(msg.runtime));
memcpy(&msg.programmed, &programmed, sizeof(msg.programmed));

//Send the message
systemWrite(START_OF_VC_SERIAL); //Start byte
systemWrite(3 + sizeof(VC_RUNTIME_MESSAGE)); //Length
systemWrite(PC_RUNTIME); //Destination
systemWrite(myVc); //Source
data = (uint8_t *)&msg;
for (int index = 0; index < sizeof(msg); index++)
systemWrite(*data++);
}
return true;
}
}
if ((commandString[2] == 'I') && (commandString[3] == '3') && (commandLength == 5))
Expand Down
12 changes: 12 additions & 0 deletions Firmware/LoRaSerial/LoRaSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ Settings tempSettings; //Temporary settings used for command processing
Settings trainingSettings; //Settings used for training other radios

char platformPrefix[25]; //Used for printing platform specific device name, ie "SAMD21 1W 915MHz"
union {
uint32_t u32[2];
uint64_t u64;
} runtime; //Amount of time the system has been running in milliseconds
uint64_t programmed; //Time the system was programmed in milliseconds

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

/*
Expand Down Expand Up @@ -660,6 +666,12 @@ void loop()
{
petWDT();

//Update the runtime
uint32_t currentMillis = millis();
if (currentMillis < runtime.u32[0])
runtime.u32[1] += 1;
runtime.u32[0] = currentMillis;

updateButton(); //Check if train button is pressed

updateSerial(); //Store incoming and print outgoing
Expand Down
8 changes: 8 additions & 0 deletions Firmware/LoRaSerial/System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ void systemPrint(int value)
systemPrint(temp);
}

//Print an integer value
void systemPrintU64(uint64_t value)
{
char temp[20 + 1];
sprintf(temp, "%ld", value);
systemPrint(temp);
}

//Print an integer value as HEX or decimal
void systemPrint(int value, uint8_t printType)
{
Expand Down
27 changes: 17 additions & 10 deletions Firmware/LoRaSerial/Virtual_Circuit_Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
//Address space 7 is reserved for the following special addresses:

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

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

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

typedef struct _VC_RUNTIME_MESSAGE
{
uint64_t runtime; //Time the system has been running in milliseconds
uint64_t programmed; //Time the system was programmed in milliseconds
} VC_RUNTIME_MESSAGE;

//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
Expand Down
Loading