Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroAir committed Nov 6, 2023
1 parent 53c3342 commit 427a6ef
Show file tree
Hide file tree
Showing 37 changed files with 2,931 additions and 1,830 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ set(api_module
${lithium_src_dir}/client/phd2client.cpp
${lithium_module_dir}/client/indiclient.cpp
${lithium_src_dir}/client/hydrogen/hydrogencamera.cpp
${lithium_src_dir}/client/hydrogen/hydrogenfilterwheel.cpp
${lithium_src_dir}/client/hydrogen/hydrogentelescope.cpp
${lithium_src_dir}/client/hydrogen/hydrogenfocuser.cpp
)

set(config_module
Expand Down Expand Up @@ -206,7 +209,7 @@ set(system_module
set(utils_module
${lithium_module_dir}/utils/time.cpp
${lithium_module_dir}/utils/string.cpp
${lithium_module_dir}/utils/switch.cpp
${lithium_module_dir}/utils/static_switch.cpp
)

set(Lithium_module
Expand Down
2 changes: 1 addition & 1 deletion locale/lithium.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-11-04 10:14+0000\n"
"POT-Creation-Date: 2023-11-06 13:28+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
1 change: 0 additions & 1 deletion modules/hydrogen_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ include_directories(${ZLIB_INCLUDE_DIR})

list(APPEND ${PROJECT_NAME}_LIBS
hydrogencore
hydrogendevice
hydrogenabstractclient
sockets
${CMAKE_THREAD_LIBS_INIT}
Expand Down
100 changes: 100 additions & 0 deletions modules/lithium_image/lithium_image_stb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <iostream>
#include <vector>
#include <string>

#include "Plugin.h"
#include "stb_image.h"

class ImageProcessingPlugin : public Plugin
{
public:
ImageProcessingPlugin(const std::string &path, const std::string &version, const std::string &author, const std::string &description)
: Plugin(path, version, author, description)
{
}

void Execute(const std::vector<std::string> &args) override
{
if (args.empty())
{
std::cout << "Usage: image_processing_plugin <image_path>" << std::endl;
return;
}

std::string imagePath = args[0];

// Load the image using stb_image
int width, height, channels;
unsigned char *imageData = stbi_load(imagePath.c_str(), &width, &height, &channels, 0);
if (!imageData)
{
std::cout << "Failed to load image: " << imagePath << std::endl;
return;
}

// Perform image processing operations here
// Example: Convert the image to grayscale
unsigned char *grayImageData = convertToGrayscale(imageData, width, height, channels);

// Save the processed image
std::string outputPath = "processed_image.jpg";
if (stbi_write_jpg(outputPath.c_str(), width, height, 1, grayImageData, 100) == 0)
{
std::cout << "Failed to save processed image." << std::endl;
}
else
{
std::cout << "Processed image saved to: " << outputPath << std::endl;
}

// Free the allocated memory
stbi_image_free(imageData);
stbi_image_free(grayImageData);
}

private:
unsigned char *convertToGrayscale(unsigned char *imageData, int width, int height, int channels)
{
unsigned char *grayImageData = new unsigned char[width * height];

if (channels == 1)
{
memcpy(grayImageData, imageData, width * height);
}
else if (channels == 3)
{
for (int i = 0; i < width * height; ++i)
{
unsigned char r = imageData[i * channels];
unsigned char g = imageData[i * channels + 1];
unsigned char b = imageData[i * channels + 2];
unsigned char gray = static_cast<unsigned char>(0.2989 * r + 0.587 * g + 0.114 * b);
grayImageData[i] = gray;
}
}
else if (channels == 4)
{
for (int i = 0; i < width * height; ++i)
{
unsigned char r = imageData[i * channels];
unsigned char g = imageData[i * channels + 1];
unsigned char b = imageData[i * channels + 2];
unsigned char a = imageData[i * channels + 3];
unsigned char gray = static_cast<unsigned char>(0.2989 * r + 0.587 * g + 0.114 * b);
grayImageData[i] = gray;
}
}

return grayImageData;
}
};

// Example usage
int main()
{
ImageProcessingPlugin plugin("path/to/plugin", "1.0", "Author", "Image processing plugin");
std::vector<std::string> args = {"path/to/image.jpg"};
plugin.Execute(args);

return 0;
}
182 changes: 182 additions & 0 deletions src/client/hydrogen/hydrogenbasic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* hydrogenbasic.cpp
*
* Copyright (C) 2023 Max Qian <lightapt.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*************************************************
Copyright: 2023 Max Qian. All rights reserved
Author: Max Qian
E-mail: [email protected]
Date: 2023-4-10
Description: Hydrogen Basic Template
**************************************************/

#include "hydrogenbasic.hpp"

#include "modules/utils/switch.hpp"

#include "config.h"

#include "loguru/loguru.hpp"

HydrogenBasic::HydrogenBasic(const std::string &name)
{
DLOG_F(INFO, "Hydrogen basic {} init successfully", name);

m_number_switch = std::make_unique<StringSwitch<INumberVectorProperty *>>();
m_switch_switch = std::make_unique<StringSwitch<ISwitchVectorProperty *>>();
m_text_switch = std::make_unique<StringSwitch<ITextVectorProperty *>>();
}

HydrogenBasic::~HydrogenBasic()
{
}

bool HydrogenBasic::connect(const json &params)
{
std::string name = params["name"];
std::string hostname = params["host"];
int port = params["port"];
DLOG_F(INFO, "Trying to connect to {}", name);
setServer(hostname.c_str(), port);
// Receive messages only for our camera.
watchDevice(name.c_str());
// Connect to server.
if (connectServer())
{
DLOG_F(INFO, "{}: connectServer done ready", getDeviceName());
connectDevice(name.c_str());
return !is_ready.load();
}
return false;
}

bool HydrogenBasic::disconnect(const json &params)
{
DLOG_F(INFO, "%s is disconnected", getDeviceName());
return true;
}

bool HydrogenBasic::reconnect(const json &params)
{
return true;
}

bool HydrogenBasic::isConnected()
{
return true;
}

void HydrogenBasic::newDevice(HYDROGEN::BaseDevice *dp)
{
if (strcmp(dp->getDeviceName(), getDeviceName().c_str()) == 0)
{
telescope_device = dp;
}
}

void HydrogenBasic::newSwitch(ISwitchVectorProperty *svp)
{
m_switch_switch->match(svp->name, svp);
}

void HydrogenBasic::newMessage(HYDROGEN::BaseDevice *dp, int messageID)
{
DLOG_F(INFO, "{} Received message: {}", _name, dp->messageQueue(messageID));
}

inline static const char *StateStr(IPState st)
{
switch (st)
{
default:
case IPS_IDLE:
return "Idle";
case IPS_OK:
return "Ok";
case IPS_BUSY:
return "Busy";
case IPS_ALERT:
return "Alert";
}
}

void HydrogenBasic::newNumber(INumberVectorProperty *nvp)
{
m_number_switch->match(nvp->name, nvp);
}

void HydrogenBasic::newText(ITextVectorProperty *tvp)
{
m_text_switch->match(tvp->name, tvp);
}

void HydrogenBasic::newBLOB(IBLOB *bp)
{
DLOG_F(INFO, "{} Received BLOB {} len = {} size = {}", _name, bp->name, bp->bloblen, bp->size);
}

void HydrogenBasic::newProperty(HYDROGEN::Property *property)
{
std::string PropName(property->getName());
HYDROGEN_PROPERTY_TYPE Proptype = property->getType();

// DLOG_F(INFO,"{} Property: {}", getDeviceName(), property->getName());

if (Proptype == HYDROGEN_NUMBER)
{
newNumber(property->getNumber());
}
else if (Proptype == HYDROGEN_SWITCH)
{
newSwitch(property->getSwitch());
}
else if (Proptype == HYDROGEN_TEXT)
{
newText(property->getText());
}
}

void HydrogenBasic::IndiServerConnected()
{
DLOG_F(INFO, "{} connection succeeded", _name);
is_connected.store(true);
}

void HydrogenBasic::IndiServerDisconnected(int exit_code)
{
DLOG_F(INFO, "{}: serverDisconnected", _name);
// after disconnection we reset the connection status and the properties pointers
ClearStatus();
// in case the connection lost we must reset the client socket
if (exit_code == -1)
DLOG_F(INFO, "{} : Hydrogen server disconnected", _name);
}

void HydrogenBasic::removeDevice(HYDROGEN::BaseDevice *dp)
{
ClearStatus();
DLOG_F(INFO, "{} disconnected", _name);
}

void HydrogenBasic::ClearStatus()
{
}
Loading

0 comments on commit 427a6ef

Please sign in to comment.