Skip to content

Commit f0dbd76

Browse files
committed
mipi: Add some more validation for DCS commands
Make sure we can actually generate a parameter for them. Some panels use arbitrary DCS commands as register writes and we can easily attempt to generate impossible code for them.
1 parent 8368148 commit f0dbd76

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

mipi.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,27 @@ def get_params(self, b: bytes):
131131
def find(payload: bytes) -> Optional[DCSCommand]:
132132
try:
133133
dcs = DCSCommand(payload[0])
134-
if dcs.nargs and len(payload) - 1 not in dcs.nargs:
135-
# Argument count does not match. Weird.
136-
return None
137-
return dcs
138134
except ValueError:
135+
# Not a specified DCS command
139136
return None
140137

138+
if dcs.nargs and len(payload) - 1 not in dcs.nargs:
139+
# Argument count does not match. Weird.
140+
expected_args = " or ".join(str(i) for i in dcs.nargs)
141+
print(f"WARNING: DCS command {dcs.name} with incorrect argument count "
142+
f"(expected: {expected_args}, is: {len(payload) - 1})")
143+
return None
144+
145+
try:
146+
# Try to parse the argument(s)
147+
dcs.get_params(payload[1:])
148+
except ValueError as e:
149+
# Not a valid argument. Weird.
150+
print(f"WARNING: DCS command {dcs.name} with invalid arguments {payload[1:]}: {e}")
151+
return None
152+
153+
return dcs
154+
141155

142156
def _generate_checked_call(method: str, args: List[str], description: str) -> str:
143157
return f'''\

0 commit comments

Comments
 (0)