def requestFilelist(self, filename=None, overwrite=False): filelist = [] resp = self.request(u"\xda\x00\x04\x05") if resp == None: return filelist, False num_files = RDLaser.toNumber(resp) for i in range(0, num_files): resp = self.request(u"\xe8\x01" + RDLaser.fromNumber(i + 1, 2)) if resp == None: break filename_ = resp[:-1].upper() ''' fileno = RDLaser.toNumber(resp[:2], 2) if i+1 != fileno: raise ValueError("Reported filenumber does not match iterator") ''' filelist.append(filename_) if filename is not None and filename.upper() == filename_[:-1]: while not daemon: print "Duplicate Filename %s, overwrite?" % filename inp = raw_input("[Y/N] ") if inp.lower() == "y": overwrite = True break elif inp.lower() == "n": break if overwrite: self.send(u"\xe8\x00" + RDLaser.fromNumber(i + 1, 2) + RDLaser.fromNumber(i + 1, 2)) return filelist, True return filelist, False if filename is not None: self.send(u"\xe8\x02\xe7\x01" + filename + u"\x00") return filelist, True
def sendSystemInfo(self, addr, opt): # 0x01 = TOTAL ON TIME (s) # 0x02 = TOTAL PROCESSING TIME (s) # 0x03 = TOTAL PROCESSING TIMES (#) # 0x08 = PREVIOUS PROCESSING TIME (ms) # 0x11 = TOTAL TRAVEL Y (m) # 0x23 = TOTAL TRAVEL X (m) self.send(addr, u"\xda\x01\x04" + chr(opt) + RDLaser.fromNumber(0))
def sendFilelist(self, addr): if self.debug: print u"\x1B[31m# SEND FILELIST\x1B[0m" files = next(os.walk(self.filedir))[2] num_files = len(files) i = 0 while i < num_files: if "." in files[i] and files[i].rsplit('.', 1)[1].lower() == "rd": i += 1 else: del files[i] num_files -= 1 fname = "" self.send(addr, u"\xda\x01\x04\x05" + RDLaser.fromNumber(len(files))) for i in range(0, len(files)): data, sender_addr = self.recv() if len(data) == 6 and ord(data[-1]) is i: if self.debug: print u"\x1B[5m\x1B[31m# DUPLICATE FILE, NO LONGER SEND FILELIST\x1B[0m\x1B[25m" return #request processing time elif data[-2] == u"\x07": self.callback(addr, data) data, sender_addr = self.recv() elif ord(data[-1]) is not i + 1: if self.debug: print u"\x1B[5m\x1B[31m# INVALID REQUEST, CANCELLED DOWNLOAD?\x1B[0m\x1B[25m" self.callback(addr, data) return fname = files[i].split('.', 1)[0] #Send filename, \0 terminated self.send( sender_addr[0], u"\xe8\x01" + (RDLaser.fromNumber(i + 1, 2) + fname[:8].upper()) + u"\x00") if self.debug: print(u"\x1B[31m# FILELIST SENT\x1B[0m")
def deleteFile(self, fileno): self.init() self.send(u"\xe8\x00" + RDLaser.fromNumber(fileno, 2) + RDLaser.fromNumber(fileno, 2))
def calculateTime(self, fileno): self.init() return RDLaser.toNumber( self.request(u"\xe8\x04" + RDLaser.fromNumber(fileno, 2)))
def getFile(self, fileno, file): self.init() self.send(u"\xe5" + RDLaser.fromNumber(fileno, 2)) while True: self.request(u"\xe5\x01\x01" + RDLaser.fromNumber(i, 5)) file.close()
def moveAxis(self, axis, nm=10000, speed=100000): self.send(u"\xc9\x02" + RDLaser.fromNumber(speed)) return self.send(u"\xd9" + chr(axis) + u"\x02" + RDLaser.toNumber(nm))
def respond(self, addr, data, n): self.send(addr, u"\xda\x01" + data[2:4] + RDLaser.fromNumber(n))