Trottinette Électrique Connectée  1.0
BTS SN-IR La Salle Avignon 2018
 Tout Classes Fichiers Fonctions Variables
Fonctions membres publiques | Fonctions de paquetage | Fonctions membres privées | Attributs privés
Référence de la classe com.example.iris.myapplication.PeripheriqueBluetooth.TReception

Thread de réception des trames en provenance de la Trottinette via le Bluetooth. Plus de détails...

Graphe de collaboration de com.example.iris.myapplication.PeripheriqueBluetooth.TReception:
Collaboration graph
[légende]

Liste de tous les membres

Fonctions membres publiques

void run ()
 Réceptionne les trames en provenance de l'aquarium via le Bluetooth.
void arreter ()
 Permet d'arrêter le thread de réception des trames.

Fonctions de paquetage

 TReception (Handler h)
 Constructeur de la classe TReception.

Fonctions membres privées

void recevoirTrame ()
 Permet de recevoir les trames Bluetooth.
void attendreProchaineLecture (int millis)
 Permet d'attendre la prochaine lecture de trames Bluetooth.
void attendreConnexion ()
 Attend la prochaine connexion Bluetooth.
void viderBuffer ()
 Permet de vider le buffer.

Attributs privés

Handler handlerUI
boolean fini
long nbTrames = 0
long link = 0
boolean envoye = false
boolean inactif = false

Description détaillée

Auteur:
Thierry Vaira <tvaira@free.fr>
HACHETTE Alexandre

Documentation des constructeurs et destructeur


Documentation des fonctions membres

Auteur:
Thierry Vaira <tvaira@free.fr>

Références com.example.iris.myapplication.PeripheriqueBluetooth.TReception.fini.

