Store

class brainstem.entity.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)

  • EEPROM_STORE (3)

getSlotCapacity(slot)[source]

Get the slot capacity.

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

return: Result:

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

getSlotLocked(slot)[source]
Gets the current lock state of the slot

Allows for write protection on a slot.

Parameters:

slot (int) – The slot number

Returns:

value: The current locked state of the provided slot. error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getSlotSize(slot)[source]

Get the slot size.

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

return: Result:

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

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.

return: Result:

Return result object with NO_ERROR set and the current state of the slot in the Result.value or an Error.

loadSlot(slot, data, _=None)[source]

Load the slot.

Parameters:
  • slot (int) – The slot number.

  • data (str, bytes) – The data.

  • _ (int) – (length Deprecated) Unused parameter, and will be removed in next minor release.

return: Result.error:

Return NO_ERROR on success, or one of the common sets of return error codes on failure.

setSlotLocked(slot, lock)[source]
Sets the locked state of the slot

Allows for write protection on a slot.

Parameters:
  • slot (int) – The slot number

  • lock (bool) – Locked state to set.

Returns (int):

Non-zero BrainStem error code on failure.

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.

return: Result:

Either Returns Result object with NO_ERROR set and its value attribute set with an object of type bytes containing the unloaded data. Or a Result object with a non-zero error.