run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  if (argResults?['pan-tilt-x'] == null &&
      argResults?['pan-tilt-y'] == null &&
      argResults?['pan-tilt-zoom'] == null) {
    throw UsageException('API usage error:',
        'Either pan-tilt (both x and y values) or pan-tilt-zoom must be specified.');
  } else if ((argResults?['pan-tilt-x'] != null &&
          argResults?['pan-tilt-y'] == null) ||
      (argResults?['pan-tilt-x'] == null &&
          argResults?['pan-tilt-y'] != null)) {
    throw UsageException('API usage error:',
        'When using pan-tilt, both pan-tilt-x or pan-tilt-y must be specified.');
  }

  Vector2D? panTilt;

  Vector1D? zoom;

  if (argResults?['pan-tilt-x'] != null &&
      argResults?['pan-tilt-y'] != null) {
    panTilt = Vector2D.fromString(
        x: argResults!['pan-tilt-x'], y: argResults!['pan-tilt-y']);
  }

  if (argResults?['pan-tilt-zoom'] != null) {
    zoom = Vector1D.fromString(x: argResults!['pan-tilt-zoom']);
  }

  await initializeOnvif();

  try {
    final place = PtzVector(
      panTilt: panTilt,
      zoom: zoom,
    );

    await ptz.absoluteMove(argResults!['profile-token'], position: place);
  } on DioException catch (err) {
    throw UsageException('API usage error:', err.usage);
  }
}