This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from oresat/3.2.0-ui_rework
3.2.0 UI rework
- Loading branch information
Showing
8 changed files
with
467 additions
and
254 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,33 +1,99 @@ | ||
from __future__ import annotations | ||
from .canmsg import CANMsg | ||
import typing | ||
from collections.abc import Iterable, Iterator | ||
|
||
|
||
class CANMsgTable: | ||
def __init__(self, | ||
name: str = "message_table", | ||
capacity: int = None): | ||
self.name = name | ||
self.message_table = {} | ||
class CANMsgTable(Iterable): | ||
""" | ||
Table of CAN Messages | ||
""" | ||
|
||
def __init__(self: CANMsgTable, capacity: int = None): | ||
self.__message_table = {} | ||
self.capacity = capacity | ||
|
||
def add(self, frame: CANMsg) -> None: | ||
if(self.capacity is not None): | ||
if(len(self.message_table) < self.capacity | ||
or (self.message_table.get(frame.arb_id) is not None)): | ||
self.message_table[frame.arb_id] = frame | ||
def __sort__(self: CANMsgTable) -> [int]: | ||
""" | ||
Overloaded sort function | ||
Sort by COB-ID | ||
Returns | ||
-------- | ||
[int]: List of keys sorted | ||
""" | ||
return sorted(self.__message_table.keys()) | ||
|
||
def __add__(self: CANMsgTable, frame: CANMsg) -> CANMsgTable: | ||
""" | ||
Overloaded add operator | ||
allows for following: | ||
CANMsgTable += CANMsg | ||
Arguments | ||
---------- | ||
frame: CANMsg to be added | ||
Returns | ||
-------- | ||
CANMsgTable: returns self after adding message | ||
""" | ||
if self.capacity is not None: | ||
if (len(self.__message_table) < self.capacity | ||
or (self.__message_table.get(frame.arb_id) is not None)): | ||
self.__message_table[frame.arb_id] = frame | ||
else: | ||
self.message_table[frame.arb_id] = frame | ||
self.__message_table[frame.arb_id] = frame | ||
|
||
return self | ||
|
||
def ids(self) -> [int]: | ||
return sorted(self.message_table.keys()) | ||
def __len__(self: CANMsgTable) -> int: | ||
""" | ||
Overloaded len function | ||
def __len__(self) -> int: | ||
return len(self.message_table) | ||
Returns | ||
-------- | ||
int: Number of CANMsg records in table | ||
""" | ||
return len(self.__message_table) | ||
|
||
def __str__(self) -> str: | ||
def __str__(self: CANMsgTable) -> str: | ||
""" | ||
Overloaded str function | ||
Returns | ||
-------- | ||
str: String representation of CANMsgTable | ||
""" | ||
attrs = [] | ||
for k, v in self.__dict__.items(): | ||
attrs += ['{}={}'.format(k, v)] | ||
return 'CANMsgTable {}\n\n'.format(', '.join(attrs)) | ||
|
||
def __getitem__(self, key: int) -> CANMsg: | ||
return self.message_table.get(key) | ||
def __getitem__(self: CANMsgTable, key: typing.Union[int, str]) -> \ | ||
typing.Union[CANMsg, None]: | ||
""" | ||
Overloaded getitem operator | ||
Example: CANMsgTable[0x40] | ||
Arguments | ||
---------- | ||
key: int or string representation of node COB-ID | ||
Returns | ||
-------- | ||
CANMsg: last message added for the provided COB-ID | ||
None: None will be returned if no messages exist for provided COB-ID | ||
""" | ||
sub_key = int(key, 16) if type(key) is str else key | ||
return self.__message_table.get(sub_key) | ||
|
||
def __iter__(self: CANMsgTable) -> Iterator[CANMsg]: | ||
""" | ||
Overloaded iter function | ||
Returns | ||
-------- | ||
Iterator[CANMsg]: iterator for contained messages | ||
""" | ||
return self.__message_table.__iter__() |
This file contains 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 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 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
Oops, something went wrong.