public ActionResult Post(string data)
        {
            try
            {
                var list = data.Split('|');
                if (list.Length == 0 || !CheckToken(list[0]))
                {
                    return(Ok());
                }

                var fnItems      = _dataStorage.GetData <TransferData.FnItems>() ?? new TransferData.FnItems();
                var validWaiting = fnItems.Source == TransferData.SourceEnum.Server && fnItems.Valid && list[2] != fnItems.ID;
                //is valid waiting - skip it
                if (!validWaiting)
                {
                    fnItems = new TransferData.FnItems();
                    ProcessStates(list, fnItems);
                    fnItems.Source = TransferData.SourceEnum.Arduino;
                    fnItems.Date   = DateTime.UtcNow;
                    _dataStorage.SaveData(fnItems);
                    //save to recovery after terminal has lost power
                    _dataStorage.SaveData(fnItems, "FnRecovery");
                }

                var cmdItems = _dataStorage.GetData <TransferData.CmdItems>() ?? new TransferData.CmdItems();
                validWaiting = cmdItems.Source == TransferData.SourceEnum.Server && cmdItems.Valid && list[9] != cmdItems.ID;
                //is valid waiting - skip it
                if (!validWaiting)
                {
                    cmdItems = new TransferData.CmdItems();
                    ProcessStates(list, cmdItems);
                    cmdItems.Source = TransferData.SourceEnum.Arduino;
                    cmdItems.Date   = DateTime.UtcNow;
                    _dataStorage.SaveData(cmdItems);
                }

                var inputItems = new TransferData.PanelItems <TransferData.InputStatusEnum>();
                ProcessStates(13, list, inputItems);
                _dataStorage.SaveData(inputItems, "InputItems");

                var outputItems = new TransferData.PanelItems <TransferData.OutputStatusEnum>();
                ProcessStates(25, list, outputItems);
                _dataStorage.SaveData(outputItems, "OutputItems");

                var args = new DataChangedArgs()
                {
                    FnItems = fnItems, CmdItems = cmdItems, InputItems = inputItems, OutputItems = outputItems
                };
                _changeNotifier.OnNotify(args);
            }
            catch (Exception ex)
            {
                _errors.ErrorList.Add(new ErrorModel(ex.ToString()));
            }

            return(Ok());
        }
 private void ProcessStates(string[] items, TransferData.FnItems fnItems)
 {
     ProcessState(items[3], TransferData.ButtonPressEnum.Termostat1, fnItems);
     ProcessState(items[4], TransferData.ButtonPressEnum.Termostat2, fnItems);
     ProcessState(items[5], TransferData.ButtonPressEnum.ElHeating, fnItems);
     ProcessState(items[6], TransferData.ButtonPressEnum.Water, fnItems);
     ProcessState(items[7], TransferData.ButtonPressEnum.Cams, fnItems);
     ProcessState(items[8], TransferData.ButtonPressEnum.Alarm, fnItems);
 }
 private void ProcessState(string value, TransferData.ButtonPressEnum buttonPress, TransferData.FnItems fnItems)
 {
     if (byte.TryParse(value, out byte iState))
     {
         fnItems.SetState(buttonPress, (TransferData.FnStateEnum)iState);
     }
 }
Esempio n. 4
0
 private void AddItemToList(List <string> list, TransferData.ButtonPressEnum buttonPress, TransferData.FnItems fnItems)
 {
     list.Add(((byte)fnItems.GetState(buttonPress)).ToString());
 }