Node and MasterNode
- olaf.NetworkError
alias of
CanNetworkError
- class olaf.NodeStop(value)[source]
Bases:
IntEnumNode stop commands.
- NO_STOP = 0
Default value for no stop.
- SOFT_RESET = 1
Just stop the app and exit. Systemd will restart the app.
- HARD_RESET = 2
Reboot system after app has stopped
- FACTORY_RESET = 3
Clear all file cachces and reboot system after app has stopped
- POWER_OFF = 4
Just power off the system.
- class olaf.Node(network: CanNetwork, od: ObjectDictionary)[source]
OreSat CANopen Node class
Jobs:
It abstracts away the canopen.LocalNode and canopen.Network from Resources and Services.
Provides access to the OD for Resources and Services.
Lets Resources and Services send TPDOs.
Lets Resources and Services send EMCY messages.
Set up the file transfer caches.
Starts/stops all Resources and Services.
Sets up all timer-base TPDOs.
Sets up all RPDO callbacks.
Basically it tries to abstract all the CANopen things as much a possible, while providing a basic API for CANopen things.
- Parameters:
network (CanNetwork) – The CAN network
od (canopen.ObjectDictionary) – The CANopen ObjectDictionary
- run() NodeStop[source]
Go into operational mode, start all the resources, start all the threads, and monitor everything in a loop.
- Returns:
Reset / power off condition.
- Return type:
- add_sdo_callbacks(index: str, subindex: str, read_cb: Callable[[None], Any], write_cb: Callable[[Any], None])[source]
Add an SDO read callback for a variable at index and optional subindex.
- Parameters:
subindex (int or str) – The subindex to call the callback on.
read_cb (Callable[[None], Any]) – The SDO read callback. Allows overriding the data being sent on a SDO read. If overriding read data return the value or return
Noneto use the the value from the od. Set toNonefor no read_cb.write_cb (Callable[[Any], None]) – The SDO writecallback. Gives access to the data being received on a SDO write. Set to
Nonefor no write_cb. Note: data is still written to object dictionary before call.
- send_tpdo(tpdo: int, raise_error: bool = True)[source]
Send a TPDO. Will not be sent if not node is not in operational state.
- send_emcy(code: EmcyCode | int, data: bytes = b'', raise_error: bool = True)[source]
Send a EMCY message.
- property od: ObjectDictionary
Access to the object dictionary.
- Type:
canopen.ObjectDictionary
- property fread_cache: OreSatFileCache
Cache the CANopen master node can read to.
- Type:
- property fwrite_cache: OreSatFileCache
Cache the CANopen master node can write to.
- Type:
- property daemons: Dict[str, Daemon]
The dictionary of external daemons that are monitored and/or controllable
- Type:
- od_get_obj(index: int | str, subindex: int | str | None = None) ODVariable | ODArray | ODRecord[source]
Quick helper function to get an object from the od.
- Returns:
The object from the OD.
- Return type:
ODVariable | ODArray | ODRecord
- od_read(index: int | str, subindex: int | str | None) int | str | float | bytes | bool[source]
Read a value from the OD.
- od_read_bitfield(index: int | str, subindex: int | str | None, field: str) int[source]
Read a field from a object from the OD.
- od_read_enum(index: int | str, subindex: int | str | None) str[source]
Read a enum str from the OD.
- od_write(index: int | str, subindex: int | str | None, value: int | str | float | bytes | bool)[source]
Write an value to the OD.
- class olaf.MasterNode(network: CanNetwork, od: ObjectDictionary, od_db: Dict[Any, ObjectDictionary])[source]
Bases:
NodeOreSat CANopen Master Node (only used by the C3)
- Parameters:
network (CanNetwork) – The CAN network
od (canopen.ObjectDictionary) – The CANopen ObjectDictionary
od_db (Dict[Any, canopen.ObjectDictionary]) – Database of other nodes’s ODs. The dict key will be used by class fields and methods.
- property remote_nodes: dict[Any, RemoteNode]
All other node as remote node.
- Type:
dict[Any, canopen.RemoteNode]
- property od_db: dict[Any, ObjectDictionary]
All other node ODs.
- Type:
dict[Any, canopen.ObjectDictionary]
- sdo_read(key: Any, index: int | str, subindex: int | str | None) int | str | float | bytes | bool[source]
Read a value from a remote node’s object dictionary using an SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO read message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- Returns:
The value read.
- Return type:
- sdo_read_bitfield(key: Any, index: int | str, subindex: int | str | None, field: str) int[source]
Read an field from a object from another node’s OD using a SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO read message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- Returns:
The field value.
- Return type:
- sdo_read_enum(key: Any, index: int | str, subindex: int | str | None) str[source]
Read an enum str from another node’s OD using a SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO read message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- Returns:
The enum str value.
- Return type:
- sdo_write(key: Any, index: int | str, subindex: int | str | None, value: int | str | float | bytes | bool)[source]
Write a value to a remote node’s object dictionary using an SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO write message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- sdo_write_bitfield(key: Any, index: int | str, subindex: int | str | None, field: str, value: int)[source]
Write a field from a object to another node’s OD using a SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO read message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- sdo_write_enum(key: Any, index: int | str, subindex: int | str | None, value: str)[source]
Write a enum str to another node’s OD using a SDO.
- Parameters:
- Raises:
NetworkError – Cannot send a SDO read message when the network is down.
canopen.sdo.exceptions.SdoError – Error with the SDO.
- send_rpdo(rpdo: int, raise_error: bool = True)[source]
Send a RPDO. Will not be sent if not node is not in operational state.
- Parameters:
- Raises:
ValueError – Invalud rpdo value.
NetworkError – Cannot send a RPDO read message when the network is down.