Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Cookie Class Reference
Pokitto Cookies are queues of 32 byte blocks that are saved in the EEPROM in a safe way. More...
#include <PokittoCookie.h>
| Public Member Functions | |
| Cookie () | |
| Cookie class constructor. | |
| int | begin (const char *, int, char *) | 
| begin - Register your Cookie with a 8-byte key to begin using it | |
| template<typename T > | |
| int | begin (const char *key, T &object) | 
| begin - Register your Cookie with a 8-byte key to begin using it | |
| int | initialize () | 
| initialize - create cookie structure. | |
| bool | saveCookie () | 
| saveCookie - Save your Cookie | |
| bool | loadCookie () | 
| loadCookie - Load your Cookie | |
| void | deleteCookie () | 
| deleteCookie - your Cookie | |
| bool | isOK () | 
| isOK - Get status of Cookie | |
| void | readKeytableEntry (int, char *) | 
| readKeytableEntry - return the key at slot n | |
| void | formatKeytable () | 
| formatKeyTable(int) - erase all keys | |
| void | eraseKeytableEntry (int) | 
| eraseKeyAt(int) - erase key at slot n | |
| void | cleanKeytable () | 
| cleanKeytable() - erase keys that have no blocks reserved from the keyTable | |
| int | exists (const char *) | 
| exists - find out if the key exists | |
| int | getFreeKeytableSlot () | 
| getFreeKeytableSlot - Are there any keys left to use | |
| int | getFreeBlocks () | 
| getFreeBlocks - Are there any storage blocks left to use | |
| int | getAssignedBlocks () | 
| getAssignedBlocks - return number of blocks already reserved for cookie | |
| bool | isFreeBlock (int) | 
| isFreeBlock - check if block n is free to use | |
| bool | isMyBlock (int) | 
| isMyBlock - check if block n is already reserved for this cookie | |
| bool | blockIsOwnedBy (int, int) | 
| blockIsOwnedBy - check if block n is owned by Keytable entry k | |
| void | writeKeyToKeytable (const char *, int) | 
| writeKeyToKeyTable - write the key into the key table | |
| char | getBlockTableEntry (int) | 
| getBlockTableEntry - read an entry from the blocktable | |
| void | readBlock (int, char *) | 
| readBlock - read the data of a block | |
| void | freeBlock (int) | 
| freeBlock - free block from blocktable and delete data of block in EEPROM | |
| bool | reserveBlock () | 
| reserveBlock - search and reserve a block from blocktable for use by this cookie | |
| void | writeQueue (char) | 
| writeQueue - write the cookie data as a stream of bytes into the EEPROM blocks | |
| char | readQueue () | 
| readQueue - write the cookie data as a stream of bytes into the EEPROM blocks | |
| int | findMyNextBlock () | 
| findMyNextBlock - find the next block assigned to this cookie | |
| Data Fields | |
| char | _key [SBKEYSIZE] | 
| keystring identification string for the Cookie | |
| char | _keyorder | 
| Keyorder order number of key in key table. | |
| bool | _status | 
| Status false = uninitialized true = ready. | |
| int | _datasize | 
| Datasize size (in bytes) of cookie data to be saved and reloaded. | |
| char * | _pointer | 
| Pointer pointer to cookie data. | |
| int | _head | 
| Head data "head" for byte write/read operations. | |
| char | _block | 
| Current block block number that we are reading/writing. | |
Detailed Description
Pokitto Cookies are queues of 32 byte blocks that are saved in the EEPROM in a safe way.
Example:
// Create saveable data and initialize your app to use Cookies class gdata : public Cookie { int highscore; } gdata gamedata; gamedata.begin("ASTEROCK"); // register your Cookie with key "ASTEROCK" // you use the data objects inside the Cookie as normal: gamedata.highscore = player.currentscore; // It's a new highscore! // Finally you call the save method to write your data to EEPROM gamedata.save;
Definition at line 78 of file PokittoCookie.h.
Constructor & Destructor Documentation
| Cookie | ( | ) | 
Cookie class constructor.
Definition at line 54 of file PokittoCookie.cpp.
Member Function Documentation
| int begin | ( | const char * | idkey, | 
| int | datasize, | ||
| char * | ptr | ||
| ) | 
begin - Register your Cookie with a 8-byte key to begin using it
- Parameters:
- 
  8-byte key string size of cookie data in bytes pointer to beginning of cookie data in memory 
- Returns:
- 0 on success (free blocks available), non-0 on failure (no more free keys/blocks)
Definition at line 104 of file PokittoCookie.cpp.
| int begin | ( | const char * | key, | 
| T & | object | ||
| ) | 
begin - Register your Cookie with a 8-byte key to begin using it
- Parameters:
- 
  8-byte key string reference to cookie data object in memory 
- Returns:
- 0 on success (free blocks available), non-0 on failure (no more free keys/blocks)
Definition at line 107 of file PokittoCookie.h.
| bool blockIsOwnedBy | ( | int | n, | 
| int | k | ||
| ) | 
blockIsOwnedBy - check if block n is owned by Keytable entry k
- Parameters:
- 
  block number keytable entry number 
- Returns:
- true when keytable entry k is owner of block n false when is not
Definition at line 213 of file PokittoCookie.cpp.
| void cleanKeytable | ( | ) | 
cleanKeytable() - erase keys that have no blocks reserved from the keyTable
Definition at line 309 of file PokittoCookie.cpp.
| void deleteCookie | ( | ) | 
deleteCookie - your Cookie
Definition at line 140 of file PokittoCookie.cpp.
| void eraseKeytableEntry | ( | int | n ) | 
eraseKeyAt(int) - erase key at slot n
- Parameters:
- 
  slot number to erase 
