def send_d_packge(packge_size = 1024, err_index=0, err_type = 0): load_size = len(data) index = 1 while(load_size ): in_data = '' if(load_size > packge_size): tran_size = packge_size else: tran_size = load_size if(err_index == index): index = index+1 send_buf = packge.build_data(ord('D'),index, tran_size, data[packge_size*(index-1):index*packge_size]) print 'send D packge index:',index,'len:',len(send_buf) index += 1 load_size = load_size - tran_size s.write(bytearray(send_buf)) ch = '' rt_no = 0 rt_no, ch = check_respons(ch,3000) if(rt_no > 0): break if(load_size == 0): time.sleep(1) rt_no, ch = check_respons(ch,3000) return rt_no, ch
def send_h_packge(err_type = -1): head_buf = packge.build_head(0x80000000, 0x80008000, 256, 284, data) send_buf = packge.build_data(ord('H'),0,284,head_buf) if(err_type>=0): #ERR1 send_buf[err_type]= chr(0xFF) elif(err_type == -2): #ERR2 del(send_buf[-1]) print '### send buf len:',len(send_buf),'err_type:',err_type elif(err_type == -11): #ERR2 del(send_buf[2:-1]) print '### send buf len:',len(send_buf),'err_type:',err_type elif(err_type == -6): #ERR6 :#define PACKGE_ERR_BIN_CRC_ERROR '6' head_buf[2] = chr(0xFF) send_buf = packge.build_data(ord('H'),0,284,head_buf) print '### send buf len:',len(send_buf),'err_type:',err_type elif(err_type == -7): #ERR7: head_buf[6] = chr(0x55) send_buf = packge.build_data(ord('H'),0,284,head_buf) print '### send buf len:',len(send_buf),'err_type:',err_type elif(err_type == -100): #ERR7 send_buf = packge.build_data(ord('H'),0,284,head_buf) for i in range(8000): send_buf.append(chr(0xFF)) print '### send buf len:',len(send_buf),'err_type:',err_type print 'send H packge len:',len(send_buf) s.write(bytearray(send_buf)) ch = '' rt_no=0 rt_no, ch = check_respons(ch,3000) return rt_no, ch