// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved


// This software makes use of tools and libraries obtained from open source projects or released for

// use by relevant hardware manufactures. However, this software is NOT a part of any open source project.

// It is released only on a "need to know" basis for beta testers of the "RiceCNC Interpolation Engine".

// Recipents of this source code must respect the confidential nature of this software and prevent any

// distribution that could result in counterfeit copies of the "RiceCNC Interpolation Engine".


// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved

#include <UDPResequence.h>

#include "SysTick.h"

#include <MySerial.h>

#include <MyEthernetUdp.h>



UDPResequence::UDPResequence( struct rxBuf* aRxBuf ) {

     remoteIP          = aRxBuf->remoteIP;

     remotePort          = aRxBuf->remotePort;

     packetLength     = aRxBuf->packetLength;

     

     memcpy(

          (char*)               &packet,               // destination pointer

          (const char*)     &aRxBuf->packet,     // source pointer

          packetLength ); };


size_t

     UDPResequence::payloadSize() {


     return

          packetLength - PacketHeaderSize; };


bool

     UDPResequence::isRestart() {

     

     return

          packet.version == 0; };


void

     UDPResequence::sendDebug() {


     char data[ 40 ];

     snprintf( data, 40,

          " rx<%d<%d<%d<%x<%d",

          packet.version,

          packet.sequence,

          packet.ack,

          packet.ackBitField,

          packetLength );

     String msg = String( data );


     char* payloadPtr = packet.payload;

     for ( int i = 0; i < packet.messageCount; i++ ) {

          msg          += "<";

          msg          += String( payloadPtr );

          while ( *payloadPtr++ ); }; // advance to next string


     msg          += "<<";

     MySerial::sendMessageNonBlocking( &msg ); };