#include "gnssCallback.h"

#include "devices/gpioIds.h"
#include "fsfw/action/HasActionsIF.h"
#include "fsfw/tasks/TaskFactory.h"

ReturnValue_t gps::triggerGpioResetPin(const uint8_t* actionData, size_t len, void* args) {
  // At least one byte which denotes which GPS to reset is required
  if (len < 1 or actionData == nullptr) {
    return HasActionsIF::INVALID_PARAMETERS;
  }
  ResetArgs* resetArgs = reinterpret_cast<ResetArgs*>(args);
  if (args == nullptr) {
    return returnvalue::FAILED;
  }
  if (resetArgs->gpioComIF == nullptr) {
    return returnvalue::FAILED;
  }
  gpioId_t gpioId;
  if (actionData[0] == 0) {
    gpioId = gpioIds::GNSS_0_NRESET;
  } else {
    gpioId = gpioIds::GNSS_1_NRESET;
  }
  resetArgs->gpioComIF->pullLow(gpioId);
  TaskFactory::delayTask(resetArgs->waitPeriodMs);
  resetArgs->gpioComIF->pullHigh(gpioId);
  return returnvalue::OK;
}