1 int cishu=0; 2 if((dataLength)%1020!=0) 3 cishu=(dataLength)/1020+1; 4 else 5 cishu=(dataLength)/1020; 6 for(int i=0;i<cishu;i++){ 7 if((dataLength-1020)>0){ 8 sendBuf[3] = (byte)(1020>>24);//小于1020的表示改帧结束,此次发送的长度是datalength 9 sendBuf[2] = (byte)(1020>>16); 10 sendBuf[1] = (byte)(1020>>8); 11 sendBuf[0] = (byte)1020; 12 }else if((dataLength-1020)<0) 13 { 14 sendBuf[3] = (byte)(dataLength>>24);//1020表示改帧未结束,此次发出的长度是1020 15 sendBuf[2] = (byte)(dataLength>>16); 16 sendBuf[1] = (byte)(dataLength>>8); 17 sendBuf[0] = (byte)dataLength; 18 }else{ 19 sendBuf[3] = (byte)(1021>>24);//1021表示表示改帧是结束帧,此次发出的长度是1020 20 sendBuf[2] = (byte)(1021>>16); 21 sendBuf[1] = (byte)(1021>>8); 22 sendBuf[0] = (byte)1021; 23 } 24 if((dataLength-1020)>0) 25 { 26 System.arraycopy(buffer, i*1020, sendBuf, 4, 1020); 27 if(xjtuActivity.cv.sendMessage(sendBuf,1024)==false){ 28 xjtuActivity.messageShow.sendEmptyMessage(6); 29 break; 30 } 31 dataLength=dataLength-1020; 32 }else{ 33 System.arraycopy(buffer,(cishu-1)*1020,sendBuf,4,dataLength); 34 if(xjtuActivity.cv.sendMessage(sendBuf,dataLength+4)==false){ 35 xjtuActivity.messageShow.sendEmptyMessage(6); 36 break; 37 } 38 dataLength=0; 39 } 40 }