Exemple #1
0
 private void Decode_Demande_Info(Communication.Communication_Message message, Trame_Decoder decoder)
 {
     if (message.Trame.Slave_Adresse == Communication.Slave_Adresses.PC)
     {
         decoder.Allow_To_Send();
     }
 }
Exemple #2
0
    private void Decode_Logger_Debug(Communication.Communication_Message message)
    {
        Logger_Debug debugger = new Logger_Debug();

        //décompose les datas du message recu
        Logger_Debug.Log_Message data = debugger.Trame_To_Data(message.Trame);
        //tranforme-les en un Log
        string time = $"{message.Heure.Hour}:{message.Heure.Minute}:{message.Heure.Second}:{message.Heure.Millisecond}";

        Color color;

        switch (data.data.Color)
        {
        default:
        case Logger_Debug.Logger_Debug_Color.Color_Black:
            color = Color.black;
            break;

        case Logger_Debug.Logger_Debug_Color.Color_Blue:
            color = Color.blue;
            break;

        case Logger_Debug.Logger_Debug_Color.Color_Red:
            color = Color.red;
            break;
        }

        Logger_New_Line.Logger_Message log = new Logger_New_Line.Logger_Message(time, data.data.Channel, color, data.str);

        Logger_New_Line.Logger_Viewer.Add_New_Logger_Line(log);
    }
Exemple #3
0
 public void Add_Message_To_Queue(Communication.Communication_Message message)
 {
     if (Decodeurs[0] != null)
     {
         Decodeurs[0].Pop_Message(message);
     }
 }
Exemple #4
0
 public void Send_Trame(Communication.Communication_Trame trame)
 {
     Communication.Communication_Message message = new Communication.Communication_Message();
     message.Heure = DateTime.Now;
     message.Trame = trame;
     Push_Message_Out(message);
 }
Exemple #5
0
    private void Send_Message(Communication.Communication_Message message_to_Send)
    {
        List <byte> OutputBuffer = new List <byte>();

        Sending_Data encoder = new Sending_Data();

        SendBytes(serialPort, encoder.Send_Trame(message_to_Send));
    }
Exemple #6
0
    public void Decodage_Message(Communication.Communication_Message message, Trame_Decoder decoder)
    {
        if (message == null)
        {
            return;
        }
        switch (message.Trame.Instruction)
        {
        default:
            break;

        case Communication.Com_Instruction.BOOTLOADER_ACK:
            Bootloader_ACK_Recieved = true;
            break;

        case Communication.Com_Instruction.LOGGER_DEBUG:
            Decode_Logger_Debug(message);
            break;

        case Communication.Com_Instruction.REPONSE_INFO_Multi_FCT:
            Decode_Reponse_Info(message);
            break;

        case Communication.Com_Instruction.REPONSE_INFO_IA:
            Decode_Reponse_Info_IA(message);
            break;

        case Communication.Com_Instruction.ASTAR_CONTENU:
            Decode_ASTAR_Contenu(message);
            break;

        case Communication.Com_Instruction.ASTAR_VECTEURS_Fixes:
            Decode_ASTAR_Vector(message, true);
            break;

        case Communication.Com_Instruction.ASTAR_VECTEURS_Mobiles:
            Decode_ASTAR_Vector(message, false);
            break;

        case Communication.Com_Instruction.STRATEGIE_CHANGEMENT_ETAT:
            Decode_Strategie_Changement_Etat(message);
            break;

        case Communication.Com_Instruction.GRAPHIQUES_ADD_DATA:
            Decode_Graphique_Datas(message);
            break;

        case Communication.Com_Instruction.DEMANDE_INFO:
            Decode_Demande_Info(message, decoder);
            break;
        }

        //compte le nombre de messages recus
        Nb_Messages_Interpretes++;
    }
Exemple #7
0
    private void Decode_Reponse_Info_IA(Communication.Communication_Message message)
    {
        Infos_Carte temp = new Infos_Carte();

        //Interprete un message de type "Infos des cartes IA"
        //Transforme la trame en un message interpretable
        Infos_Carte.Com_Reponse_Info_IA data = temp.Trame_To_Data_IA(message.Trame);

        //Maj de la classe contenant les dernieres infos pour toutes les cartes
        Last_Data_Received.Update_Last_Data_Received_IA(data);
    }
