spacepacket 0.1.2

A CCSDS compliant spacepacket en/de-coder with CRC and Sink/Stream support.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
//! Implementation of the Telemetry Frame (TM) as defined in CCSDS 132.0-B-3

use std::io::{Error, ErrorKind, Read};

use byteorder::{BigEndian, ReadBytesExt};
#[cfg(feature = "crc")]
use crc::Crc;

use crate::GroupingFlag;

use crate::tctm::randomizer::{apply_randomization, Randomization};

/// Randomization Schemes for TM Transfer Frames as defined CCSDS in 131.0-B-5
#[derive(Debug, Clone, Copy)]
pub enum TMRandomization {
    /// No randomization is applied to the TM Frame
    None,
    /// 255 Bit repeating randomization with polynomial h(x) = x^8 + x^7 + x^5 + x^3 + 1
    Tm255,
    /// 131071 Bit repeating randomization with polynomial h(x) = x^17 + x^14 + 1
    Tm131071,
}

// apply randomization to bytestream

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Flag to indicate if the associated field is present in a TM Tranfser Frame.
pub enum BooleanFieldFlag {
    NotPresent = 0,
    Present = 1,
}
impl BooleanFieldFlag {
    pub fn from_u8(val: u8) -> Result<Self, Error> {
        match val {
            0 => Ok(Self::NotPresent),
            1 => Ok(Self::Present),
            val => Err(Error::new(
                ErrorKind::InvalidData,
                format!("Invalid BooleanFieldFlag value {val:}. Can only be 1 bit."),
            )),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Flag to identify type type of data in the TM Transfer Frame Data Field.
pub enum SynchronizationFlag {
    /// Indicates the presence of octet-synchronized and forward-ordered
    /// Packets or Idle Data
    Nominal = 0,
    /// Indicates the presence of Virtual Channel Access Service Data Unit (VCA_SDU)
    /// in the data field
    VcaSdu = 1,
}
impl SynchronizationFlag {
    pub fn from_u8(val: u8) -> Result<Self, Error> {
        match val {
            0 => Ok(Self::Nominal),
            1 => Ok(Self::VcaSdu),
            val => Err(Error::new(
                ErrorKind::InvalidData,
                format!("Invalid SynchronizationFlag value {val:}. Can only be 1 bit."),
            )),
        }
    }
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// When the [TMDataFieldStatus::synchronization_flag] is set to [SynchronizationFlag::VcaSdu]
/// this field is undefined.
pub enum SegmentLength {
    /// This flag has no meaning when synchronization is set to [SynchronizationFlag::VcaSdu]
    Undefined(u8),
    /// Value is fixed to `0b11` to align with non-use of Source Packet Segments in previous standards.
    /// when synchronization is set to [SynchronizationFlag::Nominal]
    Unsegmented = 0b11,
}
impl SegmentLength {
    pub fn from_u8(value: u8) -> Result<Self, Error> {
        match value {
            val if val < 0b11 => Ok(Self::Undefined(val)),
            0b11 => Ok(Self::Unsegmented),
            val => Err(Error::new(
                ErrorKind::InvalidData,
                format!("SegmentLength can must be less than 4, found {val}"),
            )),
        }
    }

    pub fn into_u8(self) -> u8 {
        match self {
            SegmentLength::Undefined(val) => val & 0x3,
            SegmentLength::Unsegmented => 0b11,
        }
    }
}

#[repr(u16)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FirstHeaderPointer {
    /// Index of  the first header must be less than 2046
    ByteIndex(u16),
    /// This packet contains only IDLE data
    OnlyIdleData = 0b111_1111_1110,
    /// This frame is entirely a continuation of a previous packet
    /// No new packet header starts inside of this frame.
    NoPacketStart = 0b111_1111_1111,
}
impl FirstHeaderPointer {
    pub fn into_u16(self) -> u16 {
        match self {
            FirstHeaderPointer::ByteIndex(value) => value & 0x7ff,
            FirstHeaderPointer::OnlyIdleData => 0b111_1111_1110,
            FirstHeaderPointer::NoPacketStart => 0b111_1111_1111,
        }
    }

    pub fn from_u16(value: u16) -> Result<Self, Error> {
        match value {
            val if val < 2046 => Ok(Self::ByteIndex(val)),
            0b111_1111_1110 => Ok(Self::OnlyIdleData),
            0b111_1111_1111 => Ok(Self::NoPacketStart),
            val => Err(Error::new(
                ErrorKind::InvalidData,
                format!(
                    "Invalid FristHeaderPointer value. \
                    Value must be less than 2048 but received {val}."
                ),
            )),
        }
    }

    pub fn validate(&self) -> Result<(), Error> {
        match self {
            Self::ByteIndex(index) => {
                if index < &2046_u16 {
                    Ok(())
                } else {
                    Err(Error::new(
                        ErrorKind::InvalidData,
                        format!("First Header byte index must be less than 2046 found {index}"),
                    ))
                }
            }
            Self::OnlyIdleData => Ok(()),
            Self::NoPacketStart => Ok(()),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Data Field status is a 16-bit value of meta-data flags
/// used to identify how to decode the Data Field
pub struct TMDataFieldStatus {
    /// Indicated if a seconday header is attached to this TM Transfer Field
    pub secondary_header_flag: BooleanFieldFlag,

    /// Flag state is used to discern the type of data in the TM Data Field.
    pub synchronization_flag: SynchronizationFlag,

    /// as Defined in  CCSDS 132.0-B-3: If the Synchronization Flag is set to ‘0’,
    /// the Packet Order Flag is reserved for future use by the CCSDS and is set to ‘0’.
    /// If the Synchronization Flag is set to [SynchronizationFlag::VcaSdu], the
    /// use of the Packet Order Flag is undefined.
    pub packet_order: bool,

    /// When [Self::synchronization_flag] is [SynchronizationFlag::Nominal]
    /// this flag is set to a fixed value [GroupingFlag::Unsegm] to align with a previous standard version
    /// which allowed for segemneted Packets.
    ///
    /// When [Self::synchronization_flag] is [SynchronizationFlag::VcaSdu]
    /// this flag is undefined.
    pub segment_length: GroupingFlag,

    /// Identifies the byte offset of the start of the next packet inside
    /// the data field
    pub first_header_pointer: FirstHeaderPointer,
}
impl TMDataFieldStatus {
    /// Validate Data Field status values
    ///
    /// # Errors
    ///
    /// This function errors under the following circumstances
    ///  - [Self::first_header_pointer] is of type [FirstHeaderPointer::ByteIndex]  with index > 2046
    pub fn validate(&self) -> Result<(), Error> {
        self.first_header_pointer.validate()
    }

    /// Encode into a byte stream
    pub fn encode(self) -> Vec<u8> {
        let Self {
            secondary_header_flag,
            synchronization_flag,
            packet_order,
            segment_length,
            first_header_pointer,
        } = self;

        let word = ((secondary_header_flag as u16) << 15)
            | ((synchronization_flag as u16) << 14)
            | ((packet_order as u16) << 13)
            | ((segment_length as u16) << 11)
            | first_header_pointer.into_u16();

        word.to_be_bytes().to_vec()
    }

    /// Decode the Status field from a byte stream
    pub fn decode<R: Read>(buffer: &mut R) -> Result<Self, Error> {
        let first_word = buffer.read_u16::<BigEndian>()?;

        Ok(Self {
            secondary_header_flag: BooleanFieldFlag::from_u8((first_word >> 15) as u8 & 0x1_u8)?,
            synchronization_flag: SynchronizationFlag::from_u8((first_word >> 14) as u8 & 0x1_u8)?,
            packet_order: (first_word >> 13) & 0x1 == 1,
            segment_length: GroupingFlag::from_2bits((first_word >> 11) as u8 & 0x3),
            first_header_pointer: FirstHeaderPointer::from_u16(first_word & 0x7FF_u16)?,
        })
    }
}

/// Primary Header for a TM transfer Frame.
/// This header is meant to be with a [TMTransferFrame]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TMPrimaryHeader {
    /// Transfer Frame Version number.
    /// Currently fixed to '00'
    /// Encoded in 2 bits
    pub tfvn: u8,

    /// 10-bit unique identifier for the spacecraft
    pub scid: u16,

    /// The identifier of the virtual channel to which this
    /// packet belongs. 6-bits maximum.
    pub vcid: u8,

    /// Flag to identify whether the Operational Control Field
    /// is present or not in the TM Transfer Frame.
    pub ocf_flag: BooleanFieldFlag,

    /// Sequence count (modulo 256) of frames in the master channel.
    pub mc_frame_count: u8,

    /// Sequence coutn (modulo 256) of frames in the virtual channel.
    pub vc_frame_count: u8,

    /// Metadata about the Transfer Frame Data Field used to decode underlying packets.
    pub data_field_status: TMDataFieldStatus,
}
impl TMPrimaryHeader {
    /// Validate header values which require bit masks will fit in the
    /// desginate bit-depth
    ///
    /// # Errors
    ///
    /// This function errors under the following circumstances
    ///  - [Self::tfvn] > 3
    ///  - [Self::scid] > 1023
    ///  - [Self::vcid] > 7
    pub fn validate(&self) -> Result<(), Error> {
        if self.tfvn > 3 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!(
                    "Transfer frame version number must be <=3 but found {}",
                    self.tfvn
                ),
            ));
        }

        if self.scid > 1023 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!("Spacecraft ID must be <=1023 but found {}", self.scid),
            ));
        }

