public virtual void OnPayloadLenghtLSBReceided(byte e)
 {
     payloadLenghtLSB  = e;
     msgPayloadLenght += (ushort)(e << 0);
     actualState       = State.Waiting;
     OnPayloadLenghtLSBByteReceivedEvent?.Invoke(this, e);
     if (msgPayloadLenght <= ConstVar.MAX_MSG_LENGHT)
     {
         short allowedLenght = Protocol_Security.CheckFunctionLenght(msgFunction);
         if (allowedLenght != -2)
         {
             if (allowedLenght == -1 || allowedLenght == msgPayloadLenght)
             {
                 actualState     = State.Payload;
                 msgPayloadIndex = 0;
                 msgPayload      = new byte[msgPayloadLenght];
             }
             else
             {
                 OnWrongLenghtFunction();
             }
         }
         else
         {
             OnUnknowFunction();
         }
     }
     else
     {
         OnOverLenghtMessage();
     }
 }
Beispiel #2
0
        public void EncodeAndSendMessage(object sender, MessageByteArgs e)
        {
            short  PayloadLenghtTest = Protocol_Security.CheckFunctionLenght(e.MsgFunction);
            ushort msgPayloadLenght  = (ushort)e.MsgPayload.Length;

            if (PayloadLenghtTest != -2)
            {
                if (PayloadLenghtTest != -1)
                {
                    msgPayloadLenght = (ushort)PayloadLenghtTest;
                }
            }

            if (msgPayloadLenght == e.MsgPayload.Length)
            {
                byte[] msg      = EncodeWithoutChecksum(e.MsgFunction, msgPayloadLenght, e.MsgPayload);
                byte   checksum = CalculateChecksum(e.MsgFunction, msgPayloadLenght, e.MsgPayload);

                msg[msg.Length - 1] = checksum;
                OnSendMessage(e.MsgFunction, msgPayloadLenght, e.MsgPayload, checksum);
            }
            else
            {
                OnWrongPayloadSent();
            }
            if (PayloadLenghtTest == -2)
            {
                OnUnknownFunctionSent();
            }
        }
 public virtual void OnFunctionLSBReceived(byte e)
 {
     functionLSB  = e;
     msgFunction += (ushort)(e << 0);
     OnFunctionLSBByteReceivedEvent?.Invoke(this, e);
     if (Protocol_Security.CheckFunctionLenght(msgFunction) != -2)
     {
         actualState = State.PayloadLengthMSB;
     }
     else
     {
         actualState = State.Waiting;
         OnUnknowFunction();
     }
 }