Skip to content

Commit

Permalink
Make sure we get a logged path when parsing fails. (#170)
Browse files Browse the repository at this point in the history
- Drop compiled parsers, speed here is not that important, it's better
to know what things fails.
- Use a focusted sequence and switch to select the message type so the
parsing path is fixed
  • Loading branch information
yozik04 authored Jul 27, 2024
2 parents e971f2b + b799ba6 commit 063745d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions nibe/connection/nibegw.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def _encode(self, obj, context, path):
)
),
"checksum" / Checksum(Int8ub, xor8, this.fields.data),
).compile()
)


RequestData = Switch(
Expand Down Expand Up @@ -792,5 +792,5 @@ def _encode(self, obj, context, path):
)
),
"checksum" / Checksum(Int8ub, xor8, this.fields.data),
).compile()
)
# fmt: on
16 changes: 8 additions & 8 deletions nibe/console_scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
from construct import (
Const,
ConstructError,
FocusedSeq,
GreedyRange,
Int8ul,
Peek,
RawCopy,
Select,
Struct,
Terminated,
Switch,
this,
)

from ..coil import CoilData
Expand All @@ -31,12 +33,10 @@

Nak = Struct("fields" / RawCopy(Struct("Nak" / Const(0x15, Int8ul))))

Block = Select(
Terminated,
Response,
Request,
Ack,
Nak,
Block = FocusedSeq(
"data",
"start" / Peek(Int8ul),
"data" / Switch(this.start, {0x5C: Response, 0xC0: Request, 0x06: Ack, 0x15: Nak}),
)

Stream = GreedyRange(Block)
Expand Down

0 comments on commit 063745d

Please sign in to comment.