        if self.vcid > 7 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!("Virtual Channel ID must be <=7 but found {}", self.vcid),
            ));
        }

        self.data_field_status.validate()?;

        Ok(())
    }

    /// Encode self into a byte steam
    pub fn encode(self) -> Vec<u8> {
        let Self {
            tfvn,
            scid,
            vcid,
            ocf_flag,
            mc_frame_count,
            vc_frame_count,
            data_field_status,
        } = self;

        let first_word = {
            ((tfvn as u16 & 0x3_u16) << 14)
                | ((scid & 0x3ff_u16) << 4)
                | ((vcid as u16 & 0x7_u16) << 1)
                | ocf_flag as u16
        };

        let mut message = first_word.to_be_bytes().to_vec();

        message.push(mc_frame_count);
        message.push(vc_frame_count);
        message.extend_from_slice(&data_field_status.encode());

        message
    }

    /// Decode from a byte steam
    pub fn decode<R: Read>(buffer: &mut R) -> Result<Self, Error> {
        let first_word = buffer.read_u16::<BigEndian>()?;

        Ok(Self {
            tfvn: (first_word >> 14) as u8 & 0x3_u8,
            scid: (first_word >> 4) & 0x3ff_u16,
            vcid: (first_word >> 1) as u8 & 0x7_u8,
            ocf_flag: BooleanFieldFlag::from_u8((first_word & 0x1_u16) as u8)?,
            mc_frame_count: buffer.read_u8()?,
            vc_frame_count: buffer.read_u8()?,
            data_field_status: TMDataFieldStatus::decode(buffer)?,
        })
    }
}

