From 9a85d320993f80ac2703e4b8d71ce10fda3ff0f9 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 7 Jun 2017 14:18:14 +0200 Subject: [PATCH] modifica decodifica UT x gestione bigendianness --- MTC_Adapter/MTC_Adapter/AdapterGeneric.cs | 38 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index 8c23376..cfd479a 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -3622,12 +3622,12 @@ namespace MTC_Adapter byte[] tabFam_FamUt = new byte[2 * maxMemAddr]; // altre variabili - int[] idUtMontato = new int[maxNumOp]; - int[] idFamUt = new int[maxNumOp]; - int[] idTipoVitaUt = new int[maxNumOp]; - int[] valVitaUtRes = new int[maxNumOp]; - int[] tabUt = new int[maxMemAddr]; - int[] tabFamUt = new int[maxMemAddr]; + ushort[] idUtMontato = new ushort[maxNumOp]; + ushort[] idFamUt = new ushort[maxNumOp]; + ushort[] idTipoVitaUt = new ushort[maxNumOp]; + uint[] valVitaUtRes = new uint[maxNumOp]; + ushort[] tabUt = new ushort[maxMemAddr]; + ushort[] tabFamUt = new ushort[maxMemAddr]; int memIndex = 0; byte[] int32Mem = new byte[4]; byte[] int16Mem = new byte[2]; @@ -3640,6 +3640,10 @@ namespace MTC_Adapter for (int i = 0; i < maxNumOp; i++) { idUtMontato[i] = BitConverter.ToUInt16(elencoUtMem, 2 * i); + if (hasBigEndian) + { + idUtMontato[i] = Endian.SwapUInt16(idUtMontato[i]); + } } // step 2a: leggo vettore memoria dei maxMemAddr(200) UT in Tabella Utensili @@ -3648,6 +3652,10 @@ namespace MTC_Adapter for (int i = 0; i < maxMemAddr; i++) { tabUt[i] = BitConverter.ToUInt16(tabUt_UT, 2 * i); + if (hasBigEndian) + { + tabUt[i] = Endian.SwapUInt16(tabUt[i]); + } } // step 2b: devo cercare l'UT di ogni UnOp nella Tabella Utensili for (int i = 0; i < maxNumOp; i++) @@ -3664,6 +3672,10 @@ namespace MTC_Adapter memIndex = getDatiUt_step2b(ref int16Mem, j); // step 2b: leggo puntualmente la FamUt dal suo indice... idFamUt[i] = BitConverter.ToUInt16(int16Mem, 0); + if (hasBigEndian) + { + idFamUt[i] = Endian.SwapUInt16(idFamUt[i]); + } found = true; } } @@ -3676,6 +3688,10 @@ namespace MTC_Adapter for (int i = 0; i < maxMemAddr; i++) { tabFamUt[i] = BitConverter.ToUInt16(tabFam_FamUt, 2 * i); + if (hasBigEndian) + { + tabFamUt[i] = Endian.SwapUInt16(tabFamUt[i]); + } } // step 3b: devo cercare la famiglia dell'UT di ogni UnOp nella Tabella Famiglie for (int i = 0; i < maxNumOp; i++) @@ -3692,6 +3708,10 @@ namespace MTC_Adapter memIndex = getDatiUt_step3b(ref int8Mem, j); // step 3b: leggo puntualmente il TIPO DI vita UT dal suo indice... idTipoVitaUt[i] = int8Mem; + if (hasBigEndian) + { + idTipoVitaUt[i] = Endian.SwapUInt16(idTipoVitaUt[i]); + } found = true; } } @@ -3711,7 +3731,11 @@ namespace MTC_Adapter // leggo FamUt puntuale.. memIndex = getDatiUt_step4(ref int32Mem, j); // leggo puntualmente valore della vita ut residua da indice utensile... - valVitaUtRes[i] = BitConverter.ToInt32(int32Mem, 0); + valVitaUtRes[i] = BitConverter.ToUInt32(int32Mem, 0); + if (hasBigEndian) + { + valVitaUtRes[i] = Endian.SwapUInt32(valVitaUtRes[i]); + } found = true; } }