Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 142 additions & 2 deletions src/event_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include "phd.h"
#include "event_server.h"

#include <wx/sstream.h>
#include <wx/sckstrm.h>
Expand Down Expand Up @@ -116,10 +117,16 @@ struct JSeq
close();
return m_s;
}

JSeq& operator<<(JSeq& other) { return *this << other.str(); }
};

typedef JSeq<'[', ']'> JAry;
typedef JSeq<'{', '}'> JObj;
struct JAry : public JSeq<'[', ']'>
{
};
struct JObj : public JSeq<'{', '}'>
{
};

static JAry& operator<<(JAry& a, const wxString& str)
{
Expand Down Expand Up @@ -3055,3 +3062,136 @@ void EventServer::NotifyConfigurationChange()
do_notify(m_eventServerClients, ev);
m_configEventDebouncer->StartOnce(0);
}

MultiStarReport::Item::Item() : X(0), Y(0), ReferenceX(0), ReferenceY(0), Mass(0), SNR(0), HFD(0), status(0) { }

MultiStarReport::Item MultiStarReport::Item::healthy(const GuideStar& star)
{
return unhealthy(star, MultiStarReport::Item::Healthy);
}

MultiStarReport::Item MultiStarReport::Item::unused(const GuideStar& star)
{
return unhealthy(star, MultiStarReport::Item::Unused);
}

MultiStarReport::Item MultiStarReport::Item::unhealthy(const GuideStar& star, uint8_t status)
{
Item ret;
ret.X = star.X;
ret.Y = star.Y;
ret.ReferenceX = star.referencePoint.X;
ret.ReferenceY = star.referencePoint.Y;
ret.Mass = star.Mass;
ret.SNR = star.SNR;
ret.HFD = star.HFD;
ret.status = status;
return ret;
}

MultiStarReport::MultiStarReport() : refined(false), stabilizing(false) { }

void MultiStarReport::send()
{
EvtServer.NotifyMultiStarStatus(*this);
}

void MultiStarReport::addStar(MultiStarReport::Item star)
{
stars.push_back(star);
}

uint8_t MultiStarReport::Item::Missed(uint8_t count)
{
return 40 + count;
}

void MultiStarReport::setRefined(bool refined)
{
this->refined = refined;
}

void MultiStarReport::setStabilizing(bool stabilizing)
{
this->stabilizing = stabilizing;
}

static std::string statusStr(uint8_t status)
{
switch (status)
{
case MultiStarReport::Item::Unused:
return "Unused";
case MultiStarReport::Item::Healthy:
return "Healthy";
case MultiStarReport::Item::ZeroDelta:
return "DZ";
case MultiStarReport::Item::TooFar:
return "F";
case MultiStarReport::Item::Reset:
return "R";
case MultiStarReport::Item::Lost:
return "L";
case MultiStarReport::Item::InvalidMass:
return "M";
default:
if (status >= 40)
{
return "M" + std::to_string(status - 40);
}
return "Unknown(" + std::to_string(status) + ")";
}
}

void MultiStarReport::Item::toJObj(JObj& result) const
{
result << NV("X", this->X);
result << NV("Y", this->Y);
result << NV("RefX", this->ReferenceX);
result << NV("RefY", this->ReferenceY);
result << NV("Mass", this->Mass);
result << NV("SNR", this->SNR);
result << NV("HFD", this->HFD);
if (this->status == MultiStarReport::Item::Unused)
{
result << NV("used", false);
}
else
{
result << NV("used", true);
if (this->status == MultiStarReport::Item::Healthy)
{
result << NV("err", NULL_VALUE);
}
else
{
result << NV("err", statusStr(this->status));
}
}
}

void MultiStarReport::toJObj(JObj& ev) const
{
JAry stars;
for (size_t i = 0; i < this->stars.size(); i++)
{
JObj star;
this->stars[i].toJObj(star);
stars << star;
}

ev << NV("Stars", stars);
ev << NV("Refined", this->refined);
ev << NV("Stabilizing", this->stabilizing);
}

void EventServer::NotifyMultiStarStatus(const MultiStarReport& pos)
{
if (m_eventServerClients.empty())
return;

Ev ev("MultiStarReport");
pos.toJObj(ev);

do_notify(m_eventServerClients, ev);
}
80 changes: 80 additions & 0 deletions src/event_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,87 @@
#define EVENT_SERVER_INCLUDED

#include <set>
#include <vector>
#include "json_parser.h"

struct JObj;
struct JAry;