/// A flexible Platform for the Secondary Header in a TM Transfer Frame.
/// This secondary header computes the length of the Secondary Header Payload
/// at en/de-coding time, as such it should only be used along with a [TMTransferFrame]
/// to ensure correctness.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TMSecondaryHeader {
    /// The version number of the secondary header
    /// CCSDS 132.0-B-3 recognizes only one version, which is
    /// Version 1, the binary encoded Version Number of which is ‘00’.
    pub tfvn: u8,

    /// The data Field of the secondary header contains mission specific
    /// information. Maximum length is 63 bytes.
    pub data_field: Vec<u8>,
}
impl TMSecondaryHeader {
    /// Validate header values which require bit masks will fit in the
    /// desginate bit-depth.
    ///
    /// Errors:
    ///  - if [Self::tfvn] > 3
    ///  - if [Self::data_field] has length > 63
    pub fn validate(&self) -> Result<(), Error> {
        if self.tfvn > 3 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!(
                    "Transfer frame version number must be <=3 but found {}",
                    self.tfvn
                ),
            ));
        }

        if self.data_field.len() > 63 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!(
                    "Secondary Header data field must have length <=63. Found {}",
                    self.data_field.len()
                ),
            ));
        }

        Ok(())
    }

    /// Encode to a byte steam
    pub fn encode(self) -> Vec<u8> {
        let Self {
            tfvn,
            mut data_field,
        } = self;

        // the secondary header is 1 byte
        // and the encoded length is total length -1
        // so we need to take len() +1 -1 or just len
        let packet_len = (data_field.len()) as u8;
        let mut message = vec![{ ((tfvn & 0x3_u8) << 6) | packet_len }];
        message.append(&mut data_field);
        message
    }

    /// Decode from a byte steam
    pub fn decode<R: Read>(buffer: &mut R) -> Result<Self, Error> {
        let first_byte = buffer.read_u8()?;

        // the length field is total length -1, add 1 to get the length of the header too
        // then subtract again to get length of the data array
        let data_len = (first_byte & 0x3f) as usize;
        Ok(Self {
            tfvn: (first_byte >> 6) & 0x3,
            data_field: {
                let mut tmp = vec![0; data_len];
                buffer.read_exact(&mut tmp)?;
                tmp
            },
        })
    }
}

