Store

class brainstem.stem.Store(module, index)[source]

Access the store on a BrainStem Module.

The store provides a flat file system on modules that have storage capacity. Files are referred to as slots and they have simple zero-based numbers for access. Store slots can be used for generalized storage and commonly contain compiled reflex code (files ending in .map) or templates used by the system. Slots simply contain bytes with no expected organization but the code or use of the slot may impose a structure.

Stores have fixed indices based on type. Not every module contains a store of each type. Consult the module datasheet for details on which specific stores are implemented, if any, and the capacities of implemented stores.

Useful Constants:
  • INTERNAL_STORE (0)

  • RAM_STORE (1)

  • SD_STORE (2)

getSlotCapacity(slot)[source]

Get the slot capacity.

Returns the Capacity of the slot, i.e. The number of bytes it can hold.

Returns

Either the capacity of the slot in Result.value or an error.

Return type

Result

getSlotSize(slot)[source]

Get the slot size.

Returns the size of the data currently filling the slot in bytes.

Returns

Either the size of the slot in Result.value or an error.

Return type

Result

getSlotState(slot)[source]

Get slot state.

Slots which contain reflexes may be “enabled,” i.e. the reflexes contained in the slot are active.

Parameters

slot (int) – The slot number.

Returns

Return result object with NO_ERROR set and the current

state of the slot in the Result.value or an Error.

Return type

Result

loadSlot(slot, data, length)[source]

Load the slot.

Parameters
  • slot (int) – The slot number.

  • data (str, bytes) – The data.

  • length (int) – The data length in bytes.

Returns

Return NO_ERROR on success, or one of the common

sets of return error codes on failure.

Return type

Result.error

slotDisable(slot)[source]

Disable the slot

slotEnable(slot)[source]

Enable the slot

unloadSlot(slot)[source]

Unload the slot data.

Parameters

slot (int) – The slot number.

Returns

Either Returns result object with NO_ERROR set

and Result.value containing a tuple of (str|bytes, int) containing the unloaded data and length, or an Error.

Return type

Result