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 ExchangeData(self): edouard@571: self.pseudofile.write(self.OptData) edouard@571: return map(lambda x:self.pseudofile.readline(), xrange(self.expectedlines)) Lolitech@545: edouard@567: class KEEPBOOTINGTransaction(LPCBootTransaction): edouard@567: def __init__(self): edouard@571: self.expectedlines = 2 edouard@567: LPCBootTransaction.__init__(self, "md5\n") edouard@571: edouard@571: class STARTTransaction(LPCBootTransaction): edouard@571: def __init__(self): edouard@571: self.expectedlines = 0 edouard@571: LPCBootTransaction.__init__(self, "go\n") edouard@571: edouard@571: class CHECKMD5Transaction(LPCBootTransaction): edouard@571: def __init__(self, md5ref): edouard@571: self.expectedlines = 5 edouard@571: LPCBootTransaction.__init__(self, md5ref+"md5\n") 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@571: def ExchangeData(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: edouard@569: if __name__ == "__main__": edouard@571: __builtins__.BMZ_DBG = True 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))