void CProgramStorageObjectImpl::LoadAllProgramsForLevel(CLevelParserLine* levelSource, const std::string& userSource, bool loadSoluce) { int run = levelSource->GetParam("run")->AsInt(0)-1; bool allFilled = true; for (int i = 0; i < 10 || allFilled; i++) { std::string op = "script" + StrUtils::ToString<int>(i+1); // script1..script10 std::string opReadOnly = "scriptReadOnly" + StrUtils::ToString<int>(i+1); // scriptReadOnly1..scriptReadOnly10 std::string opRunnable = "scriptRunnable" + StrUtils::ToString<int>(i+1); // scriptRunnable1..scriptRunnable10 if (levelSource->GetParam(op)->IsDefined()) { std::string filename = levelSource->GetParam(op)->AsPath("ai"); GetLogger()->Trace("Loading program '%s' from level file\n", filename.c_str()); Program* program = AddProgram(); ReadProgram(program, filename); program->readOnly = levelSource->GetParam(opReadOnly)->AsBool(true); program->runnable = levelSource->GetParam(opRunnable)->AsBool(true); program->filename = levelSource->GetParam(op)->AsString(); if (m_object->Implements(ObjectInterfaceType::Programmable) && i == run) { dynamic_cast<CProgrammableObject*>(m_object)->RunProgram(program); } } else { allFilled = false; } } if (loadSoluce && levelSource->GetParam("soluce")->IsDefined()) { std::string filename = levelSource->GetParam("soluce")->AsPath("ai"); GetLogger()->Trace("Loading program '%s' as soluce file\n", filename.c_str()); Program* program = AddProgram(); ReadProgram(program, filename); program->readOnly = true; program->runnable = false; program->filename = levelSource->GetParam("soluce")->AsString(); } if (m_programStorageIndex >= 0) { GetLogger()->Debug("Loading user programs from '%s%.3d___.txt'\n", userSource.c_str(), m_programStorageIndex); for (unsigned int i = 0; i <= 999; i++) { std::string filename = userSource + StrUtils::Format("%.3d%.3d.txt", m_programStorageIndex, i); if (CResourceManager::Exists(filename)) { Program* program = GetOrAddProgram(i); if(GetCompile(program)) program = AddProgram(); // If original slot is already used, get a new one GetLogger()->Trace("Loading program '%s' from user directory\n", filename.c_str()); ReadProgram(program, filename); } } } }
void CProgramStorageObjectImpl::LoadAllProgramsForSavedScene(CLevelParserLine* levelSourceLine, const std::string& levelSource) { int run = levelSourceLine->GetParam("run")->AsInt(0)-1; m_programStorageIndex = levelSourceLine->GetParam("programStorageIndex")->AsInt(-1); for (int i = 0; i <= 999; i++) { std::string op = "script" + StrUtils::ToString<int>(i+1); // script1..script10 std::string opReadOnly = "scriptReadOnly" + StrUtils::ToString<int>(i+1); // scriptReadOnly1..scriptReadOnly10 std::string opRunnable = "scriptRunnable" + StrUtils::ToString<int>(i+1); // scriptRunnable1..scriptRunnable10 if (levelSourceLine->GetParam(op)->IsDefined()) { std::string filename = levelSourceLine->GetParam(op)->AsPath("ai"); GetLogger()->Trace("Loading program '%s' from saved scene\n", filename.c_str()); Program* program = GetOrAddProgram(i); ReadProgram(program, filename); program->readOnly = levelSourceLine->GetParam(opReadOnly)->AsBool(true); program->runnable = levelSourceLine->GetParam(opRunnable)->AsBool(true); program->filename = levelSourceLine->GetParam(op)->AsString(); if (m_object->Implements(ObjectInterfaceType::Programmable) && i == run) { dynamic_cast<CProgrammableObject*>(m_object)->RunProgram(program); } } } if(m_programStorageIndex < 0) return; GetLogger()->Debug("Loading saved scene programs from '%s/prog%.3d___.txt'\n", levelSource.c_str(), m_programStorageIndex); for (int i = 0; i <= 999; i++) { std::string opReadOnly = "scriptReadOnly" + StrUtils::ToString<int>(i+1); // scriptReadOnly1..scriptReadOnly10 std::string opRunnable = "scriptRunnable" + StrUtils::ToString<int>(i+1); // scriptRunnable1..scriptRunnable10 std::string filename = levelSource + StrUtils::Format("/prog%.3d%.3d.txt", m_programStorageIndex, i); if (CResourceManager::Exists(filename)) { GetLogger()->Trace("Loading program '%s' from saved scene\n", filename.c_str()); Program* program = GetOrAddProgram(i); ReadProgram(program, filename); program->readOnly = levelSourceLine->GetParam(opReadOnly)->AsBool(true); program->runnable = levelSourceLine->GetParam(opRunnable)->AsBool(true); if (m_object->Implements(ObjectInterfaceType::Programmable) && i == run) { dynamic_cast<CProgrammableObject*>(m_object)->RunProgram(program); } } } // Disable automatic user program storage now!! // This is to prevent overwriting auto-saved user programs with older versions from saved scenes m_allowProgramSave = false; }
// Add a log entry void SettingsAddLogEntry(unsigned short status, unsigned long timestamp, const char *message) { int len, i; // Check voltage ok to program //if (adcResult.batt < BATT_CHARGE_MIN_LOG) { return; } // Read existing data to RAM ReadProgram(LOG_ADDRESS, scratchBuffer, 512); // Move existing log entries down one row memmove(scratchBuffer + 2 * LOG_SIZE, scratchBuffer + 1 * LOG_SIZE, (LOG_COUNT - 1) * LOG_SIZE); *(unsigned short *)(scratchBuffer + 1 * LOG_SIZE) = status; *(unsigned long *)(scratchBuffer + 1 * LOG_SIZE + sizeof(unsigned short)) = timestamp; len = strlen(message); if (len > LOG_SIZE - 7) { len = LOG_SIZE - 7; } for (i = 0; i < LOG_SIZE - 6; i++) { char *p = (char *)(scratchBuffer + 1 * LOG_SIZE + sizeof(unsigned short) + sizeof(unsigned long)); if (i > len) { p[i] = '\0'; } else { p[i] = message[i]; } } // Rewrite program memory from RAM WriteProgramPage(LOG_ADDRESS, scratchBuffer, 512); return; }
// Get a log value unsigned short SettingsGetLogValue(unsigned int index) { unsigned short value = 0x0000; ReadProgram(LOG_ADDRESS + index * sizeof(unsigned short), &value, sizeof(unsigned short)); if (value == 0xffff) { value = 0x0000; } // If uninitialized return value; }
void SQueueParameters::Read(const IRegistry& reg, const string& sname) { qclass = reg.GetString(sname, "class", kEmptyStr); timeout = ReadTimeout(reg, sname); notif_hifreq_interval = ReadNotifHifreqInterval(reg, sname); notif_hifreq_period = ReadNotifHifreqPeriod(reg, sname); notif_lofreq_mult = ReadNotifLofreqMult(reg, sname); notif_handicap = ReadNotifHandicap(reg, sname); dump_buffer_size = ReadDumpBufferSize(reg, sname); run_timeout = ReadRunTimeout(reg, sname); program_name = ReadProgram(reg, sname); failed_retries = ReadFailedRetries(reg, sname); blacklist_time = ReadBlacklistTime(reg, sname); max_input_size = ReadMaxInputSize(reg, sname); max_output_size = ReadMaxOutputSize(reg, sname); subm_hosts = ReadSubmHosts(reg, sname); wnode_hosts = ReadWnodeHosts(reg, sname); wnode_timeout = ReadWnodeTimeout(reg, sname); pending_timeout = ReadPendingTimeout(reg, sname); max_pending_wait_timeout = ReadMaxPendingWaitTimeout(reg, sname); description = ReadDescription(reg, sname); run_timeout_precision = ReadRunTimeoutPrecision(reg, sname); return; }
// Retrieve a log entry const char *SettingsGetLogEntry(int index, unsigned short *status, unsigned long *timestamp) { if (index < 0 || index >= LOG_COUNT) { return NULL; } // Read existing data to RAM ReadProgram(LOG_ADDRESS, scratchBuffer, 512); if (status != NULL) *status = *(unsigned short *)(scratchBuffer + (1 + index) * LOG_SIZE); if (timestamp != NULL) *timestamp = *(unsigned long *)(scratchBuffer + (1 + index) * LOG_SIZE + sizeof(unsigned short)); return (const char *)(scratchBuffer + (1 + index) * LOG_SIZE + sizeof(unsigned short) + sizeof(unsigned long)); }
// Set a config value unsigned short SettingsSetConfigValue(unsigned int index, unsigned short value) { // Read existing data to RAM ReadProgram(SETTINGS_ADDRESS, scratchBuffer, 512); // Update value ((unsigned short *)scratchBuffer)[index] = value; // Store // Rewrite program memory from RAM WriteProgramPage(SETTINGS_ADDRESS, scratchBuffer, 512); return SettingsGetConfigValue(index); }
/* ========== ProgramsFileResource::Load Resource Load override. Loads the program info into the class. ========== */ bool ProgramsFileResource::Load( const char* path, char key ) { if (BinaryFileResource::Load(path, key)) { char* fileData = ReadFile(); unsigned char programCount = fileData[0]; char* programHeader = &fileData[1]; for ( unsigned char i = 0; i < programCount; ++i ) { ProgramInfo* program = ReadProgram( programHeader ); m_programs.push_back( program ); programHeader += program->GetDataSize(); } delete[] fileData; return true; } return false; }
// Update a log value unsigned short SettingsIncrementLogValue(unsigned int index) { unsigned short value; // Check voltage ok to program //if (adcResult.batt < BATT_CHARGE_MIN_LOG) { return 0xffff; } // Read existing data to RAM ReadProgram(LOG_ADDRESS, scratchBuffer, 512); // Update value value = ((unsigned short *)scratchBuffer)[index]; // Retrieve if (value == 0xffff) { value = 0x0000; } // If uninitialized value++; // Increment ((unsigned short *)scratchBuffer)[index] = value; // Store // Rewrite program memory from RAM WriteProgramPage(LOG_ADDRESS, scratchBuffer, 512); return value; }
// Get the device id unsigned short SettingsGetDeviceId(void) { unsigned short id = 0xffff; ReadProgram(DEVICE_ID_ADDRESS, &id, sizeof(unsigned short)); return id; }
// Get a config value unsigned short SettingsGetConfigValue(unsigned int index) { unsigned short value = 0xffff; ReadProgram(SETTINGS_ADDRESS + index * sizeof(unsigned short), &value, sizeof(unsigned short)); return value; }