Lolitech@545: from LPCProto import * Lolitech@545: Lolitech@545: class LPCBootProto(LPCProto): Lolitech@545: def HandleTransaction(self, transaction): Lolitech@545: self.TransactionLock.acquire() Lolitech@545: try: Lolitech@545: transaction.SetPseudoFile(self.serialPort) Lolitech@545: res = transaction.ExchangeData() Lolitech@545: finally: Lolitech@545: self.TransactionLock.release() Lolitech@545: return "Stopped", res Lolitech@545: Lolitech@545: class LPCBootTransaction: Lolitech@545: def __init__(self, optdata = ""): Lolitech@545: self.OptData = optdata Lolitech@545: self.pseudofile = None Lolitech@545: Lolitech@545: def SetPseudoFile(self, pseudofile): Lolitech@545: self.pseudofile = pseudofile Lolitech@545: Lolitech@545: def SendData(self): Lolitech@548: res = self.pseudofile.write(self.OptData) Lolitech@548: return True Lolitech@545: Lolitech@545: def GetData(self): Lolitech@545: pass # not impl Lolitech@545: Lolitech@545: def ExchangeData(self): Lolitech@545: pass Lolitech@545: edouard@567: class KEEPBOOTINGTransaction(LPCBootTransaction): edouard@567: def __init__(self): edouard@567: LPCBootTransaction.__init__(self, "md5\n") edouard@567: ExchangeData = LPCBootTransaction.SendData edouard@567: Lolitech@545: class LOADTransaction(LPCBootTransaction): edouard@569: def __init__(self, data, PLCprint): edouard@569: self.PLCprint = PLCprint Lolitech@545: LPCBootTransaction.__init__(self, data) Lolitech@545: edouard@569: def sendDataHook(self): edouard@569: #file("fw.bin","w").write(self.OptData) edouard@569: data = self.OptData edouard@569: loptdata = len(self.OptData) edouard@569: count=0 edouard@569: self.PLCprint("%dkB:" % (loptdata/1024)) edouard@569: while len(data)>0: edouard@569: res = self.pseudofile.write(data[:loptdata/100]) edouard@569: data = data[res:] edouard@569: count += 1 edouard@569: if count % 10 == 0 : edouard@569: self.PLCprint("%d%%" % count) edouard@569: else : edouard@569: self.PLCprint(".") edouard@569: self.PLCprint("\n") edouard@569: return True edouard@569: ExchangeData = sendDataHook edouard@569: edouard@569: if __name__ == "__main__": edouard@569: TestConnection = LPCBootProto(2,115200,1200) edouard@569: mystr=file("fw.bin").read() edouard@569: def mylog(blah): edouard@569: print blah, edouard@569: edouard@569: TestConnection.HandleTransaction(LOADTransaction(mystr, mylog))