Checks format and length of the provided .fseq file
(file)
| 14 | duration_s: int |
| 15 | |
| 16 | def validate(file): |
| 17 | """Checks format and length of the provided .fseq file""" |
| 18 | magic = file.read(4) |
| 19 | start, minor, major = struct.unpack("<HBB", file.read(4)) |
| 20 | file.seek(10) |
| 21 | channel_count, frame_count, step_time = struct.unpack("<IIB", file.read(9)) |
| 22 | file.seek(20) |
| 23 | compression_type, = struct.unpack("<B", file.read(1)) |
| 24 | |
| 25 | if (magic != b'PSEQ') or (start < 24) or (frame_count < 1) or (step_time < 15): |
| 26 | raise ValidationError("Unknown file format, expected FSEQ v2.0") |
| 27 | if channel_count != 48 and channel_count != 200: |
| 28 | raise ValidationError(f"Expected 48 or 200 channels, got {channel_count}") |
| 29 | if compression_type != 0: |
| 30 | raise ValidationError("Expected file format to be V2 Uncompressed") |
| 31 | duration_s = (frame_count * step_time / 1000) |
| 32 | if duration_s > 4*60*60: |
| 33 | raise ValidationError(f"Expected total duration to be less than 4 hours, got {datetime.timedelta(seconds=duration_s)}") |
| 34 | if ((minor != 0) and (minor != 2)) or (major != 2): |
| 35 | print("") |
| 36 | print(f"WARNING: FSEQ version is {major}.{minor}. Only version 2.0 and 2.2 have been validated.") |
| 37 | print(f"If the car fails to read this file, download an older version of XLights at https://github.com/smeighan/xLights/releases") |
| 38 | print(f"Please report this message at https://github.com/teslamotors/light-show/issues") |
| 39 | print("") |
| 40 | |
| 41 | return ValidationResults(frame_count, step_time, duration_s) |
| 42 | |
| 43 | if __name__ == "__main__": |
| 44 | # Expected usage: python3 validator.py lightshow.fseq |
no test coverage detected