/// A Telemetry (TM) Transfer Frame used in telemetry downlink defined in  CCSDS 132.0-B-3
/// Operational Control Field and Frame Error Control Field are not automatically
/// decoded and are left in the data_field of this structure.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TMTransferFrame {
    /// TM primary header meta-data
    pub primary_header: TMPrimaryHeader,

    /// The Data Field of telemetry values. May have a [TMSecondaryHeader]
    /// at the beginning. This is indicated by the presence of [TMDataFieldStatus::secondary_header_flag]
    ///
    /// The length of this field is fixed on a per physical channel basis.
    /// As such it is impossible to decode one without apriori knowledge of the
    /// length.
    pub data_field: Vec<u8>,
}
impl TMTransferFrame {
    fn _encode_helper(self) -> Vec<u8> {
        let Self {
            primary_header,
            mut data_field,
        } = self;
        let mut message = primary_header.encode();
        message.append(&mut data_field);
        message
    }
    /// Encode this packet into a byte stream
    pub fn encode(self, randomization: TMRandomization) -> Vec<u8> {
        match randomization {
            TMRandomization::None => self._encode_helper(),
            TMRandomization::Tm255 => {
                apply_randomization(self._encode_helper().as_slice(), Randomization::Tm255)
            }
            TMRandomization::Tm131071 => {
                apply_randomization(self._encode_helper().as_slice(), Randomization::Tm131071)
            }
        }
    }

    fn _decode_helper<R: Read>(
        mut buffer: R,
        length: usize,
        randomization: TMRandomization,
    ) -> Result<Vec<u8>, Error> {
        let byte_array = {
            let mut tmp = vec![0_u8; length];
            buffer.read_exact(&mut tmp)?;
            tmp
        };

        let buffer_vec = match randomization {
            TMRandomization::None => byte_array,
            TMRandomization::Tm255 => {
                apply_randomization(byte_array.as_slice(), Randomization::Tm255)
            }
            TMRandomization::Tm131071 => {
                apply_randomization(byte_array.as_slice(), Randomization::Tm131071)
            }
        };
        Ok(buffer_vec)
    }

