Skip to content

Commit 63fedee

Browse files
committed
MP: Discovery is also syncing the clock upon receiving HEARTBEAT frames
The MP_HEARTBEAT frame did not include the millis field. Add the millis field to the MP_HEARTBEAT frame to enable the clock to properly synchronize. Prior to adding this field the synchronization would be random and typically larger than 40 mSec. With the millis value in the HEARTBEAT frame the clock synchronization drops to less than 2 mSec. Testing was done by modifying the discovery code to save the millis value when the code transitioned to the RADIO_MP_STANDBY state. In the RADIO_MP_STANDBY if the client had run more than 5 seconds then it would change states to RADIO_DISCOVER_BEGIN. A five minute log was captured and the following clock synchronization offsets were recorded: 759 uSec - from HEARTBEAT frame 431 uSec - from HEARTBEAT frame 405 uSec - from HEARTBEAT frame 240 uSec - from HEARTBEAT frame 258 uSec - from HEARTBEAT frame 79 uSec - from HEARTBEAT frame 145 uSec - from HEARTBEAT frame 663 uSec - from HEARTBEAT frame 131 uSec - from HEARTBEAT frame 370 uSec - from HEARTBEAT frame 410 uSec - from HEARTBEAT frame 438 uSec - from HEARTBEAT frame 344 uSec - from HEARTBEAT frame 564 uSec - from HEARTBEAT frame 668 uSec - from HEARTBEAT frame The scope was setup to record 10 GSamples at 1 MHz. D0 and D2 are connected to the server and D1 and D3 are connected to the client. The trigger parameters were: triggerWidth = 10; triggerWidthIsMultiplier = true; triggerEnable = 127; TRIGGER_TRANSACTION_COMPLETE, //14 TRIGGER_CHANNEL_TIMER_ISR, //24 TRIGGER_RX_SYNC_CLOCKS, //34 TRIGGER_TX_SYNC_CLOCKS, //44 TRIGGER_RX_HEARTBEAT, //54 TRIGGER_TX_HEARTBEAT, //64 TRIGGER_SYNC_CHANNEL_TIMER, //74
1 parent 793e699 commit 63fedee

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Firmware/LoRaSerial/LoRaSerial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const int FIRMWARE_VERSION_MINOR = 0;
6464
#define UNIQUE_ID_BYTES 16 //Number of bytes in the unique ID
6565

6666
//Frame lengths
67-
#define MP_HEARTBEAT_BYTES 1 //Number of data bytes in the MP_HEARTBEAT frame
67+
#define MP_HEARTBEAT_BYTES (sizeof(uint8_t) + sizeof(unsigned long)) //Number of data bytes in the MP_HEARTBEAT frame
6868
#define P2P_FIND_PARTNER_BYTES sizeof(unsigned long) //Number of data bytes in the FIND_PARTNER frame
6969
#define P2P_SYNC_CLOCKS_BYTES (sizeof(uint8_t) + sizeof(unsigned long)) //Number of data bytes in the SYNC_CLOCKS frame
7070
#define P2P_ZERO_ACKS_BYTES sizeof(unsigned long) //Number of data bytes in the ZERO_ACKS frame

Firmware/LoRaSerial/Radio.ino

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,7 @@ bool xmitDatagramP2PSyncClocks()
931931
radioCallHistory[RADIO_CALL_xmitDatagramP2PSyncClocks] = currentMillis;
932932

933933
startOfData = endOfTxData;
934-
memcpy(endOfTxData, &channelNumber, sizeof(channelNumber));
935-
endOfTxData += sizeof(channelNumber);
934+
*endOfTxData++ = channelNumber;
936935

937936
memcpy(endOfTxData, &currentMillis, sizeof(currentMillis));
938937
endOfTxData += sizeof(unsigned long);
@@ -1149,18 +1148,20 @@ bool xmitDatagramMpHeartbeat()
11491148
radioCallHistory[RADIO_CALL_xmitDatagramMpHeartbeat] = millis();
11501149

11511150
startOfData = endOfTxData;
1152-
memcpy(endOfTxData, &channelNumber, sizeof(channelNumber));
1153-
endOfTxData += sizeof(channelNumber);
1151+
*endOfTxData++ = channelNumber;
1152+
1153+
memcpy(endOfTxData, &currentMillis, sizeof(currentMillis));
1154+
endOfTxData += sizeof(unsigned long);
11541155

11551156
/*
1156-
endOfTxData ---.
1157-
|
1158-
V
1159-
+----------+---------+----------+------------+---------+----------+
1160-
| Optional | | Optional | Optional | Channel | |
1161-
| NET ID | Control | C-Timer | SF6 Length | Number | Trailer |
1162-
| 8 bits | 8 bits | 2 bytes | 8 bits | 1 byte | n Bytes |
1163-
+----------+---------+----------+------------+---------+----------+
1157+
endOfTxData ---.
1158+
|
1159+
V
1160+
+----------+---------+----------+------------+---------+---------+----------+
1161+
| Optional | | Optional | Optional | Channel | | |
1162+
| NET ID | Control | C-Timer | SF6 Length | Number | Millis | Trailer |
1163+
| 8 bits | 8 bits | 2 bytes | 8 bits | 1 byte | 4 bytes | n Bytes |
1164+
+----------+---------+----------+------------+---------+---------+----------+
11641165
*/
11651166

11661167
//Verify the data length

Firmware/LoRaSerial/States.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,6 @@ void updateRadioState()
13051305
startChannelTimer();
13061306
channelTimerStart -= settings.maxDwellTime;
13071307
syncChannelTimer(txSyncClocksUsec);
1308-
triggerEvent(TRIGGER_RX_SYNC_CLOCKS);
13091308

13101309
if (settings.debugSync)
13111310
{

0 commit comments

Comments
 (0)