virtual void Execute(){ bool valid = false; string input; console_.SystemPrompt("[CONFIG] "); console_.UserPrompt("[CONFIG] "); if(Interact()) { console_.Write("Enter the new FPGA image\n",CC::SYSTEM); console_.UserPrompt(); getline(cin, input); erase_all(input, " "); } else input = argList_[0]; fileName_ = IMAGE_PATH + input + IMAGE_EXT; ifstream in(fileName_.c_str(), std::ios::in); if(!in) console_.Write(input + " does not exist\n",CC::SYSTEM); else{ valid = true; mutex_.Lock(); if(okFrontPanel_.ConfigureFPGA(fileName_) < 0) console_.Write("failed to load" + fileName_ + "\n" ,CC::SYSTEM); else console_.Write("Loaded" + fileName_ + "\n",CC::SYSTEM); mutex_.Unlock(); } }
// setup the _var_info[] table bool AP_Param::setup(const AP_Param::Info *info, uint8_t num_vars, uint16_t eeprom_size) { struct EEPROM_header hdr; _eeprom_size = eeprom_size; _var_info = info; _num_vars = num_vars; if (!check_var_info()) { return false; } serialDebug("setup %u vars", (unsigned)num_vars); // check the header eeprom_read_block(&hdr, 0, sizeof(hdr)); if (hdr.magic[0] != k_EEPROM_magic0 || hdr.magic[1] != k_EEPROM_magic1 || hdr.revision != k_EEPROM_revision) { // header doesn't match. We can't recover any variables. Wipe // the header and setup the sentinal directly after the header serialDebug("bad header in setup - erasing"); erase_all(); } return true; }
prvreader::PrvEvent* prvreader::PrvParser::parseHeader(tokenizer<escaped_list_separator<char> > *tokens) { tokenizer<escaped_list_separator<char> >::iterator tokensIterator=tokens->begin(); string temp=*tokensIterator; erase_all(temp, GENERIC_SEP); replace(temp.begin(), temp.end(), '*', ':'); prvMetaData->setComment(temp); tokensIterator++; temp=*tokensIterator; tokensIterator++; vector<string> tokensTemp; split(tokensTemp, temp, is_any_of(PRV_HEADER_SEP_DURATION)); if (tokensTemp.size()>0){ prvMetaData->setDuration(stol(tokensTemp.operator [](PRV_HEADER_SUBFIELD_DURATION_VALUE))); } if (tokensTemp.size()>1){ prvMetaData->setTimeUnit(tokensTemp[PRV_HEADER_SUBFIELD_DURATION_UNIT]); }else{ prvMetaData->setTimeUnit(""); } temp=*tokensIterator; tokensIterator++; tokensTemp.clear(); split(tokensTemp, temp, is_any_of(GENERIC_SEP)); int nodes=atoi(tokensTemp.operator [](PRV_HEADER_SUBFIELD_HW_NODES).c_str()); prvMetaData->setNodes(nodes); vector<int> * cpus = new vector<int>(); temp=tokensTemp.operator [](PRV_HEADER_SUBFIELD_HW_CPUS); split(tokensTemp, temp, is_any_of(PRV_HEADER_SEP_HW_CPUS)); for (int i=0; i<tokensTemp.size(); i++){ cpus->push_back(atoi(tokensTemp.operator [](i).c_str())); } prvMetaData->setCpus(cpus); return new PrvOther(lineNumber, prveventtype::Header); }
/* re-initialise, using current mem_buffer */ bool AP_FlashStorage::re_initialise(void) { if (!flash_erase_ok()) { return false; } if (!erase_all()) { return false; } return write_all(); }
static void normalise(map<s32, CharReach> &look) { // We can erase entries where the reach is "all characters". vector<s32> dead; for (const auto &m : look) { if (m.second.all()) { dead.push_back(m.first); } } erase_all(&look, dead); }
bool addition_init::index_c(const std::string& name,char& ch) { if(name.empty()) return false; string cur_name = name; erase_all(cur_name,item_def::name_of(item_def::ADDI)); if(cur_name=="") return false; ch = cur_name[0]; return true; }
bool addition_dimension::parse(const std::string& name_value, addition_dimension::COL& col, string& value) {/*{{{*/ if(name_value.length()<2) return false; string symbol =item_def::name_of(item_def::ADDI); string name = name_value; erase_all(name,symbol); char index_c = name_value[0]; if(!addition_init::is_define(index_c)) return false; col = addition_init::index(index_c); value = name_value.c_str()+1; return true; }/*}}}*/
// setup the _var_info[] table bool AP_Param::setup(void) { struct EEPROM_header hdr; serialDebug("setup %u vars", (unsigned)_num_vars); // check the header hal.storage->read_block(&hdr, 0, sizeof(hdr)); if (hdr.magic[0] != k_EEPROM_magic0 || hdr.magic[1] != k_EEPROM_magic1 || hdr.revision != k_EEPROM_revision) { // header doesn't match. We can't recover any variables. Wipe // the header and setup the sentinal directly after the header serialDebug("bad header in setup - erasing"); erase_all(); } return true; }
void Object::ConnectScriptEvent(Object* sender, string name, Sqrat::Object receiver, string funcName) { Sqrat::Function func (receiver, funcName.c_str()); erase_all(name, " "); // name = type::Name(sender) + "::" + name; EventScript* con = nullptr; for(auto& evt : sender->events) { if(evt.first == name && typeid(*evt.second) == typeid(EventScript)) { con = static_cast<EventScript*>(evt.second.get()); con->Register(func); return; } } con = new EventScript(); con->Register(func); sender->events[name] = con; }
void test_initialize_filesystem(void) { int rv; erase_all(); rv = mkdir(BASE_FOR_TEST, S_IRWXU | S_IRWXG | S_IRWXO); rtems_test_assert(rv == 0); rtems_resource_snapshot_take(&before_mount); rv = mount( NULL, BASE_FOR_TEST, RTEMS_FILESYSTEM_TYPE_JFFS2, RTEMS_FILESYSTEM_READ_WRITE, &mount_data ); rtems_test_assert(rv == 0); }
static void normaliseLeftfix(map<s32, CharReach> &look) { // We can erase entries where the reach is "all characters", except for the // very first one -- this might be required to establish a minimum bound on // the literal's match offset. // TODO: It would be cleaner to use a literal program instruction to check // the minimum bound explicitly. if (look.empty()) { return; } const auto earliest = begin(look)->first; vector<s32> dead; for (const auto &m : look) { if (m.second.all() && m.first != earliest) { dead.push_back(m.first); } } erase_all(&look, dead); }
void update(int dummy) { int i, dir_diff, unclean; PLANE *pp, *p1, *p2; clck++; erase_all(); /* put some planes in the air */ do { unclean = 0; for (pp = ground.head; pp != NULL; pp = pp->next) { if (pp->new_altitude > 0) { delete(&ground, pp); append(&air, pp); unclean = 1; break; } } } while (unclean); /* do altitude change and basic movement */ for (pp = air.head; pp != NULL; pp = pp->next) { /* type 0 only move every other turn */ if (pp->plane_type == 0 && clck & 1) continue; pp->fuel--; if (pp->fuel < 0) loser(pp, "ran out of fuel."); pp->altitude += SGN(pp->new_altitude - pp->altitude); if (!pp->delayd) { dir_diff = pp->new_dir - pp->dir; /* * Allow for circle commands */ if (pp->new_dir >= 0 && pp->new_dir < MAXDIR) { if (dir_diff > MAXDIR/2) dir_diff -= MAXDIR; else if (dir_diff < -(MAXDIR/2)) dir_diff += MAXDIR; } if (dir_diff > 2) dir_diff = 2; else if (dir_diff < -2) dir_diff = -2; pp->dir += dir_diff; if (pp->dir >= MAXDIR) pp->dir -= MAXDIR; else if (pp->dir < 0) pp->dir += MAXDIR; } pp->xpos += displacement[pp->dir].dx; pp->ypos += displacement[pp->dir].dy; if (pp->delayd && pp->xpos == sp->beacon[pp->delayd_no].x && pp->ypos == sp->beacon[pp->delayd_no].y) { pp->delayd = 0; if (pp->status == S_UNMARKED) pp->status = S_MARKED; } switch (pp->dest_type) { case T_AIRPORT: if (pp->xpos == sp->airport[pp->dest_no].x && pp->ypos == sp->airport[pp->dest_no].y && pp->altitude == 0) { if (pp->dir != sp->airport[pp->dest_no].dir) loser(pp, "landed in the wrong direction."); else { pp->status = S_GONE; continue; } } break; case T_EXIT: if (pp->xpos == sp->exit[pp->dest_no].x && pp->ypos == sp->exit[pp->dest_no].y) { if (pp->altitude != 9) loser(pp, "exited at the wrong altitude."); else { pp->status = S_GONE; continue; } } break; default: loser(pp, "has a bizarre destination, get help!"); } if (pp->altitude > 9) /* "this is impossible" */ loser(pp, "exceeded flight ceiling."); if (pp->altitude <= 0) { for (i = 0; i < sp->num_airports; i++) if (pp->xpos == sp->airport[i].x && pp->ypos == sp->airport[i].y) { if (pp->dest_type == T_AIRPORT) loser(pp, "landed at the wrong airport."); else loser(pp, "landed instead of exited."); } loser(pp, "crashed on the ground."); } if (pp->xpos < 1 || pp->xpos >= sp->width - 1 || pp->ypos < 1 || pp->ypos >= sp->height - 1) { for (i = 0; i < sp->num_exits; i++) if (pp->xpos == sp->exit[i].x && pp->ypos == sp->exit[i].y) { if (pp->dest_type == T_EXIT) loser(pp, "exited via the wrong exit."); else loser(pp, "exited instead of landed."); } loser(pp, "illegally left the flight arena."); } } /* * Traverse the list once, deleting the planes that are gone. */ for (pp = air.head; pp != NULL; pp = p2) { p2 = pp->next; if (pp->status == S_GONE) { safe_planes++; delete(&air, pp); } } draw_all(); for (p1 = air.head; p1 != NULL; p1 = p1->next) for (p2 = p1->next; p2 != NULL; p2 = p2->next) if (too_close(p1, p2, 1)) { static char buf[80]; (void)snprintf(buf, sizeof buf, "collided with plane '%c'.", name(p2)); loser(p1, buf); } /* * Check every other update. Actually, only add on even updates. * Otherwise, prop jobs show up *on* entrance. Remember that * we don't update props on odd updates. */ if ((atcrandom() % sp->newplane_time) == 0) addplane(); }
// initialise storage bool AP_FlashStorage::init(void) { debug("running init()\n"); // start with empty memory buffer memset(mem_buffer, 0, storage_size); // find state of sectors struct sector_header header[2]; // read headers and possibly initialise if bad signature for (uint8_t i=0; i<2; i++) { if (!flash_read(i, 0, (uint8_t *)&header[i], sizeof(header[i]))) { return false; } bool bad_header = (header[i].signature != signature); enum SectorState state = (enum SectorState)header[i].state; if (state != SECTOR_STATE_AVAILABLE && state != SECTOR_STATE_IN_USE && state != SECTOR_STATE_FULL) { bad_header = true; } // initialise if bad header if (bad_header) { return erase_all(); } } // work out the first sector to read from using sector states enum SectorState states[2] {(enum SectorState)header[0].state, (enum SectorState)header[1].state}; uint8_t first_sector; if (states[0] == states[1]) { if (states[0] != SECTOR_STATE_AVAILABLE) { return erase_all(); } first_sector = 0; } else if (states[0] == SECTOR_STATE_FULL) { first_sector = 0; } else if (states[1] == SECTOR_STATE_FULL) { first_sector = 1; } else if (states[0] == SECTOR_STATE_IN_USE) { first_sector = 0; } else if (states[1] == SECTOR_STATE_IN_USE) { first_sector = 1; } else { // doesn't matter which is first first_sector = 0; } // load data from any current sectors for (uint8_t i=0; i<2; i++) { uint8_t sector = (first_sector + i) & 1; if (states[sector] == SECTOR_STATE_IN_USE || states[sector] == SECTOR_STATE_FULL) { if (!load_sector(sector)) { return erase_all(); } } } // clear any write error write_error = false; reserved_space = 0; // if the first sector is full then write out all data so we can erase it if (states[first_sector] == SECTOR_STATE_FULL) { current_sector = first_sector ^ 1; if (!write_all()) { return erase_all(); } } // erase any sectors marked full for (uint8_t i=0; i<2; i++) { if (states[i] == SECTOR_STATE_FULL) { if (!erase_sector(i)) { return false; } } } reserved_space = 0; // ready to use return true; }