def poll_tracker(self, time_limit): interm = UART.poll_tracker_params() if interm['ERROR'] == None: self.timings['last_tracker_poll'] = time.time() self.bools['tracker_polled'] = True update_existing_keys(self.tracker_params, interm) if self.tracer == True: self.calc_avg_wind_speed() else: if self.tracer == True: if time.time( ) - self.timings['last_tracker_poll'] > time_limit: if self.bools['tracker_polled'] == True: supDB.update_rpi_status('tracer RS458 read failure') logger.warn( "tracer failed to poll the tracker for more than %d sec" % time_limit) self.bools['tracker_polled'] = False else: if time.time() - self.timings[ 'last_tracker_poll'] > config.MAX_UART_DOWN_TIME: if self.bools['tracker_polled'] == True: supDB.update_rpi_status('RS458 read failure') logger.critical("RS485 read failure for more than %d seconds"\ %config.MAX_UART_DOWN_TIME) self.bools['tracker_polled'] = False
def set_wind_factor(self): success = UART.send_write_command(config.d['WindFactor'],config.WIND_MULTIPLIER) if success['ERROR'] == None: self.timings['last_tracker_update'] = time.time() self.bools['tracker_updated'] == True else: if time.time() - self.timings['last_tracker_update'] > config.MAX_UART_DOWN_TIME: if self.bools['tracker_updated'] == True: #logger.warn("RS485 write failure for more than %d seconds"\ #%config.MAX_UART_DOWN_TIME) supDB.update_rpi_status('RS458 write failure') self.bools['tracker_updated'] = 'False'
def clear_tracker_errors(self): success = UART.send_write_command(136,'clear') if success['ERROR'] == None: self.timings['last_tracker_update'] = time.time() self.bools['tracker_updated'] = True else: if time.time() - self.timings['last_tracker_update'] > config.MAX_UART_DOWN_TIME: if self.bools['tracker_updated'] == True: #logger.warn("RS485 write failure for more than %d seconds"\ #%config.MAX_UART_DOWN_TIME) supDB.update_rpi_status('RS458 write failure') self.bools['tracker_updated'] = 'False'
def poll_server(self): interm = httpReq.poll_server_params() if interm['ERROR'] == None: self.timings['last_http_req'] = time.time() self.bools['http_polled'] = True update_existing_keys(self.server_params,interm) else: if time.time() - self.timings['last_http_req'] > config.MAX_SERVERDOWN_TIME: if self.bools['http_polled'] == True: #logger.warn("Server is inactive for more than %d seconds"%config.MAX_SERVERDOWN_TIME) supDB.update_rpi_status("server_down") self.bools['http_polled'] = False
def tracker_activate(self): success = UART.send_write_command(config.d['Mode'], 'y') if success['ERROR'] == None: self.timings['last_tracker_update'] = time.time() self.bools['tracker_updated'] = True else: if time.time() - self.timings['last_tracker_update'] > \ config.MAX_UART_DOWN_TIME: if self.bools['tracker_updated'] == True: supDB.update_rpi_status('RS458 write failure') logger.warn("RS485 write failure for more than %d seconds"\ %config.MAX_UART_DOWN_TIME) self.bools['tracker_updated'] = 'False'
def IO_MGR(): global io_counter global current_state global id global sub_boss global max_wind_poll_counter global wind_poll_counter global ok_status if sub_boss.tracer == True: sub_boss.poll_tracker(max_wind_poll_counter) sub_boss.update_wind_ok(max_wind_poll_counter) else: if io_counter % 5 == 0: sub_boss.poll_tracker(max_wind_poll_counter) if io_counter == config.POLLING_INTERVAL: sub_boss.poll_server() sub_boss.update_cpu_temp() if sub_boss.tracer == False: sub_boss.db_update(current_state, max_wind_poll_counter) inst_status = True for each in sub_boss.bools.itervalues(): inst_status = inst_status and each if inst_status == False: break ok_status = inst_status if ok_status == True: supDB.update_rpi_status(current_state) if wind_poll_counter >= max_wind_poll_counter: if sub_boss.tracer == True: sub_boss.db_update(current_state, max_wind_poll_counter) else: sub_boss.update_wind_ok(max_wind_poll_counter) if io_counter >= config.POLLING_INTERVAL: io_counter = 0 sub_boss.reset_wifi() else: io_counter += 1 update_wind_counter_limit() if wind_poll_counter >= max_wind_poll_counter: wind_poll_counter = 0 else: if sub_boss.tracer == True: wind_poll_counter += 5 else: wind_poll_counter += 2
def update_wind_ok(self, time_limit): if self.tracer == False: interm = supDB.db_wind_poll() if interm['ERROR'] == None and \ time.time() - time.mktime(time.strptime(interm['last_modified'])) \ < 2*time_limit: self.tracker_params['wind_ok'] = interm['wind_ok'] self.polled_wind_speed = interm['wind_speed'] self.timings['last_wind_poll'] = time.time() self.bools['wind_polled'] = True else: if interm['ERROR'] == None: if self.bools['wind_polled'] == True: supDB.update_rpi_status('Tracer DB_inactivity') logger.warn("The tracer hasn't updated the db " "for more than %d seconds" % (2 * time_limit)) self.bools['wind_polled'] = False self.tracker_params['wind_ok'] = 'NO' else: if self.bools['wind_polled'] == True: logger.warn("DB down for more than %d sec" % (2 * time_limit)) self.bools['wind_polled'] = False ##action on no wind detection else: speed_now = config.MAX_INST_WIND_SPEED / 2 speed_avg = config.MAX_AVG_WIND_SPEED / 2 try: speed_now = float(self.tracker_params[config.d['WindSpeed']]) speed_avg = float(self.tracker_params['avg_wind_speed']) except Exception as err: logger.exception(err) if speed_now > config.MAX_INST_WIND_SPEED or speed_avg > \ config.MAX_AVG_WIND_SPEED or self.bools['tracker_polled'] == False: self.tracker_params['wind_ok'] = 'NO' else: self.tracker_params['wind_ok'] = 'YES' if self.bools['tracker_polled'] == True: self.timings['last_wind_poll'] = time.time() self.bools['wind_polled'] = True else: if time.time() - self.timings['last_wind_poll'] > \ 2*time_limit: if self.bools['wind_polled'] == True: logger.warn("No wind detection for more than %d sec" % (2 * time_limit)) self.bools['wind_polled'] = False
def send_to_idle(self): success1 = UART.send_write_command(config.d['Mode'],'n') time.sleep(0.5) success2 = UART.send_write_command(config.d['Angle_A'],config.IDLEA) time.sleep(0.5) success3 = UART.send_write_command(config.d['Angle_B'], config.IDLEB) if success1['ERROR'] == None and success2['ERROR'] == None \ and success3['ERROR'] == None: self.timings['last_tracker_update'] = time.time() self.bools['tracker_updated'] = True else: if time.time() - self.timings['last_tracker_update'] > config.MAX_UART_DOWN_TIME: if self.bools['tracker_updated'] == True: #logger.warn("RS485 write failure for more than %d seconds"\ #%config.MAX_UART_DOWN_TIME) supDB.update_rpi_status('RS458 write failure') self.bools['tracker_updated'] = 'False'
def tracker_update_motors(self): currentH = self.tracker_params[config.d['Target_Default_H']] currentV = self.tracker_params[config.d['Target_Default_V']] targetH = self.server_params['target_position_H'] targetV = self.server_params['target_position_V'] if currentH != targetH: successH = UART.send_write_command(config.d['Target_Default_H'], targetH) if currentV != targetV: successV = UART.send_write_command(config.d['Target_Default_V'], targetV) if successH['ERROR'] == None and successV['ERROR'] == None: self.timings['last_tracker_update'] = time.time() self.bools['tracker_updated'] = True else: if time.time() - self.timings['last_tracker_update'] > \ config.MAX_UART_DOWN_TIME: if self.bools['tracker_updated'] == True: supDB.update_rpi_status('RS458 write failure') logger.warn("RS485 write failure for more than %d seconds"\ %config.MAX_UART_DOWN_TIME) self.bools['tracker_updated'] = 'False'
def IO_MGR(): global io_counter global current_state global id global sub_boss global max_wind_poll_counter global wind_poll_counter global ok_status print io_counter print wind_poll_counter if not sub_boss.freeze: if sub_boss.tracer == True: print "tracer polling tracker" sub_boss.poll_tracker(max_wind_poll_counter) print "tracer update wind_ok" sub_boss.update_wind_ok(max_wind_poll_counter) else: if io_counter % 5 == 0: print "notracer poll tracker" sub_boss.poll_tracker(max_wind_poll_counter) if io_counter == config.POLLING_INTERVAL: print "poll server" sub_boss.poll_server() print "update temp" sub_boss.update_cpu_temp() if sub_boss.tracer == False: print "nontracer update db" sub_boss.db_update(current_state, max_wind_poll_counter) inst_status = True for each in sub_boss.bools.itervalues(): inst_status = inst_status and each if inst_status == False: break ok_status = inst_status if ok_status == True: print "update rpi status" supDB.update_rpi_status(current_state) if wind_poll_counter >= max_wind_poll_counter: if sub_boss.tracer == True: print "tracer update db" sub_boss.db_update(current_state, max_wind_poll_counter) else: print "nontracer update wind_ok" sub_boss.update_wind_ok(max_wind_poll_counter) if io_counter >= config.POLLING_INTERVAL: io_counter = 0 sub_boss.reset_wifi() else: io_counter += 1 update_wind_counter_limit() if wind_poll_counter >= max_wind_poll_counter: wind_poll_counter = 0 else: if sub_boss.tracer == True: wind_poll_counter += 5 else: wind_poll_counter += 2