15 namespace AlignmentSubsystem
19 pthread_cond_init(&DriverActionCompleteCondition,
nullptr);
20 pthread_mutex_init(&DriverActionCompleteMutex,
nullptr);
25 pthread_cond_destroy(&DriverActionCompleteCondition);
26 pthread_mutex_destroy(&DriverActionCompleteMutex);
32 WaitForDriverCompletion();
34 auto pAction =
Action->getSwitch();
37 if (
APPEND != pAction->findOnSwitchIndex())
44 WaitForDriverCompletion();
45 if (
IPS_OK != pAction->getState())
47 IDLog(
"AppendSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
52 if (!SendEntryData(CurrentValues))
57 pCommit->at(0)->setState(
ISS_ON);
60 WaitForDriverCompletion();
61 if (
IPS_OK != pCommit->getState())
63 IDLog(
"AppendSyncPoint - Bad Commit switch state %s\n", pCommit->getStateAsString());
73 WaitForDriverCompletion();
75 auto pAction =
Action->getSwitch();
79 if (
CLEAR != pAction->findOnSwitchIndex())
86 WaitForDriverCompletion();
87 if (
IPS_OK != pAction->getState())
89 IDLog(
"ClearSyncPoints - Bad Action switch state %s\n", pAction->getStateAsString());
95 pCommit->at(0)->setState(
ISS_ON);
98 WaitForDriverCompletion();
99 if (
IPS_OK != pCommit->getState())
101 IDLog(
"ClearSyncPoints - Bad Commit switch state %s\n", pCommit->getStateAsString());
111 WaitForDriverCompletion();
113 auto pAction =
Action->getSwitch();
114 auto pCurrentEntry = CurrentEntry->
getNumber();
118 if (
DELETE != pAction->findOnSwitchIndex())
125 WaitForDriverCompletion();
126 if (
IPS_OK != pAction->getState())
128 IDLog(
"DeleteSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
134 pCurrentEntry->at(0)->setValue(Offset);
137 WaitForDriverCompletion();
138 if (
IPS_OK != pCurrentEntry->getState())
140 IDLog(
"DeleteSyncPoint - Bad Current Entry state %s\n", pCurrentEntry->getStateAsString());
146 pCommit->at(0)->setState(
ISS_ON);
149 WaitForDriverCompletion();
150 if (
IPS_OK != pCommit->getState())
152 IDLog(
"DeleteSyncPoint - Bad Commit switch state %s\n", pCommit->getStateAsString());
162 WaitForDriverCompletion();
164 auto pAction =
Action->getSwitch();
165 auto pCurrentEntry = CurrentEntry->
getNumber();
169 if (
EDIT != pAction->findOnSwitchIndex())
176 WaitForDriverCompletion();
177 if (
IPS_OK != pAction->getState())
179 IDLog(
"EditSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
185 pCurrentEntry->at(0)->setValue(Offset);
188 WaitForDriverCompletion();
189 if (
IPS_OK != pCurrentEntry->getState())
191 IDLog(
"EditSyncPoint - Bad Current Entry state %s\n", pCurrentEntry->getStateAsString());
195 if (!SendEntryData(CurrentValues))
200 pCommit->at(0)->setState(
ISS_ON);
203 WaitForDriverCompletion();
204 if (
IPS_OK != pCommit->getState())
206 IDLog(
"EditSyncPoint - Bad Commit switch state %s\n", pCommit->getStateAsString());
220 ClientAPIForAlignmentDatabase::BaseClient =
BaseClient;
226 WaitForDriverCompletion();
228 auto pAction =
Action->getSwitch();
229 auto pCurrentEntry = CurrentEntry->
getNumber();
233 if (
INSERT != pAction->findOnSwitchIndex())
240 WaitForDriverCompletion();
241 if (
IPS_OK != pAction->getState())
243 IDLog(
"InsertSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
249 pCurrentEntry->at(0)->setValue(Offset);
252 WaitForDriverCompletion();
253 if (
IPS_OK != pCurrentEntry->getState())
255 IDLog(
"InsertSyncPoint - Bad Current Entry state %s\n", pCurrentEntry->getStateAsString());
259 if (!SendEntryData(CurrentValues))
264 pCommit->at(0)->setState(
ISS_ON);
267 WaitForDriverCompletion();
268 if (
IPS_OK != pCommit->getState())
270 IDLog(
"InsertSyncPoint - Bad Commit switch state %s\n", pCommit->getStateAsString());
280 WaitForDriverCompletion();
282 auto pAction =
Action->getSwitch();
293 WaitForDriverCompletion();
294 if (
IPS_OK != pAction->getState())
296 IDLog(
"LoadDatabase - Bad Action switch state %s\n", pAction->getStateAsString());
303 pCommit->at(0)->setState(
ISS_ON);
306 WaitForDriverCompletion();
307 if (
IPS_OK != pCommit->getState())
309 IDLog(
"LoadDatabase - Bad Commit state %s\n", pCommit->getStateAsString());
318 if (strcmp(BLOBPointer->bvp->name,
"ALIGNMENT_POINT_OPTIONAL_BINARY_BLOB") == 0)
320 if (
IPS_BUSY != BLOBPointer->bvp->s)
322 auto pAction =
Action->getSwitch();
323 int Index = pAction->findOnSwitchIndex();
325 SignalDriverCompletion();
332 Device = DevicePointer;
337 if (strcmp(NumberVectorProperty->
name,
"ALIGNMENT_POINT_MANDATORY_NUMBERS") == 0)
341 auto pAction =
Action->getSwitch();
342 int Index = pAction->findOnSwitchIndex();
344 SignalDriverCompletion();
347 else if (strcmp(NumberVectorProperty->
name,
"ALIGNMENT_POINTSET_CURRENT_ENTRY") == 0)
351 auto pAction =
Action->getSwitch();
352 int Index = pAction->findOnSwitchIndex();
354 SignalDriverCompletion();
361 bool GotOneOfMine =
true;
363 if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINT_MANDATORY_NUMBERS") == 0)
364 MandatoryNumbers = PropertyPointer;
365 else if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINT_OPTIONAL_BINARY_BLOB") == 0)
367 OptionalBinaryBlob = PropertyPointer;
369 OptionalBinaryBlob->
getBLOB()->
at(0)->setFormat(
"alignmentPrivateData");
371 else if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINTSET_SIZE") == 0)
372 PointsetSize = PropertyPointer;
373 else if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINTSET_CURRENT_ENTRY") == 0)
374 CurrentEntry = PropertyPointer;
375 else if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINTSET_ACTION") == 0)
377 else if (strcmp(PropertyPointer->
getName(),
"ALIGNMENT_POINTSET_COMMIT") == 0)
378 Commit = PropertyPointer;
380 GotOneOfMine =
false;
383 if (GotOneOfMine && (
nullptr != MandatoryNumbers) && (
nullptr != OptionalBinaryBlob) && (
nullptr != PointsetSize) &&
384 (
nullptr != CurrentEntry) && (
nullptr !=
Action) && (
nullptr != Commit))
389 SignalDriverCompletion();
395 if (strcmp(SwitchVectorProperty->
name,
"ALIGNMENT_POINTSET_ACTION") == 0)
398 SignalDriverCompletion();
400 else if (strcmp(SwitchVectorProperty->
name,
"ALIGNMENT_POINTSET_COMMIT") == 0)
403 SignalDriverCompletion();
410 WaitForDriverCompletion();
412 auto pAction =
Action->getSwitch();
413 auto pMandatoryNumbers = MandatoryNumbers->
getNumber();
414 auto pBLOB = OptionalBinaryBlob->
getBLOB();
415 auto pCurrentEntry = CurrentEntry->
getNumber();
426 WaitForDriverCompletion();
427 if (
IPS_OK != pAction->getState())
429 IDLog(
"ReadIncrementSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
436 pCommit->at(0)->setState(
ISS_ON);
439 WaitForDriverCompletion();
440 if ((
IPS_OK != pCommit->getState()) || (
IPS_OK != pMandatoryNumbers->getState()) || (
IPS_OK != pBLOB->getState()) ||
441 (
IPS_OK != pCurrentEntry->getState()))
443 IDLog(
"ReadIncrementSyncPoint - Bad Commit/Mandatory numbers/Blob/Current entry state %s %s %s %s\n",
444 pCommit->getStateAsString(), pMandatoryNumbers->getStateAsString(), pBLOB->getStateAsString(), pCurrentEntry->getStateAsString());
462 WaitForDriverCompletion();
464 auto pAction =
Action->getSwitch();
465 auto pMandatoryNumbers = MandatoryNumbers->
getNumber();
466 auto pBLOB = OptionalBinaryBlob->
getBLOB();
467 auto pCurrentEntry = CurrentEntry->
getNumber();
471 if (
READ != pAction->findOnSwitchIndex())
478 WaitForDriverCompletion();
479 if (
IPS_OK != pAction->getState())
481 IDLog(
"ReadSyncPoint - Bad Action switch state %s\n", pAction->getStateAsString());
487 pCurrentEntry->at(0)->setValue(Offset);
490 WaitForDriverCompletion();
491 if (
IPS_OK != pCurrentEntry->getState())
493 IDLog(
"ReadSyncPoint - Bad Current Entry state %s\n", pCurrentEntry->getStateAsString());
499 pCommit->at(0)->setState(
ISS_ON);
502 WaitForDriverCompletion();
503 if ((
IPS_OK != pCommit->getState()) || (
IPS_OK != pMandatoryNumbers->getState()) || (
IPS_OK != pBLOB->getState()))
505 IDLog(
"ReadSyncPoint - Bad Commit/Mandatory numbers/Blob state %s %s %s\n", pCommit->getStateAsString(),
506 pMandatoryNumbers->getStateAsString(), pBLOB->getStateAsString());
524 WaitForDriverCompletion();
526 auto pAction =
Action->getSwitch();
537 WaitForDriverCompletion();
538 if (
IPS_OK != pAction->getState())
540 IDLog(
"SaveDatabase - Bad Action switch state %s\n", pAction->getStateAsString());
547 pCommit->at(0)->setState(
ISS_ON);
550 WaitForDriverCompletion();
551 if (
IPS_OK != pCommit->getState())
553 IDLog(
"Save Database - Bad Commit state %s\n", pCommit->getStateAsString());
564 auto pMandatoryNumbers = MandatoryNumbers->
getNumber();
565 auto pBLOB = OptionalBinaryBlob->
getBLOB();
575 WaitForDriverCompletion();
576 if (
IPS_OK != pMandatoryNumbers->getState())
578 IDLog(
"SendEntryData - Bad mandatory numbers state %s\n", pMandatoryNumbers->getStateAsString());
590 WaitForDriverCompletion();
591 if (
IPS_OK != pBLOB->getState())
593 IDLog(
"SendEntryData - Bad BLOB state %s\n", pBLOB->getStateAsString());
600 bool ClientAPIForAlignmentDatabase::SetDriverBusy()
602 int ReturnCode = pthread_mutex_lock(&DriverActionCompleteMutex);
606 DriverActionComplete =
false;
607 IDLog(
"SetDriverBusy\n");
608 ReturnCode = pthread_mutex_unlock(&DriverActionCompleteMutex);
609 return ReturnCode == 0;
612 bool ClientAPIForAlignmentDatabase::SignalDriverCompletion()
614 int ReturnCode = pthread_mutex_lock(&DriverActionCompleteMutex);
618 DriverActionComplete =
true;
619 ReturnCode = pthread_cond_signal(&DriverActionCompleteCondition);
622 ReturnCode = pthread_mutex_unlock(&DriverActionCompleteMutex);
625 IDLog(
"SignalDriverCompletion\n");
626 ReturnCode = pthread_mutex_unlock(&DriverActionCompleteMutex);
627 return ReturnCode == 0;
630 bool ClientAPIForAlignmentDatabase::WaitForDriverCompletion()
632 int ReturnCode = pthread_mutex_lock(&DriverActionCompleteMutex);
634 while (!DriverActionComplete)
636 IDLog(
"WaitForDriverCompletion - Waiting\n");
637 ReturnCode = pthread_cond_wait(&DriverActionCompleteCondition, &DriverActionCompleteMutex);
638 IDLog(
"WaitForDriverCompletion - Back from wait ReturnCode = %d\n", ReturnCode);
641 ReturnCode = pthread_mutex_unlock(&DriverActionCompleteMutex);
645 IDLog(
"WaitForDriverCompletion - Finished waiting\n");
646 ReturnCode = pthread_mutex_unlock(&DriverActionCompleteMutex);
647 return ReturnCode == 0;
void sendNewSwitch(INDI::Property pp)
Send new Switch command to server.
void finishBlob()
Send closing tag for BLOB command to server.
void sendOneBlob(IBLOB *bp)
Send ONE blob content to server. The BLOB data in raw binary format and will be converted to base64 a...
void sendNewNumber(INDI::Property pp)
Send new Number command to server.
void startBlob(const char *devName, const char *propName, const char *timestamp)
Send opening tag for BLOB command to server.
bool AppendSyncPoint(const AlignmentDatabaseEntry &CurrentValues)
Append a sync point to the database.
bool SaveDatabase()
Save the database to persistent storage.
bool ReadSyncPoint(unsigned int Offset, AlignmentDatabaseEntry &CurrentValues)
Read a sync point from the database.
virtual ~ClientAPIForAlignmentDatabase()
Virtual destructor.
bool InsertSyncPoint(unsigned int Offset, const AlignmentDatabaseEntry &CurrentValues)
Insert a sync point in the database.
bool LoadDatabase()
Load the database from persistent storage.
void Initialise(INDI::BaseClient *BaseClient)
Initialise the API.
bool EditSyncPoint(unsigned int Offset, const AlignmentDatabaseEntry &CurrentValues)
Edit a sync point in the database.
bool ReadIncrementSyncPoint(AlignmentDatabaseEntry &CurrentValues)
Increment the current offset then read a sync point from the database.
void ProcessNewNumber(INumberVectorProperty *NumberVectorProperty)
Process new number message from driver. This routine should be called from within the newNumber handl...
void ProcessNewDevice(INDI::BaseDevice *DevicePointer)
Process new device message from driver. This routine should be called from within the newDevice handl...
void ProcessNewBLOB(IBLOB *BLOBPointer)
Process new BLOB message from driver. This routine should be called from within the newBLOB handler i...
void ProcessNewSwitch(ISwitchVectorProperty *SwitchVectorProperty)
Process new switch message from driver. This routine should be called from within the newSwitch handl...
bool ClearSyncPoints()
Delete all sync points from the database.
ClientAPIForAlignmentDatabase()
Default constructor.
void ProcessNewProperty(INDI::Property *PropertyPointer)
Process new property message from driver. This routine should be called from within the newProperty h...
int GetDatabaseSize()
Return the number of entries in the database.
bool DeleteSyncPoint(unsigned int Offset)
Delete a sync point from the database.
Class to provide basic client functionality.
Class to provide basic INDI device functionality.
const char * getDeviceName() const
Provides generic container for INDI properties.
INDI::PropertyViewSwitch * getSwitch() const
INDI::PropertyViewBlob * getBLOB() const
INDI::PropertyViewNumber * getNumber() const
const char * getName() const
void IDLog(const char *fmt,...)
const char * indi_timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Implementations for common driver routines.
@ ENTRY_OBSERVATION_JULIAN_DATE
Namespace to encapsulate INDI client, drivers, and mediator classes.
One Blob (Binary Large Object) descriptor.
Entry in the in memory alignment database.
double RightAscension
Right ascension in decimal hours. N.B. libnova works in decimal degrees so conversion is always neede...
double ObservationJulianDate
TelescopeDirectionVector TelescopeDirection
Normalised vector giving telescope pointing direction. This is referred to elsewhere as the "apparent...
double Declination
Declination in decimal degrees.
int PrivateDataSize
This size in bytes of any private data.
std::unique_ptr< unsigned char > PrivateData
Private data associated with this sync point.
WidgetType * at(size_t index) const
Number vector property descriptor.
Switch vector property descriptor.