Przeglądaj źródła

Ensure ETX byte is preceded by a DLE byte when using the ETX as an end of packet marker

master
The6P4C 7 lat temu
rodzic
commit
71682decf0
1 zmienionych plików z 2 dodań i 3 usunięć
  1. +2
    -3
      ThunderboltTimeSync/ThunderboltSerialPort.cs

+ 2
- 3
ThunderboltTimeSync/ThunderboltSerialPort.cs Wyświetl plik

@@ -86,8 +86,6 @@ namespace ThunderboltTimeSync {


bool inStuffedDLE = false; bool inStuffedDLE = false;
foreach (byte b in data) { foreach (byte b in data) {
Debug.WriteLine(string.Format("{0:X2}", b));

if (b == CHAR_DLE) { if (b == CHAR_DLE) {
if (!inStuffedDLE) { if (!inStuffedDLE) {
newData.Add(b); newData.Add(b);
@@ -141,7 +139,8 @@ namespace ThunderboltTimeSync {


// Check buffer length to ensure we've reached a plausible end of packet. // Check buffer length to ensure we've reached a plausible end of packet.
// 5 bytes is [DLE]<id><1 byte of data>[DLE][ETX] // 5 bytes is [DLE]<id><1 byte of data>[DLE][ETX]
if (currentByte == CHAR_ETX && packetBuffer.Count >= 5) {
// Must check if previous character is a [DLE], otherwise an ETX with a malformed and unstuffed [DLE] will cause issues
if (currentByte == CHAR_ETX && packetBuffer.Count >= 5 && packetBuffer[packetBuffer.Count - 2] == CHAR_DLE) {
int numberOfPrecedingDLEs = 0; int numberOfPrecedingDLEs = 0;


// Count number of DLEs, excluding the first two bytes (initial DLE and id) // Count number of DLEs, excluding the first two bytes (initial DLE and id)


Ładowanie…
Anuluj
Zapisz