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.CmdItems cmdItems) { ProcessState(items[10], TransferData.ButtonPressEnum.GSM, cmdItems); ProcessState(items[11], TransferData.ButtonPressEnum.WIFI, cmdItems); ProcessState(items[12], TransferData.ButtonPressEnum.AlarmOff, cmdItems); }
private void ProcessState(string value, TransferData.ButtonPressEnum buttonPress, TransferData.CmdItems cmdItems) { if (byte.TryParse(value, out byte iState)) { cmdItems.SetPressed(buttonPress, iState == 1); } }
private void AddItemToList(List <string> list, TransferData.ButtonPressEnum buttonPress, TransferData.CmdItems cmdItems) { list.Add(cmdItems.GetPressed(buttonPress) ? "1" : "0"); }