Skip to content

Commit

Permalink
Find WebsocketSP Property
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Oct 2, 2024
1 parent 01cb192 commit d122fb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
}
},
// Pass any arguments to configure CMake here (e.g. -DINDI_BUILD_WEBSOCKET=On)
"cmake.configureArgs": []
}
32 changes: 16 additions & 16 deletions libs/indibase/indiccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ bool CCD::updateProperties()

#ifdef HAVE_WEBSOCKET
if (HasWebSocket())
defineProperty(&WebSocketSP);
defineProperty(WebSocketSP);
#endif

defineProperty(FastExposureToggleSP);
Expand Down Expand Up @@ -719,7 +719,7 @@ bool CCD::updateProperties()
if (HasCooler())
{
deleteProperty(TemperatureNP);
deleteProperty(TemperatureRampNP.getName());
deleteProperty(TemperatureRampNP);
}
if (HasST4Port())
{
Expand All @@ -741,8 +741,8 @@ bool CCD::updateProperties()
#ifdef HAVE_WEBSOCKET
if (HasWebSocket())
{
deleteProperty(WebSocketSP.name);
deleteProperty(WebSocketSettingsNP.name);
deleteProperty(WebSocketSP);
deleteProperty(WebSocketSettingsNP);
}
#endif
deleteProperty(FastExposureToggleSP);
Expand Down Expand Up @@ -1593,26 +1593,26 @@ bool CCD::ISNewSwitch(const char * dev, const char * name, ISState * states, cha

#ifdef HAVE_WEBSOCKET
// Websocket Enable/Disable
if (!strcmp(name, WebSocketSP.name))
if (WebSocketSP.isNameMatch(name))
{
IUUpdateSwitch(&WebSocketSP, states, names, n);
WebSocketSP.s = IPS_OK;
WebSocketSP.update(states, names, n);
WebSocketSP.setState(IPS_OK);

if (WebSocketS[WEBSOCKET_ENABLED].s == ISS_ON)
if (WebSocketSP[WEBSOCKET_ENABLED].getState() == ISS_ON)
{
wsThread = std::thread(&wsThreadHelper, this);
WebSocketSettingsN[WS_SETTINGS_PORT].value = wsServer.generatePort();
WebSocketSettingsNP.s = IPS_OK;
defineProperty(&WebSocketSettingsNP);
WebSocketSettingsNP[WS_SETTINGS_PORT].setValue(wsServer.generatePort());
WebSocketSettingsNP.setState(IPS_OK);
defineProperty(WebSocketSettingsNP);
}
else if (wsServer.is_running())
{
wsServer.stop();
wsThread.join();
deleteProperty(WebSocketSettingsNP.name);
deleteProperty(WebSocketSettingsNP);
}

IDSetSwitch(&WebSocketSP, nullptr);
WebSocketSP.apply();
return true;
}
#endif
Expand Down Expand Up @@ -2787,13 +2787,13 @@ bool CCD::uploadFile(CCDChip * targetChip, const void * fitsData, size_t totalBy
if (sendImage)
{
#ifdef HAVE_WEBSOCKET
if (HasWebSocket() && WebSocketS[WEBSOCKET_ENABLED].s == ISS_ON)
if (HasWebSocket() && WebSocketSP[WEBSOCKET_ENABLED].getState() == ISS_ON)
{
auto start = std::chrono::high_resolution_clock::now();

// Send format/size/..etc first later
wsServer.send_text(std::string(targetChip->FitsB.format));
wsServer.send_binary(targetChip->FitsB.blob, targetChip->FitsB.bloblen);
wsServer.send_text(std::string(targetChip->FitsBP[0].getFormat()));
wsServer.send_binary(targetChip->FitsBP[0].getBlob(), targetChip->FitsBP[0].getBlobLen());

auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
Expand Down
4 changes: 2 additions & 2 deletions libs/indibase/stream/streammanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ bool StreamManagerPrivate::uploadStream(const uint8_t * buffer, uint32_t nbytes)
// Upload to client now
#ifdef HAVE_WEBSOCKET
if (dynamic_cast<INDI::CCD*>(currentDevice)->HasWebSocket()
&& dynamic_cast<INDI::CCD*>(currentDevice)->WebSocketS[CCD::WEBSOCKET_ENABLED].s == ISS_ON)
&& dynamic_cast<INDI::CCD*>(currentDevice)->WebSocketSP[CCD::WEBSOCKET_ENABLED].getState() == ISS_ON)
{
if (Format != ".streajpg")
{
Expand Down Expand Up @@ -1215,7 +1215,7 @@ bool StreamManagerPrivate::uploadStream(const uint8_t * buffer, uint32_t nbytes)
{
#ifdef HAVE_WEBSOCKET
if (dynamic_cast<INDI::CCD*>(currentDevice)->HasWebSocket()
&& dynamic_cast<INDI::CCD*>(currentDevice)->WebSocketS[CCD::WEBSOCKET_ENABLED].s == ISS_ON)
&& dynamic_cast<INDI::CCD*>(currentDevice)->WebSocketSP[CCD::WEBSOCKET_ENABLED].getState() == ISS_ON)
{
if (Format != ".stream")
{
Expand Down

0 comments on commit d122fb1

Please sign in to comment.