static void file_sample(orcm_sensor_sampler_t *sampler) { opal_output_verbose(5, orcm_sensor_base_framework.framework_output, "%s sensor file : file_sample: called", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); if (!mca_sensor_file_component.use_progress_thread) { collect_sample(sampler); } }
static void perthread_file_sample(int fd, short args, void *cbdata) { orcm_sensor_sampler_t *sampler = (orcm_sensor_sampler_t*)cbdata; opal_output_verbose(5, orcm_sensor_base_framework.framework_output, "%s sensor file : perthread_file_sample: called", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); /* this has fired in the sampler thread, so we are okay to * just go ahead and sample since we do NOT allow both the * base thread and the component thread to both be actively * calling this component */ collect_sample(sampler); /* we now need to push the results into the base event thread * so it can add the data to the base bucket */ ORCM_SENSOR_XFER(&sampler->bucket); /* clear the bucket */ OBJ_DESTRUCT(&sampler->bucket); OBJ_CONSTRUCT(&sampler->bucket, opal_buffer_t); /* set ourselves to sample again */ opal_event_evtimer_add(&sampler->ev, &sampler->rate); }
void AP_AccelCal::update() { if (!get_calibrator(0)) { // no calibrators return; } if (_started) { update_status(); AccelCalibrator *cal; uint8_t num_active_calibrators = 0; for(uint8_t i=0; (cal = get_calibrator(i)); i++) { num_active_calibrators++; } if (num_active_calibrators != _num_active_calibrators) { fail(); return; } if(_start_collect_sample) { collect_sample(); } switch(_status) { case ACCEL_CAL_NOT_STARTED: fail(); return; case ACCEL_CAL_WAITING_FOR_ORIENTATION: { // if we're waiting for orientation, first ensure that all calibrators are on the same step uint8_t step; if ((cal = get_calibrator(0)) == nullptr) { fail(); return; } step = cal->get_num_samples_collected()+1; for(uint8_t i=1 ; (cal = get_calibrator(i)) ; i++) { if (step != cal->get_num_samples_collected()+1) { fail(); return; } } // if we're on a new step, print a message describing the step if (step != _step) { _step = step; if(_use_gcs_snoop) { const char *msg; switch (step) { case ACCELCAL_VEHICLE_POS_LEVEL: msg = "level"; break; case ACCELCAL_VEHICLE_POS_LEFT: msg = "on its LEFT side"; break; case ACCELCAL_VEHICLE_POS_RIGHT: msg = "on its RIGHT side"; break; case ACCELCAL_VEHICLE_POS_NOSEDOWN: msg = "nose DOWN"; break; case ACCELCAL_VEHICLE_POS_NOSEUP: msg = "nose UP"; break; case ACCELCAL_VEHICLE_POS_BACK: msg = "on its BACK"; break; default: fail(); return; } _printf("Place vehicle %s and press any key.", msg); _waiting_for_mavlink_ack = true; } } uint32_t now = AP_HAL::millis(); if (now - _last_position_request_ms > AP_ACCELCAL_POSITION_REQUEST_INTERVAL_MS) { _last_position_request_ms = now; _gcs->send_accelcal_vehicle_position(step); } break; } case ACCEL_CAL_COLLECTING_SAMPLE: // check for timeout for(uint8_t i=0; (cal = get_calibrator(i)); i++) { cal->check_for_timeout(); } update_status(); if (_status == ACCEL_CAL_FAILED) { fail(); } return; case ACCEL_CAL_SUCCESS: // save if (_saving) { bool done = true; for(uint8_t i=0; i<_num_clients; i++) { if (client_active(i) && _clients[i]->_acal_get_saving()) { done = false; break; } } if (done) { success(); } return; } else { for(uint8_t i=0; i<_num_clients; i++) { if(client_active(i) && _clients[i]->_acal_get_fail()) { fail(); return; } } for(uint8_t i=0; i<_num_clients; i++) { if(client_active(i)) { _clients[i]->_acal_save_calibrations(); } } _saving = true; } return; default: case ACCEL_CAL_FAILED: fail(); return; } } else if (_last_result != ACCEL_CAL_NOT_STARTED) { // only continuously report if we have ever completed a calibration uint32_t now = AP_HAL::millis(); if (now - _last_position_request_ms > AP_ACCELCAL_POSITION_REQUEST_INTERVAL_MS) { _last_position_request_ms = now; switch (_last_result) { case ACCEL_CAL_SUCCESS: _gcs->send_accelcal_vehicle_position(ACCELCAL_VEHICLE_POS_SUCCESS); break; case ACCEL_CAL_FAILED: _gcs->send_accelcal_vehicle_position(ACCELCAL_VEHICLE_POS_FAILED); break; default: // should never hit this state break; } } } }
BOOL FPIFN FN_CALLBACK (WORD event_, WORD param_, DWORD flags_, LPCSTR message_, DWORD refdata_) { char name[200]; char fullname[500]; char eventstring[100]; char actionstring[100]; char virusmessage[300]; DWORD tickStart; DWORD tickNow; switch (event_) { case FPIEVENT_QUERYABORT: #if defined _CONSOLE && !defined UNIX if (kbhit()) { int c = getch(); if (c=='x') { printboth("\n[STOPPED BY USER]\n"); bExitScan = TRUE; return TRUE; } } #endif tickStart = get_ticks_from_refdata(refdata_); tickNow = GetTickCount(); if (tickStart != 0) { if (options.max_time > 0 && (double)(tickNow - tickStart) > options.max_time*1000.0) { printboth("\n[SINGLE-FILE TIME LIMIT EXCEEDED]\n"); return TRUE; } } return FALSE; case FPIEVENT_QUERY: break; case FPIEVENT_INFECTION: break; case FPIEVENT_ERROR: break; case FPIEVENT_DBVALIDATION: return event_dbvalidation(event_, param_, flags_, message_, refdata_); default: printboth("%s:\tFPI violation: Invalid event (%hu)\n", fullname, event_); nApiErrors++; break; } get_name_from_refdata(refdata_, name, sizeof name); get_fullname_from_refdata(refdata_, fullname, sizeof fullname); FPIFILEHANDLE handle = get_handle_from_refdata(refdata_); isFileClean = FALSE; virusmessage[0] = '\0'; if (event_ == FPIEVENT_QUERY || event_ == FPIEVENT_INFECTION) { strcpy(eventstring, "Infection"); if (flags_ & FPIFLAG_SUSPECTED) strcat(eventstring, "/suspected"); if ((flags_ & FPIFLAG_HEURISTIC) == FPIFLAG_HEURISTIC) strcat(eventstring, "/heuristic"); if ((flags_ & FPIFLAG_INTEGRITY) == FPIFLAG_INTEGRITY) strcat(eventstring, "/integrity"); if (flags_ & FPIFLAG_SUSPECTED) { isFileSuspicious = TRUE; if (flags_ & FPIFLAG_MSGEXTRA) { // message_ given, but no virus name available because it is only suspected strcat(virusmessage, message_); } else { // message_ ignored } } else { isFileInfected = TRUE; if (flags_ & FPIFLAG_MSGEXTRA) { // message_ contains actual virus name delimited with \x01 const char* firstdelim; BOOL bNameUnknown = FALSE; firstdelim = strchr(message_, '\x01'); if (firstdelim == NULL) { strcat(virusmessage, "Name unknown - invalid message format (FPI violation)"); nApiErrors++; bNameUnknown = TRUE; } else { int len = strcspn(firstdelim+1, "\x01"); strncat(virusmessage, firstdelim+1, len); } if (options.fullmessage || bNameUnknown) { strcat(virusmessage, "\tFull message:\t"); strcat(virusmessage, message_); } } else { // message_ *is* actual virus name strcpy(virusmessage, message_); } } } else if (event_ == FPIEVENT_ERROR) { strcpy(eventstring, "Error"); isFileFailed = TRUE; } switch (event_) { case FPIEVENT_QUERY: if (options.interest_infections) { if (options.ask) printboth("%s:\t%s:\t%s\n", fullname, eventstring, virusmessage); else printlog("%s:\t%s:\t%s\n", fullname, eventstring, virusmessage); collect_sample("inf", FPICONTAINERHANDLE_NULL, fullname, name, handle); } break; case FPIEVENT_INFECTION: if (options.interest_infections) { printlog("%s:\t%s:\t%s\n", fullname, eventstring, virusmessage); collect_sample("inf", FPICONTAINERHANDLE_NULL, fullname, name, handle); } break; case FPIEVENT_ERROR: if (options.interest_errors) { if (param_!=FPIERROR_WRONGAPI || !options.terse) { printboth("%s:\t%s\t(%hu = %s) %s\n", fullname, eventstring, param_, (param_ <= FPIERROR_LASTERROR ? fpierror[param_] : "unknown"), (message_ == NULL ? "" : message_)); collect_sample("err", FPICONTAINERHANDLE_NULL, fullname, name, handle); } } break; } if (event_ == FPIEVENT_INFECTION) { if (flags_ & FPIFLAG_SUSPECTED) { nSuspicious++; sumTicksSuspicious += GetTickCount() - tickStartFile; } else { nInfections++; sumTicksInfected += GetTickCount() - tickStartFile; } } if (event_ == FPIEVENT_ERROR) { nScanErrors++; } if (event_ == FPIEVENT_QUERY && param_ != FPIACTION_NONE) { if (param_ == FPIACTION_DISINFECT) strcpy(actionstring, "Disinfect"); else sprintf(actionstring, "Invalid action (%hu)", param_); if (!options.ask) { if (options.interest_infections) printlog("\tQuery: %s (yes, without asking)\n", actionstring); return TRUE; } else { if (query(actionstring)) { if (options.interest_infections) printboth(" yes\n"); return TRUE; } else { if (options.interest_infections) printboth(" no\n"); return FALSE; } } } if (event_ == FPIEVENT_INFECTION) { if (param_ == FPIACTION_NONE) { if (options.disinfect) strcpy(actionstring, "Nothing done"); else strcpy(actionstring, ""); } else if (param_ == FPIACTION_DISINFECT) { strcpy(actionstring, "Disinfected"); isFileDisinfected = TRUE; nDisinfections++; } else { sprintf(actionstring, "Invalid action performed (%hu)", param_); } if (actionstring[0] != '\0') { if (options.interest_infections) printlog("\t%s\n", actionstring); } } return FALSE; }
void AP_AccelCal::update() { if (!get_calibrator(0)) { // no calibrators return; } if (_started) { update_status(); AccelCalibrator *cal; uint8_t num_active_calibrators = 0; for(uint8_t i=0; (cal = get_calibrator(i)); i++) { num_active_calibrators++; } if (num_active_calibrators != _num_active_calibrators) { fail(); return; } if(_start_collect_sample) { collect_sample(); _gcs->set_snoop(NULL); _start_collect_sample = false; } switch(_status) { case ACCEL_CAL_NOT_STARTED: fail(); return; case ACCEL_CAL_WAITING_FOR_ORIENTATION: { // if we're waiting for orientation, first ensure that all calibrators are on the same step uint8_t step; if ((cal = get_calibrator(0)) == NULL) { fail(); return; } step = cal->get_num_samples_collected()+1; for(uint8_t i=1 ; (cal = get_calibrator(i)) ; i++) { if (step != cal->get_num_samples_collected()+1) { fail(); return; } } // if we're on a new step, print a message describing the step if (step != _step) { _step = step; const char *msg; switch (step) { case 1: msg = "level"; break; case 2: msg = "on its LEFT side"; break; case 3: msg = "on its RIGHT side"; break; case 4: msg = "nose DOWN"; break; case 5: msg = "nose UP"; break; case 6: msg = "on its BACK"; break; default: fail(); return; } _printf("Place vehicle %s and press any key.", msg); } // setup snooping of packets so we can see the COMMAND_ACK _gcs->set_snoop(_snoop); break; } case ACCEL_CAL_COLLECTING_SAMPLE: // check for timeout for(uint8_t i=0; (cal = get_calibrator(i)); i++) { cal->check_for_timeout(); } update_status(); if (_status == ACCEL_CAL_FAILED) { fail(); } return; case ACCEL_CAL_SUCCESS: // save if (_saving) { bool done = true; for(uint8_t i=0; i<_num_clients; i++) { if (client_active(i) && _clients[i]->_acal_get_saving()) { done = false; break; } } if (done) { success(); } return; } else { for(uint8_t i=0; i<_num_clients; i++) { if(client_active(i) && _clients[i]->_acal_get_fail()) { fail(); return; } } for(uint8_t i=0; i<_num_clients; i++) { if(client_active(i)) { _clients[i]->_acal_save_calibrations(); } } _saving = true; } return; default: case ACCEL_CAL_FAILED: fail(); return; } } }