Device Base Class
This class acts as a base for hardware devices and similar. In particular those devices which need to raise events for display on the screen or initiate actions as part of automation. Events are queued. Although many devices may raise events there is only one reader. Typically the device class is a abstract class. I.e not instantiated independently.
| Class Method | by |
Find a device object by type and name |
| Class Method | get |
get the event report at top of queue |
| Class Method | get |
Get items from the device table. |
| Class Method | get |
Get device names (keys) from the device table. |
| Static Method | check |
Check on core 0 |
| Method | __init__ |
Initialise Device |
| Method | report |
Add event report to the queue |
| Async Method | wait |
Wait for available event |
| Constant | BD |
Block Detect Device Type |
| Constant | BLK |
Block occupied - RailCom channel 1 info. |
| Constant | BLK |
Block unoccupied |
| Constant | BLK |
Block not powered. |
| Constant | BLK |
Block occupied - Load detected but no info. |
| Constant | CH2 |
Channel 2 report queue full |
| Constant | GBL |
Global RailCom Device Type |
| Constant | INDETERMINATE |
State indeterminate (e.g. action in progress) |
| Constant | LCL |
Local RailCom Device Type |
| Constant | MC |
Closed |
| Constant | MC |
Broker connected |
| Constant | MC |
MQTT Client device type |
| Constant | MC |
OS Error on write or read |
| Constant | MC |
Ping cannot be sent (wrong state) |
| Constant | MC |
Protocol error - ill formed response etc |
| Constant | MC |
Publication received |
| Constant | MC |
Initial subscriptions registered / no publication in progress |
| Constant | MC |
Sending (connection request, subscription, or publication) |
| Constant | MC |
no encoding info for ID7 subindex |
| Constant | POM |
event code for reporting a CV value from read or write. |
| Constant | POM |
event code for reporting NAK received. |
| Constant | POM |
event code for reporting POM access timeout. |
| Constant | SET |
State Set / on / true or action complete if > 2 operables states |
| Constant | TO |
Turnout/Point device type |
| Constant | TO |
Turnout/Point state update |
| Constant | UNKNOWN |
State unavalable (e.g start of day |
| Constant | UNSET |
State unset / off / false |
| Constant | WF |
Connected OK |
| Constant | WF |
Connection in progress |
| Constant | WF |
Wi-Fi device type (w) |
| Constant | WF |
Wi-Fi disconnected |
| Constant | WF |
Wi-Fi starting |
| Property | name |
Get the device name |
| Property | type |
Get the device type |
| Class Variable | _device |
Undocumented |
| Class Variable | _q |
Undocumented |
| Class Variable | _queue |
Undocumented |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _ready |
Undocumented |
| Instance Variable | _type |
Undocumented |
Find a device object by type and name
| Parameters | |
| cls | |
| type | the type of the device |
| name | the name of the device |
| Returns | |
| refererence to the object |
| Raises | |
IndexError if not found | |
get the event report at top of queue
This is synchronous if wait true and will wait forever while the queue is empty. If wait is false it returns None immediately if the queue is empty.
If the queue is not empty the returned tuple holds:
- source, 'self' from the object reporting the event
- event, one of ACTION_DONE, ACTION_ERROR, ACTION_INIT or as defined for device
- data, depends on source object and event
| Parameters | |
| wait | if True wait for an event report otherwise return immediately |
| Returns | |
| None or a tuple |
Get items from the device table.
The device table holds a list of the device objects keyed by their type and name.
| Returns | |
| a list of items - name and device object pairs |
Get device names (keys) from the device table.
The device table holds a list of the device objects keyed by their name.
| Returns | |
| a list of device names |
Check on core 0
'Soft' ISRs associated with timer events and hw related ISRs now appear to run in core 0. This implentation assumes this and the method here allows a 'soft' serivice routine to check it's on core 0. The get_ident method return core number + 1!
| Raises | |
Run time error if not on core 0. | |
Initialise Device
This initialises the device. Usally invoked by super().__init__() from the child.
Save the name (should be unique but not formally tested) & type. Type is a single character. Could used __class__ but that would be more complex.
| Parameters | |
| name | string containing the device name |
| type | character specifying the type of device (i.e. class of child) |
Add event report to the queue
The event report is added to the queue.
| Parameters | |
| event | event code - a Device class constant |
| data | event data to qualify code - device dependent |
| Raises | |
ThreadQError | The queue is full |