| 1 |
/******************************************************************************* |
| 2 |
Copyright(c) 2019 Jasem Mutlaq. All rights reserved. |
| 3 |
|
| 4 |
NexDome Driver for Firmware v3+ |
| 5 |
|
| 6 |
Change Log: |
| 7 |
|
| 8 |
2019.10.07: Driver is completely re-written to work with Firmware v3 since |
| 9 |
Firmware v1 is obsolete from NexDome. |
| 10 |
2017.01.01: Driver for Firmware v1 is developed by Rozeware Development Ltd. |
| 11 |
|
| 12 |
This library is free software; you can redistribute it and/or |
| 13 |
modify it under the terms of the GNU Library General Public |
| 14 |
License version 2 as published by the Free Software Foundation. |
| 15 |
. |
| 16 |
This library is distributed in the hope that it will be useful, |
| 17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 |
Library General Public License for more details. |
| 20 |
. |
| 21 |
You should have received a copy of the GNU Library General Public License |
| 22 |
along with this library; see the file COPYING.LIB. If not, write to |
| 23 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 |
Boston, MA 02110-1301, USA. |
| 25 |
*******************************************************************************/ |
| 26 |
|
| 27 |
#pragma once |
| 28 |
|
| 29 |
#include <indidome.h> |
| 30 |
|
| 31 |
#include <math.h> |
| 32 |
#include <map> |
| 33 |
#include <string> |
| 34 |
#include <sys/time.h> |
| 35 |
|
| 36 |
#include "nex_dome_constants.h" |
| 37 |
|
| 38 |
class NexDome : public INDI::Dome |
| 39 |
{ |
| 40 |
public: |
| 41 |
NexDome(); |
| 42 |
|
| 43 |
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; |
| 44 |
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; |
| 45 |
virtual bool initProperties() override; |
| 46 |
const char *getDefaultName() override; |
| 47 |
bool updateProperties() override; |
| 48 |
|
| 49 |
//static void checkJamHelper(void *context); |
| 50 |
|
| 51 |
protected: |
| 52 |
bool Handshake() override; |
| 53 |
void TimerHit() override; |
| 54 |
|
| 55 |
// Motion |
| 56 |
virtual IPState MoveAbs(double az) override; |
| 57 |
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override; |
| 58 |
virtual bool Sync(double az) override; |
| 59 |
|
| 60 |
// Shutter |
| 61 |
virtual IPState ControlShutter(ShutterOperation operation) override; |
| 62 |
|
| 63 |
// Abort |
| 64 |
virtual bool Abort() override; |
| 65 |
|
| 66 |
// Config |
| 67 |
virtual bool saveConfigItems(FILE * fp) override; |
| 68 |
|
| 69 |
// Parking |
| 70 |
virtual IPState Park() override; |
| 71 |
virtual IPState UnPark() override; |
| 72 |
virtual bool SetCurrentPark() override; |
| 73 |
virtual bool SetDefaultPark() override; |
| 74 |
|
| 75 |
///////////////////////////////////////////////////////////////////////////// |
| 76 |
/// Properties |
| 77 |
///////////////////////////////////////////////////////////////////////////// |
| 78 |
ISwitchVectorProperty GoHomeSP; |
| 79 |
ISwitch GoHomeS[2]; |
| 80 |
enum |
| 81 |
{ |
| 82 |
HOME_FIND, |
| 83 |
HOME_GOTO, |
| 84 |
}; |
| 85 |
|
| 86 |
INumberVectorProperty HomePositionNP; |
| 87 |
INumber HomePositionN[1]; |
| 88 |
|
| 89 |
INumberVectorProperty ShutterBatteryLevelNP; |
| 90 |
INumber ShutterBatteryLevelN[1]; |
| 91 |
|
| 92 |
ITextVectorProperty RotatorFirmwareVersionTP; |
| 93 |
IText RotatorFirmwareVersionT[1] {}; |
| 94 |
|
| 95 |
ITextVectorProperty ShutterFirmwareVersionTP; |
| 96 |
IText ShutterFirmwareVersionT[1] {}; |
| 97 |
|
| 98 |
ISwitchVectorProperty RotatorFactorySP; |
| 99 |
ISwitch RotatorFactoryS[3]; |
| 100 |
|
| 101 |
ISwitchVectorProperty ShutterFactorySP; |
| 102 |
ISwitch ShutterFactoryS[3]; |
| 103 |
enum |
| 104 |
{ |
| 105 |
FACTORY_DEFAULTS, |
| 106 |
FACTORY_LOAD, |
| 107 |
FACTORY_SAVE, |
| 108 |
}; |
| 109 |
|
| 110 |
// Settings |
| 111 |
enum |
| 112 |
{ |
| 113 |
S_RAMP, |
| 114 |
S_VELOCITY, |
| 115 |
S_ZONE, |
| 116 |
S_RANGE |
| 117 |
}; |
| 118 |
|
| 119 |
INumberVectorProperty RotatorSettingsNP; |
| 120 |
INumber RotatorSettingsN[4]; |
| 121 |
|
| 122 |
INumberVectorProperty ShutterSettingsNP; |
| 123 |
INumber ShutterSettingsN[2]; |
| 124 |
|
| 125 |
INumberVectorProperty RotatorSyncNP; |
| 126 |
INumber RotatorSyncN[1]; |
| 127 |
|
| 128 |
INumberVectorProperty ShutterSyncNP; |
| 129 |
INumber ShutterSyncN[1]; |
| 130 |
|
| 131 |
private: |
| 132 |
/////////////////////////////////////////////////////////////////////////////// |
| 133 |
/// Startup |
| 134 |
/////////////////////////////////////////////////////////////////////////////// |
| 135 |
bool getStartupValues(); |
| 136 |
|
| 137 |
/////////////////////////////////////////////////////////////////////////////// |
| 138 |
/// Settings |
| 139 |
/////////////////////////////////////////////////////////////////////////////// |
| 140 |
bool executeFactoryCommand(uint8_t command, ND::Targets target); |
| 141 |
bool processRotatorReport(const std::string &report); |
| 142 |
bool processShutterReport(const std::string &report); |
| 143 |
|
| 144 |
/////////////////////////////////////////////////////////////////////////////// |
| 145 |
/// Utility Functions |
| 146 |
/////////////////////////////////////////////////////////////////////////////// |
| 147 |
bool setParameter(ND::Commands command, ND::Targets target, int32_t value = -1e6); |
| 148 |
bool getParameter(ND::Commands command, ND::Targets target, std::string &value); |
| 149 |
bool checkEvents(std::string &response); |
| 150 |
bool processEvent(const std::string &event); |
| 151 |
bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1); |
| 152 |
void hexDump(char * buf, const char * data, int size); |
| 153 |
|
| 154 |
std::string <rim(std::string &str, const std::string &chars = "\t\n\v\f\r "); |
| 155 |
std::string &rtrim(std::string &str, const std::string &chars = "\t\n\v\f\r "); |
| 156 |
std::string &trim(std::string &str, const std::string &chars = "\t\n\v\f\r "); |
| 157 |
std::vector<std::string> split(const std::string &input, const std::string ®ex); |
| 158 |
|
| 159 |
/////////////////////////////////////////////////////////////////////////////// |
| 160 |
/// Private Members |
| 161 |
/////////////////////////////////////////////////////////////////////////////// |
| 162 |
bool m_ShutterConnected { false }; |
| 163 |
int32_t m_TargetAZSteps {1000000}; |
| 164 |
double StepsPerDegree { 153.0 }; |
| 165 |
|
| 166 |
}; |
| 167 |
|