    /// Decode a Transfer Frame from a byte stream.
    /// Frame lengths are fixed on per-mission physical channel basis.
    /// As such it is impossible to decode one without apriori knowledge of the
    /// length.
    ///
    /// The length parameter to this function is the length of the entire Frame:
    ///  - Primary Header [6-bytes]
    ///  - Secondary Header (<= 64 bytes, if present)
    ///  - Trailer (2, 4, or 6 bytes, if present)
    pub fn decode<R: Read>(
        buffer: R,
        length: usize,
        randomization: TMRandomization,
    ) -> Result<Self, Error> {
        let buffer = Self::_decode_helper(buffer, length, randomization)?;
        let mut buffer = buffer.as_slice();

        Ok(Self {
            primary_header: TMPrimaryHeader::decode(&mut buffer)?,
            data_field: {
                let mut tmp = vec![0_u8; length - 6];
                buffer.read_exact(&mut tmp)?;
                tmp
            },
        })
    }

    #[cfg(feature = "crc")]
    #[cfg_attr(docsrs, doc(cfg(feature = "crc")))]
    /// Encode the TM Tansfer Frame and append a CRC-16 value using the provied [Crc].
    pub fn encode_crc(self, crc: &Crc<u16>, randomization: TMRandomization) -> Vec<u8> {
        let mut message = self._encode_helper();
        message.extend(crc.checksum(message.as_slice()).to_be_bytes());
        match randomization {
            TMRandomization::None => message,
            TMRandomization::Tm255 => apply_randomization(message.as_slice(), Randomization::Tm255),
            TMRandomization::Tm131071 => {
                apply_randomization(message.as_slice(), Randomization::Tm131071)
            }
        }
    }

    #[cfg(feature = "crc")]
    #[cfg_attr(docsrs, doc(cfg(feature = "crc")))]
    /// Decode a CCSDS packet with an appended a CRC-16 value using the provied [Crc].
    /// This method assumes the length of the CRC should be **included** in the payload length of the Transfer Frame.
    /// The crc is stripped from the byte stream and not included in the returned packet.
    /// Error if the packet's CRC is not valid.
    pub fn decode_crc<R: Read>(
        buffer: &mut R,
        length: usize,
        randomization: TMRandomization,
        crc: &Crc<u16>,
    ) -> Result<Self, Error> {
        let buffer = Self::_decode_helper(buffer, length, randomization)?;
        let mut buffer = buffer.as_slice();
        // subtract 2 to accound for the CRC
        let mut msg_buffer = vec![0_u8; length - 2];
        buffer.read_exact(&mut msg_buffer)?;

        let attached_crc = buffer.read_u16::<BigEndian>()?;
        let computed_crc = crc.checksum(msg_buffer.as_slice());

        if computed_crc != attached_crc {
            return Err(Error::new(
                ErrorKind::InvalidData,
                format!(
                    "CRC failure on TM Transfer Frame. \
                    Exepcted {attached_crc:#04X} Computer {computed_crc:#04X}"
                ),
            ));
        }
        Ok(Self {
            primary_header: TMPrimaryHeader::decode(&mut buffer)?,
            data_field: {
                let mut tmp = vec![0_u8; length - 6];
                buffer.read_exact(&mut tmp)?;
                tmp
            },
        })
    }
}

#[cfg(test)]
mod test {
    use super::*;

    use rstest::rstest;

    #[rstest]
    #[case(0, 5, 2, 12)]
    #[case(0, 1023, 7, 2045)]
    #[should_panic]
    // tfvn out of bounds
    #[case(4, 5, 2, 2045)]
    #[should_panic]
    // scid out of bounds
    #[case(0, 1024, 5, 1023)]
    #[should_panic]
    // vcid out of bounds
    #[case(0, 7, 8, 1023)]
    #[should_panic]
    // first header index out of bounds
    #[case(0, 100, 3, 2049)]
    fn tm_header_validation(
        #[case] tfvn: u8,
        #[case] scid: u16,
        #[case] vcid: u8,
        #[case] index: u16,
    ) {
        let header = TMPrimaryHeader {
            tfvn,
            scid,
            vcid,
            ocf_flag: BooleanFieldFlag::Present,
            mc_frame_count: 7,
            vc_frame_count: 244,
            data_field_status: TMDataFieldStatus {
                secondary_header_flag: BooleanFieldFlag::NotPresent,
                synchronization_flag: SynchronizationFlag::Nominal,
                packet_order: false,
                segment_length: GroupingFlag::Unsegm,
                first_header_pointer: FirstHeaderPointer::ByteIndex(index),
            },
        };

        assert!(header.validate().is_ok())
    }