Exemple #8
0
    private void Decode_Graphique_Datas(Communication.Communication_Message message)
    {
        Graphique.st_Graph_Datas datas = new Graphique.st_Graph_Datas();
        //décompose les datas du message recu
        datas = Graph_viewer.GetComponent <Graphique>().Trame_To_Data(message.Trame);

        //Ajoute les data au graphique
        if (Graph_viewer != null)
        {
            Graph_viewer.GetComponent <Graphique>().Ajoute_Data(datas);
        }
    }
Exemple #9
0
    public void Pick_Message(out Communication.Communication_Message message)
    {
        if (Received_Messages.Count > 0)
        {
            message = Received_Messages.Dequeue();
            return;
        }

        message = null;
        //Aucun message à lire
        return;
    }
Exemple #10
0
    public void Decodage_and_Save_Message(Communication.Communication_Message message, Trame_Decoder decoder)
    {
        if (message == null)
        {
            return;
        }
        //Pour chaque décodeur (chacun son tour)
        Decodage_Message(message, decoder);

        //Enregistre pour le log
        Save_Message(message);
    }
Exemple #11
0
    public void Push_Message_Out(Communication.Communication_Message message)
    {
        Nb_Messages_Envoies++;

        //Log le message envoyé
        this.GetComponent <Interprete_Message>().Save_Message(message);

        //Envoi le message sur chaque port connecté
        foreach (Trame_Decoder encoder in Decodeurs)
        {
            encoder.Push_Message_Out(message);
        }
    }
Exemple #12
0
    /* Prend un message, et transforme-le en trame pret à partir, avec en-tête X-bee et CRC */
    public byte[] Send_Trame(Communication.Communication_Message Message_to_send)
    {
        Message_to_send.Trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;         //Envoie du PC vers tous les XBEE par defaut

        byte[] data = new byte[Message_to_send.Trame.Length + 11];
        data[0] = 0x7E;                                 //Xbee API start byte

        int length = Message_to_send.Trame.Length + 7;

        data[1] = (byte)(length >> 8);                                      //length high
        data[2] = (byte)(length & 0xFF);                                    //length low

        data[3] = 0x01;                                                     //Frame type: Tx, 16 bits addr
        data[4] = 0x01;                                                     //Frame ID

        data[5] = (byte)((int)Message_to_send.Trame.XBEE_DEST_ADDR >> 8);   //add high
        data[6] = (byte)((int)Message_to_send.Trame.XBEE_DEST_ADDR & 0xFF); //add low

        data[7] = 0x00;                                                     //Option

        byte index = 0;
        //Datas
        {
            data[8] = (byte)(Message_to_send.Trame.Instruction);

            data[9] = (byte)(Message_to_send.Trame.Slave_Adresse);

            for (index = 0; index < Message_to_send.Trame.Length; index++)
            {
                data[10 + index] = Message_to_send.Trame.Data[index];
            }
        }

        short API_CRC = 0;

        for (index = 3; index < 10 + Message_to_send.Trame.Length; index++)
        {
            API_CRC += data[index];
        }

        API_CRC &= 0xFF;
        API_CRC  = (byte)(0xFF - API_CRC);

        data[index] = (byte)(API_CRC);

        return(data);
    }
Exemple #13
0
    private void Decode_Strategie_Changement_Etat(Communication.Communication_Message message)
    {
        Action_Strategie decoder = new Action_Strategie();

        Action_Strategie.Action_Datas data = new Action_Strategie.Action_Datas();
        //décompose les datas du message recu
        data = decoder.Trame_To_Data(message.Trame);

        //Ajoute une ligne à l'historique des changements d'états de la Strategie
        if (Action_History_go != null)
        {
            Action_History_go.GetComponent <Action_History>().Update_Action(data);
        }

        //Met à jour le tableau avec l'ensemble des actions
        Action_Liste.Update_Action(data, data.Robot_ID);
    }
Exemple #14
0
    public void Add_Data(Communication.Communication_Message message_to_add)
    {
        if (message_to_add.Trame.Data.Length != Communication.COMMUNICATION_TRAME_MAX_DATA)
        {
            byte[] new_data = new byte[Communication.COMMUNICATION_TRAME_MAX_DATA];
            for (int index = 0; index < message_to_add.Trame.Data.Length; index++)
            {
                new_data[index] = message_to_add.Trame.Data[index];
            }

            message_to_add.Trame.Data = new_data;
        }


        messages.Add(message_to_add);
        Nombre_Messages = messages.Count;
    }
