-
Notifications
You must be signed in to change notification settings - Fork 32
extended FSWTabDict class #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JimHofman
wants to merge
7
commits into
NASA-AMMOS:master
Choose a base branch
from
JimHofman:issue-376
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eacbb9f
extended FSWTabDict class
JHofman728 a6dd09c
issue-376: update new branch
JHofman728 9fbae8b
item-376 extensions for table.py
JHofman728 763ce15
modifications based on rewiew
JHofman728 7def8d4
reverts in table, and update util
JHofman728 b0daf40
conflict with a comment
JHofman728 3ed3b43
Merge branch 'master' into issue-376
JimHofman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| The ait.core.cmd module provides commands and command dictionaries. | ||
| Dictionaries contain command and argument definitions. | ||
|
|
||
| """ | ||
|
|
||
| import os | ||
|
|
@@ -43,6 +44,7 @@ class ArgDefn(json.SlotSerializer, object): | |
|
|
||
| A fixed argument (fixed=True) defines a fixed bit pattern in that | ||
| argument's byte position(s). | ||
|
|
||
| """ | ||
| __slots__ = [ | ||
| "name", "desc", "units", "_type", "bytes", "_enum", "range", | ||
|
|
@@ -96,8 +98,10 @@ def startbit(self): | |
| return self.slice().start % 2 * 8 | ||
|
|
||
| def decode(self, bytes): | ||
| """Decodes the given bytes according to this AIT Argument | ||
| """ | ||
| Decodes the given bytes according to this AIT Argument | ||
| Definition. | ||
|
|
||
| """ | ||
| value = self.type.decode(bytes) | ||
| if self._enum is not None: | ||
|
|
@@ -108,18 +112,22 @@ def decode(self, bytes): | |
| return value | ||
|
|
||
| def encode(self, value): | ||
| """Encodes the given value according to this AIT Argument | ||
| """ | ||
| Encodes the given value according to this AIT Argument | ||
| Definition. | ||
|
|
||
| """ | ||
| if type(value) == str and self.enum and value in self.enum: | ||
| value = self.enum[value] | ||
| return self.type.encode(value) if self.type else bytearray() | ||
|
|
||
| def slice(self, offset=0): | ||
| """Returns a Python slice object (e.g. for array indexing) indicating | ||
| """ | ||
| Returns a Python slice object (e.g. for array indexing) indicating | ||
| the start and stop byte position of this Command argument. The | ||
| start and stop positions may be translated by the optional byte | ||
| offset. | ||
|
|
||
| """ | ||
| if type(self.bytes) is int: | ||
| start = self.bytes | ||
|
|
@@ -131,9 +139,11 @@ def slice(self, offset=0): | |
| return slice(start + offset, stop + offset) | ||
|
|
||
| def validate(self, value, messages=None): | ||
| """Returns True if the given Argument value is valid, False otherwise. | ||
| """ | ||
| Returns True if the given Argument value is valid, False otherwise. | ||
| Validation error messages are appended to an optional messages | ||
| array. | ||
|
|
||
| """ | ||
| valid = True | ||
| primitive = value | ||
|
|
@@ -163,16 +173,19 @@ def log(msg): | |
| return valid | ||
|
|
||
|
|
||
|
|
||
| class Cmd(object): | ||
| """Cmd - Command | ||
| """ | ||
| Cmd - Command | ||
|
|
||
| Commands reference their Command Definition and may contain arguments. | ||
|
|
||
| """ | ||
| def __init__(self, defn, *args, **kwargs): | ||
| """Creates a new AIT Command based on the given command | ||
| """ | ||
| Creates a new AIT Command based on the given command | ||
| definition and command arguments. A Command may be created | ||
| with either positional or keyword arguments, but not both. | ||
|
|
||
| """ | ||
| self.defn = defn | ||
|
|
||
|
|
@@ -193,7 +206,6 @@ def __init__(self, defn, *args, **kwargs): | |
| self.args = args | ||
| self._unrecognized = kwargs | ||
|
|
||
|
|
||
| def __repr__(self): | ||
| return self.defn.name + " " + " ".join([str(a) for a in self.args]) | ||
|
|
||
|
|
@@ -223,7 +235,8 @@ def argdefns(self): | |
| return self.defn.argdefns | ||
|
|
||
| def encode(self, pad=106): | ||
| """Encodes this AIT command to binary. | ||
| """ | ||
| Encodes this AIT command to binary. | ||
|
|
||
| If pad is specified, it indicates the maximum size of the encoded | ||
| command in bytes. If the encoded command is less than pad, the | ||
|
|
@@ -233,6 +246,7 @@ def encode(self, pad=106): | |
| (128 bytes) with 11 words (22 bytes) of CCSDS overhead (SSP | ||
| 52050J, Section 3.2.3.4). This leaves 53 words (106 bytes) for | ||
| the command itself. | ||
|
|
||
| """ | ||
| opcode = struct.pack('>H', self.defn.opcode) | ||
| offset = len(opcode) | ||
|
|
@@ -255,21 +269,24 @@ def encode(self, pad=106): | |
| return encoded | ||
|
|
||
| def validate(self, messages=None): | ||
| """Returns True if the given Command is valid, False otherwise. | ||
| """ | ||
| Returns True if the given Command is valid, False otherwise. | ||
| Validation error messages are appended to an optional messages | ||
| array. | ||
|
|
||
| """ | ||
| return self.defn.validate(self, messages) | ||
|
|
||
|
|
||
|
|
||
| class CmdDefn(json.SlotSerializer, object): | ||
| """CmdDefn - Command Definition | ||
| """ | ||
| mdDefn - Command Definition | ||
|
|
||
| Command Definitions encapsulate all information required to define a | ||
| single command. This includes the command name, its opcode, | ||
| subsystem, description and a list of argument definitions. Name and | ||
| opcode are required. All others are optional. | ||
|
|
||
| """ | ||
| __slots__ = ( 'name', '_opcode', 'subsystem', 'ccsds', 'title', 'desc', | ||
| 'argdefns' ) | ||
|
|
@@ -287,32 +304,37 @@ def __init__(self, *args, **kwargs): | |
| if self.argdefns is None: | ||
| self.argdefns = [] | ||
|
|
||
|
|
||
| def __repr__(self): | ||
| return util.toRepr(self) | ||
|
|
||
| @property | ||
| def args (self): | ||
| """The argument definitions to this command (excludes fixed | ||
| """ | ||
| The argument definitions to this command (excludes fixed | ||
| arguments). | ||
|
|
||
| """ | ||
| return filter(lambda a: not a.fixed, self.argdefns) | ||
|
|
||
| @property | ||
| def nargs(self): | ||
| """The number of arguments to this command (excludes fixed | ||
| """ | ||
| The number of arguments to this command (excludes fixed | ||
| arguments). | ||
|
|
||
| """ | ||
| return len(list(self.args)) | ||
|
|
||
| @property | ||
| def nbytes(self): | ||
| """The number of bytes required to encode this command. | ||
| """ | ||
| The number of bytes required to encode this command. | ||
|
|
||
| Encoded commands are comprised of a two byte opcode, followed by a | ||
| one byte size, and then the command argument bytes. The size | ||
| indicates the number of bytes required to represent command | ||
| arguments. | ||
|
|
||
| """ | ||
| return len(self.opcode) + 1 + sum(arg.nbytes for arg in self.argdefns) | ||
|
|
||
|
|
@@ -376,7 +398,6 @@ def validate(self, cmd, messages=None): | |
| return valid | ||
|
|
||
|
|
||
|
|
||
| class CmdDict(dict): | ||
| """CmdDict | ||
|
|
||
|
|
@@ -412,7 +433,6 @@ def add(self, defn): | |
| log.error(msg) | ||
| raise util.YAMLError(msg) | ||
|
|
||
|
|
||
| def create(self, name, *args, **kwargs): | ||
| """Creates a new AIT command with the given arguments.""" | ||
| tokens = name.split() | ||
|
|
@@ -434,7 +454,6 @@ def create(self, name, *args, **kwargs): | |
|
|
||
| return createCmd(defn, *args, **kwargs) | ||
|
|
||
|
|
||
| def decode(self, bytes): | ||
| """Decodes the given bytes according to this AIT Command | ||
| Definition. | ||
|
|
@@ -486,7 +505,6 @@ def toJSON(self): | |
| return { name: defn.toJSON() for name, defn in self.items() } | ||
|
|
||
|
|
||
|
|
||
| def getDefaultCmdDict(reload=False): | ||
| return getDefaultDict(reload=reload) | ||
|
|
||
|
|
@@ -539,14 +557,16 @@ def YAMLCtor_CmdDefn(loader, node): | |
| fields['argdefns'] = fields.pop('arguments', None) | ||
| return createCmdDefn(**fields) | ||
|
|
||
|
|
||
| def YAMLCtor_include(loader, node): | ||
| # Get the path out of the yaml file | ||
| name = os.path.join(os.path.dirname(loader.name), node.value) | ||
| data = None | ||
| with open(name,'r') as f: | ||
| data = yaml.load(f) | ||
| data = yaml.load(f, Loader=yaml.Loader) | ||
| return data | ||
|
Comment on lines
142
to
598
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This overwrites previous definition of |
||
|
|
||
|
|
||
| yaml.add_constructor('!include' , YAMLCtor_include) | ||
| yaml.add_constructor('!Command' , YAMLCtor_CmdDefn) | ||
| yaml.add_constructor('!Argument', YAMLCtor_ArgDefn) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ | |
| import sys | ||
| import re | ||
|
|
||
| from ait.core import cmd, dmc, log, util | ||
| from ait.core import cmd, dmc, log, util, table | ||
|
||
|
|
||
|
|
||
| # PrimitiveTypes | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took out loader=yaml.loader.
We might want to get rid of data=None and use a try/except around the open block.