internal override bool DecodeArgument(byte b) { switch (_receivedStep) { case Steps.VariableCountHigh: // get number of functions Variables.Clear(); _nbVariables = b; _receivedStep = Steps.VariableCountLow; break; case Steps.VariableCountLow: _nbVariables = _nbVariables + 256 * b; if (_nbVariables == 0) { _receivedStep = Steps.End; // if no function, stop parsing } else { _receivedStep = Steps.VariableType; } break; case Steps.VariableType: // get return type _currentVariable = new SharerVariable(); _currentVariable.Type = (SharerType)b; _nameByte.Clear(); _receivedStep = Steps.VariableName; break; case Steps.VariableName: // get function name // if end of name if (b == 0) { _currentVariable.Name = System.Text.Encoding.UTF8.GetString(_nameByte.ToArray(), 0, _nameByte.Count); Variables.Add(_currentVariable); if (Variables.Count >= _nbVariables) // if enought function { _receivedStep = Steps.End; } else // else, go to next function { _receivedStep = Steps.VariableType; } } else // else, store value { _nameByte.Add(b); } break; default: break; } return(_receivedStep == Steps.End); }
/// <summary> /// Create a command to write a variable on Arduino /// </summary> /// <param name="variable">Variable to write</param> /// <param name="value">Value to write</param> public SharerWriteValue(SharerVariable variable, object value) { if (variable == null) { throw new ArgumentNullException("variable"); } if (string.IsNullOrEmpty(variable.Name)) { throw new ArgumentNullException("variable.Name"); } if (value == null) { throw new ArgumentNullException("value"); } this.Name = variable.Name; this.Value = value; }