History

GSF.PhasorProtocols: Fixed issues with CFG3 parsing/generation related to proper appliction of FRAMESIZE field when spanning multiple frames.

J. Ritchie Carroll committed 5 years ago

Commit a780a471 parent 50b521c1 file · +16 −6Browse files

Unified · Split

Source/Libraries/GSF.PhasorProtocols/IEEEC37_118/ConfigurationFrame3.cs+16−6
@@ -154,7 +154,7 @@ namespace GSF.PhasorProtocols.IEEEC37_118 · 153 unmodified lines
154154 byte[] image = this.BinaryImage();
155155 int imageLength = image.Length;
156156
157− if (imageLength < MaxFrameLength)
157+ if (imageLength <= MaxFrameLength)
158158 {
159159 // Full image fits within one frame, return current image as-is
160160 yield return image;
@@ -202,14 +202,18 @@ namespace GSF.PhasorProtocols.IEEEC37_118 · 41 unmodified lines
202202
203203 if (firstFrame)
204204 {
205− byte[] frame = image.BlockCopy(0, frameSize);
205+ // Copy in FRAMESIZE for first frame (should always be 65535)
206+ BigEndian.CopyBytes((ushort)frameSize, image, 2);
206207
207208 // Initial frame already has full header, replace CONT_IDX with a value of 1
208209 // that indicates this is the first frame in a series of frames that follow:
209− Buffer.BlockCopy(BigEndian.GetBytes(continuationIndex), 0, frame, CommonFrameHeader.FixedLength, 2);
210−
210+ Buffer.BlockCopy(BigEndian.GetBytes(continuationIndex), 0, image, CommonFrameHeader.FixedLength, 2);
211+
212+ // Fix CRC of cumulative image with updated initial frame header
213+ BigEndian.CopyBytes(CalculateChecksum(image, 0, imageLength - 2), image, imageLength - 2);
214+
211215 // Return first frame
212− yield return frame;
216+ yield return image.BlockCopy(0, frameSize);
213217 }
214218 else
215219 {
@@ -217,7 +221,10 @@ namespace GSF.PhasorProtocols.IEEEC37_118 · 1 unmodified line
217221
218222 // Copy fixed header bytes into frame
219223 Buffer.BlockCopy(header, 0, frame, 0, CommonFrameHeader.FixedLength);
220−
224+
225+ // Copy FRAMESIZE into frame
226+ BigEndian.CopyBytes((ushort)frame.Length, frame, 2);
227+
221228 // Copy CONT_IDX into frame
222229 Buffer.BlockCopy(BigEndian.GetBytes(continuationIndex), 0, frame, CommonFrameHeader.FixedLength, 2);
223230
@@ -268,6 +275,9 @@ namespace GSF.PhasorProtocols.IEEEC37_118 · 44 unmodified lines
268275 length = frameImages.BinaryLength;
269276 startIndex = 0;
270277
278+ // Fix parsed binary length to be the cumulative frame image length
279+ State.ParsedBinaryLength = length;
280+
271281 // Base class will check CRC for entire image
272282 return base.ParseBinaryImage(buffer, startIndex, length);
273283 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t