#include "BaseStation.h"



namespace SSR {
struct HULC_Status_Message;
}


std::optional<SSR::CPR::Position> BaseStation::get_pos() {
  std::lock_guard g(mtx);
  return SSR::CPR::Position{hulc.get_latitude(), hulc.get_longitude()};
}
void BaseStation::set_msg(const SSR::HULC_Status_Message& msg) {
  std::lock_guard g(mtx);
  hulc = msg;
  if (handle_when_updated) handle_when_updated(msg);
}
std::string BaseStation::to_string() {
  std::lock_guard g(mtx);
  return "BaseStation:[" + std::to_string(hulc.get_latitude()) + ", " + std::to_string(hulc.get_longitude()) + "]";
}
Psc::JSON BaseStation::to_Json() {
  std::lock_guard g(mtx);
  auto ret = Psc::JSON::object();
  ret.append({"序列号", hulc.SerNum});
  ret.append({"状态标志", hulc.Flags});
  ret.append({"内部使用", hulc.I_U_});
  ret.append({"时间", Psc::utc_2_local_time(hulc.xTime)});
  ret.append({"latitude", hulc.get_latitude()});
  ret.append({"longitude", hulc.get_longitude()});
  ret.append({"height", hulc.Alt});
  ret.append({"卫星数量", hulc.Sat});
  ret.append({"HDOP", hulc.get_HDOP()});
  ret.append({"GPS设备检测到", hulc.GPS_device_detected()});
  ret.append({"GPS有效", hulc.GPS_valid()});
  ret.append({"GPS有效定位", hulc.GPS_has_valid_fix()});
  ret.append({"GPS高精度时间", hulc.GPS_high_accuracy_time()});
  ret.append({"启动以来TX队列溢出", hulc.TX_queue_overflow_since_startup()});
  ret.append({"过去一秒TX队列溢出", hulc.TX_queue_overflow_last_second()});
  ret.append({"发现过多NMEA数据", hulc.excessive_NMEA_found()});
  return ret;
}