Exemple #15
0
 private void Decode_ASTAR_Vector(Communication.Communication_Message message, bool fixes)
 {
     ASTAR_VECT.Reception_Message_Astar_Vector(message.Trame, fixes);
 }
Exemple #16
0
 private void Decode_ASTAR_Contenu(Communication.Communication_Message message)
 {
     ASTAR.Reception_Message_Astar(message.Trame);
 }
Exemple #17
0
 public void Save_Message(Communication.Communication_Message message)
 {
     message.message_number = message_number++;
     file_Logger.Write_Logging_Data(message);
 }
Exemple #18
0
    private void Reading_Task(string file)
    {
        //vérifie qu'il y a bien des données à lire
        if (deserialized_data.messages.Count == 0)
        {
            return;
        }

        Interprete_Message Interpreter = this.GetComponent <Interprete_Message>();

        //start asynchronous data sending
        tasks.Add(Task.Factory.StartNew(async() =>
        {
            Logger_New_Line.Log($"Start Reading logged data: {System.IO.Path.GetFileName(file)}", 6, Color.black);
            Communication.Communication_Message message_output = new Communication.Communication_Message();

            DateTime heure_premier_enregistrement = deserialized_data.messages[0].Heure;

            TimeSpan delay     = new TimeSpan();
            DateTime last_hour = heure_premier_enregistrement;

            //Si une pause dans la lecture est demandee
            while (Pause_Reading_Token)
            {
                await Task.Delay(100);
            }

            //Pour chaque message dans la Liste
            foreach (Communication.Communication_Message message in deserialized_data.messages)
            {
                //Attend que l'heure de traiter ce message soit venue
                delay = message.Heure.Subtract(last_hour);

                await Task.Delay(Math.Abs((int)(delay.TotalMilliseconds / Reading_Speed)));

                //interprete ce message
                try
                {
                    Interpreter.Add_Message_To_Queue(message);
                }
                catch
                {
                    Logger_New_Line.Log("Exception while reading", 6, Color.red);
                }

                Nb_Lines_Read++;

                last_hour = message.Heure;

                //si on demande l'arret de la lecture
                if (Stop_Reading_Token)
                {
                    throw new TaskCanceledException();
                }

                //Si une pause dans la lecture est demandee
                while (Pause_Reading_Token)
                {
                    await Task.Delay(100);
                }
            }
        }));
    }
Exemple #19
0
    private static async Task <bool> EnvoiAsync(System.IO.Ports.SerialPort serialPort1, Trame_Decoder decoder)
    {
        byte[] data_to_send;

        //Envoie le message
        Sending_Data comm = new Sending_Data();

        Communication.Communication_Message trame = new Communication.Communication_Message();

        trame.Trame.Instruction = Communication.Com_Instruction.BOOTLOADER;

        trame.Trame.Slave_Adresse = (Communication.Slave_Adresses)destination_board;

        trame.Trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;


        int page_length = 0;

        //start listening for messages and copy the messages back to the client
        foreach (string _line in _lines)
        {
            byte _line_length = TwoChar_To_Byte(_line[1], _line[2]);

            page_length += _line_length;

            data_to_send = ReadHexLine_to_ByteArray(_line);

            trame.Trame.Length = (byte)data_to_send.Length;
            for (int i = 0; i < data_to_send.Length; i++)
            {
                trame.Trame.Data[i] = data_to_send[i];
            }

            //Envoi du message
            decoder.Push_Message_Out(trame);

            //Cree une trame de communication
            line_number_position++;


            /*await Task.Delay(2);
             * if(page_length >= 4096)
             * {
             *  await Task.Delay(200);
             *  page_length = 0;
             * }*/

            //await Task.Delay(1);

            while (decoder.Received_Messages.Count == 0)
            {
                ;
            }
            if (decoder.Received_Messages.Dequeue().Trame.Instruction == Communication.Com_Instruction.BOOTLOADER_ACK)
            {
                await Task.Delay(1);
            }
            else
            {
                return(false);
            }

            if (cancellationToken)
            {
                throw new TaskCanceledException();
            }
        }

        return(true);
    }
Exemple #20
0
 public void Push_Message_Out(Communication.Communication_Message message)
 {
     this.serialport.OutputMessages.Enqueue(message);
 }
