public MovementCommand(string unparsedText) { if (unparsedText == null) { throw new ArgumentNullException("Null string received"); } if (IsValidIdentifier(unparsedText) == false) { throw new ArgumentException("Invalid identifier found in command: " + unparsedText); } rawCommand = unparsedText; try { motorSide = ParseMotorSide(rawCommand); motor1Direction = ParseDirection(rawCommand, 0); motor2Direction = ParseDirection(rawCommand, 1); motor3Direction = ParseDirection(rawCommand, 2); foreach (string motorDirectionReading in new string[] {motor1Direction, motor2Direction, motor3Direction}) { if(motorDirectionReading != CommandMetadata.Movement.Forward && motorDirectionReading != CommandMetadata.Movement.Backward) { throw new ArgumentException("Invalid direction value found in command: " + unparsedText); } } motor1Speed = ParseSpeed(rawCommand, 0); motor2Speed = ParseSpeed(rawCommand, 1); motor3Speed = ParseSpeed(rawCommand, 2); foreach (int motorSpeedReading in new int[]{motor1Speed, motor2Speed, motor3Speed}) { if (motorSpeedReading > CommandMetadata.Movement.MaxSpeed || motorSpeedReading < CommandMetadata.Movement.MinSpeed) { throw new ArgumentException("Invalid speed value found in command: " + unparsedText); } } } catch (ArgumentException) { throw; } microcontroller = MicrocontrollerSingleton.Instance; }
public MovementCommand(string unparsedText) { if (unparsedText == null) { throw new ArgumentNullException("Null string received"); } if (IsValidIdentifier(unparsedText) == false) { throw new ArgumentException("Invalid identifier found in command: " + unparsedText); } rawCommand = unparsedText; try { motorSide = ParseMotorSide(rawCommand); motor1Direction = ParseDirection(rawCommand, 0); motor2Direction = ParseDirection(rawCommand, 1); motor3Direction = ParseDirection(rawCommand, 2); foreach (string motorDirectionReading in new string[] { motor1Direction, motor2Direction, motor3Direction }) { if (motorDirectionReading != CommandMetadata.Movement.Forward && motorDirectionReading != CommandMetadata.Movement.Backward) { throw new ArgumentException("Invalid direction value found in command: " + unparsedText); } } motor1Speed = ParseSpeed(rawCommand, 0); motor2Speed = ParseSpeed(rawCommand, 1); motor3Speed = ParseSpeed(rawCommand, 2); foreach (int motorSpeedReading in new int[] { motor1Speed, motor2Speed, motor3Speed }) { if (motorSpeedReading > CommandMetadata.Movement.MaxSpeed || motorSpeedReading < CommandMetadata.Movement.MinSpeed) { throw new ArgumentException("Invalid speed value found in command: " + unparsedText); } } } catch (ArgumentException) { throw; } microcontroller = MicrocontrollerSingleton.Instance; }
public TiltCommand(string unparsedCommand) { if (unparsedCommand == null) { throw new ArgumentNullException("Null string received"); } rawCommand = unparsedCommand; try { camIndex = ParseCamIndex(unparsedCommand); tiltAngle = ParseTiltAngle(unparsedCommand); } catch (ArgumentException e) { Console.WriteLine(e.Message); throw; } microcontroller = MicrocontrollerSingleton.Instance; }
public PanCommand(string unparsedCommand) { //Extra error handling might be needed on a per-servo basis (ex: some servos are expected to do 360 degrees while others arent) if (unparsedCommand == null) { throw new ArgumentNullException("Null string received"); } rawCommand = unparsedCommand; try { camIndex = ParseCamIndex(unparsedCommand); panAngle = ParsePanAngle(unparsedCommand); } catch (ArgumentException) { throw; } microcontroller = MicrocontrollerSingleton.Instance; }
public KeepAliveCommand() { microcontroller = MicrocontrollerSingleton.Instance; }