commit b6f7a16a7b9229127198463ba106d11459e7cd23
Author: mtoutant <martin.toutant@inrae.fr>
Date:   Tue Oct 4 12:02:36 2022 +0200

    add ReponseRFID + implement HoneyWellInternReader

diff --git a/TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs b/TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs
index 8cef096..67cff5e 100644
--- a/TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs
+++ b/TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs
@@ -72,7 +72,7 @@ namespace TestXamConnections.Device.Balance.Balea
                 else if (_bufferedData[2] == '6')
                 {
                     PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
-                } 
+                }
                 else
                 {
                     PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
@@ -98,11 +98,22 @@ namespace TestXamConnections.Device.Balance.Balea
         /// Envoi d'une commande au Teo.
         /// </summary>
         /// <param name="commandType">La commande à envoyer.</param>
-        /// <returns></returns>
+        /// <returns>true si l'envoi a réussi, false sinon.</returns>
         public async Task<bool> SendCommandAsync(TeoConstants.TeoCommandType cmd)
         {
             byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(cmd);
             return await ConnectionService.SendCommand(commandValue);
         }
+
+        /// <summary>
+        /// Envoie d'une commande d'émission de poids au Teo.
+        /// </summary>
+        /// <returns>true si l'envoi a réussi, false sinon.</returns>
+        public async Task<bool> ReadWeightAsync()
+        {
+            byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(TeoConstants.TeoCommandType.EmissionPoids);
+            return await ConnectionService.SendCommand(commandValue);
+        }
+
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs b/TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs
index cb0bdf0..f0cfdb3 100644
--- a/TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs
+++ b/TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs
@@ -26,5 +26,12 @@ namespace TestXamConnections.Device.Balance
         /// <returns></returns>
         Task<bool> SendCommandAsync(TeoCommandType cmd);
 
+        // <summary>
+        /// Envoie d'une commande de pesée simple à la balance.
+        /// </summary>
+        /// <param name="commandType">La commande à envoyer.</param>
+        /// <returns></returns>
+        Task<bool> ReadWeightAsync();
+
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs b/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs
index 9b609c4..75f6c0f 100644
--- a/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs
+++ b/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs
@@ -1,5 +1,6 @@
 ﻿using System;
 using System.Collections.Generic;
+using System.Text;
 using System.Threading.Tasks;
 using TestXamConnections.Connection;
 using Xamarin.Forms;
@@ -25,10 +26,11 @@ namespace TestXamConnections.Device.Barcode.Honeywell
 
         private void BluetoothDataReceived(object sender, byte[] e)
         {
-            BarcodeDataReceivedEvent.Invoke(this, e);
+            string data = Encoding.ASCII.GetString(e);
+            BarcodeDataReceivedEvent.Invoke(this, data);
         }
 
-        public async Task<bool> ConnectToBTReaderAsync()
+        public async Task<bool> EnableServiceAsync()
         {
             Dictionary<string, string> param = new Dictionary<string, string>()
             {
@@ -37,5 +39,10 @@ namespace TestXamConnections.Device.Barcode.Honeywell
             bool ret = await ConnectionService.Connect(param);
             return ret;
         }
+
+        public Task<bool> StartScanAsync()
+        {
+            throw new NotImplementedException();
+        }
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs b/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs
index 423e99d..31181d8 100644
--- a/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs
+++ b/TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs
@@ -1,4 +1,6 @@
 ﻿using System;
+using System.Collections.Generic;
+using System.Text;
 using System.Threading.Tasks;
 using TestXamConnections.Connection;
 using Xamarin.Forms;
@@ -8,7 +10,7 @@ namespace TestXamConnections.Device.Barcode.Honeywell
     public class HoneywellInternReader : IBarcodeReader
     {
         public DeviceInfo DeviceI { get; set; }
-        public IConnectionService ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
+        public IConnectionService ConnectionService { get; set; }
 
         /// <summary>
         /// Événement déclenché à la reception de données par le lecteur Honeywell .
@@ -18,12 +20,51 @@ namespace TestXamConnections.Device.Barcode.Honeywell
         public HoneywellInternReader(DeviceInfo deviceI)
         {
             DeviceI = deviceI;
-            
+            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
+            ConnectionService.DataReceivedEvent += InternDataReceived;
         }
 
-        public Task<bool> ConnectToBTReaderAsync()
+        private void InternDataReceived(object sender, byte[] intent)
         {
-            throw new NotImplementedException();
+            string data = Encoding.ASCII.GetString(intent);
+            data = data == HoneyWellConstants.ACTION_SCAN_ERROR ? "err" : data;
+            BarcodeDataReceivedEvent.Invoke(this, data);
+        }
+
+
+        /// <summary>
+        /// Initialise la lecture de code barre avec lecteur interne Honeywell.
+        /// </summary>
+        /// <returns>true la connexion a réussi, false sinon.</returns>
+        public async Task<bool> EnableServiceAsync()
+        {
+            bool ret;
+            // Enregistrement des intents recevable par Agrident
+            List<string> intentsList = new List<string>()
+            {
+                HoneyWellConstants.ACTION_SCAN_SUCCESS,
+                HoneyWellConstants.ACTION_SCAN_ERROR
+            };
+            string intents = string.Join(',', intentsList);
+
+            // Encapsulation des intents recevables pour envoyer au service de connexion
+            Dictionary<string, string> param = new Dictionary<string, string>()
+            {
+                { ConnectionConstants.RECEIVABLE_INTENTS_KEY, intents }
+            };
+
+            ret = await ConnectionService.Connect(param);
+            return ret;
+        }
+
+        /// <summary>
+        /// Lance un scan de code barre avec le lecteur Honeywell interne.
+        /// </summary>
+        /// <returns>true si le scan s'est lancé correctement, false sinon.</returns>
+        public async Task<bool> StartScanAsync()
+        {
+            byte[] startIntentBytes = Encoding.ASCII.GetBytes(HoneyWellConstants.HONEYWELL_BARCODE);
+            return await ConnectionService.SendCommand(startIntentBytes);
         }
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs b/TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs
index ce3d25a..fa1bbc8 100644
--- a/TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs
+++ b/TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs
@@ -10,6 +10,16 @@ namespace TestXamConnections.Device.Barcode
         /// </summary>
         public EventHandler<string> BarcodeDataReceivedEvent { get; set; }
 
-        Task<bool> ConnectToBTReaderAsync();
+        /// <summary>
+        /// Initialise la lecture de code barre.
+        /// </summary>
+        /// <returns>true l'init a réussi, false sinon.</returns>
+        Task<bool> EnableServiceAsync();
+
+        /// <summary>
+        /// Lance un scan de code barre.
+        /// </summary>
+        /// <returns>true si le scan s'est lancé correctement, false sinon.</returns>
+        Task<bool> StartScanAsync();
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs b/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs
index 9df4a06..d8bed03 100644
--- a/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs
+++ b/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs
@@ -11,5 +11,6 @@
         public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service";
         public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ";
         public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge";
+        public const string KEY_BARCODE_DATA = "BarcodeData";
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs b/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs
index 814b69b..9ed4b29 100644
--- a/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs
+++ b/TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
 using TestXamConnections.Connection;
+using TestXamConnections.Models;
 using Xamarin.Forms;
 
 namespace TestXamConnections.Device.RFID.Agrident
@@ -17,7 +18,7 @@ namespace TestXamConnections.Device.RFID.Agrident
         /// <summary>
         /// Événement déclenché à la reception de données par le lecteur RFID Agrident.
         /// </summary>
-        public EventHandler<string> RFIDDataReceivedEvent { get; set; }
+        public EventHandler<ReponseRFID> RFIDDataReceivedEvent { get; set; }
 
         public AgridentInternReader(DeviceInfo deviceI)
         {
@@ -37,17 +38,33 @@ namespace TestXamConnections.Device.RFID.Agrident
         private void InternDataReceived(object sender, byte[] intent)
         {
             string data = Encoding.ASCII.GetString(intent);
-
-            switch (data)
+            ReponseRFID ret = new ReponseRFID();
+            
+            if (data == AgridentConstants.ACTION_AGRIDENT_ERROR)
             {
-                case AgridentConstants.ACTION_AGRIDENT_ERROR:
-                    RFIDDataReceivedEvent.Invoke(this, "");
-                    break;
-
-                default:
-                    RFIDDataReceivedEvent.Invoke(this, data);
-                    break;
+                ret.IsoRfid = "No Tag";
+                ret.TagLu = false;
+            } else
+            {
+                /* Par défaut le lecteur envoie le numéro sur 16 chiffres 
+                 * (le code pays peut théoriquement être > 999). Donc on se retrouve avec un 0 devant.
+                 * Un paramêtre permet de supprimer l'envoie de ce premier 0. 
+                 * Mais comme on sait pas si se paramétre est coché ou pas, 
+                 * on fait en sorte de traiter tjs sur 16 chiffres.
+                 */
+                if (data.Length == 15)
+                {
+                    data = "0" + data;
+                }
+                ret.IsoRfid = data.Substring(1, 15);
+                ret.CodePays = data.Substring(1, 3);
+                ret.NumeroAnimal = data.Substring(4, 12);
+                ret.TypeTag = "";
+                ret.IsoEtendu = data;
+                ret.CodeEtendu = data.Substring(0, 1);
+                ret.TagLu = true;
             }
+            RFIDDataReceivedEvent.Invoke(this, ret);
         }
 
         /// <summary>
diff --git a/TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs b/TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs
index 1628cf9..3cd1841 100644
--- a/TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs
+++ b/TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs
@@ -1,5 +1,6 @@
 ﻿using System;
 using System.Threading.Tasks;
+using TestXamConnections.Models;
 
 namespace TestXamConnections.Device.RFID
 {
@@ -8,12 +9,12 @@ namespace TestXamConnections.Device.RFID
         /// <summary>
         /// Événement déclenché à la reception de données par le lecteur RFID.
         /// </summary>
-        public EventHandler<string> RFIDDataReceivedEvent { get; set; }
+        public EventHandler<ReponseRFID> RFIDDataReceivedEvent { get; set; }
 
         /// <summary>
         /// Initialise la lecture de tag RFID.
         /// </summary>
-        /// <returns>true la connexion a réussi, false sinon.</returns>
+        /// <returns>true l'init a réussi, false sinon.</returns>
         Task<bool> EnableServiceAsync();
 
         /// <summary>
diff --git a/TestXamConnections/TestXamConnections/Models/ReponseRFID.cs b/TestXamConnections/TestXamConnections/Models/ReponseRFID.cs
index 7b71968..4cfe45b 100644
--- a/TestXamConnections/TestXamConnections/Models/ReponseRFID.cs
+++ b/TestXamConnections/TestXamConnections/Models/ReponseRFID.cs
@@ -2,6 +2,34 @@
 {
     public class ReponseRFID
     {
-        // TODO (doc JF Bompa)
+        /// <summary>
+        /// Numéro rfid 15 chiffres
+        /// </summary>
+        public string IsoRfid { get; set; }
+        /// <summary>
+        /// Code pays, ou fabriquant, 3 chiffres
+        /// </summary>
+        public string CodePays { get; set; }
+        /// <summary>
+        /// Numéro animal 12 chiffres
+        /// </summary>
+        public string NumeroAnimal { get; set; }
+        /// <summary>
+        /// Type tag, HDX ou FDX
+        /// </summary>
+        public string TypeTag { get; set; }
+        /// <summary>
+        /// Numéro Iso étendu 
+        /// </summary>
+        public string IsoEtendu { get; set; }
+        /// <summary>
+        /// Code de l'extention de l'Iso etendu
+        /// </summary>
+        public string CodeEtendu { get; set; }
+        /// <summary>
+        /// Un tag à été lu
+        /// </summary>
+        public bool TagLu { get; set; }
+
     }
 }
diff --git a/TestXamConnections/TestXamConnections/ViewModels/BarcodeReaderViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/BarcodeReaderViewModel.cs
index be79267..8505216 100644
--- a/TestXamConnections/TestXamConnections/ViewModels/BarcodeReaderViewModel.cs
+++ b/TestXamConnections/TestXamConnections/ViewModels/BarcodeReaderViewModel.cs
@@ -43,7 +43,7 @@ namespace TestXamConnections.ViewModels
 
         public async Task<bool> ConnectToDevice()
         {
-            if (await bcReader.ConnectToBTReaderAsync())
+            if (await bcReader.EnableServiceAsync())
             {
                 ConnectionIndicator = "Connecté";
                 CIColor = "Green";
@@ -74,10 +74,10 @@ namespace TestXamConnections.ViewModels
             bcReader.BarcodeDataReceivedEvent -= DataReceived;
         }
 
-        private void DataReceived(object sender, byte[] e)
+        private void DataReceived(object sender, string receivedData)
         {
             IsVisibleData = true;
-            Data += Encoding.ASCII.GetString(e) + "\n";
+            Data += receivedData + "\n";
         }
     }
 }
diff --git a/TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs
index b25938d..35b81c3 100644
--- a/TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs
+++ b/TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
 using System.Windows.Input;
 using TestXamConnections.Device.RFID;
 using TestXamConnections.Device.RFID.Agrident;
+using TestXamConnections.Models;
 using Xamarin.Forms;
 
 namespace TestXamConnections.ViewModels
@@ -77,17 +78,17 @@ namespace TestXamConnections.ViewModels
             ShowRFID = false;
         }
 
-        private void OnRFIDResultReceived(object sender, string e)
+        private void OnRFIDResultReceived(object sender, ReponseRFID reponseRFID)
         {
             ResetAffichage();
-            if (e == "")
+            if (reponseRFID.TagLu == false)
             {
                 ShowError = true;
                 ErrorMessage = "Pas de TAG RFID detecté";
             } else
             {
                 ShowRFID = true;
-                RFIDResult = e;
+                RFIDResult = reponseRFID.IsoEtendu;
             }
             IsScanning = false;
         }
diff --git a/TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs
index c7c123f..b8efe9e 100644
--- a/TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs
+++ b/TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs
@@ -91,7 +91,7 @@ namespace TestXamConnections.ViewModels
         {
             // Appel au Balance provider pour récupérer l'item TeoBalancea avec les fonctions d'initiation
             TeoScale = BalanceProvider.GetBalance(Balance.TeoBalance, ConnectionType.Bluetooth, device);
-            TeoScale.SendCommandAsync(TeoConstants.TeoCommandType.EmissionPoids)
+            TeoScale.SendCommandAsync(TeoConstants.TeoCommandType.EmissionPoids);
             Init();
         }
 
diff --git a/TestXamConnections/TestXamConnections/Views/InternServiceView.xaml b/TestXamConnections/TestXamConnections/Views/InternServiceView.xaml
index 00b9992..2c9135c 100644
--- a/TestXamConnections/TestXamConnections/Views/InternServiceView.xaml
+++ b/TestXamConnections/TestXamConnections/Views/InternServiceView.xaml
@@ -51,7 +51,9 @@
                                 Color="#4f5a64" />
 
                             <Label
+                                Margin="0,10"
                                 FontAttributes="Bold"
+                                FontSize="17"
                                 HorizontalTextAlignment="Center"
                                 Text="{Binding RFIDResult}"
                                 TextColor="White" />
