Пример #1
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();
            }
        }
Пример #2
0
 static public void PrintWrongMessage(object sender, MessageByteArgs e)
 {
     if (Console.CursorLeft != 0)
     {
         Console.WriteLine();
     }
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("\n /!\\ WARNING AN MESSAGED HAD BEEN CORRUPTED /!\\");
     Console.ResetColor();
 }
Пример #3
0
 static public void PrintSendMsg(object sender, MessageByteArgs e)
 {
     Console.ResetColor();
     if (Console.CursorLeft != 0)
     {
         Console.WriteLine();
     }
     Console.Write(hex_sender_index++ + ": ");
     Console.ForegroundColor = ConsoleColor.Black;
     Console.BackgroundColor = ConsoleColor.Magenta;
     Console.Write("0x" + e.SOF.ToString("X2") + " ");
     Console.BackgroundColor = ConsoleColor.Yellow;
     Console.Write("0x" + e.functionMsb.ToString("X2") + " 0x" + e.functionLsb.ToString("X2") + " ");
     Console.BackgroundColor = ConsoleColor.Cyan;
     Console.Write("0x" + e.lenghtMsb.ToString("X2") + " 0x" + e.lenghtLsb.ToString("X2") + " ");
     Console.BackgroundColor = ConsoleColor.White;
     foreach (byte x in e.MsgPayload)
     {
         Console.Write("0x" + x.ToString("X2") + " ");
     }
     Console.BackgroundColor = ConsoleColor.Green;
     Console.Write("0x" + e.checksum.ToString("X2") + " ");
     Console.ResetColor();
 }
Пример #4
0
 //Input CallBack
 public void ProcessRobotDecodedMessage(object sender, MessageByteArgs e)
 {
     ProcessDecodedMessage((Int16)e.MsgFunction, (Int16)e.MsgPayloadLength, e.MsgPayload);
 }
Пример #5
0
 static public void PrintWrongChecksum(object sender, MessageByteArgs e)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("0x" + e.checksum.ToString("X2") + " ");
     Console.ResetColor();
 }
Пример #6
0
 public void DisplayMessageDecodedError(object sender, MessageByteArgs e)
 {
     nbMsgReceivedErrors += 1;
 }