From 82e529caf7998a5baa81e6e99e2fd9a9e698a7e8 Mon Sep 17 00:00:00 2001 From: Ben Dudley Date: Sat, 25 Dec 2021 13:54:01 +0000 Subject: [PATCH 1/3] Added memory usage exception to validate method --- README.md | 9 ++++++++- validator.py | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d5dd0b5..b6e4161 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,13 @@ Found 2247 frames, step time of 20 ms for a total duration of 0:00:44.940000. Used 16.45% of the available memory ``` +Errors in the sequence will be highlighted & prepended with a Validation Error message: +``` +> python3 validator.py invalidlightshow.fseq +WARNING: FSEQ file should be renamed to 'lightshow.fseq' before playing in a Tesla +VALIDATION ERROR: Expected file format to be V2 Uncompressed +``` + ## Boolean Light Channels Most lights available on the vehicle can only turn on or off instantly, which corresponds to 0% or 100% brightness of an 'Effect' in xLights. - For off, use blank space in the xLights timeline @@ -292,4 +299,4 @@ To command a closure to move in a particular manner, add an 'On' effect and adju - Vehicles without rear fog lights will not use any other light in place of rear fog lights. #### Tail lights and License Plate Lights -- On Model 3 built before October 2020: left tail, right tail, and license plate lights operate together. They will activate during ```(Left tail || Right tail)``` requests from xLights - note that the license plate lights xLights channel will have no effect on these vehicles. \ No newline at end of file +- On Model 3 built before October 2020: left tail, right tail, and license plate lights operate together. They will activate during ```(Left tail || Right tail)``` requests from xLights - note that the license plate lights xLights channel will have no effect on these vehicles. diff --git a/validator.py b/validator.py index 2a8b374..30bb4e5 100644 --- a/validator.py +++ b/validator.py @@ -4,11 +4,15 @@ import sys import argparse import datetime +from pathlib import Path MEMORY_LIMIT = 681 + class ValidationError(Exception): - pass + def __init__(self, message): + super(ValidationError, self).__init__(f"VALIDATION ERROR: {message}") + @dataclasses.dataclass class ValidationResults: @@ -17,7 +21,12 @@ class ValidationResults: duration_s: int memory_usage: float + def validate(file): + file_name = Path(file.name).name + if file_name != "lightshow.fseq": + print(f"WARNING: FSEQ file should be renamed to 'lightshow.fseq' before playing in a Tesla.") + """Calculates the memory usage of the provided .fseq file""" magic = file.read(4) start, minor, major = struct.unpack(" 1: + raise ValidationError(f"Sequence uses more than 100% of the available memory: {memory_usage * 100:.2f}%") + + return ValidationResults(frame_count, step_time, duration_s, memory_usage) + if __name__ == "__main__": # Expected usage: python3 validator.py lightshow.fseq @@ -83,5 +98,3 @@ def validate(file): print(f"Found {results.frame_count} frames, step time of {results.step_time} ms for a total duration of {datetime.timedelta(seconds=results.duration_s)}.") print(f"Used {results.memory_usage*100:.2f}% of the available memory") - if results.memory_usage > 1: - sys.exit(1) From a63102112a1e508d92d80368dbca6665264fb9f7 Mon Sep 17 00:00:00 2001 From: Ben Dudley Date: Sun, 26 Dec 2021 23:43:29 +0000 Subject: [PATCH 2/3] Updated command count validation to be more informative --- validator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/validator.py b/validator.py index 30bb4e5..806299d 100644 --- a/validator.py +++ b/validator.py @@ -20,7 +20,7 @@ class ValidationResults: step_time: int duration_s: int memory_usage: float - + command_count: int def validate(file): file_name = Path(file.name).name @@ -78,9 +78,9 @@ def validate(file): memory_usage = count / MEMORY_LIMIT if memory_usage > 1: - raise ValidationError(f"Sequence uses more than 100% of the available memory: {memory_usage * 100:.2f}%") + raise ValidationError(f"Sequence uses {count} commands. The maximum allowed is {MEMORY_LIMIT}.") - return ValidationResults(frame_count, step_time, duration_s, memory_usage) + return ValidationResults(frame_count, step_time, duration_s, memory_usage, count) if __name__ == "__main__": From 1c9fe7bc270267e4a56ee5685eba36240ad687e1 Mon Sep 17 00:00:00 2001 From: bendudz <44963664+bendudz@users.noreply.github.com> Date: Tue, 28 Dec 2021 09:37:01 +0000 Subject: [PATCH 3/3] Update validator.py Great suggestion Co-authored-by: Domenic Santangelo --- validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator.py b/validator.py index 806299d..385c3bd 100644 --- a/validator.py +++ b/validator.py @@ -96,5 +96,5 @@ def validate(file): print(e) sys.exit(1) - print(f"Found {results.frame_count} frames, step time of {results.step_time} ms for a total duration of {datetime.timedelta(seconds=results.duration_s)}.") + print(f"Found {results.frame_count} frames and {results.command_count} commands, step time of {results.step_time} ms for a total duration of {datetime.timedelta(seconds=results.duration_s)}.") print(f"Used {results.memory_usage*100:.2f}% of the available memory")