diff --git a/.vscode/settings.json b/.vscode/settings.json index 21231eb..dd08119 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,57 @@ { "files.associations": { - "list": "cpp" + "list": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/src/pPowerManger/pPowerManger.moos b/bin/pPowerManger.moos similarity index 100% rename from src/pPowerManger/pPowerManger.moos rename to bin/pPowerManger.moos diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index c6148cd..2a13780 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -9,9 +9,17 @@ #include "MBUtils.h" #include "ACTable.h" #include "PowerManger.h" +#include "MOOS/libMOOS/Utils/ConsoleColours.h" using namespace std; + +bool _ListenCB(void * pParam) +{ + PowerManger* pMe = (PowerManger* )pParam; + return pMe->ListenLoopCCU(); +} + //--------------------------------------------------------- // Constructor() @@ -75,7 +83,7 @@ bool PowerManger::Iterate() { AppCastingMOOSApp::Iterate(); // Do your thing here! - AppCastingMOOSApp::PostReport(); + //AppCastingMOOSApp::PostReport(); return(true); } @@ -111,8 +119,15 @@ bool PowerManger::OnStartUp() reportUnhandledConfigWarning(orig); } - + registerVariables(); + + if(m_pCcuUdpComm = setUdpScoket(IPORT)) + MOOSTrace("UDP set succeed"); + else + MOOSTrace("UDP set faile"); + m_ListenThread.Initialise(_ListenCB,this); + m_ListenThread.Start(); return(true); } @@ -144,6 +159,32 @@ bool PowerManger::buildReport() return(true); } +//------------------------------------------------------------ +// Procedure: setUdpScoket() +XPCUdpSocket* PowerManger::setUdpScoket(long lPort) +{ + XPCUdpSocket* pUdpSocket = new XPCUdpSocket(lPort); + try + { + pUdpSocket->vBindSocket(); + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + return NULL; + } + return pUdpSocket; +} - - +bool PowerManger::ListenLoopCCU() +{ + unsigned char Buff[MAX_UDP_PKT_SIZE]; + cout << "------------------" << endl; + while(!m_ListenThread.IsQuitRequested()) + { + int nRead = m_pCcuUdpComm->iRecieveMessage(Buff,sizeof(Buff)); + cout<