private void PrepareBroadcastFrame(byte[] msg) { curBroadcastSeqNum++; // Some testing cases //System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); //msg = encoding.GetBytes(@"what is the problem of you?"); //payloadSizeUDP = 2; int pktPayloadSize = payloadSizeUDP; int numPkt = (int)Math.Ceiling((double)msg.Length / pktPayloadSize); curBroadcastFrame = new List<byte[]>(numPkt); curFrameLastPktSize = msg.Length - (numPkt - 1) * payloadSizeUDP; int seqNum; for (seqNum = 0; seqNum < numPkt; seqNum++) { byte[] curMsg; if (seqNum < numPkt - 1) { curMsg = msg.Skip(seqNum * pktPayloadSize).Take(pktPayloadSize).ToArray(); } else { curMsg = msg.Skip(seqNum * pktPayloadSize).Take(msg.Length - seqNum * pktPayloadSize).ToArray(); } BroadcastContentPar par = new BroadcastContentPar(); par.frameNum = curBroadcastSeqNum; par.seqNum = seqNum; byte[] newMsg = msgParser.getBroadcastCotentMsg(ref par, curMsg); curBroadcastFrame.Add(newMsg); } }
public byte[] getBroadcastCotentMsg(ref BroadcastContentPar par, byte[] data) { byte[] parBytes = new byte[POIMsgDefinition.POI_MAXPARAMETERSSIZE]; int offset = 0; serializeInt32(parBytes, ref offset, par.frameNum); serializeInt32(parBytes, ref offset, par.seqNum); parBytes = parBytes.Take(offset).ToArray(); return composePacket(POIMsgDefinition.POI_BROADCASTCONTENT, parBytes, data); }