unsigned char R5EEPROM::setServerParams(R5ServerParamsType *pServerParams) { EEPROMStorageType *pEEPROM = 0; int nAddr = (int)&pEEPROM->sServerParams; return (setBytesAtOffset((unsigned char *)pServerParams, sizeof(R5ServerParamsType), nAddr) ? 1 : 0);
unsigned char R5EEPROM::setSpeakRules(R5SpeakRulesType *pSpeakRules) { EEPROMStorageType *pEEPROM = 0; int nAddr = (int)&pEEPROM->speakRules; return (setBytesAtOffset((unsigned char *)pSpeakRules, sizeof(R5SpeakRulesType)*INSTINCT_NODE_TYPES*INSTINCT_RUNTIME_NOT_RELEASED, nAddr) ? 1 : 0);
// write the plan to the EEPROM unsigned char R5EEPROM::writeData(Instinct::CmdPlanner *pPlan, const unsigned int uiDataLen, unsigned char *pData) { Instinct::PlanNode sPlanNode; Instinct::instinctID bPlanElements[INSTINCT_NODE_TYPES]; Instinct::instinctID bElemCount = pPlan->planSize(); // total number of elements; unsigned int nPlanMemoryUsage = pPlan->planUsage(NULL); // total space used in RAM // calculate how much EEPROM we will use and return false if not enough unsigned int nEEPROMUsage = nPlanMemoryUsage + (bElemCount * sizeof(sPlanNode.bNodeType)) + uiDataLen; if (EEPROM.length() < (nEEPROMUsage + sizeof(EEPROMStorageType))) return false; Instinct::instinctID bMaxElementID = pPlan->maxElementID(); EEPROMStorageType *pEEPROM = 0; // first we store the number of Node structures we are going to write out pPlan->planSize(bPlanElements); // get the array of element counts from the plan setBytesAtOffset(bPlanElements, sizeof(bPlanElements), (int)&pEEPROM->bPlanElements); setIntAtOffset(pPlan->getPlanID(), (int)&pEEPROM->nPlanID); int nAddr = (int)&pEEPROM->bPlan; // read each element from the plan into a buffer and then write it to EEPROM for ( Instinct::instinctID i = 0; i < bMaxElementID; i++) { if (pPlan->getNode(&sPlanNode, i+1)) { int nSize = pPlan->sizeFromNodeType(sPlanNode.bNodeType); if (!nSize) // some bad thing has happened return false; nSize += sizeof(sPlanNode.bNodeType); nAddr += setBytesAtOffset((unsigned char *)&sPlanNode, nSize, nAddr); } } if (pData && uiDataLen) { // store the binary data at the end setBytesAtOffset(pData, uiDataLen, nAddr); setIntAtOffset(uiDataLen, (int)&pEEPROM->uiDataLen); } return true;
void DataSection::setBytesAtAddress(uint64_t addr, uint32_t size, char* content){ ASSERT(getSectionHeader()->inRange(addr)); ASSERT(size); ASSERT(getSectionHeader()->inRange(addr + size - 1)); setBytesAtOffset(addr - getSectionHeader()->GET(sh_addr), size, content); }