Browse Source

Ensure greater than zero DLEs are seen before an ETX to signify the end of a packet

master
The6P4C 7 years ago
parent
commit
74f81bea9e
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      ThunderboltTimeSync/ThunderboltSerialPort.cs

+ 5
- 2
ThunderboltTimeSync/ThunderboltSerialPort.cs View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports; using System.IO.Ports;


namespace ThunderboltTimeSync { namespace ThunderboltTimeSync {
@@ -85,6 +86,8 @@ 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);
@@ -148,8 +151,8 @@ namespace ThunderboltTimeSync {
} }
} }


// Odd number of DLEs means the ETX does in fact signify the end of the packet
if (numberOfPrecedingDLEs % 2 == 1) {
// Odd number (greater than zero) of DLEs means the ETX does in fact signify the end of the packet
if (numberOfPrecedingDLEs % 2 == 1 && numberOfPrecedingDLEs > 0) {
ProcessPacket(); ProcessPacket();


packetBuffer.Clear(); packetBuffer.Clear();


Loading…
Cancel
Save