class MultiStarReport
{
public:
class Item
{
friend class MultiStarReport;

protected:
double Mass;
double SNR;
double HFD;
double ReferenceX, ReferenceY;
double X, Y;
uint8_t status;
Item();

void toJObj(JObj& obj) const;

public:
static constexpr uint8_t Unused = 0;
static constexpr uint8_t Healthy = 1;
// Star ignore because one delta is exaclty zero
static constexpr uint8_t ZeroDelta = 2;
// Star is too far from reference
static constexpr uint8_t TooFar = 3;
// Star was reset due to beeing too far for too long
static constexpr uint8_t Reset = 4;
// Star lost
static constexpr uint8_t Lost = 5;
// Mass does not match
static constexpr uint8_t InvalidMass = 6;
static uint8_t Missed(uint8_t missCount);

static Item healthy(const GuideStar& star);
static Item unhealthy(const GuideStar& star, uint8_t reason);
static Item unused(const GuideStar& star);
};

std::vector<Item> stars;
bool stabilizing = false;
bool refined = false;

public:
MultiStarReport();

void addStar(Item star);
void send();
void setRefined(bool refined);
void setStabilizing(bool stabilizing);

void toJObj(JObj& obj) const;
};

template<class M>
class DeferedEvent
{
private:
bool emitted;

public:
M value;
void send()
{
if (!emitted)
{
emitted = true;
value.send();
}
}

DeferedEvent() : value(), emitted(false) { }

~DeferedEvent() { send(); }
};

class EventServer : public wxEvtHandler
{
public:
Expand All @@ -63,6 +142,7 @@ class EventServer : public wxEvtHandler
void NotifyLooping(unsigned int exposure, const Star *star, const FrameDroppedInfo *info);
void NotifyLoopingStopped();
void NotifySingleFrameComplete(bool succeeded, const wxString& errorMsg, const SingleExposure& info);
void NotifyMultiStarStatus(const MultiStarReport& p);
void NotifyStarSelected(const PHD_Point& pos);
void NotifyStarLost(const FrameDroppedInfo& info);
void NotifyGuidingStarted();
Expand Down
6 changes: 4 additions & 2 deletions src/guider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*
*/
#include "phd.h"
#include "event_server.h"
#include "nudge_lock.h"
#include "comet_tool.h"
#include "polardrift_tool.h"
Expand Down Expand Up @@ -1307,8 +1308,8 @@ void Guider::UpdateGuideState(usImage *pImage, bool bStopping)

GuiderOffset ofs;
FrameDroppedInfo info;

if (UpdateCurrentPosition(pImage, &ofs, &info)) // true means error
DeferedEvent<MultiStarReport> frameStarPositions;
if (UpdateCurrentPosition(pImage, &ofs, &info, &frameStarPositions.value)) // true means error
{
info.frameNumber = pImage->FrameNum;
info.time = pFrame->TimeSinceGuidingStarted();
Expand Down Expand Up @@ -1526,6 +1527,7 @@ void Guider::UpdateGuideState(usImage *pImage, bool bStopping)
case STATE_STOP:
break;
}
frameStarPositions.send();
}
catch (const wxString& Msg)
{
Expand Down
5 changes: 4 additions & 1 deletion src/guider.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct LockPosShiftParams
};

class DefectMap;
class MultiStarReport;

/*
* The Guider class is responsible for running the state machine
Expand Down Expand Up @@ -205,6 +206,7 @@ class Guider : public wxWindow
bool PaintHelper(wxAutoBufferedPaintDCBase& dc, wxMemoryDC& memDC);
void SetState(GUIDER_STATE newState);
void UpdateCurrentDistance(double distance, double distanceRA);
virtual void reportSecondaryStarsAsUnused(MultiStarReport *multiStarReport) = 0;

void ToggleBookmark(const wxRealPoint& pt);

Expand Down Expand Up @@ -297,7 +299,8 @@ class Guider : public wxWindow
virtual void InvalidateCurrentPosition(bool fullReset = false) = 0;

private:
virtual bool UpdateCurrentPosition(const usImage *pImage, GuiderOffset *ofs, FrameDroppedInfo *errorInfo) = 0;
virtual bool UpdateCurrentPosition(const usImage *pImage, GuiderOffset *ofs, FrameDroppedInfo *errorInfo,
MultiStarReport *multiStarReport) = 0;
virtual bool SetCurrentPosition(const usImage *pImage, const PHD_Point& position) = 0;

public:
Expand Down
Loading