Référencé par com.example.iris.myapplication.PeripheriqueBluetooth.deconnecter().

        {
            if(fini == false)
            {
                fini = true;
            }
            try
            {
                Thread.sleep(250);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }

Références com.example.iris.myapplication.PeripheriqueBluetooth.TReception.fini, et com.example.iris.myapplication.PeripheriqueBluetooth.socket.

        {
            /* attente connexion */
            if(!fini)
            {
                while (!socket.isConnected())
                {
                    try
                    {
                        Log.d("Réception run()", "Attente connexion ..."); // d = debug
                        Thread.sleep(150);
                    } catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        }
Paramètres:
millisun int qui représente une durée en millisecondes (ms)

Références com.example.iris.myapplication.PeripheriqueBluetooth.CODE_ACTIF, com.example.iris.myapplication.PeripheriqueBluetooth.CODE_INACTIF, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.envoye, com.example.iris.myapplication.PeripheriqueBluetooth.gestionnaire, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.inactif, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.link, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.nbTrames, com.example.iris.myapplication.PeripheriqueBluetooth.PERIODE_INACTIVE, et com.example.iris.myapplication.PeripheriqueBluetooth.PROCHAINE_LECTURE.

Référencé par com.example.iris.myapplication.PeripheriqueBluetooth.TReception.recevoirTrame().

        {
            try
            {
                /* attente prochaine lecture */
                Thread.sleep(millis);
                if(envoye)
                {
                    envoye = false;
                    link = 0;
                    if(inactif)
                    {
                        /* informe l'activité principale */
                        Message msg = Message.obtain();
                        msg.what = PeripheriqueBluetooth.CODE_ACTIF;
                        if (gestionnaire.sendMessage(msg))
                        {
                            Log.d("run()", "Socket active : " + nbTrames); // d = debug
                        } else
                        {
                            Log.e("run()", "Message non envoyé !");
                        }
                        inactif = false;
                    }
                }
                else
                {
                    link += PeripheriqueBluetooth.PROCHAINE_LECTURE;

                    /* perte du lien */
                    if(link >= PeripheriqueBluetooth.PERIODE_INACTIVE)
                    {
                        /* informe l'activité principale */
                        Message msg = Message.obtain();
                        msg.what = PeripheriqueBluetooth.CODE_INACTIF;
                        if (gestionnaire.sendMessage(msg))
                        {
                            Log.d("run()", "Socket inactive : " + nbTrames); // d = debug
                        } else
                        {
                            Log.e("run()", "Message non envoyé !");
                        }
                        inactif = true;
                        link = 0;
                    }
                }
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }

Références com.example.iris.myapplication.PeripheriqueBluetooth.TReception.attendreProchaineLecture(), com.example.iris.myapplication.PeripheriqueBluetooth.CODE_RECEPTION, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.fini, com.example.iris.myapplication.PeripheriqueBluetooth.fluxEntree, com.example.iris.myapplication.PeripheriqueBluetooth.getAdresse(), com.example.iris.myapplication.PeripheriqueBluetooth.getNom(), com.example.iris.myapplication.PeripheriqueBluetooth.TReception.handlerUI, com.example.iris.myapplication.PeripheriqueBluetooth.PROCHAINE_LECTURE, com.example.iris.myapplication.PeripheriqueBluetooth.socket, et com.example.iris.myapplication.PeripheriqueBluetooth.TAILLE_BUFFER.

        {
            try
            {
                if(fluxEntree.available() > 0)
                {
                    byte buffer[] = new byte[PeripheriqueBluetooth.TAILLE_BUFFER];
                    if(!fini && socket.isConnected())
                    {
                        int k = fluxEntree.read(buffer, 0, PeripheriqueBluetooth.TAILLE_BUFFER);

                        if (k > 0)
                        {
                            byte rawdata[] = new byte[k];
                            for (int i = 0; i < k; i++)
                                rawdata[i] = buffer[i];

                            String datas = new String(rawdata);
                            System.out.println("<Bluetooth> Reception " + datas);
                            StringBuffer d = new StringBuffer(datas);
                            Message message = Message.obtain();
                            Bundle paquet = new Bundle();
                            paquet.putString("nom", getNom());
                            paquet.putString("adresse", getAdresse());
                            paquet.putInt("etat", CODE_RECEPTION);
                            paquet.putString("donnees", datas);
                            message.setData(paquet);
                            handlerUI.sendMessage(message);

                        }
                    }
                }
                attendreProchaineLecture(PeripheriqueBluetooth.PROCHAINE_LECTURE);
            }
            catch (IOException e)
            {
                System.out.println("<Socket> Erreur read");
                e.printStackTrace();
            }

        }
Auteur:
Thierry Vaira <tvaira@free.fr>

Références com.example.iris.myapplication.PeripheriqueBluetooth.CODE_RECEPTION, com.example.iris.myapplication.PeripheriqueBluetooth.TReception.fini, com.example.iris.myapplication.PeripheriqueBluetooth.fluxEntree, com.example.iris.myapplication.PeripheriqueBluetooth.getAdresse(), com.example.iris.myapplication.PeripheriqueBluetooth.getNom(), et com.example.iris.myapplication.PeripheriqueBluetooth.TReception.handlerUI.

        {
            System.out.println("<Bluetooth> Attente reception");
            while(!fini)
            {
                try
                {
                    if(fluxEntree.available() > 0)
                    {
                        byte buffer[] = new byte[100];
                        int k = fluxEntree.read(buffer, 0, 100);

                        if(k > 0)
                        {
                            byte rawdata[] = new byte[k];
                            for(int i=0;i<k;i++)
                                rawdata[i] = buffer[i];

                            String data = new String(rawdata);
                            System.out.println("<Bluetooth> Reception " + data);

                            Message msg = Message.obtain();
                            Bundle b = new Bundle();
                            b.putString("nom", getNom());
                            b.putString("adresse", getAdresse());
                            b.putInt("etat", CODE_RECEPTION);
                            b.putString("donnees", data);
                            msg.setData(b);
                            handlerUI.sendMessage(msg);
                        }
                    }
                    try
                    {
                        Thread.sleep(250);
                    }
                    catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
        }

Références com.example.iris.myapplication.PeripheriqueBluetooth.TReception.fini, com.example.iris.myapplication.PeripheriqueBluetooth.fluxEntree, com.example.iris.myapplication.PeripheriqueBluetooth.socket, et com.example.iris.myapplication.PeripheriqueBluetooth.TAILLE_BUFFER.

        {
            try
            {
                Thread.sleep(1000);
                    /* doit-on vider le buffer ? */
                if(!fini && socket.isConnected())
                {
                    while (fluxEntree.available() > PeripheriqueBluetooth.TAILLE_BUFFER)
                    {
                        Log.d("Réception run()", "Vide le buffer : " + fluxEntree.skip(fluxEntree.available()) + " octets"); // d = debug
                    }
                }
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }

Documentation des données membres


La documentation de cette classe a été générée à partir du fichier suivant :
 Tout Classes Fichiers Fonctions Variables