Exemple #21
0
    public void Start()
    {
        data_test = new Infos_Carte.Com_Reponse_Info();

        data_test.Numero_Robot = Infos_Carte.Com_Position_Robot_Identification.Gros_Robot;
        data_test.Numero_Carte = 1;

        data_test.PositionRobot.Position_X = 2500;
        data_test.PositionRobot.Position_Y = 10000;
        data_test.PositionRobot.Angle      = 12300;

        data_test.Position_Servos             = new Infos_Carte.Com_Position_Servos();
        data_test.Position_Servos.Position    = new ushort[Infos_Carte.NB_SERVO];
        data_test.Position_Servos.Position[0] = 500;
        data_test.Position_Servos.Position[1] = 600;
        data_test.Position_Servos.Position[2] = 300;
        data_test.Position_Servos.Position[3] = 800;
        data_test.Position_Servos.Position[4] = 100;
        data_test.Position_Servos.Position[5] = 50;

        data_test.Position_AX12             = new Infos_Carte.Com_Position_AX12();
        data_test.Position_AX12.Position    = new ushort[Infos_Carte.NB_AX_12];
        data_test.Position_AX12.Position[0] = 500;
        data_test.Position_AX12.Position[1] = 250;
        data_test.Position_AX12.Position[2] = 26;
        data_test.Position_AX12.Position[3] = 128;

        data_test.Position_AX12.Torque    = new short[Infos_Carte.NB_AX_12];
        data_test.Position_AX12.Torque[0] = 500;
        data_test.Position_AX12.Torque[1] = 250;
        data_test.Position_AX12.Torque[2] = 26;
        data_test.Position_AX12.Torque[3] = 128;

        data_test.Mesures_Analogiques           = new Infos_Carte.Com_Mesures_Analogiques();
        data_test.Mesures_Analogiques.Mesure    = new ushort[Infos_Carte.NB_MES_ANA];
        data_test.Mesures_Analogiques.Mesure[0] = 1023;
        data_test.Mesures_Analogiques.Mesure[1] = 2046;
        data_test.Mesures_Analogiques.Mesure[2] = 3069;
        data_test.Mesures_Analogiques.Mesure[3] = 4092;

        data_test.Tension_Batterie = 1524;

        data_test.Etat_Alim        = 0b11111111;
        data_test.Etat_Contacteurs = 0b11111111;

        Communication com = new Communication();

        Communication.Communication_Message message = new Communication.Communication_Message();
        message.Heure             = DateTime.Now;
        message.Trame.Instruction = Communication.Com_Instruction.REPONSE_INFO_Multi_FCT;
        message.Trame.Data        = com.COPYDATA(data_test);

        //Communication_GO.GetComponent<Interprete_Message>().Decodage_and_Save_Message(message);



        data_test.Numero_Robot = Infos_Carte.Com_Position_Robot_Identification.Petit_Robot;
        data_test.Numero_Carte = 1;

        data_test.PositionRobot.Position_X = 10000;
        data_test.PositionRobot.Position_Y = 15000;
        data_test.PositionRobot.Angle      = 0;
        message.Trame.Data = com.COPYDATA(data_test);

        //this.StartCoroutine("test_logger_quantity");
        //this.StartCoroutine(test_logger_saver());


        Trame_Decoder[] encoder = Communication_GO.GetComponentsInChildren <Trame_Decoder>();



        tasks.Add(Task.Factory.StartNew(async() =>
        {
            await Task.Delay(15000);


            for (int i = 0; i < 4000; i++)
            {
                data_test.PositionRobot.Position_X++;
                //data_test.PositionRobot.Position_Y--;
                data_test.PositionRobot.Angle += 3;

                message                   = new Communication.Communication_Message();
                message.Heure             = DateTime.Now;
                message.Trame.Instruction = Communication.Com_Instruction.REPONSE_INFO_Multi_FCT;
                message.Trame.Data        = com.COPYDATA(data_test);


                encoder[0].Push_Message_Out(message);

                await Task.Delay(150);
            }
        }));
    }
