Platform API
Command
Bases: Enum
Command the platform should execute.
Source code in sramplatform/packet.py
Packet
Packet used for the communication protocol.
Attributes:
Name | Type | Description |
---|---|---|
command |
Command the platform should execute. |
|
pic |
Position In Chain of the device. |
|
options |
Metadata for the packet. |
|
uid |
UID of the device. |
|
data |
Actual data of the packet. |
|
bytes |
Bytes representation of the packet. |
|
checksum |
Optional[int]
|
CRC of the packet for integrity. |
Source code in sramplatform/packet.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
command
property
Getter for command
data
property
Getter for data
options
property
Getter for options
pic
property
Getter for pic
uid
property
Getter for uid
craft()
Craft a packet to send.
Calculate the checksum if it hasn't been calculated yet, and create the bytes representation of the packet.
Source code in sramplatform/packet.py
extract_sensors()
Extract the values of the sensors from the data.
The information of the sensors is stored in the following way:
temp_110_cal
: Temperature calibration at 110 Celsius.temp_30_cal
: Temperature calibration at 30 Celsius.temp_raw
: Raw value of temperature.vdd_cal
: Calibration of VDD.vdd_raw
: Raw value of VDD.
All the values are stored in 2 bytes.
Returns:
Type | Description |
---|---|
Dict
|
Dictionary containing |
Source code in sramplatform/packet.py
from_bytes(data_size, raw_data)
classmethod
Create a packet from bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_data |
bytes
|
Bytes representing the packet. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the length of |
Returns:
Type | Description |
---|---|
Packet created from the bytes. |
Source code in sramplatform/packet.py
is_crafted()
Check if a packet is ready to be sent.
Returns:
Type | Description |
---|---|
bool
|
True if bytes is not None. |
to_bytes()
Return the bytes representation the packet.
Returns:
Type | Description |
---|---|
bytes
|
Bytes representation of the packet. |
Source code in sramplatform/packet.py
with_checksum(checksum)
with_command(command)
with_data(data)
with_options(options)
with_pic(pic)
crc16(buffer)
Calculate the CRC16 from a byte buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer |
bytes
|
Buffer of bytes. |
required |
Returns:
Type | Description |
---|---|
int
|
The calculated CRC. |
Source code in sramplatform/packet.py
format_uid(uid)
Format a device UID.
If the uid is bytes, remove the null terminator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uid |
Union[str, bytes]
|
UID of the device. |
required |
Returns:
Type | Description |
---|---|
str
|
Ther formmated UID as a string. |
Source code in sramplatform/packet.py
offset_to_address(offset, data_size, sram_start=536870912)
Convert an offset in memory to absolute memory address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
Offset from the start of the SRAM. |
required |
sram_start |
int
|
Byte representing the start of the SRAM. 0x20000000 by default. |
536870912
|
Raises:
Type | Description |
---|---|
ValueError
|
If offset is negative. |
Returns:
Type | Description |
---|---|
str
|
Address formated as 0xXXXXXXXX. |
Source code in sramplatform/packet.py
DBManager
Class to manage the communication with the database.
The default database is PostreSQL. However, another database can be used in place by configuring the DBManager.
The manager is allowed to insert into the database any object as long as it has been registered by using TableBase
. For more instructions on how to register objects to the database please see https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html
.
Example
from sramplatform.storage import DBManager, TableBase
class Users(TableBase): tablename = "User" id = Column(Integer, primary_key=True) name = Column(String, nullable=False)
manager = DBManager(url)
Queries can be made by using the session attribute.
Example
manager.session.query(User).all
Attributes:
Name | Type | Description |
---|---|---|
session |
Session to the DB |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
Union[str, DBParameters]
|
DBParameters instance or string containing the url to connect. |
required |
Source code in sramplatform/storage.py
DBParameters
dataclass
Class to manage database connection parameters.
By default it is assumed that the database is PostgreSQL.
For a list of supported engines, please see https://docs.sqlalchemy.org/en/14/core/engines.html
.
Attributes:
Name | Type | Description |
---|---|---|
user |
str
|
Username to connect to the database. |
password |
str
|
User password to connect to the database. |
dbname |
Optional[str]
|
Name of the database to connect. |
engine |
Optional[str]
|
Database to use. Defaults to 'postgresql'. |
host |
Optional[str]
|
Hostname for the database. Defaults to 'localhost'. |
port |
Optional[int]
|
Connection port for the database. Defaults to 5432. |
Source code in sramplatform/storage.py
Reader
Interface of a device reader.
The reader acts as a proxy between the station and the devices.
Attributes:
Name | Type | Description |
---|---|---|
name |
Descriptive name of the reader. |
Source code in sramplatform/reader.py
LogLevelFilter
Bases: logging.Filter
https://stackoverflow.com/a/7447596/190597 (robert)
Source code in sramplatform/logbook.py
MailHandler
Bases: logging.StreamHandler
Log handler for Email.
Source code in sramplatform/logbook.py
RabbitMQHandler
TelegramHandler
Bases: logging.StreamHandler
Log handler for Telegram.
Source code in sramplatform/logbook.py
create_handler(name, conf)
Create a handler from a name and a dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the handler to create. |
required |
conf |
Dict[str, Any]
|
Dictionary containing the handler configuration. |
required |
Returns:
Type | Description |
---|---|
HandlerType
|
The configured handler. |
Source code in sramplatform/logbook.py
make_formatter(conf, fmt_default, datefmt_default)
Create a Log formatter from a dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
Dict[str, str]
|
Dictionary containing format and datefmt |
required |
fmt_default |
str
|
Default format to use if none specified. |
required |
datefmt_default |
str
|
Default datefmt to use if none specified. |
required |
Source code in sramplatform/logbook.py
Dispatcher
Class used to dispatch reader methods based on the commands received.
Attributes:
Name | Type | Description |
---|---|---|
agent |
Fenneq agent to listen for commands. |
|
logger |
Logger used to log information. |
|
db_session |
Session to a DB to store data. |
Source code in sramplatform/platform.py
from_config(config_path, reader_cls)
Read a YAML config to generate the components for a Dispatcher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
Path to the YAML config. |
required |
reader_cls |
ReaderType
|
Class to use to instanciate a Reader. |
required |
Returns:
Type | Description |
---|---|
Tuple[Agent, ReaderType, object]
|
A tuple containing the Agent, Reader and Logger |