Changeset 296 for PinConnection/UCommFrame.pas
- Timestamp:
- Nov 16, 2011, 7:24:09 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/UCommFrame.pas
r288 r296 8 8 Classes, UStreamHelper, Dialogs, SysUtils, 9 9 UCommPin; 10 11 const12 SpecialChar = $fe;13 ControlCodeFrameStart = $fd;14 ControlCodeFrameEnd = $fc;15 ControlCodeSpecialChar = $fb;16 TimeoutRepeatCount = 3;17 10 18 11 type … … 33 26 FrameDataPin: TCommPin; 34 27 PacketLoss: Real; 28 SpecialChar: Byte; 29 ControlCodeFrameStart: Byte; 30 ControlCodeFrameEnd: Byte; 31 ControlCodeSpecialChar: Byte; 35 32 procedure RawDataReceive(Sender: TCommPin; Stream: TStream); 36 33 procedure RawSetStatus(Sender: TCommPin; Status: Integer); 37 34 procedure FrameDataReceive(Sender: TCommPin; Stream: TStream); 38 35 procedure FrameSetStatus(Sender: TCommPin; Status: Integer); 36 function ComputeRawSize(DataStream: TStream): Integer; 39 37 constructor Create; 40 38 destructor Destroy; override; … … 56 54 FrameDataPin.OnReceive := FrameDataReceive; 57 55 PacketLoss := 0.005; 56 SpecialChar := $fe; 57 ControlCodeFrameStart := $fd; 58 ControlCodeFrameEnd := $fc; 59 ControlCodeSpecialChar := $fb; 58 60 end; 59 61 … … 99 101 RawData.WriteByte(SpecialChar); 100 102 RawData.WriteByte(ControlCodeFrameEnd); 101 //if Random >= PacketLoss then103 if Random >= PacketLoss then 102 104 RawDataPin.Send(RawData); 103 105 … … 110 112 begin 111 113 RawDataPin.Status := Status; 114 end; 115 116 function TCommFrame.ComputeRawSize(DataStream: TStream): Integer; 117 begin 118 Result := 5; // FrameStart + CRC + FrameEnd 119 DataStream.Position := 0; 120 while DataStream.Position < DataStream.Size do 121 if DataStream.ReadByte = SpecialChar then Inc(Result, 2) 122 else Inc(Result, 1); 112 123 end; 113 124 … … 170 181 Polynom: Byte = $18; 171 182 begin 183 Pom := 0; 172 184 Stream.Position := 0; 173 185 Result := 0;
Note:
See TracChangeset
for help on using the changeset viewer.