2828typedef struct _VIRTUAL_CIRCUIT
2929{
3030 int vcState ;
31+ uint8_t uniqueId [UNIQUE_ID_BYTES ];
32+ bool valid ;
3133} VIRTUAL_CIRCUIT ;
3234
3335bool 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