Exemple #22
0
    /* Reception des octets reçus et transformation en une trame brute */
    public static Communication.Communication_Message ReadTrame(Virtual_SerialPort _SerialPort)
    {
        Communication.Communication_Message received_message = new Communication.Communication_Message();

        byte  API_start = 0, API_LENGTH_HIGH = 0, API_LENGTH_LOW = 0, API_DUMMY, API_FRAME_TYPE = 0;
        short API_LENGTH = 0;
        short crc = 0;
        byte  index = 0, rx_crc = 0;

        //reception de l'heure de la trame
        received_message.Heure = DateTime.Now;

        //Reception En-tête API
        byte boucle = 0;

        while (API_start != 0x7E)
        {
            _SerialPort.ReadRemoveInputByte(out API_start);
            boucle++;
            if (boucle > 5)
            {
                Debug.Log("API_start != 0x7E");
                return(null);
            }
        }

        //Le start byte est recu, on demarre la lecture de la trame
        _SerialPort.ReadRemoveInputByte(out API_LENGTH_HIGH);
        _SerialPort.ReadRemoveInputByte(out API_LENGTH_LOW);

        API_LENGTH   = API_LENGTH_HIGH;
        API_LENGTH <<= 8;
        API_LENGTH  += API_LENGTH_LOW;

        if (API_LENGTH > Communication.COMMUNICATION_TRAME_MAX_DATA + 11)
        {
            Debug.Log("API_LENGTH > Communication.COMMUNICATION_TRAME_MAX_DATA + 11");
            return(null);
        }

        //Packet Type
        _SerialPort.ReadRemoveInputByte(out API_FRAME_TYPE);
        crc += API_FRAME_TYPE;

        if (API_FRAME_TYPE == 0x89)
        {
            //Tx status
            _SerialPort.ReadRemoveInputByte(out API_DUMMY);
            crc += API_DUMMY;

            _SerialPort.ReadRemoveInputByte(out API_DUMMY);
            crc += API_DUMMY;

            if (API_DUMMY == 00)
            {
                //Mess tx succes
                //RxXbeeAck = OK;
            }

            //API CRC
            _SerialPort.ReadRemoveInputByte(out rx_crc);
            return(null);
        }

        boucle = 0;
        while (_SerialPort.Number_Byte_To_Read() < API_LENGTH - 1)
        {
            boucle++;
            if (boucle > 50)
            {
                Debug.Log($"_SerialPort.InputBuffer.Count < API_LENGTH - 1; boucle {_SerialPort.Number_Byte_To_Read()}/{API_LENGTH + 1}");
                return(null);
            }
            Task.Delay(1);
        }

        //Tx Address
        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        crc += API_DUMMY;

        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        crc += API_DUMMY;

        //RSSI
        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        crc += API_DUMMY;

        //Option
        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        crc += API_DUMMY;

        //Reception datas
        //Instruction
        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        received_message.Trame.Instruction = (Communication.Com_Instruction)(API_DUMMY);
        crc += (byte)received_message.Trame.Instruction;

        //Slave Address
        _SerialPort.ReadRemoveInputByte(out API_DUMMY);
        received_message.Trame.Slave_Adresse = (Communication.Slave_Adresses)(API_DUMMY);
        crc += (byte)received_message.Trame.Slave_Adresse;

        //Trame length
        received_message.Trame.Length = (byte)(API_LENGTH - 7);

        if (received_message.Trame.Length > Communication.COMMUNICATION_TRAME_MAX_DATA)
        {
            Debug.Log("received_message.Trame.Length > Communication.COMMUNICATION_TRAME_MAX_DATA");
            return(null);
        }


        boucle = 0;
        while (_SerialPort.Number_Byte_To_Read() < received_message.Trame.Length + 1)
        {
            boucle++;
            if (boucle > 50)
            {
                Debug.Log("SerialPort.InputBuffer.Count < received_message.Trame.Length + 1; boucle");
                return(null);
            }
            Task.Delay(1);
        }

        //Reception des data
        for (index = 0; index < received_message.Trame.Length; index++)
        {
            _SerialPort.ReadRemoveInputByte(out received_message.Trame.Data[index]);
            crc += (byte)(received_message.Trame.Data[index]);
        }

        //API CRC
        _SerialPort.ReadRemoveInputByte(out rx_crc);

        //Contrôle CRC
        crc &= 0xFF;
        crc  = (byte)(0xFF - crc);

        //Vérifie le CRC
        if (crc == rx_crc)
        {
            return(received_message);
        }
        else
        {
            if (index == 0)
            {
                Debug.Log($"Error Comm CRC: {crc}/RX crc: {rx_crc}; previous: {(byte)received_message.Trame.Slave_Adresse}, instruction: {received_message.Trame.Instruction}");
            }
            else
            {
                Debug.Log($"Error Comm CRC: {crc}/RX crc: {rx_crc}; previous: {received_message.Trame.Data[index - 1]}, instruction: {received_message.Trame.Instruction}");
            }
            return(null);
        }
    }
Exemple #23
0
 public void Pop_Message(Communication.Communication_Message message)
 {
     Received_Messages.Enqueue(message);
 }