NASA-AMMOS / NASA-AMMOS/AIT-Core
Cmd decoding approach doesn't play nice with Cmd extensions
@MJJoyce is already working on this.
Since Mar 19, 2021.
- Dominant language
- Python
- Stars
- 56
- Forks
- 35
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 3
Description
The current command decoding approach doesn't work too nicely if you've added a Cmd class extension.
Generally, Cmd extensions are added to customize command encoding format. The current decode handling is performed by CmdDict.decode:
def decode(self, bytes):
"""Decodes the given bytes according to this AIT Command
Definition.
"""
opcode = struct.unpack(">H", bytes[0:2])[0]
nbytes = struct.unpack("B", bytes[2:3])[0]
name = None
args = []
if opcode in self.opcodes:
defn = self.opcodes[opcode]
name = defn.name
stop = 3
for arg in defn.argdefns:
start = stop
stop = start + arg.nbytes
if arg.fixed:
pass # FIXME: Confirm fixed bytes are as expected?
else:
args.append(arg.decode(bytes[start:stop]))
return self.create(name, *args)
This the mirror of the default Cmd.encode
opcode = struct.pack('>H', self.defn.opcode)
offset = len(opcode)
size = max(offset + self.defn.argsize, pad)
encoded = bytearray(size)
encoded[0:offset] = opcode
encoded[offset] = self.defn.argsize
offset += 1
index = 0
for defn in self.defn.argdefns:
if defn.fixed:
value = defn.value
else:
value = self.args[index]
index += 1
encoded[defn.slice(offset)] = defn.encode(value)
return encoded
Obviously these won't line up when you implement a custom Cmd extension.
"So, implement a custom CmdDict to deal with that"
Well, aside from that being a bit annoying to have to do, you can't do so in a convenient way because cmd.getDefaultDict hard codes cmd.CmdDict.
return util.getDefaultDict(__name__, 'cmddict', CmdDict, reload)
So even if you create a custom CmdDict extension it's just ignored if you load your dictionary the way everything in the toolkit loads the dictionary. Not great.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.