    #[rstest]
    fn tm_primary_header(
        #[values(0, 5, 1023)] scid: u16,
        #[values(0, 3, 7)] vcid: u8,
        #[values(BooleanFieldFlag::NotPresent, BooleanFieldFlag::Present)]
        ocf_flag: BooleanFieldFlag,
        #[values(BooleanFieldFlag::NotPresent, BooleanFieldFlag::Present)]
        secondary_header_flag: BooleanFieldFlag,
        #[values(SynchronizationFlag::Nominal, SynchronizationFlag::VcaSdu)]
        synchronization_flag: SynchronizationFlag,
        #[values(GroupingFlag::First, GroupingFlag::Unsegm)] segment_length: GroupingFlag,
        #[values(0, 2045, 2046, 2047)] index: u16,
    ) {
        let expected = TMPrimaryHeader {
            tfvn: 0b11,
            scid,
            vcid,
            ocf_flag,
            mc_frame_count: 77,
            vc_frame_count: 128,
            data_field_status: TMDataFieldStatus {
                secondary_header_flag,
                synchronization_flag,
                packet_order: false,
                segment_length,
                first_header_pointer: FirstHeaderPointer::from_u16(index)
                    .expect("Bad index number"),
            },
        };

        let bytes = expected.encode();

        let recovered = TMPrimaryHeader::decode(&mut bytes.as_slice())
            .expect("Unable to decode TMPrimaryHeader");

        assert_eq!(expected, recovered)
    }

    #[test]
    fn tm_compare_spacepy() {
        // test data from https://github.com/Stefan-Korner/SpacePyLibrary/blob/master/UnitTest/testData.py
        // TM_FRAME_01
        let mut input_bytes: &[u8] = &[
            0x2F, 0x61, 0x00, 0x00, 0x18, 0x00, 0x0C, 0xD2, 0xC0, 0x00, 0x00, 0x1A, 0x10, 0x03,
            0x19, 0x16, 0x92, 0x5E, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0xE4, 0x07, 0xFF, 0xC0,
            0x00, 0x04, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0xC9, 0x48, 0x01, 0x00, 0x00, 0x00, 0xBB, 0xD6,
        ];

        let expected = TMTransferFrame {
            primary_header: TMPrimaryHeader {
                tfvn: 0,
                scid: 758,
                vcid: 0,
                ocf_flag: BooleanFieldFlag::Present,
                mc_frame_count: 0,
                vc_frame_count: 0,
                data_field_status: TMDataFieldStatus {
                    secondary_header_flag: BooleanFieldFlag::NotPresent,
                    synchronization_flag: SynchronizationFlag::Nominal,
                    packet_order: false,
                    segment_length: GroupingFlag::Unsegm,
                    first_header_pointer: FirstHeaderPointer::ByteIndex(0),
                },
            },
            data_field: vec![
                0x0C, 0xD2, 0xC0, 0x00, 0x00, 0x1A, 0x10, 0x03, 0x19, 0x16, 0x92, 0x5E, 0x92, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x89, 0xE4, 0x07, 0xFF, 0xC0, 0x00, 0x04, 0x27, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC9, 0x48, 0x01, 0x00, 0x00,
                0x00, 0xBB, 0xD6,
            ],
        };

        let parsed_tm = TMTransferFrame::decode(&mut input_bytes, 1115, TMRandomization::None)
            .expect("Unable to parse TM Frame.");

        assert_eq!(expected, parsed_tm)
    }
}