Skip to content

Commit 8fac078

Browse files
committed
VC: Pass the unique ID to the PC during VC state changes
1 parent 70c0488 commit 8fac078

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Firmware/LoRaSerial/States.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,10 @@ void vcSendPcStateMessage(int8_t vcIndex, uint8_t state)
30493049
//Build the VC state message
30503050
VC_STATE_MESSAGE message;
30513051
message.vcState = state;
3052+
if (virtualCircuitList[vcIndex].flags.valid)
3053+
memcpy(&message.uniqueId[0], &virtualCircuitList[vcIndex].uniqueId[0], sizeof(message.uniqueId));
3054+
else
3055+
memset(message.uniqueId, UNIQUE_ID_ERASE_VALUE, sizeof(message.uniqueId));
30523056

30533057
//Build the message header
30543058
VC_SERIAL_MESSAGE_HEADER header;

Firmware/LoRaSerial/Virtual_Circuit_Protocol.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ typedef struct _VC_SERIAL_MESSAGE_HEADER
140140
} VC_SERIAL_MESSAGE_HEADER;
141141

142142
#define VC_SERIAL_HEADER_BYTES (sizeof(VC_SERIAL_MESSAGE_HEADER)) //Length of the serial VC header in bytes
143+
#define UNIQUE_ID_ERASE_VALUE 0xff
144+
#ifndef UNIQUE_ID_BYTES
145+
#define UNIQUE_ID_BYTES 16
146+
#endif //UNIQUE_ID_BYTES
143147

144148
typedef struct _VC_STATE_MESSAGE
145149
{
146-
uint8_t vcState; //VC state
150+
uint8_t vcState; //VC state
151+
uint8_t uniqueId[UNIQUE_ID_BYTES]; //Unique ID for the LoRaSerial radio, all 0xFF if unknown
147152
} VC_STATE_MESSAGE;
148153

149154
typedef enum

Firmware/Tools/VcServerTest.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
typedef struct _VIRTUAL_CIRCUIT
2929
{
3030
int vcState;
31+
uint8_t uniqueId[UNIQUE_ID_BYTES];
32+
bool valid;
3133
} VIRTUAL_CIRCUIT;
3234

3335
bool commandStatus;
@@ -304,6 +306,7 @@ void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t length)
304306
int newState;
305307
int previousState;
306308
int srcVc;
309+
uint8_t uniqueId[UNIQUE_ID_BYTES];
307310
VC_STATE_MESSAGE * vcMsg;
308311

309312
//Remember the previous state
@@ -315,6 +318,47 @@ void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t length)
315318
newState = vcMsg->vcState;
316319
virtualCircuitList[srcVc].vcState = newState;
317320

321+
//Save the LoRaSerial radio's unique ID
322+
//Determine if the PC's value is valid
323+
memset(uniqueId, UNIQUE_ID_ERASE_VALUE, sizeof(uniqueId));
324+
if (!virtualCircuitList[srcVc].valid)
325+
{
326+
//Determine if the radio knows the value
327+
if (memcmp(vcMsg->uniqueId, uniqueId, sizeof(uniqueId)) != 0)
328+
{
329+
//The radio knows the value, save it in the PC
330+
memcpy(virtualCircuitList[srcVc].uniqueId, vcMsg->uniqueId, sizeof(vcMsg->uniqueId));
331+
virtualCircuitList[srcVc].valid = true;
332+
333+
//Display this ID value
334+
printf("VC %d unique ID: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
335+
srcVc,
336+
vcMsg->uniqueId[0], vcMsg->uniqueId[1], vcMsg->uniqueId[2], vcMsg->uniqueId[3],
337+
vcMsg->uniqueId[4], vcMsg->uniqueId[5], vcMsg->uniqueId[6], vcMsg->uniqueId[7],
338+
vcMsg->uniqueId[8], vcMsg->uniqueId[9], vcMsg->uniqueId[10], vcMsg->uniqueId[11],
339+
vcMsg->uniqueId[12], vcMsg->uniqueId[13], vcMsg->uniqueId[14], vcMsg->uniqueId[15]);
340+
}
341+
}
342+
else
343+
{
344+
//Determine if the radio has changed for this VC
345+
if ((memcmp(vcMsg->uniqueId, virtualCircuitList[srcVc].uniqueId, sizeof(vcMsg->uniqueId)) != 0)
346+
&& (memcmp(vcMsg->uniqueId, uniqueId, sizeof(uniqueId)) != 0))
347+
{
348+
//The radio knows the value, save it in the PC
349+
memcpy(virtualCircuitList[srcVc].uniqueId, vcMsg->uniqueId, sizeof(vcMsg->uniqueId));
350+
virtualCircuitList[srcVc].valid = true;
351+
352+
//Display this ID value
353+
printf("VC %d unique ID: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
354+
srcVc,
355+
vcMsg->uniqueId[0], vcMsg->uniqueId[1], vcMsg->uniqueId[2], vcMsg->uniqueId[3],
356+
vcMsg->uniqueId[4], vcMsg->uniqueId[5], vcMsg->uniqueId[6], vcMsg->uniqueId[7],
357+
vcMsg->uniqueId[8], vcMsg->uniqueId[9], vcMsg->uniqueId[10], vcMsg->uniqueId[11],
358+
vcMsg->uniqueId[12], vcMsg->uniqueId[13], vcMsg->uniqueId[14], vcMsg->uniqueId[15]);
359+
}
360+
}
361+
318362
//Display the state if requested
319363
if (DISPLAY_STATE_TRANSITION)
320364
printf("VC%d: %s --> %s\n", srcVc, vcStateNames[previousState], vcStateNames[newState]);

0 commit comments

Comments
 (0)