/************************************************************/ /* NAME: Xiaobin Zeng */ /* ORGN: MIT */ /* FILE: SurfaceSupportComm.h */ /* DATE: */ /************************************************************/ #ifndef SurfaceSupportComm_HEADER #define SurfaceSupportComm_HEADER #include #include #include #include #include #include #include #include #include #include "MOOS/libMOOS/MOOSLib.h" #include "MOOS/libMOOS/Thirdparty/AppCasting/AppCastingMOOSApp.h" #include #include #include #include "PeriodicUDPEvent.h" struct Landmark { float lon; float lat; float depth; float speed; }; struct EstimatedState { float referenceLon; float referenceLat; float referenceAltitude; float currentLon; float currentLat; float currentAltitude; float offsetNorth; float offsetEast; float offsetDown; float roll; float pitch; float yaw; float linearVelocityNorth; float linearVelocityEast; float linearVelocityDown; float height; float depth; }; struct DeviceStatus { unsigned int batteryVoltage; unsigned int batteryLevel; float batteryTemp; unsigned int controllerTemp; int thrustRpm; unsigned int lightEnable; unsigned int throwingLoadEnable; unsigned int dvlStatus; }; class SurfaceSupportComm : public CMOOSApp // class SurfaceSupportComm : public AppCastingMOOSApp { public: SurfaceSupportComm(); ~SurfaceSupportComm(); protected: // Standard MOOSApp functions to overload bool OnNewMail(MOOSMSG_LIST &NewMail); bool Iterate(); bool OnConnectToServer(); bool OnStartUp(); void RegisterVariables(); // bool buildReport(); private: char recv_buf[2048]; DUNE::Network::UDPSocket sock_udp_send; DUNE::Network::TCPSocket sock_tcp_receive; DUNE::IO::Poll m_poll; uint16_t header_src, header_dst; uint8_t header_src_ent, header_dst_ent; std::string planConfigPath; struct EstimatedState estimatedState; struct DeviceStatus deviceStatus; struct Client { DUNE::Network::TCPSocket* socket; // Socket handle. DUNE::Network::Address address; // Client address. uint16_t port; // Client port. DUNE::IMC::Parser parser; // Parser handle }; typedef std::list ClientList; ClientList m_clients; bool udpSendToServer(DUNE::IMC::Message * msg, std::string addr, int port); void tcpReceiveFromClient(char* buf, unsigned int cap, double timeout); void tcpSendToClient(char* buf, unsigned int cap); void acceptNewClient(void); void handleClients(char* buf, unsigned int cap); void closeConnection(Client& c, std::exception& e); void processMessage(DUNE::IMC::Message * message); void ConvertLLAToNED(std::vector init_lla, std::vector point_lla, std::vector& point_ned); void ConvertNEDToLLA(std::vector init_lla, std::vector point_ned, std::vector &point_lla); void ConvertLLAToENU(std::vector init_lla, std::vector point_lla, std::vector& point_enu); void ConvertENUToLLA(std::vector init_lla, std::vector point_enu, std::vector &point_lla); void BatchConvertCoordinate(Json::Value &object); void ParsePlanConfig(Json::Value inputJsonValue); int simulateGetEntityStatus(DUNE::IMC::EntityParameters& entityParameter, std::string name, std::string value); int retrieveEntityStatus(DUNE::IMC::MsgList& equipmentMsgList); template inline int getEntityStatus(DUNE::IMC::EntityParameters& entityParameter, std::string name, Type& value); int testFlag = 0; double TimeLast; int sendCount = 0; PeriodicUDPEvent udpEvent; // PeriodicTCPEvent tcpEvent; std::string missionStatusString; }; #endif