Database

Parameter database and ring buffers.

Both classes below are verbatim from the device firmware (firmware_core.py of Logger Pro and the findyIoT module). The parameter registry itself (databaseParams, aka db.params) lives in the user-editable last.py and is passed into the database constructor - see System IDs for the entry format and the full ID table.

Note

Methods reference the firmware module globals (modem, db, device, setError…) exactly as on the device.

class findylab.database.database(params)[source]

Persistent key/value storage on top of btree (the “mydb” file).

Verbatim class from firmware_core.py. Keys are HiGPS parameter IDs registered in the dict passed to the constructor - on a device that dict is databaseParams from the user-editable last.py:

db = database(databaseParams)

Values are stored as bytes; read() also returns the encoded default for a registered-but-missing key.

__init__(params)[source]

Loads the existing “mydb” btree file into RAM.

Parameters:

params (dict) – The parameter registry (databaseParams from last.py); stored as the class-level database.params.

getParameterData(uri)[source]

Returns the registry row for a parameter ID.

Parameters:

uri (str) – Parameter ID, e.g. '421'.

Returns:

The registry entry, or False for unknown IDs.

Return type:

list

getParameterByHiGPS(higpsId)[source]

Returns the registry row for a HiGPS parameter ID.

Parameters:

higpsId (str) – Parameter ID.

Returns:

The registry entry, or False for unknown IDs.

Return type:

list

initDefaults()[source]

Factory-initializes the database.

Deletes an existing “mydb” (and resets so the next boot starts clean), reads the IMEI from the modem, then writes every storage-type-0 parameter’s default value.

read(property, echo=True)[source]

Reads a parameter value.

Parameters:
  • property (str or bytes) – Parameter ID.

  • echo (bool) – Print the value while reading (debug aid).

Returns:

The stored value; the encoded default when the key is missing but registered; False for unknown IDs.

Return type:

bytes

write(property, value)[source]

Writes a parameter value into RAM.

int/str values are converted to bytes. Call store() to persist to flash.

Parameters:
  • property (str or bytes) – Parameter ID.

  • value (int or str or bytes) – New value.

Returns:

True on success.

Return type:

bool

store()[source]

Persists the RAM changes to the “mydb” btree file.

No-op when nothing was written since the last store. Buffer-type parameters (type 3) also store their child slots (key0..``key99``).

Returns:

True.

Return type:

bool

class findylab.database.buffer[source]

Ring buffers over database (slots "540"+n).

Verbatim class from firmware_core.py. Never instantiated - the methods take no self and are called directly:

buffer.create('540')

Used to keep pulse-count series between successful reports; the current slot index lives in parameters 538/539.

create()[source]

Opens a fresh buffer slot.

Finds a free slot (0..99), writes the header (log period + timestamp + base counter value) and records the slot index in parameter 538/539.

Parameters:

bufferName (str) – '540' or '541'.

Returns:

The slot index used.

Return type:

int

get()[source]

Returns the first full buffer slot.

Parameters:

bufferName (str) – '540' or '541'.

Returns:

(period, timestamp, base_value, data) or False when no slot holds data.

Return type:

tuple

put(data)[source]

Appends bytes to the current buffer slot.

Parameters:
  • bufferName (str) – '540' or '541'.

  • data (bytes) – Payload to append (e.g. a 2-byte pulse delta).

remove()[source]

Clears the first full buffer slot.

Parameters:

bufferName (str) – '540' or '541'.

Returns:

True when a slot was cleared.

Return type:

bool