(ctx context.Context, cmd command.Message)
| 334 | } |
| 335 | |
| 336 | func (s *Sensor) SendCommand(ctx context.Context, cmd command.Message) error { |
| 337 | msg, err := command.Encode(cmd) |
| 338 | if err != nil { |
| 339 | return fmt.Errorf("cannot encode command %q: %w", cmd, err) |
| 340 | } |
| 341 | log.Debugf("Sending command to the test sensor: %s", string(msg)) |
| 342 | |
| 343 | if len(s.contID) == 0 { |
| 344 | return errNotStarted |
| 345 | } |
| 346 | |
| 347 | if s.client == nil { |
| 348 | return errors.New("IPC client isn't initialized - is sensor running?") |
| 349 | } |
| 350 | |
| 351 | // TODO: Use timeout from ctx. |
| 352 | resp, err := s.client.SendCommand(cmd) |
| 353 | if err != nil || resp.Status != command.ResponseStatusOk { |
| 354 | return fmt.Errorf("IPC client.SendCommand() failed with response %q: %w", resp, err) |
| 355 | } |
| 356 | |
| 357 | return nil |
| 358 | } |
| 359 | |
| 360 | func (s *Sensor) SendStartCommand( |
| 361 | ctx context.Context, |
no test coverage detected