Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
big problem!!!!
  • Loading branch information
AstroAir committed Oct 20, 2023
1 parent 4a43158 commit 75d4d06
Show file tree
Hide file tree
Showing 56 changed files with 1,146 additions and 821 deletions.
2 changes: 1 addition & 1 deletion src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int main(int argc, char *argv[])
}
catch (const std::runtime_error &e)
{
DLOG_F(ERROR, _("Failed to parser command line : %s"), e.what());
LOG_F(ERROR, _("Failed to parser command line : %s"), e.what());
std::exit(1);
}

Expand Down
13 changes: 8 additions & 5 deletions src/LithiumApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Description: Lithium App Enter
#include "config.h"

#include "loguru/loguru.hpp"
#include "nlohmann/json.hpp"

using json = nlohmann::json;

namespace Lithium
{
Expand Down Expand Up @@ -64,7 +67,7 @@ namespace Lithium
}
catch (const std::exception &e)
{
DLOG_F(ERROR, _("Failed to load Lithium App , error : {}"), e.what());
LOG_F(ERROR, _("Failed to load Lithium App , error : {}"), e.what());
throw std::runtime_error("Failed to load Lithium App");
}
}
Expand Down Expand Up @@ -269,7 +272,7 @@ namespace Lithium
}
else
{
DLOG_F(ERROR, _("Failed to run chai command : {}"), command);
LOG_F(ERROR, _("Failed to run chai command : {}"), command);
}
return false;
}
Expand All @@ -287,7 +290,7 @@ namespace Lithium
{
result += str + "\n";
}
DLOG_F(ERROR, _("Failed to run chai multi command {}"), result);
LOG_F(ERROR, _("Failed to run chai multi command {}"), result);
}
return true;
}
Expand All @@ -300,7 +303,7 @@ namespace Lithium
}
else
{
DLOG_F(ERROR, _("Failed to load chaiscript file {}"), filename);
LOG_F(ERROR, _("Failed to load chaiscript file {}"), filename);
return false;
}
}
Expand All @@ -313,7 +316,7 @@ namespace Lithium
}
else
{
DLOG_F(ERROR, _("Failed to run chai script {}"), filename);
LOG_F(ERROR, _("Failed to run chai script {}"), filename);
return false;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/client/ascom/ascom_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool ASCOMDevice::connect(const IParams &params)
setConnected(true);
if (!getConnected())
{
//DLOG_F(ERROR, "Failed to establish connection with %s", name.c_str());
//LOG_F(ERROR, "Failed to establish connection with %s", name.c_str());
return false;
}
//DLOG_F(INFO, "Connected to %s", name.c_str());
Expand All @@ -88,7 +88,7 @@ bool ASCOMDevice::disconnect(const IParams &params)
setConnected(false);
if (getConnected())
{
DLOG_F(ERROR, "Failed to disconnect with %s", getDeviceName());
LOG_F(ERROR, "Failed to disconnect with %s", getDeviceName());
return false;
}
return true;
Expand All @@ -98,11 +98,11 @@ bool ASCOMDevice::reconnect(const IParams &params)
{
if (!disconnect(params))
{
DLOG_F(ERROR, "Failed to reconnect with %s, falied when trying to disconnect with", getDeviceName());
LOG_F(ERROR, "Failed to reconnect with %s, falied when trying to disconnect with", getDeviceName());
}
if (!connect(params))
{
DLOG_F(ERROR, "Failed to reconnect %s, falied when trying to connect to", getDeviceName());
LOG_F(ERROR, "Failed to reconnect %s, falied when trying to connect to", getDeviceName());
}
return true;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ const std::string ASCOMDevice::get(const std::string &attribute, const json &dat
}
catch (const std::exception &e)
{
DLOG_F(ERROR, "Exception occurred during GET request: %s", e.what());
LOG_F(ERROR, "Exception occurred during GET request: %s", e.what());
throw;
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ const std::string ASCOMDevice::put(const std::string &attribute, const json &dat
}
catch (const std::exception &e)
{
DLOG_F(ERROR, "Exception occurred during PUT request: %s", e.what());
LOG_F(ERROR, "Exception occurred during PUT request: %s", e.what());
throw;
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/client/astap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace Lithium::API::ASTAP
FILE *pipe = popen(command.c_str(), "r");
if (!pipe)
{
DLOG_F(ERROR, "Error: failed to run command '%s'.", command.c_str());
LOG_F(ERROR, "Error: failed to run command '%s'.", command.c_str());
return "";
}
std::string output = "";
Expand All @@ -141,7 +141,7 @@ namespace Lithium::API::ASTAP

if (attempts_left < 1)
{
DLOG_F(ERROR, "Exceeded maximum attempts");
LOG_F(ERROR, "Exceeded maximum attempts");
throw std::runtime_error("Exceeded maximum attempts");
}

Expand All @@ -153,7 +153,7 @@ namespace Lithium::API::ASTAP
{
if (attempts_left == 1)
{
DLOG_F(ERROR, "Failed to execute function after multiple attempts");
LOG_F(ERROR, "Failed to execute function after multiple attempts");
throw;
}
else
Expand All @@ -171,17 +171,17 @@ namespace Lithium::API::ASTAP
// 输入参数合法性检查
if (ra < 0.0 || ra > 360.0)
{
DLOG_F(ERROR, "RA should be within [0, 360]");
LOG_F(ERROR, "RA should be within [0, 360]");
return "";
}
if (dec < -90.0 || dec > 90.0)
{
DLOG_F(ERROR, "DEC should be within [-90, 90]");
LOG_F(ERROR, "DEC should be within [-90, 90]");
return "";
}
if (fov <= 0.0 || fov > 180.0)
{
DLOG_F(ERROR, "FOV should be within (0, 180]");
LOG_F(ERROR, "FOV should be within (0, 180]");
return "";
}
if (!image.empty())
Expand All @@ -190,7 +190,7 @@ namespace Lithium::API::ASTAP
file.open(image, std::ios::in | std::ios::out);
if (!file.good())
{
DLOG_F(ERROR, "Error: image file '%s' is not accessible.", image.c_str());
LOG_F(ERROR, "Error: image file '%s' is not accessible.", image.c_str());
return "";
}
file.close();
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace Lithium::API::ASTAP
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start_time).count();
if (elapsed_time > timeout)
{
DLOG_F(ERROR, "Error: command timed out after %s seconds.", std::to_string(timeout).c_str());
LOG_F(ERROR, "Error: command timed out after %s seconds.", std::to_string(timeout).c_str());
return "";
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace Lithium::API::ASTAP
if (status != 0)
{
ret_struct["message"] = "Error: cannot open FITS file '" + image + "'.";
DLOG_F(ERROR, "%s", ret_struct["message"].c_str());
LOG_F(ERROR, "%s", ret_struct["message"].c_str());
return ret_struct;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ namespace Lithium::API::ASTAP
if (status != 0)
{
ret_struct["message"] = "Error: failed to close FITS file '" + image + "'.";
DLOG_F(ERROR, "%s", ret_struct["message"].c_str());
LOG_F(ERROR, "%s", ret_struct["message"].c_str());
return ret_struct;
}

Expand Down Expand Up @@ -362,7 +362,7 @@ namespace Lithium::API::ASTAP
}
else
{
DLOG_F(ERROR, "Failed to solve the image");
LOG_F(ERROR, "Failed to solve the image");
ret_struct["message"] = "Failed to solve the image";
}

Expand Down
22 changes: 11 additions & 11 deletions src/client/phd2client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SocketClient::SocketClient()
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
DLOG_F(ERROR, "Failed to initialize Winsock");
LOG_F(ERROR, "Failed to initialize Winsock");
throw std::runtime_error("Failed to initialize Winsock");
}
#endif
Expand All @@ -41,7 +41,7 @@ bool SocketClient::Connect(const std::string &serverIP, int serverPort)
#endif
if (socket_ == INVALID_SOCKET)
{
DLOG_F(ERROR, "Failed to create socket");
LOG_F(ERROR, "Failed to create socket");
#ifdef _WIN32
WSACleanup();
#endif
Expand All @@ -55,22 +55,22 @@ bool SocketClient::Connect(const std::string &serverIP, int serverPort)
#ifdef _WIN32
if (InetPton(AF_INET, serverIP.c_str(), &(serverAddress.sin_addr)) <= 0)
{
DLOG_F(ERROR, "Invalid server IP address");
LOG_F(ERROR, "Invalid server IP address");
closesocket(socket_);
WSACleanup();
throw std::runtime_error("Invalid server IP address");
}
#else
if (inet_pton(AF_INET, serverIP.c_str(), &(serverAddress.sin_addr)) <= 0)
{
DLOG_F(ERROR, "Invalid server IP address");
LOG_F(ERROR, "Invalid server IP address");
throw std::runtime_error("Invalid server IP address");
}
#endif

if (connect(socket_, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0)
{
DLOG_F(ERROR, "Failed to connect to server");
LOG_F(ERROR, "Failed to connect to server");
throw std::runtime_error("Failed to connect to server");
}

Expand Down Expand Up @@ -107,13 +107,13 @@ void SocketClient::Send(const std::string &message)
{
if (socket_ == INVALID_SOCKET)
{
DLOG_F(ERROR, "Not connected to server");
LOG_F(ERROR, "Not connected to server");
return;
}

if (send(socket_, message.c_str(), message.length(), 0) < 0)
{
DLOG_F(ERROR, "Failed to send data");
LOG_F(ERROR, "Failed to send data");
throw std::runtime_error("Failed to send data");
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ void SocketClient::ReceiveThread()
{
if (bytesRead < 0)
{
DLOG_F(ERROR, "Failed to receive data: %d", bytesRead);
LOG_F(ERROR, "Failed to receive data: %d", bytesRead);
}
else
{
Expand Down Expand Up @@ -461,7 +461,7 @@ void PHD2Client::_star_lost(const json &message)
_starlost_status["avg_dist"] = message["AvgDist"];
_starlost_error = message["Status"];

DLOG_F(ERROR, "Star Lost, SNR: {}, StarMass: {}, AvgDist: {}",
LOG_F(ERROR, "Star Lost, SNR: {}, StarMass: {}, AvgDist: {}",
_starlost_status["snr"], _starlost_status["star_mass"], _starlost_status["avg_dist"]);

_is_guiding = false;
Expand Down Expand Up @@ -532,13 +532,13 @@ void PHD2Client::_guiding_dithered(const json &message)
void PHD2Client::_lock_position_lost(const json &message)
{
_is_star_locked = true;
DLOG_F(ERROR, "Star Lock Position Lost");
LOG_F(ERROR, "Star Lock Position Lost");
}

void PHD2Client::_alert(const json &message)
{
_last_error = message["Msg"];
DLOG_F(ERROR, "Alert: %s", _last_error.c_str());
LOG_F(ERROR, "Alert: %s", _last_error.c_str());
}

void PHD2Client::_guide_param_change(const json &message)
Expand Down
12 changes: 6 additions & 6 deletions src/core/deviceio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ void SocketServer::start()
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
DLOG_F(ERROR, "Failed to initialize Winsock");
LOG_F(ERROR, "Failed to initialize Winsock");
return;
}
#endif

serverSocket = socket(AF_INET, SOCK_STREAM, 0); // 修改 IPPROTO_TCP 为 0
if (serverSocket == INVALID_SOCKET)
{
DLOG_F(ERROR, "Failed to create socket");
LOG_F(ERROR, "Failed to create socket");
#ifdef _WIN32
WSACleanup();
#endif
Expand All @@ -74,7 +74,7 @@ void SocketServer::start()

if (bind(serverSocket, (sockaddr *)&serverAddress, sizeof(serverAddress)) == SOCKET_ERROR)
{
DLOG_F(ERROR, "Failed to bind socket");
LOG_F(ERROR, "Failed to bind socket");
closesocket(serverSocket);
#ifdef _WIN32
WSACleanup();
Expand All @@ -84,7 +84,7 @@ void SocketServer::start()

if (listen(serverSocket, 5) == SOCKET_ERROR)
{
DLOG_F(ERROR, "Failed to listen on socket");
LOG_F(ERROR, "Failed to listen on socket");
closesocket(serverSocket);
#ifdef _WIN32
WSACleanup();
Expand Down Expand Up @@ -139,7 +139,7 @@ void SocketServer::acceptClientConnection()
SOCKET clientSocket = accept(serverSocket, (sockaddr *)&clientAddress, &clientAddressLength);
if (clientSocket == INVALID_SOCKET)
{
DLOG_F(ERROR, "Failed to accept client connection");
LOG_F(ERROR, "Failed to accept client connection");
return;
}

Expand All @@ -154,7 +154,7 @@ void SocketServer::handleClientMessage(SOCKET clientSocket)
int bytesRead = recv(clientSocket, buffer, sizeof(buffer), 0);
if (bytesRead == SOCKET_ERROR)
{
DLOG_F(ERROR, "Failed to read from client socket");
LOG_F(ERROR, "Failed to read from client socket");
}
else if (bytesRead == 0)
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/shared_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ class SharedMemory
handle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, sizeof(T) + sizeof(bool), name.c_str());
if (handle_ == nullptr)
{
DLOG_F(ERROR, "Failed to create file mapping.");
LOG_F(ERROR, "Failed to create file mapping.");
throw std::runtime_error("Failed to create file mapping.");
}

buffer_ = MapViewOfFile(handle_, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(T) + sizeof(bool));
if (buffer_ == nullptr)
{
CloseHandle(handle_);
DLOG_F(ERROR, "Failed to map view of file.");
LOG_F(ERROR, "Failed to map view of file.");
throw std::runtime_error("Failed to map view of file.");
}
#else // Unix-like
fd_ = shm_open(name.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd_ == -1)
{
DLOG_F(ERROR, "Failed to create shared memory.");
LOG_F(ERROR, "Failed to create shared memory.");
throw std::runtime_error("Failed to create shared memory.");
}

Expand All @@ -51,7 +51,7 @@ class SharedMemory
if (buffer_ == MAP_FAILED)
{
shm_unlink(name.c_str());
DLOG_F(ERROR, "Failed to map shared memory.");
LOG_F(ERROR, "Failed to map shared memory.");
throw std::runtime_error("Failed to map shared memory.");
}
#endif
Expand Down
Loading

0 comments on commit 75d4d06

Please sign in to comment.