private string Interpreter(string rawData) { HyScript hyScript = new HyScript(); string response = "false"; string telegram = ""; response = hyScript.call("return License.check('EGEEEGEE','I1ARCQI0')"); if (response == "true") { if (rawData != "") { string cmd = "local ri = nil " + " ri = RadioInterpreter.new() " + " ri:setProcessLevel() " + " local dl = nil;" + " dl = DeviceList.new();" + " mi= MBusInterpreter.new() " + " mi:addManuSpec2TelegramConverter(HydrometerSpec2TelegramConverter.new());" + " mi:setMergeEmbeddedData(true);" + " mi: setEnableInterpretationExtension(bit.bor(SDH_TELEGRAM, SDH_COMPACTPROFILE, SDH_DMFUNCTIONBLOCK, SDH_HYDVERSION, SDH_DEVICEID_MBUS, SDH_DEVICEID_SPDE)) " + " ri:setMBusInterpreter(mi);" + " ri:setDeviceList(ref(dl));" + " h1 = HexString.new('" + rawData + "');" + " telegramMbt = mi:interpret(h1);" + " telegramRt = ri:interpret(h1)" + " if (telegramMbt:getInterpretationError() == INTPRET_NO_ERROR) then return telegramMbt else return telegramRt end "; telegram = hyScript.call(cmd); } } return(telegram); }
public IHttpActionResult GetVersion() { try { HyScript hyScript = new HyScript(); var version = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return Environment.getVersion()"); if (version == null) { return(NotFound()); } return(Ok(version)); } catch (Exception ex) { _logger.Info($"Echec get version : {ex}"); return(BadRequest("Echec appel get version, consultez les logs.")); } }
public string SetDeviceConfiguration(string portcom, List <ConfigParam> configParamList) { HyScript hyScript = new HyScript(); string result = ""; int port = Convert.ToInt32(portcom); string comPort = "com://" + port; string sBTHead = "hybtoh://"; string response = "false"; string sScript = ""; string sRep = ""; string sS1 = ""; string sS2 = ""; string sS3 = ""; string radioAddress = ""; ConfigParam configParam = new ConfigParam(); string luaScriptPath = "C:\\Temp\\IZAR@CSI\\Script\\CSILib_OPTO.lua"; _logger.Info("----------------------Writeback------------------------"); _logger.Info("--- Check licence"); sRep = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return License.check('EGEEEGEE','I1ARCQI0')"); _logger.Info("--- Resultat : " + response); if (sRep == "true" && configParamList != null) { sScript = luaScriptPath.Replace(@"\", @"\\"); //Chargement du script de configuration sRep = hyScript.call("return exec('" + sScript + "')"); if (sRep == luaScriptPath) { // Start identification of a product sRep = hyScript.call("return indentifyProduct('" + comPort + "', '" + sBTHead + "', '" + sS1 + "', '" + sS2 + "', '" + sS3 + "')"); if (sRep == "true") { //vérifier que le module en cours de configuration est égale à celui passer en paramètre radioAddress = hyScript.call("return dc:getValue('RadioAddress')"); configParam = (ConfigParam)configParamList.Where(c => c.Value == radioAddress); if (configParam != null) { foreach (var item in configParamList) { configParam = (ConfigParam)item; sRep = hyScript.call("return setValue('" + configParam.Name + "', '" + configParam.Value + "')"); } result = hyScript.call("return writeback()"); } else { result = "false"; } } else { result = "false"; } } else { result = "false"; } } else { result = "false"; } return(result); }
public List <ConfigParam> GetDeviceConfiguration(string portcom) { HyScript hyScript = new HyScript(); //string errorMessage = ""; //string cmd = ""; int port = Convert.ToInt32(portcom); string comPort = "com://" + port; string sBTHead = "hybtoh://";//"btspp://00802543739B"; string response = "false"; string sScript = ""; //string sScriptModule = ""; string sRep = ""; string sList = ""; string sS1 = ""; string sS2 = ""; string sS3 = ""; //string paramsList = ""; //string deviceModulePath = "C:\\Temp\\IZAR@CSI\\DeviceModules"; List <ConfigParam> configParamList = new List <ConfigParam>(); ConfigParam configParam = new ConfigParam(); string luaScriptPath = "C:\\Temp\\IZAR@CSI\\Script\\CSILib_OPTO.lua"; _logger.Info("----------------------------------------------"); _logger.Info("--------CONFIGURATION MODULE------------------"); _logger.Info("----------------------------------------------"); _logger.Info("--- Check licence"); response = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return License.check('EGEEEGEE','I1ARCQI0')"); _logger.Info("--- Resultat : " + response); if (response == "true") { sScript = luaScriptPath.Replace(@"\", @"\\"); //Chargement du script de configuration sRep = hyScript.call("return exec('" + sScript + "')"); if (sRep == luaScriptPath) { // Start identification of a product sRep = hyScript.call("return indentifyProduct('" + comPort + "', '" + sBTHead + "', '" + sS1 + "', '" + sS2 + "', '" + sS3 + "')"); if (sRep == "true") { //Description: Nom du produit string getDescription = hyScript.call("return getDescription()"); _logger.Info("--- Nom du produit: " + getDescription); //Nom du script de config en cours d'emploi string getDMName = hyScript.call("return getDMName()"); _logger.Info("--- Nom du produit: " + getDMName); //Version du script de config en cours d'emploi string getDMVersion = hyScript.call("return getDMVersion()"); _logger.Info("--- Nom du produit: " + getDMVersion); //----- Get Paramater list sRep = hyScript.call("return getParamNameList()"); sList = sRep; while (sRep != "") { sRep = hyScript.call("return retMobile(0)"); sList = sList + sRep; } //Parse parameter list to get the value of parameters ---char(9)=Tab=\t string[] tabNames = sList.Split((char)9); if (tabNames != null) { foreach (var nomParam in tabNames) { configParam.Name = nomParam; configParam.Value = hyScript.call("return dc:getValue('" + nomParam + "')"); _logger.Info(configParam.Name + " ====> " + configParam.Value); configParamList.Add(configParam); } } } else { _logger.Info("ERREUR : NO DEVICE DETECTED"); } } else { _logger.Info("ERREUR: Script execution : " + sScript + " : Result = " + sRep); } } else { _logger.Info("ERREUR: License activation "); } _logger.Info("Parameter List: " + configParamList.ToString()); return(configParamList); }
public string Read() { HyScript hyScript = new HyScript(); string response = "false"; string dataJSON = ""; string cmdClear = "if(dc~=nil) then dc:close(); cl=nil; pl=nil; dc=nil"; _logger.Info("commande1 : Check Licence"); response = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return License.check('EGEEEGEE','I1ARCQI0')"); _logger.Info("resultat cmd1 : " + response); if (response == "true") { hyScript.call(cmdClear); string cmd = "dc = DataConcentrator.new();" + " ds = BtReceiverDataSource.new();" + " ds:setDataConcentrator(ref(dc));" + " pl = IPhysicalLayer.new('com://6');" + " cl = ICommunicationLayer.new('hybtoh://', ref(pl));" + " ds:setCommunicationLayer(ref(cl));" + " local ri = RadioInterpreter.new();" + " ri:setProcessLevel();" + " dc:setRadioInterpreter(ri);" + " ri:enableDecryption(false);" + " tsf=ToStringFormater.new();" + " tsf:setAddSPDEAddress(true);" + " setFormater(tsf);" + " ds:setSourceId('0012f318e03e');" + " ds:config('timeoutNoAnswer', 150);" + " ds:config('timeoutNoDataFollows', 2);" + " ds:config('timeoutAfterTelegram', 10) return true"; _logger.Info("commande2: " + cmd); response = hyScript.call(cmd); _logger.Info("resultat cmd2 : " + response); if (response == "true") { //startASync _logger.Info("commande3: ds:startASync()"); hyScript.call("ds:startASync()"); Thread.Sleep(2000); //stopASync _logger.Info("commande 4 : ds:stopASync()"); hyScript.call("ds:stopASync()"); string telegramProcessed = hyScript.call("return dc:getNumberOfProcessedTelegrams()"); _logger.Info("resultat number of telegram Processed: " + telegramProcessed); string telegramCollected = hyScript.call("return dc:getNumberOfCollectedTelegrams()"); _logger.Info("resultat number of telegram collected: " + telegramCollected); string falseTelegram = hyScript.call("return dc:getNumberOfFalseTelegrams()"); _logger.Info("resultat number of false telegram : " + falseTelegram); string foundedDevice = hyScript.call("return dc:getNumberOfFoundedDevices()"); _logger.Info("resultat number of devices found : " + foundedDevice); //device founded if (Convert.ToInt32(foundedDevice) > 0) { _logger.Info("commande5 :dc:getDeviceList()"); dataJSON = hyScript.call("return dc:getDeviceList():__tostring(dc:getDeviceList():getBeginDeviceDescriptionIterator(true))"); _logger.Info("resultat commande5 : " + dataJSON); } hyScript.call("dc:getDeviceList():clear()"); } } else { dataJSON = hyScript.call("dc:clearLastException() val=dc:getValue(valueIdent) ret = {val, dc:getLastException()} return ret"); } return(dataJSON); }
public void Init() { HyScript hyScript = new HyScript(); string initResponse = hyScript.call("init"); string licenseResponse = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return License.check('EGEEEGEE','I1ARCQI0')"); }
public List <FrameResponse> ReadAllTelegram(string portcom, string macadresseprt) { List <FrameResponse> myFrameList = new List <FrameResponse>(); HyScript hyScript = new HyScript(); int port = Convert.ToInt32(portcom); string comPort = "com://" + port; string response = "false"; string dataJSON = ""; string rawDataInterpretJSON = ""; string cmdClear = "if(dc~=nil) then dc:close(); cl=nil; pl=nil; dc=nil"; _logger.Info("Check Licence"); response = hyScript.call("setLogLevel(-1); setLogFileName('IzarCSI.log'); return License.check('EGEEEGEE','I1ARCQI0')"); _logger.Info("resultat Check Licence : " + response); if (response == "true") { hyScript.call(cmdClear); string cmd = "dc = DataConcentrator.new();" + " ds = BtReceiverDataSource.new();" + " ds:setDataConcentrator(ref(dc));" + " pl = IPhysicalLayer.new('" + comPort + "');" + " cl = ICommunicationLayer.new('hybtoh://', ref(pl));" + " ds:setCommunicationLayer(ref(cl));" + " local ri = RadioInterpreter.new();" + " ri:setProcessLevel();" + " dc:setRadioInterpreter(ri);" + " ri:enableDecryption(false);" + " tsf=ToStringFormater.new();" + " tsf:setAddSPDEAddress(true);" + " setFormater(tsf);" + " ds:setSourceId('" + macadresseprt + "');" + " ds:config('timeoutNoAnswer', 150);" + " ds:config('timeoutNoDataFollows', 2);" + " ds:config('timeoutAfterTelegram', 10); return true"; _logger.Info("Init: " + cmd); response = hyScript.call(cmd); _logger.Info("resultat Init : " + response); if (response == "true") { //startASync _logger.Info("ds:startASync()"); hyScript.call("ds:startASync()"); Thread.Sleep(2000); //stopASync _logger.Info("ds:stopASync()"); hyScript.call("ds:stopASync()"); string telegramProcessed = hyScript.call("return dc:getNumberOfProcessedTelegrams()"); _logger.Info("Nombre de télégrammes traités: " + telegramProcessed); string telegramCollected = hyScript.call("return dc:getNumberOfCollectedTelegrams()"); _logger.Info("Nombre de télégrammes collectés: " + telegramCollected); string falseTelegram = hyScript.call("return dc:getNumberOfFalseTelegrams()"); _logger.Info("Nombre de faux télégrammes : " + falseTelegram); string foundedDevice = hyScript.call("return dc:getNumberOfFoundedDevices()"); _logger.Info("Nombre de modules trouvés : " + foundedDevice); //device founded if (Convert.ToInt32(foundedDevice) > 0) { _logger.Info("dc:getDeviceList()"); dataJSON = hyScript.call("return dc:getDeviceList():__tostring(dc:getDeviceList():getBeginDeviceDescriptionIterator(true))"); _logger.Info("resultat getDeviceList : " + dataJSON); try { FrameResponse dataFrame; SappelResponseContract sappelResponseContract = JsonConvert.DeserializeObject <SappelResponseContract>(dataJSON); List <Entry> entries = sappelResponseContract.entries.ToList(); foreach (var entry in entries) { List <Telegram> telegrams = entry.value.meteringPoint.telegrams.ToList(); foreach (var telegram in telegrams) { dataFrame = new FrameResponse(); if (telegram.telegramTypeSpecifica.qualityIndicator.rssi > 25) { dataFrame.deviceId = telegram.mBusData.deviceId.spdeid.spde; dataFrame.manuString = telegram.mBusData.deviceId.manuString; dataFrame.ciField = telegram.mBusData.ciField; dataFrame.structure = telegram.mBusData.deviceId.spdeid.format; //Récupération des alarmes if (telegram.mBusData.alarmField.data != "00" && telegram.mBusData.alarmField.data != "00 00") { dataFrame.alarmeCode = TelegramAlarmFormat(telegram.mBusData.alarmField.data); } string rawData = TelegramFormat(telegram.mBusData.rawData.data); //On récupére la raw data rawDataInterpretJSON = Interpreter(rawData); Telegram telegramResponse = JsonConvert.DeserializeObject <Telegram>(rawDataInterpretJSON); List <MBusValue> mBusValues = telegramResponse.mBusData.mBusValues.ToList(); foreach (var mBusValue in mBusValues) { if ((mBusValue.valid == true)) { if (mBusValue.dimension.stringId == "VOLUME") { //volume if (mBusValue.storageNumber == 0 && mBusValue.tariffNumber == 0 && mBusValue.subUnitNumber == 0) { dataFrame.volumeValue = Convert.ToInt32(mBusValue.formated); dataFrame.volumeIndex = CalculIndex(Convert.ToInt32(mBusValue.formated), Convert.ToInt32(mBusValue.exponent)); dataFrame.volumeCode = mBusValue.dimension.stringId; dataFrame.volumeUnite = mBusValue.unit.stringId; dataFrame.volumeExponent = Convert.ToInt32(mBusValue.exponent); dataFrame.volumeFormat = dataFrame.volumeCode + " " + dataFrame.volumeIndex + " m3"; } } if (mBusValue.dimension.stringId == "ENERGY") { //Energy if (mBusValue.storageNumber == 0 && mBusValue.tariffNumber == 0 && mBusValue.subUnitNumber == 0) { dataFrame.energyValue = Convert.ToInt32(mBusValue.formated); dataFrame.energyIndex = CalculIndex(Convert.ToInt32(mBusValue.formated), Convert.ToInt32(mBusValue.exponent)); dataFrame.energyCode = mBusValue.dimension.stringId; dataFrame.energyUnite = mBusValue.unit.stringId; dataFrame.energyExponent = Convert.ToInt32(mBusValue.exponent); dataFrame.energyFormat = dataFrame.energyCode + " " + dataFrame.energyIndex + " " + dataFrame.energyUnite; } } if (mBusValue.dimension.stringId == "OPERATIONTIMEBATTERY") { dataFrame.batteryCode = mBusValue.dimension.stringId; dataFrame.batteryFormated = Convert.ToInt32(mBusValue.formated); dataFrame.batteryUnite = mBusValue.unit.stringId; } if (mBusValue.dimension.stringId == "TIMEPOINT") { dataFrame.date = mBusValue.formated.ToString(); } } } if (!myFrameList.Where(x => x.deviceId == dataFrame.deviceId).Any()) { if ((dataFrame.volumeCode != null || dataFrame.energyCode != null) && dataFrame.ciField != 0) { myFrameList.Add(dataFrame); } } } } } } catch (Exception ex) { _logger.Info("ERREUR : " + ex.Message); } } hyScript.call("dc:getDeviceList():clear()"); } else { dataJSON = hyScript.call("dc:clearLastException() val=dc:getValue(valueIdent) ret = {val, dc:getLastException()} return ret"); _logger.Info("Erreur Init and StartASync: " + dataJSON); } } else { dataJSON = hyScript.call("dc:clearLastException() val=dc:getValue(valueIdent) ret = {val, dc:getLastException()} return ret"); _logger.Info("Erreur check licence: " + dataJSON); } _logger.Info("ResultMyFrameList : " + myFrameList.ToString()); return(myFrameList); }
public string GetVersion() { HyScript hyScript = new HyScript(); return(hyScript.call("return Environment.getVersion()")); }
public void Init() { HyScript hyScript = new HyScript(); string initResponse = hyScript.call("init"); string licenseResponse = hyScript.call("return License.check('EGEEEGEE','I1ARCQI0')"); }