| 1 | /* |
| 2 | PlaneWave Delta Protocol |
| 3 | |
| 4 | Copyright (C) 2020 Jasem Mutlaq ([email protected]) |
| 5 | |
| 6 | This library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | This library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with this library; if not, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | |
| 25 | #include "indifocuser.h"cxx . . $ `<file>/libs/indibase/indifocuser.h`/ |
| 26 | #include "pid/pid.h"cxx . . $ `<file>/libs/indibase/pid/pid.h`/ |
| 27 | |
| 28 | #include <memory> |
| 29 | #include <map> |
| 30 | |
| 31 | class DeltaTcxx . . $ DeltaT# : public INDIcxx . . $ INDI/::DefaultDevicecxx . . $ INDI/DefaultDevice# |
| 32 | { |
| 33 | public: |
| 34 | DeltaTcxx . . $ DeltaT#DeltaT(49f6e7a06ebc5aa8).(); |
| 35 | |
| 36 | virtual bool Handshakecxx . . $ DeltaT#Handshake(c9857a73d68e59ba).(); |
| 37 | const char *getDefaultNamecxx . . $ DeltaT#getDefaultName(33a1f659e94feb42).() override; |
| 38 | virtual bool initPropertiescxx . . $ DeltaT#initProperties(c9857a73d68e59ba).() override; |
| 39 | virtual bool updatePropertiescxx . . $ DeltaT#updateProperties(c9857a73d68e59ba).() override; |
| 40 | |
| 41 | virtual bool ISNewNumbercxx . . $ DeltaT#ISNewNumber(b910d3521abb33fb).(const char *dev, const char *name, double values[], char *names[], int n) override; |
| 42 | virtual bool ISNewSwitchcxx . . $ DeltaT#ISNewSwitch(e439c05866add404).(const char *dev, const char *name, ISStatecxx . . $ ISState# *states, char *names[], int n) override; |
| 43 | |
| 44 | enumcxx . . $ DeltaT#$anonymous_type_0# |
| 45 | { |
| 46 | TEMP_GETcxx . . $ DeltaT#TEMP_GET. = 0x26, |
| 47 | CMD_FORCE_RESETcxx . . $ DeltaT#CMD_FORCE_RESET. = 0x80, |
| 48 | CMD_FORCE_BOOTcxx . . $ DeltaT#CMD_FORCE_BOOT. = 0x81, |
| 49 | COH_NUMHEATERScxx . . $ DeltaT#COH_NUMHEATERS. = 0xB0, |
| 50 | COH_ON_MANUALcxx . . $ DeltaT#COH_ON_MANUAL. = 0xB1, |
| 51 | COH_OFFcxx . . $ DeltaT#COH_OFF. = 0xB4, |
| 52 | COH_REPORTcxx . . $ DeltaT#COH_REPORT. = 0xB5, |
| 53 | COH_RESCANcxx . . $ DeltaT#COH_RESCAN. = 0xBF, |
| 54 | CMD_GET_VERSIONcxx . . $ DeltaT#CMD_GET_VERSION. = 0xFE, |
| 55 | }; |
| 56 | |
| 57 | enumcxx . . $ DeltaT#$anonymous_type_1# |
| 58 | { |
| 59 | DEVICE_PCcxx . . $ DeltaT#DEVICE_PC. = 0x20, |
| 60 | DEVICE_HCcxx . . $ DeltaT#DEVICE_HC. = 0x0D, |
| 61 | DEVICE_FOCcxx . . $ DeltaT#DEVICE_FOC. = 0x12, |
| 62 | DEVICE_FANcxx . . $ DeltaT#DEVICE_FAN. = 0x13, |
| 63 | DEVICE_TEMPcxx . . $ DeltaT#DEVICE_TEMP. = 0x12, |
| 64 | DEVICE_DELTAcxx . . $ DeltaT#DEVICE_DELTA. = 0x32 |
| 65 | }; |
| 66 | |
| 67 | typedef structcxx . . $ DeltaT#$anonymous_type_2# |
| 68 | { |
| 69 | uint8_tcxx . . $ uint8_t# StateUBcxx . . $ DeltaT#$anonymous_type_2#StateUB.; |
| 70 | uint8_tcxx . . $ uint8_t# ModeUBcxx . . $ DeltaT#$anonymous_type_2#ModeUB.; |
| 71 | uint16_tcxx . . $ uint16_t# SetPointUWcxx . . $ DeltaT#$anonymous_type_2#SetPointUW.; |
| 72 | uint8_tcxx . . $ uint8_t# TempHtrIdUBcxx . . $ DeltaT#$anonymous_type_2#TempHtrIdUB.; |
| 73 | uint16_tcxx . . $ uint16_t# TempHtrUWcxx . . $ DeltaT#$anonymous_type_2#TempHtrUW.; |
| 74 | uint16_tcxx . . $ uint16_t# TempAmbUWcxx . . $ DeltaT#$anonymous_type_2#TempAmbUW.; |
| 75 | uint16_tcxx . . $ uint16_t# PeriodUWcxx . . $ DeltaT#$anonymous_type_2#PeriodUW.; |
| 76 | uint8_tcxx . . $ uint8_t# DutyCycleUBcxx . . $ DeltaT#$anonymous_type_2#DutyCycleUB.; |
| 77 | } HeaterReportcxx . . $ DeltaT#HeaterReport#; |
| 78 | |
| 79 | |
| 80 | protected: |
| 81 | virtual void TimerHitcxx . . $ DeltaT#TimerHit(49f6e7a06ebc5aa8).() override; |
| 82 | virtual bool saveConfigItemscxx . . $ DeltaT#saveConfigItems(dc9e5a301483124c).(FILE *fp) override; |
| 83 | |
| 84 | private: |
| 85 | /////////////////////////////////////////////////////////////////////////////////// |
| 86 | /// Query functions |
| 87 | /////////////////////////////////////////////////////////////////////////////////// |
| 88 | bool readReportcxx . . $ DeltaT#readReport(cef82f9be00a201a).(uint8_tcxx . . $ uint8_t# index); |
| 89 | bool readTemperaturecxx . . $ DeltaT#readTemperature(c9857a73d68e59ba).(); |
| 90 | bool initializeHeaterscxx . . $ DeltaT#initializeHeaters(c9857a73d68e59ba).(); |
| 91 | |
| 92 | /////////////////////////////////////////////////////////////////////////////////// |
| 93 | /// Set functions |
| 94 | /////////////////////////////////////////////////////////////////////////////////// |
| 95 | bool setHeaterEnabledcxx . . $ DeltaT#setHeaterEnabled(e6c03217c9f46667).(uint8_tcxx . . $ uint8_t# index, bool enabled); |
| 96 | bool setHeaterParamcxx . . $ DeltaT#setHeaterParam(94da69a27ea7b7a7).(uint8_tcxx . . $ uint8_t# index, double period, double duty); |
| 97 | bool forceBootcxx . . $ DeltaT#forceBoot(c9857a73d68e59ba).(); |
| 98 | bool forceResetcxx . . $ DeltaT#forceReset(c9857a73d68e59ba).(); |
| 99 | |
| 100 | /////////////////////////////////////////////////////////////////////////////// |
| 101 | /// Communication Functions |
| 102 | /////////////////////////////////////////////////////////////////////////////// |
| 103 | bool sendCommandcxx . . $ DeltaT#sendCommand(4c19a25d08756358).(const char * cmd, char * res, uint32_tcxx . . $ uint32_t# cmd_len, uint32_tcxx . . $ uint32_t# res_len); |
| 104 | void hexDumpcxx . . $ DeltaT#hexDump(3e2c863ed83053e8).(char * buf, const char * data, uint32_tcxx . . $ uint32_t# size); |
| 105 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> splitcxx . . $ DeltaT#split(c47e161d59f8b6e7).(const stdcxx . . $ std/::stringcxx . . $ std/string# &input, const stdcxx . . $ std/::stringcxx . . $ std/string# ®ex); |
| 106 | |
| 107 | /////////////////////////////////////////////////////////////////////////////////// |
| 108 | /// Misc |
| 109 | /////////////////////////////////////////////////////////////////////////////////// |
| 110 | double calculateTemperaturecxx . . $ DeltaT#calculateTemperature(649a08ca3bdd3b47).(uint8_tcxx . . $ uint8_t# lsb, uint8_tcxx . . $ uint8_t# msb); |
| 111 | uint8_tcxx . . $ uint8_t# calculateCheckSumcxx . . $ DeltaT#calculateCheckSum(9853b803eda04fee).(const char *cmd, uint32_tcxx . . $ uint32_t# len); |
| 112 | const char *getHeaterNamecxx . . $ DeltaT#getHeaterName(f7ae7e56280f18ae).(int index); |
| 113 | template <typename T> stdcxx . . $ std/::stringcxx . . $ std/string# to_stringcxx . . $ DeltaT#to_string(9f38edc4b3b1607e).(const T a_value, const int n = 2); |
| 114 | |
| 115 | /////////////////////////////////////////////////////////////////////////////////// |
| 116 | /// Properties |
| 117 | /////////////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | // Delta-T Informatin |
| 120 | ITextVectorPropertycxx . . $ ITextVectorProperty# InfoTPcxx . . $ DeltaT#InfoTP.; |
| 121 | ITextcxx . . $ IText# InfoTcxx . . $ DeltaT#InfoT.[1] {}; |
| 122 | enumcxx . . $ DeltaT#$anonymous_type_3# |
| 123 | { |
| 124 | INFO_VERSIONcxx . . $ DeltaT#INFO_VERSION. |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | // Force Control |
| 129 | ISwitchVectorPropertycxx . . $ ISwitchVectorProperty# ForceSPcxx . . $ DeltaT#ForceSP.; |
| 130 | ISwitchcxx . . $ ISwitch# ForceScxx . . $ DeltaT#ForceS.[2]; |
| 131 | enumcxx . . $ DeltaT#$anonymous_type_4# |
| 132 | { |
| 133 | FORCE_RESETcxx . . $ DeltaT#FORCE_RESET., |
| 134 | FORCE_BOOTcxx . . $ DeltaT#FORCE_BOOT. |
| 135 | }; |
| 136 | |
| 137 | // Heater Control |
| 138 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISwitchVectorPropertycxx . . $ ISwitchVectorProperty#>> HeaterControlSPcxx . . $ DeltaT#HeaterControlSP.; |
| 139 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISwitchcxx . . $ ISwitch#[]>> HeaterControlScxx . . $ DeltaT#HeaterControlS.; |
| 140 | enumcxx . . $ DeltaT#$anonymous_type_5# |
| 141 | { |
| 142 | HEATER_OFFcxx . . $ DeltaT#HEATER_OFF., |
| 143 | HEATER_ONcxx . . $ DeltaT#HEATER_ON., |
| 144 | HEATER_CONTROLcxx . . $ DeltaT#HEATER_CONTROL., |
| 145 | HEATER_THRESHOLDcxx . . $ DeltaT#HEATER_THRESHOLD. |
| 146 | }; |
| 147 | |
| 148 | // Control Params |
| 149 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<INumberVectorPropertycxx . . $ INumberVectorProperty#>> HeaterParamNPcxx . . $ DeltaT#HeaterParamNP.; |
| 150 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<INumbercxx . . $ INumber#[]>> HeaterParamNcxx . . $ DeltaT#HeaterParamN.; |
| 151 | enumcxx . . $ DeltaT#$anonymous_type_6# |
| 152 | { |
| 153 | PARAM_PERIODcxx . . $ DeltaT#PARAM_PERIOD., |
| 154 | PARAM_DUTYcxx . . $ DeltaT#PARAM_DUTY., |
| 155 | PARAM_CONTROLcxx . . $ DeltaT#PARAM_CONTROL., |
| 156 | PARAM_THRESHOLDcxx . . $ DeltaT#PARAM_THRESHOLD., |
| 157 | }; |
| 158 | |
| 159 | // Monitor |
| 160 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<INumberVectorPropertycxx . . $ INumberVectorProperty#>> HeaterMonitorNPcxx . . $ DeltaT#HeaterMonitorNP.; |
| 161 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<INumbercxx . . $ INumber#[]>> HeaterMonitorNcxx . . $ DeltaT#HeaterMonitorN.; |
| 162 | enumcxx . . $ DeltaT#$anonymous_type_7# |
| 163 | { |
| 164 | MONITOR_PERIODcxx . . $ DeltaT#MONITOR_PERIOD., |
| 165 | MONITOR_DUTYcxx . . $ DeltaT#MONITOR_DUTY. |
| 166 | }; |
| 167 | |
| 168 | // Read Only Temperature Reporting |
| 169 | INumberVectorPropertycxx . . $ INumberVectorProperty# TemperatureNPcxx . . $ DeltaT#TemperatureNP.; |
| 170 | INumbercxx . . $ INumber# TemperatureNcxx . . $ DeltaT#TemperatureN.[3]; |
| 171 | enumcxx . . $ DeltaT#$anonymous_type_8# |
| 172 | { |
| 173 | // Primary is 0 , not used in this driver. |
| 174 | // 1 |
| 175 | TEMPERATURE_AMBIENTcxx . . $ DeltaT#TEMPERATURE_AMBIENT., |
| 176 | // 2 |
| 177 | TEMPERATURE_SECONDARYcxx . . $ DeltaT#TEMPERATURE_SECONDARY., |
| 178 | // 3 |
| 179 | TEMPERATURE_BACKPLATEcxx . . $ DeltaT#TEMPERATURE_BACKPLATE., |
| 180 | }; |
| 181 | |
| 182 | ///////////////////////////////////////////////////////////////////////////// |
| 183 | /// Private variables |
| 184 | ///////////////////////////////////////////////////////////////////////////// |
| 185 | Connectioncxx . . $ Connection/::Serialcxx . . $ Connection/Serial# *serialConnectioncxx . . $ DeltaT#serialConnection. { nullptr }; |
| 186 | double m_LastTemperaturecxx . . $ DeltaT#m_LastTemperature.[3]; |
| 187 | int PortFDcxx . . $ DeltaT#PortFD. { -1 }; |
| 188 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<PIDcxx . . $ PID#>> m_Controllerscxx . . $ DeltaT#m_Controllers.; |
| 189 | |
| 190 | ///////////////////////////////////////////////////////////////////////////// |
| 191 | /// Static Helper Values |
| 192 | ///////////////////////////////////////////////////////////////////////////// |
| 193 | // Start of Message |
| 194 | static const char DRIVER_SOMcxx . . $ DeltaT#DRIVER_SOM. { 0x3B }; |
| 195 | // Temperature Reporting threshold |
| 196 | static constexpr double TEMPERATURE_REPORT_THRESHOLDcxx . . $ DeltaT#TEMPERATURE_REPORT_THRESHOLD. { 0.05 }; |
| 197 | // Temperature Control threshold |
| 198 | static constexpr double TEMPERATURE_CONTROL_THRESHOLDcxx . . $ DeltaT#TEMPERATURE_CONTROL_THRESHOLD. { 0.1 }; |
| 199 | static constexpr const uint8_tcxx . . $ uint8_t# DRIVER_LENcxx . . $ DeltaT#DRIVER_LEN. {32}; |
| 200 | // Wait up to a maximum of 3 seconds for serial input |
| 201 | static constexpr const uint8_tcxx . . $ uint8_t# DRIVER_TIMEOUTcxx . . $ DeltaT#DRIVER_TIMEOUT. {3}; |
| 202 | |
| 203 | // Primary Backplate heater |
| 204 | static constexpr const char *PRIMARY_TABcxx . . $ DeltaT#PRIMARY_TAB. = "Primary Backplate Heater"; |
| 205 | // Secondary Mirror heater |
| 206 | static constexpr const char *SECONDARY_TABcxx . . $ DeltaT#SECONDARY_TAB. = "Secondary Mirror Heater"; |
| 207 | }; |