import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:dmc_app/transport/msp/msp_frame.dart'; /// Erwartete Bytefolgen unabhaengig (in Python, CRC8-DVB-S2 mit Poly 0xD5, /// Startwert 0) nachgerechnet - siehe Kommentare. void main() { group('crc8DvbS2', () { test('leerer Header (flags=0, function=106, size=0) ergibt 0x93', () { final header = Uint8List.fromList([0x00, 0x6A, 0x00, 0x00, 0x00]); expect(crc8DvbS2Update(0, header), 0x93); }); }); group('encodeMspV2Request', () { test('MSP_RAW_GPS (106) ohne Payload', () { final bytes = encodeMspV2Request(106); expect(bytes, Uint8List.fromList([ 0x24, 0x58, 0x3C, // '$', 'X', '<' 0x00, 0x6A, 0x00, 0x00, 0x00, // flags, fn LE, size LE 0x93, // crc ])); }); test('MSP2_INAV_STATUS (0x2000) ohne Payload', () { final bytes = encodeMspV2Request(0x2000); expect(bytes, Uint8List.fromList([ 0x24, 0x58, 0x3C, 0x00, 0x00, 0x20, 0x00, 0x00, 0x32, ])); }); test('Anfrage mit Payload', () { final bytes = encodeMspV2Request( 1, Uint8List.fromList([0xAA, 0xBB, 0xCC]), ); expect(bytes, Uint8List.fromList([ 0x24, 0x58, 0x3C, 0x00, 0x01, 0x00, 0x03, 0x00, 0xAA, 0xBB, 0xCC, 0x1A, ])); }); }); group('encodeMspV2Frame', () { test('Antwortrahmen (dir = \'>\') fuer MSP_ALTITUDE', () { // estAlt=1234cm (i32 LE), vario=-50cm/s (i16 LE), baroAlt=1200cm (i32 LE) final payload = Uint8List.fromList( [0xD2, 0x04, 0x00, 0x00, 0xCE, 0xFF, 0xB0, 0x04, 0x00, 0x00], ); final bytes = encodeMspV2Frame(MspDirection.response, 109, payload); expect( bytes, Uint8List.fromList([ 0x24, 0x58, 0x3E, 0x00, 0x6D, 0x00, 0x0A, 0x00, ...payload, 0x73, ]), ); }); }); }