/* Idle, received gene. Replace current gene with new gene */ int action_s0_e4(convo_state_t* state) { DEBUGMSG; const char* content = mc_AclGetContent(state->acl); char* str = strdup(content+5); char* tok; int i; /* The beginning part of the content should be "GENE ", followed by 20 double * numbers. */ tok = strtok(str, " "); for(i = 0; i < GENE_SIZE; i++) { sscanf(tok, "%lf", &gene[i]); tok = strtok(NULL, " "); } g_fitness = costFunction(gene); mc_AgentVariableSave(mc_current_agent, "g_fitness"); /* Publish the fitness */ mc_AgentDataShare_Add(mc_current_agent, "fitness", &g_fitness, sizeof(g_fitness)); /* Save my fitness to a logfile */ saveLogFile(); /* printf("Agent received genes of fitness %le ", g_fitness); for(i = 0; i < GENE_SIZE; i++) { printf("%lf ", gene[i]); } printf("\n"); */ free(str); DEBUGMSG; return 1; }
void resetSystem(void) { // set watchdog timer to reset device; 0x780A (Watchdog Reset Control Register) // see GPL Programmer's Manual (V1.0 Dec 20,2006), Section 3.5, page 18 checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast stop(); if (PLEASE_WAIT_IDX && context.package) { // prevents trying to insert this sound before config & control files are loaded. insertSound(&pkgSystem.files[PLEASE_WAIT_IDX],NULL,TRUE); } checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast saveVolumeProfile(); logString((char *)"* RESET *",ASAP,LOG_ALWAYS); saveLogFile(0); fs_safexit(); // should close all open files disk_safe_exit(0); // try to get the sd card in a safe state - reverse what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); playBip(); setLED(LED_ALL,FALSE); *P_WatchDog_Ctrl &= ~0x4001; // clear bits 14 and 0 for resetting system and time=0.125 sec *P_WatchDog_Ctrl |= 0x8004; // set bits 2 and 15 for 0.125 sec, system reset, and enable watchdog while(1); }
void setOperationalMode(int newmode) { extern void buildMyStatsCSV(); extern void saveLogFile(int); if(newmode == (int)P_WAIT) { // stop(); --- should we see if we can WAIT while paused in an audio file? SysIntoWaitMode(); // when leaving wait mode, next instruction is executed, so we return here return; } else { // give visual feedback of shutting down (aural feedback when user causes shutdown in takeAction()) setLED(LED_ALL,TRUE); buildMyStatsCSV(); buildExchgOstats(); clearDeleteQueue(); write_config_bin(); // build a config.bin writeVersionToDisk(SYSTEM_PATH); // make sure the version file is correct confirmSNonDisk(); // make sure the serial number file is correct //cleanUpOldRevs(); // cleanup any old revs // assume calling for sleep or halt *P_Clock_Ctrl |= 0x200; //bit 9 KCEN enable IOB0-IOB2 key change interrupt if (newmode == (int)P_HALT) logString((char *)"Halting",BUFFER,LOG_NORMAL); else // newmode == (int)P_SLEEP logString((char *)"Sleeping",BUFFER,LOG_NORMAL); saveLogFile(0); Snd_Stop(); // no logging setLED(LED_ALL,FALSE); turnAmpOff(); disk_safe_exit(0); // try to get the sd card in a safe state - reversw what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); turnNORoff(); if (newmode == (int)P_HALT) { /* setRTCalarmSeconds(61); // device should come back on in 61 seconds */ SysIntoHaltMode(); } else { // newmode == (int)P_SLEEP disk_safe_exit(0); _SystemOnOff(); } while(1); // cpu reset on exiting halt/sleep mode, so nothing below here executes } }
void housekeeping() { // give visual feedback of shutting down (aural feedback when user causes shutdown in takeAction()) setLED(LED_ALL,TRUE); saveVolumeProfile(); exportFlashStats(); write_config_bin(); // build a config.bin //checkDoubleSRNprefix(); // this can be removed once the dup serial number prefixes are fixed //confirmSNonDisk(); // make sure the serial number file is correct buildMyStatsCSV(); buildExchgOstats(); clearDeleteQueue(); saveLogFile(0); }