def main(): g = gpio.gpio() w = watchdog.watchdog(gpio=g) while True: w.pet() common.msleep(10 * 1000)
def resetSettings(self): self.logger.log.info("Resetting settings") self.connection.sendRaw(self.command["reset"]) # Sleep for 10 milliseconds as per the documentation # It seems sometimes it takes longer to reset the board, 1 sec is safe common.msleep(1000)
def clearScreen(self): self.logger.log.info("Clearing screen") self.connection.sendRaw(self.command["clearScreen"]) # Sleep for 10 milliseconds as per the documentation # It seems sometimes it takes longer to reset the board, 1 sec is safe common.msleep(1000)
def update_sensor(self, row_number, update_string): """ Update a given OSD row, with a given string Input: row_number: row number to update (int, 1 through 11) update_string: string to put in this row (string, 28 characters) """ self.osd232.setPosition(row=row_number) common.msleep(self.sleeptime) self.osd232.display(update_string) common.msleep(self.sleeptime)
def executeCommands(self, withDelay=None): while self.groundCommandList: command = self.groundCommandList.pop() try: command.execute(interfaces=self.interfaces) if withDelay: common.msleep(withDelay) except Exception as e: self.logger.log.error("Got exception: {} trying to execute command: {}".format(e, command.commandString)) self.logger.log.info("Executed command: {}".format(command.commandString))
def reset(self): """ Sends reset to the pressure sensor, ensures PROM is properly loaded to internal registers RETURNS boolean of write completion status: True=completed, False=failed """ # send reset self.deviceLogger.log.debug( "Sending reset to ensure PROM is properly loaded into internal registers..." ) write_status = self.sendWrite(pressSensorMS5607.REG_RESET) # wait non-zero amount of time for reset common.msleep(10) return write_status
def pet(self, withHoldTime=None): """ Pets the watchdog timer by pulsing the GPIO pin for the number of milliseconds specified by self.holdTime or withHoldTime (if present) """ self.set() if withHoldTime is not None: common.msleep(withHoldTime) elif self.holdTime is not None: common.msleep(self.holdTime) self.unset() self.logger.log.info("Toggled watchdog timer")
def execute(self, interfaces): # Execute osd command if osdCommand.subCommand[self.sub] == osdCommand.subCommand["OFF"]: # Turn off OSD self.logger.log.info("Command executing to turn off the OSD") interfaces.habip_osd.power_off() elif osdCommand.subCommand[self.sub] == osdCommand.subCommand["ON"]: # Turn on OSD self.logger.log.info("Command executing to turn on the OSD") interfaces.habip_osd.power_on() elif osdCommand.subCommand[self.sub] == osdCommand.subCommand["RST"]: # Reset OSD self.logger.log.info("Command executing to reset the OSD") interfaces.habip_osd.power_off() common.msleep(1000) interfaces.habip_osd.power_on() elif osdCommand.subCommand[self.sub] == osdCommand.subCommand["TEMP"]: # Update OSD temp sensor self.logger.log.info("Command executing to update the OSD temp") # sensorString = "{}:{}".format(self.board, self.sensor) # data = interfaces.boards[self.board].data[self.sensor] # interfaces.habip_osd.update_temp(data_source=sensorString, data_value=data) temperatureSensor = board.sensor(boardID=self.board, sensorID=self.sensor) interfaces.habip_osd.temperatureSensor = temperatureSensor elif osdCommand.subCommand[self.sub] == osdCommand.subCommand["PRES"]: # Update OSD pressure sensor self.logger.log.info("Command executing to update the OSD pressure") # sensorString = "{}:{}".format(self.board, self.sensor) # data = interfaces.boards[self.board].data[self.sensor] # interfaces.habip_osd.update_pres(data_source=sensorString, data_value=data) pressureSensor = board.sensor(boardID=self.board, sensorID=self.sensor) interfaces.habip_osd.pressureSensor = pressureSensor elif osdCommand.subCommand[self.sub] == osdCommand.subCommand["HUM"]: # Update OSD humidity sensor self.logger.log.info("Command executing to update the OSD humidity") # sensorString = "{}:H".format(self.board) # data = interfaces.boards[self.board].data["H"] # interfaces.habip_osd.update_humid(data_source=sensorString, data_value=data) humiditySensor = board.sensor(boardID=self.board, sensorID=self.sensor) interfaces.habip_osd.humiditySensor = humiditySensor
def streamTelemetry(self): stream = [] data = self.dataManager.getTelemetryStream() tmp = "" for item in data: if (len(tmp) + len(item)) > self.interfaces.beacon.MAX_PACKET_LEN: stream.append(tmp) tmp = item + ';' else: tmp += item + ';' if tmp: stream.append(tmp) for item in stream: item = item.strip(';') self.interfaces.beacon.send(item) common.msleep(100)
def main(): intf = interfaces.interfaces() intf.openspi() intf.opendaqcs() d = intf.daqcs while True: print "----------" print d.currentState # d.queueCommand("{06:1491592543}") # d.queueCommand("{05:B0}") # d.queueCommand("{06:1491592543}") d.update() for name, board in intf.boards.iteritems(): print "Data for board: {}".format(name) board.printAllData() common.msleep(3000)
def main(): osd = osd232.osd232(port=PORT, baudrate=BAUDRATE) osd.clearScreen() osd.resetSettings() osd.setPosition(row=1, column=8) common.msleep(100) osd.display("{} RIT TEAM HABIP {}".format(osd.symbol["satellite"], osd.symbol["heart"])) common.msleep(100) osd.setPosition(row=11) common.msleep(100) osd.display("KC3HUO") common.msleep(100) fakeData() osd.connection.close()
# Split the data from the various censors (semicolon separated) dataList = packetDataString.split(";") # Loop through the sensor data received for data in dataList: # Data goes boardNum:sensorAbbrev:value dataParts = data.split(":") # Grab the boardNum:sensorAbbrev portion of the data sensor = dataParts[0] + ":" + dataParts[1] # Grab the value for the sensor value = dataParts[2] # Add the value to the sensor data list if it is a valid sensor if sensor in habipSensors.keys(): habipSensorIndex = habipSensors[sensor] habipSensorData[habipSensorIndex] = value # Log data for all sensors if received any if receivedData: # Loop through the sensor data list and add the sensor values to the data log file, comma-separated dataToStoreString = "" for sensorData in habipSensorData: dataToStoreString += sensorData + "," dataLogger.info(dataToStoreString) # Sleep a bit common.msleep(1000)
def fakeData(): temp = 35.0 alt = 10000 pressure = 1.0 north = 43.0848 west = 77.6793 common.msleep(5000) for x in range(0, 20): counter = 6 osd.setPosition(row=counter) common.msleep(100) osd.display("Temp: {}C".format(str(temp))) common.msleep(100) temp -= 3 counter += 1 osd.setPosition(row=counter) common.msleep(100) osd.display("Alt: {}ft".format(str(alt))) common.msleep(100) alt += 10000 counter += 1 osd.setPosition(row=counter) common.msleep(100) osd.display("Pressure: {}B".format(str(pressure))) common.msleep(100) pressure -= 0.1 counter += 1 osd.setPosition(row=counter) common.msleep(100) osd.display("GPS: N{} W{}".format(north, west)) common.msleep(100) north += 0.034 west += 0.219 counter += 1 common.msleep(5000)
def readAll(self): """ Read the temperature (c/f), pressure (mBar, Pa), and calculate altitude (m/ft) RETURNS list of floats: [temp_c, temp_f, press_mbar, press_pa, altitude_m, altitude_f] """ # trigger D1 (digital pressure value) conversion write_status = self.sendWrite(pressSensorMS5607.REG_CONV_D1_4096) if (write_status == False): return [None, None, None, None, None] # wait longer than the max ADC conversion time (9.04ms for OSR=4096) or data will be corrupt common.msleep(10) # read the 24-bit (3 byte) ADC pressure result adc_pressure = self.readBlock(pressSensorMS5607.REG_ADC_READ, 3) if (adc_pressure == None): return [None, None, None, None, None] # trigger D2 (digital temperature value) conversion write_status = self.sendWrite(pressSensorMS5607.REG_CONV_D2_4096) if (write_status == False): return [None, None, None, None, None] # wait longer than the max ADC conversion time (9.04ms for OSR=4096) or data will be corrupt common.msleep(10) # read the 24-bit (3 byte) ADC temperature result adc_temperature = self.readBlock(pressSensorMS5607.REG_ADC_READ, 3) if (adc_temperature == None): return [None, None, None, None, None] # convert stored ADC value byte list to 24-bit value d1_pressure = (adc_pressure[0] << 16) | (adc_pressure[1] << 8) | ( adc_pressure[2]) d2_temp = (adc_temperature[0] << 16) | (adc_temperature[1] << 8) | ( adc_temperature[2]) # calculate temperature dT = d2_temp - self.T_REF # 25bit value, Difference between actual and reference temperature TEMP = 2000 + ( (dT * self.TEMPSENS) >> 23 ) # Actual temperature (-40...85C with 0.01C resolution) # second order temperature compensation T2 = 0 OFF2 = 0 SENS2 = 0 # if TEMP is < 2000 (aka less than 20.00C) if (TEMP < 2000): T2 = (dT**2) >> 31 OFF2 = (61 * ((TEMP - 2000)**2)) >> 4 SENS2 = 2 * ((TEMP - 2000)**2) self.deviceLogger.log.debug( "Read temperature is less than 20.00C, performing second order temperature compensation: T2 = {}, OFF2 = {}, SENS2 = {}" .format(hex(T2), hex(OFF2), hex(SENS2))) if (TEMP < -1500): OFF2 = OFF2 + (15 * ((TEMP + 1500)**2)) SENS2 = SENSE2 + (8 * ((TEMP + 1500)**2)) self.deviceLogger.log.debug( "Read temperature is ALSO less than -15.00C, modifying OFF2 and SENS2: OFF2 = {}, SENS2 = {}" .format(hex(OFF2), hex(SENS2))) # calculate temperature compensated pressure TEMP = TEMP - T2 # Adjusting TEMP with second order compensation (if no compensation then TEMP2 = 0) OFF = self.OFF_T1 + ( (self.TCO * dT) >> 6) # Offset at actual temperature OFF = OFF - OFF2 # Adjusting OFF with second order compensation (if no compensation then OFF2 = 0) SENS = self.SENS_T1 + ( (self.TCS * dT) >> 7) # Sensitivity at actual temperature SENS = SENS - SENS2 # Adjusting SENS with second order compensation (if no compensation then SENS2 = 0) P = ( ((d1_pressure * SENS) >> 21) - OFF ) >> 15 # Temperature compensated pressure (0...6000mbar with 0.03mbar resolution) press_pa = P # Pressure in Pascals # convert pressure to mBar press_mbar = P / 100.0 # Pressur in mBar # calculate altitude (in meters and feet) from the pressure reading altitude_m, altitude_ft = self.calculate_altitude(press_pa) # convert temp to proper sensor units temp_c = TEMP / 100.0 # Temperature in C temp_f = temp_c * (9.0 / 5.0) + 32 # Temperature in F self.prev_temp_c = temp_c self.prev_temp_f = temp_f self.prev_press_mbar = press_mbar self.prev_press_pa = press_pa self.prev_altitude_m = altitude_m self.prev_altitude_ft = altitude_ft #return [temp_c, temp_f, press_mbar, press_pa, altitude_m, altitude_ft] return [ "{:+08.3f}".format(temp_c), "{:+08.3f}".format(temp_f), "{:08.3f}".format(press_mbar), "{:08.1f}".format(press_pa), "{:010.3f}".format(altitude_m), "{:010.3f}".format(altitude_ft) ]