def getTrack(self, trackPtr): checksum = Utilities.checkersum("05800100%s" % (trackPtr)) self._writeSerial('getTracks', **{'trackPtr':trackPtr, 'checksum':checksum}) newtrack = None i = 0 while True: data = self._readPayload() time.sleep(0) if data != '8A000000': #did we get a new train data session ? self.logger.debug(data) if len(data) == 136 or len(data) == 120: self.logger.debug('initalizing new track') #save the old track if it exists and instantiate a new one newtrack = TrackWithLaps().fromHex(data[6:-2], self.timezone) i = 1 #new laps data session is always after train header elif i == 1: self.logger.debug('adding laps') newtrack.addLapsFromHex(data[54:-2]) i = 2 #new points data session? else: self.logger.debug('adding trackpoints from new session') newtrack.addTrackpointsFromHex(data[54:-2]) # progress bars are nice progress = int(100 * len(newtrack.trackpoints)/newtrack.trackpointCount) bar = progress/2 print '\r[{0}] {1}%'.format('#'*bar + '-'*(50-bar), progress), sys.stdout.flush() self._writeSerial('requestNextTrackSegment') else: #we are done, do maintenance work here if sys.platform == 'linux' or sys.platform == 'linux2': os.system('setterm -cursor on') print for lap in newtrack.laps: lap.calculateCoordinates(newtrack.trackpoints) #self.logger.debug(lap) break self.logger.debug('added 1 track') return newtrack
def setWaypoints(self, waypoints): waypointsConverted = ''.join([hex(waypoint) for waypoint in waypoints]) numberOfWaypoints = Utilities.swap(Utilities.dec2hex(len(waypoints), 8)) payload = Utilities.dec2hex(5 + (20 * len(waypoints)), 4) checksum = Utilities.checkersum("%s76%s%s" % (str(payload), str(numberOfWaypoints), waypointsConverted)) response = self._querySerial('setWaypoints', **{'payload':payload, 'numberOfWaypoints':numberOfWaypoints, 'waypoints': waypointsConverted, 'checksum':checksum}) if response[:6] == '760004': waypointsUpdated = int(Utilities.swap(response[6:10]), 16) self.logger.debug('waypoints updated: %i' % waypointsUpdated) return waypointsUpdated else: self.logger.error('error uploading waypoints') return False