static void txudp(Byte[] txdata, Byte txtype, Byte filestat) { // add the txtype and filestatus at the beginning Byte[] darr = new byte[statics.PayloadLen + 2]; darr[0] = txtype; darr[1] = filestat; Array.Copy(txdata, 0, darr, 2, statics.PayloadLen); Udp.UdpSendData(darr); // Console.WriteLine("TX filestat: " + filestat+ " data:" + darr[2].ToString("X2") + " " + darr[3].ToString("X2")); }
// runs every 10 ms static void TimerTick(object stateInfo) { // check if we need to send something if (getSending() == false) { return; // nothing to send } // check the TX buffer, do not feed more data into // the buffer if it has already more than 10 entries if (Udp.GetBufferCount() > 3) { return; } Byte[] txarr = new byte[statics.PayloadLen]; // check if txdata is smaller or equal one payload if (filestat == statics.FirstFrame) { // send the first frame if (txlen <= statics.PayloadLen) { // we just need to send one frame txudp(txdata, txtype, statics.SingleFrame); setSending(false); // transmission complete } else { // additional frame follow // from txdata send one chunk of length statics.PayloadLen // frame is repeated for preamble by hsmodem.cpp Array.Copy(txdata, 0, txarr, 0, statics.PayloadLen); txudp(txarr, txtype, statics.FirstFrame); txpos = statics.PayloadLen; filestat = statics.NextFrame; } return; } if (filestat == statics.NextFrame) { // check if this is the last frame int restlen = txlen - txpos; if (restlen <= statics.PayloadLen) { // send as the last frame Array.Copy(txdata, txpos, txarr, 0, restlen); // unused byte will be 0 // send the last frame a couple of times for (int i = 0; i < 10; i++) { txudp(txarr, txtype, statics.LastFrame); } setSending(false); // transmission complete } else { // additional frame follows // from txdata send one chunk of length statics.PayloadLen Array.Copy(txdata, txpos, txarr, 0, statics.PayloadLen); txudp(txarr, txtype, statics.NextFrame); txpos += statics.PayloadLen; } return; } }