Esempio n. 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();
     }
 }
Esempio n. 2
0
    public void Bootloader_Start_BurningAsync()
    {
        if (Application_HEX_File_Path == null)
        {
            Status.GetComponent <TextMeshProUGUI>().text = "No file path found";
            return;
        }

        int index = Portcom_dropdown.GetComponent <TMPro.TMP_Dropdown>().value;
        var list  = Portcom_dropdown.GetComponent <TMPro.TMP_Dropdown>().options;

        this.GetComponent <Virtual_SerialPort>().portSpeed = portSpeed;

        //Set port COM name
        this.GetComponent <Virtual_SerialPort>().Connect(list[index].text);

        if (this.GetComponent <Virtual_SerialPort>().getserialPort().IsOpen == false)
        {
            Status.GetComponent <TextMeshProUGUI>().text = "No port opened";
            return;
        }


        //Read all file lines:
        _lines = System.IO.File.ReadAllLines(Application_HEX_File_Path);

        try
        {
            max_line_number = _lines.Length;

            destination_board = Destination.GetComponent <TMPro.TMP_Dropdown>().value;

            ProgressBar.GetComponent <Slider>().maxValue = _lines.Length;

            Status.GetComponent <TextMeshProUGUI>().text = "Burning";

            Trame_Decoder decoder = this.GetComponent <Trame_Decoder>();
            System.IO.Ports.SerialPort serialport = this.GetComponent <Virtual_SerialPort>().getserialPort();

            tasks.Add(Task.Factory.StartNew(async() =>
            {
                bool received = await EnvoiAsync(serialport, decoder);

                if (received)
                {
                    burn_ended = true;
                }
                else
                {
                    Status.GetComponent <TextMeshProUGUI>().text = "Error while burning target!!";
                }
            }));
        }
        catch
        {
        }
    }
Esempio n. 3
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++;
    }
Esempio n. 4
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);
    }
Esempio n. 5
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);
    }