Definition at line 300 of file PokittoCookie.cpp.
| int exists | ( | const char * | idkey ) | 
exists - find out if the key exists
- Parameters:
- 
  8-byte key string 
- Returns:
- slotnumber on key exists , SBINVALIDSLOT on does not exist
Definition at line 152 of file PokittoCookie.cpp.
| int findMyNextBlock | ( | ) | 
findMyNextBlock - find the next block assigned to this cookie
- Returns:
- number of next block
Definition at line 358 of file PokittoCookie.cpp.
| void formatKeytable | ( | ) | 
formatKeyTable(int) - erase all keys
- Parameters:
- 
  slot number to erase 
Definition at line 262 of file PokittoCookie.cpp.
| void freeBlock | ( | int | n ) | 
freeBlock - free block from blocktable and delete data of block in EEPROM
- Parameters:
- 
  block index number 
Definition at line 272 of file PokittoCookie.cpp.
| int getAssignedBlocks | ( | ) | 
getAssignedBlocks - return number of blocks already reserved for cookie
- Returns:
- number of blocks assigned to cookie
Definition at line 177 of file PokittoCookie.cpp.
| char getBlockTableEntry | ( | int | n ) | 
getBlockTableEntry - read an entry from the blocktable
- Parameters:
- 
  block table index number 
- Returns:
- block table entry (1 byte)
Definition at line 245 of file PokittoCookie.cpp.
| int getFreeBlocks | ( | ) | 
getFreeBlocks - Are there any storage blocks left to use
- Returns:
- number of blocks available
Definition at line 185 of file PokittoCookie.cpp.
| int getFreeKeytableSlot | ( | ) | 
getFreeKeytableSlot - Are there any keys left to use
- Returns:
- slot number 0...47 on success -1 on failure
Definition at line 167 of file PokittoCookie.cpp.
| int initialize | ( | ) | 
initialize - create cookie structure.
Can be called many times
- Returns:
- 0 on success (free blocks available), non-0 on failure (no more free keys/blocks)
Definition at line 59 of file PokittoCookie.cpp.
| bool isFreeBlock | ( | int | n ) | 
isFreeBlock - check if block n is free to use
- Parameters:
- 
  block number 
- Returns:
- true when free false when reserved
Definition at line 193 of file PokittoCookie.cpp.
| bool isMyBlock | ( | int | n ) | 
isMyBlock - check if block n is already reserved for this cookie
- Parameters:
- 
  block number 
- Returns:
- true when is already reserved false when is not
Definition at line 201 of file PokittoCookie.cpp.
| bool isOK | ( | ) | 
| bool loadCookie | ( | ) | 
loadCookie - Load your Cookie
- Returns:
- true on success false on failure
Definition at line 130 of file PokittoCookie.cpp.
| void readBlock | ( | int | n, | 
| char * | data | ||
| ) | 
readBlock - read the data of a block
- Parameters:
- 
  block index number pointer to a buffer of SBBLOCKSIZE size to hold the return data 
Definition at line 253 of file PokittoCookie.cpp.
| void readKeytableEntry | ( | int | n, | 
| char * | answer | ||
| ) | 
readKeytableEntry - return the key at slot n
- Parameters:
- 
  slot number to check pointer to a 9 char buffer for return answer 
Definition at line 235 of file PokittoCookie.cpp.
| char readQueue | ( | ) | 
readQueue - write the cookie data as a stream of bytes into the EEPROM blocks
- Returns:
- byte value from EEPROM memory
Definition at line 332 of file PokittoCookie.cpp.
| bool reserveBlock | ( | ) | 
reserveBlock - search and reserve a block from blocktable for use by this cookie
- Returns:
- true when it was possible to reserve a block false when it was not
Definition at line 286 of file PokittoCookie.cpp.
| bool saveCookie | ( | ) | 
saveCookie - Save your Cookie
- Returns:
- true on success (saved successfully and verified), false on failure (something is wrong)
Definition at line 119 of file PokittoCookie.cpp.
| void writeKeyToKeytable | ( | const char * | key, | 
| int | slot | ||
| ) | 
writeKeyToKeyTable - write the key into the key table
- Parameters:
- 
  8-byte key string slot number into which the key is written 0...47 
Definition at line 226 of file PokittoCookie.cpp.
| void writeQueue | ( | char | data ) | 
writeQueue - write the cookie data as a stream of bytes into the EEPROM blocks
- Parameters:
- 
  byte to be written 
Definition at line 347 of file PokittoCookie.cpp.
Field Documentation
| char _block | 
Current block block number that we are reading/writing.
Definition at line 336 of file PokittoCookie.h.
| int _datasize | 
Datasize size (in bytes) of cookie data to be saved and reloaded.
Definition at line 321 of file PokittoCookie.h.
| int _head | 
Head data "head" for byte write/read operations.
Definition at line 331 of file PokittoCookie.h.
| char _key[SBKEYSIZE] | 
keystring identification string for the Cookie
Definition at line 305 of file PokittoCookie.h.
| char _keyorder | 
Keyorder order number of key in key table.
Definition at line 310 of file PokittoCookie.h.
| char* _pointer | 
Pointer pointer to cookie data.
Definition at line 326 of file PokittoCookie.h.
| bool _status | 
Status false = uninitialized true = ready.
Definition at line 316 of file PokittoCookie.h.
Generated on Tue Jul 12 2022 21:03:53 by
 1.7.2
 1.7.2