static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) { int i = 0; pressure_t setpoint; setpoint.mbar = 0; struct event *ev = get_next_event(dc->events, "SP change"); if (!ev) return; do { i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds); setpoint.mbar = ev->value; if (setpoint.mbar) dc->divemode = CCR; ev = get_next_event(ev->next, "SP change"); } while (ev); set_setpoint(pi, i, setpoint.mbar, ~0u); }
configuration_result* tempcont::configure(const configuration_device_section& conf, int run) { std::map<const std::string,std::string>::const_iterator get=conf.attributes.find("get"); if (get!=conf.attributes.end()) { temp_history* h=get_history(0); configuration_result* res=h->as_result(); delete h; return res; } std::map<const std::string,std::string>::const_iterator set=conf.attributes.find("set"); if (set!=conf.attributes.end()) { // read new temperature setpoint const char* temp_str=set->second.c_str(); char* temp_str_end=NULL; double new_temperature=strtod(temp_str,&temp_str_end); if (temp_str_end!=set->second.size()+temp_str) { throw tempcont_error("could not read new temperature setpoint from attributes"); } // set the temperature double new_temp_return=set_setpoint(new_temperature); if (new_temp_return!=new_temperature) { char error_message[256]; snprintf(error_message, sizeof(error_message), "could not set new temperature setpoint %f!=%f", new_temp_return, new_temperature); throw tempcont_error(error_message); } // report success configuration_result* res=new configuration_result(0); XMLCh* myname=XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(conf.name.c_str()); XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* newelement=res->tag->createElement(myname); res->tag->insertBefore(newelement,NULL); XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&myname); return res; } return NULL; }
int pos_controller_old::reset() { set_setpoint(pos); return 0; }
// wildi ToDo this thread must go into a separate file void * oak_digin_thread(void * args) { int ret ; // wildi ToDo int *values = xmalloc(devInfo.numberOfChannels * sizeof(int)); int *values = malloc(200 * sizeof(int)); int rd_stat; int bits = 0xff; int print_bits = 0xff; int bit; int i ; int lastDoorStateTest= DS_UNDEF ; int lastDoorState= DS_UNDEF ; int stop_motor= STOP_MOTOR_UNDEFINED ; char bits_str[32] ; struct timespec sl ; struct timespec rsl ; static struct timeval time_last_stat; static struct timeval time_enq; gettimeofday(&time_last_stat, NULL); // debug int print =0 ; oak_thread_state= THREAD_STATE_UNDEFINED ; // make it "reentrant" sl.tv_sec= 0. ; sl.tv_nsec= (long ) 200 * 1000 * 1000 ; if( test_oak== TEST_OAK) { fprintf( stderr, "oak_digin_thread: test_oak== TEST_OK, sleep %d milliseconds\n", SLEEP_TEST_OAK_MILLISECONDS); } fprintf( stderr, "oak_digin_thread: thread started\n"); while (1) { oak_digin_thread_heart_beat++ ; if( oak_digin_thread_heart_beat > HEART_BEAT_UPPER_LIMIT) { oak_digin_thread_heart_beat= 0 ; } rd_stat = readInterruptReport(oakDiginHandle, values); if ((rd_stat < 0) && (errno == EINTR)) { oak_thread_state= THREAD_STATE_UNDEFINED ; // wildi ToDo something sensible here values[1]= fprintf( stderr, "oak_digin_thread: problems reading from oak device\n") ; } bits = values[1] & 0xff ; print_bits= values[1] & 0xff ; print= 0 ; for (i = 0; i < 8; i++) { bit = (print_bits & 0x1) ; if( bit) { bits_str[7-i]= '1' ; print++ ; } else { bits_str[7-i]= '0' ; } print_bits = print_bits >> 1; } bits_str[8]= '\0' ; //fprintf( stderr, "oak_digin_thread: doorState=%d, bits %s\n", doorState, bits_str) ; // turn off the motor first if((( bits & OAK_MASK_CLOSED) > 0) && (( doorState== DS_STOPPED_CLOSED) || ( doorState== DS_RUNNING_OPEN))) { // let the motor open the door stop_motor= STOP_MOTOR_UNDEFINED ; } else if((( bits & OAK_MASK_OPENED) > 0) && (( doorState== DS_STOPPED_OPENED) || ( doorState== DS_RUNNING_CLOSE) || ( doorState== DS_RUNNING_CLOSE_UNDEFINED))) { // let the motor close the door stop_motor= STOP_MOTOR_UNDEFINED ; } else if((( bits & OAK_MASK_CLOSED) > 0) && ( motorState== SSD650V_MS_RUNNING)) { // 2nd expr. necessary not to overload SSD650v on RS 232 stop_motor= STOP_MOTOR ; fprintf( stderr, "oak_digin_thread: found ( bits & OAK_MASK_CLOSED) > 0), bits %s\n", bits_str) ; } else if((( bits & OAK_MASK_OPENED) > 0) && ( motorState== SSD650V_MS_RUNNING)){ stop_motor= STOP_MOTOR ; fprintf( stderr, "oak_digin_thread: found (bits & OAK_MASK_OPENED) > 0), bits %s\n", bits_str) ; } else if ( (bits & OAK_MASK_END_SWITCHES) > 0) { // the motor is turned off and eventually OAK devices too (no cummunication possible) stop_motor= STOP_MOTOR ; } else if ( (bits & OAK_MASK_END_SWITCHES) == 0) { // both end switches are zero // the door is inbetween, (or beyond the software end switches :-(( = very close to the end switches) //fprintf( stderr, "oak_digin_thread: might be a bad reading from oak device\n") ; // see above ToDo // wildi ToDo: not yet defined what to do } // test if( test_oak== TEST_OAK) { if( lastDoorStateTest != doorState) { lastDoorStateTest= doorState ; gettimeofday(&time_last_stat, NULL); fprintf( stderr, "oak_digin_thread: status change resetting timer\n") ; } if( motorState== SSD650V_MS_RUNNING) { gettimeofday(&time_enq, NULL); if (difftimeval(&time_enq, &time_last_stat) > (SLEEP_TEST_OAK_MILLISECONDS * 1000)) { // milliseconds stop_motor= STOP_MOTOR ; fprintf( stderr, "oak_digin_thread: motorState== (DS_RUNNING_OPEN|DS_RUNNING_CLOSE), stopping now, diff %d[msec]\n", (int)difftimeval(&time_enq, &time_last_stat)) ; gettimeofday(&time_last_stat, NULL); fprintf( stderr, "oak_digin_thread: stopping motor after time ellapsed\n") ; } } if(( print > 0) && ( stop_motor != STOP_MOTOR)) { stop_motor= STOP_MOTOR ; fprintf( stderr, "oak_digin_thread: print stop_motor= STOP_MOTOR \n") ; } } // end test // manual mode, in case an endswitch erroneously indicates contact if(ignoreEndswitch==NOT_IGNORE_END_SWITCH){ if( stop_motor== STOP_MOTOR) { fprintf( stderr, "oak_digin_thread: stopping motor now\n") ; while(( ret= motor_off()) != SSD650V_MS_STOPPED) { // fprintf( stderr, "oak_digin_thread: can not turn motor off\n") ; ret= nanosleep( &sl, &rsl) ; if((errno== EFAULT) || ( errno== EINTR)||( errno== EINVAL )) { fprintf( stderr, "Error in nanosleep\n") ; errno= 0 ; } } set_setpoint(0.); fprintf( stderr, "oak_digin_thread: motor stopped\n") ; stop_motor= STOP_MOTOR_UNDEFINED ; struct ln_date utm; ln_get_date_from_sys( &utm) ; sprintf( date_time, "%4d-%02d-%02dT%02d:%02d:%02d", utm.years, utm.months, utm.days, utm.hours, utm.minutes, (int) utm.seconds) ; } } // door status if( motorState== SSD650V_MS_STOPPED) { // change status here if( bits & OAK_MASK_CLOSED) { // true if OAK sees the door doorState= DS_STOPPED_CLOSED ; if( lastDoorState != doorState) { lastDoorState= doorState ; fprintf( stderr, "oak_digin_thread: state is DS_STOPPED_CLOSED\n") ; } } else if( bits & OAK_MASK_OPENED) { // true if OAK sees the door doorState= DS_STOPPED_OPENED ; if( lastDoorState != doorState) { lastDoorState= doorState ; fprintf( stderr, "oak_digin_thread: state is DS_STOPPED_OPENED\n") ; } } else { doorState= DS_STOPPED_UNDEF ; lastDoorState= doorState ; //fprintf( stderr, "oak_digin_thread: state is DS_STOPPED_UNDEFINED\n") ; } } else if( motorState== SSD650V_MS_RUNNING) { // keep status here if( doorState == DS_RUNNING_OPEN) { } else if( doorState == DS_RUNNING_CLOSE) { } else if( doorState == DS_RUNNING_CLOSE_UNDEFINED) { } else { // should occasianally occur if the door is stopped manually doorState= DS_RUNNING_UNDEF ; lastDoorState= doorState ; //fprintf( stderr, "oak_digin_thread: motorState== SSD650V_MS_RUNNING, state is DS_RUNNING_UNDEF\n") ; } } else if( motorState== SSD650V_MS_UNDEFINED) { doorState= DS_UNDEF ; lastDoorState= doorState ; if( bits & OAK_MASK_OPENED) { // true if OAK sees the door fprintf( stderr, "oak_digin_thread: state is DS_UNDEF, door is opened, motor is undefined\n") ; } else if( bits & OAK_MASK_CLOSED) { // true if OAK sees the door fprintf( stderr, "oak_digin_thread: state is DS_UNDEF, door is closed, motor is undefined\n") ; } else { fprintf( stderr, "oak_digin_thread: state is DS_UNDEF, door is undefined, motor is undefined\n") ; } } else { // should never occur doorState= DS_UNDEF ; lastDoorState= doorState ; fprintf( stderr, "oak_digin_thread: state is DS_UNDEF, should never never occur\n") ; } CHECK_OAK_CALL(rd_stat); // wildi ToDo: what's that? } /* while (1) */ return NULL; }