public override async Task <string> ExecuteAsync(IPortPlug port) { if (port == null || !port.IsOpen) { Response = string.Empty; return(string.Empty); } var currentStepTask = executeStep(_steps.First(), port); bool next = false; foreach (var step in _steps.Skip(1)) { await currentStepTask.ContinueWith(completedStepTask => { next = !completedStepTask.IsFaulted && completedStepTask.Result == true; if (next) { currentStepTask = executeStep(step, port); } }); if (!next) { break; } } await currentStepTask; return(Response); }
public async Task <bool> HasInternationalFormat(IPortPlug port) { var matches = await scaMatches(port); int tosca = 0; return(matches != null && matches.Count > 1 && int.TryParse(matches[1].Value, out tosca) && tosca == Constants.InternationalAddressType); }
public virtual async Task <string> ExecuteAsync(IPortPlug port) { if (port == null || !port.IsOpen) { Response = string.Empty; return(string.Empty); } return(Response = await port.SendAndReceiveAsync(prepareCommand())); }
public async Task <bool> AuthenticateIfNotReady(IPortPlug port, int pin) { bool authenticated = await IsAuthenticated(port); if (!authenticated) { authenticated = await Authenticate(port, pin); } return(authenticated); }
private async Task <bool> executeStep(ICommandParameter step, IPortPlug port) { _currentCommand = step.IsNextParameter ? string.Empty : Command; _currentOperator = step.IsNextParameter ? string.Empty : "="; _currentParam = step.Value; Parameter = step; await base.ExecuteAsync(port); return(base.Succeeded()); }
public async Task <IEnumerable <MessageStorageState> > StorageState(IPortPlug port) { var result = Enumerable.Empty <MessageStorageState>(); await _storageQuery.ExecuteAsync(port); if (_storageQuery.Succeeded()) { result = getStorageState(_storageQuery.Response); } return(result); }
public async Task <bool> SelectStorage(IPortPlug port, Constants.MessageStorage readStore = Constants.MessageStorage.MobileEquipment, Constants.MessageStorage writeStore = Constants.MessageStorage.Unspecified, Constants.MessageStorage receivedStore = Constants.MessageStorage.Unspecified) { if (readStore == Constants.MessageStorage.Unspecified) { return(false); } var storageParam = new CommandParameter(getStorageParam(readStore, writeStore, receivedStore), Constants.BasicSuccessfulResponse); var storageCmd = new ParamATCommand(ATCommand.MessageStorage.Command(), storageParam); await storageCmd.ExecuteAsync(port); return(storageCmd.Succeeded()); }
public async Task <bool> Authenticate(IPortPlug port, int pin) { if (pin < 0) { return(false); } var pinParam = new CommandParameter(pin.ToString(), Constants.BasicSuccessfulResponse); var pinCmd = new ParamATCommand(ATCommand.PinAuthenticate.Command(), pinParam); await pinCmd.ExecuteAsync(port); return(pinCmd.Succeeded()); }
public async Task <IEnumerable <MessageStorageItem> > List(IPortPlug port) { var result = Enumerable.Empty <MessageStorageItem>(); if (await setFormat(port)) { await _listQuery.ExecuteAsync(port); if (_listQuery.Succeeded()) { result = getStorageItems(_listQuery.Response); } } return(result); }
public async Task <bool> SetAddress(IPortPlug port, long address, bool international) { if (address < 0) { return(false); } var sign = international ? "+" : string.Empty; var tosca = international ? Constants.InternationalAddressType : Constants.DomesticAddressType; var scaParam = new CommandParameter($"\"{sign}{address}\",{tosca}", Constants.BasicSuccessfulResponse); var scaCmd = new ParamATCommand(ATCommand.ServiceCenterAddress.Command(), scaParam); await scaCmd.ExecuteAsync(port); return(scaCmd.Succeeded()); }
public async Task <bool> Delete(IPortPlug port, MessageStorageItem item, DeleteFlag deleteFlag = DeleteFlag.SpecifiedByIndex) { bool result = false; if (item == null || !item.IsValid) { return(result); } if (await setFormat(port)) { var deleteParam = new CommandParameter($"{item.Index},{deleteFlag.ToValueString()}", Constants.BasicSuccessfulResponse); var deleteCmd = new ParamATCommand(ATCommand.MessageDelete.Command(), deleteParam); await deleteCmd.ExecuteAsync(port); result = deleteCmd.Succeeded(); } return(result); }
public async Task <bool> Send(IPortPlug port, long destination, string message) { bool send = false; var formatSet = await setFormat(port); if (formatSet) { int length = 0; string packet = _sendProfile.GetPacket(destination, message, out length); var lengthStep = new StepwiseCommandParameter($"{length}{Constants.CR}", Constants.ContinueResponse, false); var messageStep = new StepwiseCommandParameter($"{packet}{Constants.SUB}", Constants.BasicSuccessfulResponse, true, true); var sendCmd = new StepwiseATCommand(ATCommand.MessageSend.Command(), new ICommandParameter[] { lengthStep, messageStep }); await sendCmd.ExecuteAsync(port); send = sendCmd.Succeeded(); } return(send); }
public async Task <MessageDetails> Read(IPortPlug port, MessageStorageItem item) { MessageDetails result = new MessageDetails(); if (item == null || !item.IsValid || !_manager.ContainsProfile("default-receive")) { return(result); } if (await setFormat(port)) { var readParam = new CommandParameter(item.Index.ToString(), Constants.BasicSuccessfulResponse); var readCmd = new ParamATCommand(ATCommand.MessageRead.Command(), readParam); await readCmd.ExecuteAsync(port); if (readCmd.Succeeded()) { result = getMessage(readCmd.Response); } } return(result); }
public async Task <string> GetAddress(IPortPlug port) { var matches = await scaMatches(port); return(matches != null && matches.Count > 0 ? matches[0].Value : string.Empty); }
private async Task <bool> setFormat(IPortPlug port) { await _mfCmd.ExecuteAsync(port); return(_mfCmd.Succeeded()); }
private async Task <MatchCollection> scaMatches(IPortPlug port) { await _scaQuery.ExecuteAsync(port); return(_scaQuery.Succeeded() ? Regex.Matches(_scaQuery.Response, @"\+?\d+") : null); }
/// <summary> /// Requires PIN. /// </summary> public async Task <string> ReceivedSignalCodePower(IPortPlug port) { await _rscp.ExecuteAsync(port); return(_rscp.Succeeded() ? _rscp.Response : port?.LastError?.Message ?? "operation failed"); }
/// <summary> /// Doesn't require PIN. /// </summary> public async Task <string> SystemInfo(IPortPlug port) { await _sysInfo.ExecuteAsync(port); return(_sysInfo.Succeeded() ? _sysInfo.Response : port?.LastError?.Message ?? "operation failed"); }
public async Task <bool> IsAuthenticated(IPortPlug port) { await _pinQuery.ExecuteAsync(port); return(_pinQuery.Succeeded()); }
public async Task <bool> IsDefined(IPortPlug port) { var matches = await scaMatches(port); return(matches != null && matches.Count > 0); }