From 3427b5d565bb82b6a314b61a86c8029dfaadfdd4 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 00:27:45 +0800 Subject: [PATCH 1/9] Driver for WandererBox Pro V3 added --- drivers.xml | 4 + drivers/auxiliary/CMakeLists.txt | 8 + drivers/auxiliary/wandererbox_pro_v3.cpp | 1335 ++++++++++++++++++++++ drivers/auxiliary/wandererbox_pro_v3.h | 281 +++++ 4 files changed, 1628 insertions(+) create mode 100644 drivers/auxiliary/wandererbox_pro_v3.cpp create mode 100644 drivers/auxiliary/wandererbox_pro_v3.h diff --git a/drivers.xml b/drivers.xml index 7b7c00a838..da691c0579 100644 --- a/drivers.xml +++ b/drivers.xml @@ -749,6 +749,10 @@ indi_wanderer_cover 1.0 + + indi_wandererbox_pro_v3 + 1.0 + diff --git a/drivers/auxiliary/CMakeLists.txt b/drivers/auxiliary/CMakeLists.txt index 3bfb2ca35a..95b9781a3d 100644 --- a/drivers/auxiliary/CMakeLists.txt +++ b/drivers/auxiliary/CMakeLists.txt @@ -2,6 +2,14 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") INSTALL(FILES 99-indi_auxiliary.rules DESTINATION ${UDEVRULES_INSTALL_DIR}) ENDIF() +# ########## Wanderer Box Pro V3 ############### +SET(indi_wandererbox_pro_v3_SRC + wandererbox_pro_v3.cpp) + +add_executable(indi_wandererbox_pro_v3 ${indi_wandererbox_pro_v3_SRC}) +target_link_libraries(indi_wandererbox_pro_v3 indidriver) +install(TARGETS indi_wandererbox_pro_v3 RUNTIME DESTINATION bin) + # ########## Wanderer Cover V3 ############### SET(wandererCover_SRC wanderer_cover.cpp) diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp new file mode 100644 index 0000000000..bc0839bfa1 --- /dev/null +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -0,0 +1,1335 @@ +/******************************************************************************* + Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + + WandererBox Pro V3 + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#include "wandererbox_pro_v3.h" +#include "indicom.h" +#include "connectionplugins/connectionserial.h" +#include +#include +#include +#include +#include +#include +#include +#include + +// We declare an auto pointer to WandererBoxProV3. +static std::unique_ptr wandererboxprov3(new WandererBoxProV3()); + + + +WandererBoxProV3::WandererBoxProV3() +{ + setVersion(1, 0); +} + +bool WandererBoxProV3::initProperties() +{ + + INDI::DefaultDevice::initProperties(); + setDriverInterface(AUX_INTERFACE); + + + addAuxControls(); + + + // Calibrate + IUFillSwitch(&CalibrateS[0], "Calibrate", "Calibrate Current", ISS_OFF); + IUFillSwitchVector(&CalibrateSP, CalibrateS, 1, getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + + // Power Monitor + IUFillNumber(&PowerMonitorN[VOLTAGE], "VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&PowerMonitorN[TOTAL_CURRENT], "TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&PowerMonitorN[V19_CURRENT], "V19_CURRENT", "DC2 Current (A))", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&PowerMonitorN[AR_CURRENT], "AR_CURRENT", "DC3-4 Current (A)", "%4.2f", 0, 999, 100, 0); + IUFillNumberVector(&PowerMonitorNP, PowerMonitorN, 4, getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); + + + + // Firmware version + IUFillText(&FirmwareT[0], "Version", "Version", nullptr); + + + // USB31 Control + IUFillSwitch(&usb31ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&usb31ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&usb31ControlSP, usb31ControlS, 2, getDeviceName(), "USB3.0_1", "USB3.0_1", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + + // USB32 Control + IUFillSwitch(&usb32ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&usb32ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&usb32ControlSP, usb32ControlS, 2, getDeviceName(), "USB3.0_2", "USB3.0_2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + + // USB33 Control + IUFillSwitch(&usb33ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&usb33ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&usb33ControlSP, usb33ControlS, 2, getDeviceName(), "USB3.0_3", "USB3.0_3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // USB21 Control + IUFillSwitch(&usb21ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&usb21ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&usb21ControlSP, usb21ControlS, 2, getDeviceName(), "USB2.0_1-3", "USB2.0_1-3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // USB22 Control + IUFillSwitch(&usb22ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&usb22ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&usb22ControlSP, usb22ControlS, 2, getDeviceName(), "USB2.0_4-6", "USB2.0_4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC567 + IUFillNumber(&dc5ControlN[DC5], "DC5", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + IUFillNumberVector(&dc5ControlNP, dc5ControlN, 1, getDeviceName(), "PWM", "DC5", DC5_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&dc6ControlN[DC6], "DC6", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + IUFillNumberVector(&dc6ControlNP, dc6ControlN, 1, getDeviceName(), "DC6", "DC6", DC6_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&dc7ControlN[DC7], "DC7", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + IUFillNumberVector(&dc7ControlNP, dc7ControlN, 1, getDeviceName(), "DC7", "DC7", DC7_TAB, IP_RW, 60, IPS_IDLE); + // DC34SET + IUFillNumber(&setDC34voltageN[setDC34voltage], "DC34SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); + IUFillNumberVector(&setDC34voltageNP, setDC34voltageN, 1, getDeviceName(), "DC34voltageSET", "Set DC3-4", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + // DC3-4 Control + IUFillSwitch(&dc3_4ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&dc3_4ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&dc3_4ControlSP, dc3_4ControlS, 2, getDeviceName(), "DC3-4", "DC3-4", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC8-9 Control + IUFillSwitch(&dc8_9ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&dc8_9ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&dc8_9ControlSP, dc8_9ControlS, 2, getDeviceName(), "DC8-9", "DC8-9", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC10-11 Control + IUFillSwitch(&dc10_11ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&dc10_11ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&dc10_11ControlSP, dc10_11ControlS, 2, getDeviceName(), "DC10-11", "DC10-11", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC5 TEMP Difference Control + IUFillSwitch(&dc5diffS[DC5_Manual], "Manual", "Manual", ISS_ON); + IUFillSwitch(&dc5diffS[DC5_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); + IUFillSwitch(&dc5diffS[DC5_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); + IUFillSwitchVector(&dc5dewSP, dc5diffS, 3, getDeviceName(), "DC5_DIFF", "DC5 Dew Mode", DC5_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + IUFillNumber(&dc5diffSETN[DC5DIFFSET], "DC5 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + IUFillNumberVector(&dc5diffSETNP, dc5diffSETN, 1, getDeviceName(), "DC5_DIFF_SET", "DPD Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&dc5constSETN[DC5CONSTSET], "DC5 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + IUFillNumberVector(&dc5constSETNP, dc5constSETN, 1, getDeviceName(), "DC5_CONST_SET", "CT Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); + + // DC6 TEMP Difference Control + IUFillSwitch(&dc6diffS[DC6_Manual], "Manual", "Manual", ISS_ON); + IUFillSwitch(&dc6diffS[DC6_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); + IUFillSwitch(&dc6diffS[DC6_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); + IUFillSwitchVector(&dc6dewSP, dc6diffS, 3, getDeviceName(), "DC6_DIFF", "DC6 Dew Mode", DC6_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + IUFillNumber(&dc6diffSETN[DC6DIFFSET], "DC6 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + IUFillNumberVector(&dc6diffSETNP, dc6diffSETN, 1, getDeviceName(), "DC6_DIFF_SET", "DPD Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&dc6constSETN[DC6CONSTSET], "DC6 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + IUFillNumberVector(&dc6constSETNP, dc6constSETN, 1, getDeviceName(), "DC6_CONST_SET", "CT Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); + + // DC7 TEMP Difference Control + IUFillSwitch(&dc7diffS[DC7_Manual], "Manual", "Manual", ISS_ON); + IUFillSwitch(&dc7diffS[DC7_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); + IUFillSwitch(&dc7diffS[DC7_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); + IUFillSwitchVector(&dc7dewSP, dc7diffS, 3, getDeviceName(), "DC7_DIFF", "DC7 Dew Mode", DC7_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + IUFillNumber(&dc7diffSETN[DC7DIFFSET], "DC7 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + IUFillNumberVector(&dc7diffSETNP, dc7diffSETN, 1, getDeviceName(), "DC7_DIFF_SET", "DPD Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&dc7constSETN[DC7CONSTSET], "DC7 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + IUFillNumberVector(&dc7constSETNP, dc7constSETN, 1, getDeviceName(), "DC7_CONST_SET", "CT Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); + + //ENV + IUFillNumber(&ENVMonitorN[Probe1_Temp], "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[Probe2_Temp], "Probe2_Temp", "Probe2 Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[Probe3_Temp], "Probe3_Temp", "Probe3 Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[ENV_Humidity], "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[ENV_Temp], "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[DEW_Point], "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumberVector(&ENVMonitorNP, ENVMonitorN, 6, getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); + serialConnection = new Connection::Serial(this); + serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); + serialConnection->registerHandshake([&]() + { + return getData(); + }); + registerConnection(serialConnection); + + return true; +} + +bool WandererBoxProV3::getData() +{ + try + { + PortFD = serialConnection->getPortFD(); + tcflush(PortFD, TCIOFLUSH); + int nbytes_read_name = 0,rc=-1; + char name[64] = {0}; + + //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_INFO("No data received, the device may not be WandererBox Pro V3, please check the serial port!","Updated"); + LOGF_ERROR("Device read error: %s", errorMessage); + return false; + } + name[nbytes_read_name - 1] = '\0'; + if(strcmp(name, "ZXWBPlusV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) + { + LOGF_INFO("The device is not WandererBox Pro V3!","Updated"); + return false; + } + if(strcmp(name, "ZXWBProV3")!=0) + throw std::exception(); + // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// + int nbytes_read_version = 0; + version[64] = {0}; + tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); + + version[nbytes_read_version - 1] = '\0'; + IUSaveText(&FirmwareT[0], version); + IDSetText(&FirmwareTP, nullptr); + + + // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// + char temp1[64] = {0}; + int nbytes_read_temp1= 0; + tty_read_section(PortFD, temp1, 'A', 5, &nbytes_read_temp1); + temp1[nbytes_read_temp1 - 1] = '\0'; + temp1read = std::strtod(temp1,NULL); + + // Temp probe 2////////////////////////////////////////////////////////////////////////////////////////// + char temp2[64] = {0}; + int nbytes_read_temp2= 0; + tty_read_section(PortFD, temp2, 'A', 5, &nbytes_read_temp2); + temp2[nbytes_read_temp2 - 1] = '\0'; + temp2read = std::strtod(temp2,NULL); + + // Temp probe 3////////////////////////////////////////////////////////////////////////////////////////// + char temp3[64] = {0}; + int nbytes_read_temp3= 0; + tty_read_section(PortFD, temp3, 'A', 5, &nbytes_read_temp3); + temp3[nbytes_read_temp3 - 1] = '\0'; + temp3read = std::strtod(temp3,NULL); + + // DHTH////////////////////////////////////////////////////////////////////////////////////////// + char DHTH[64] = {0}; + int nbytes_read_DHTH= 0; + tty_read_section(PortFD, DHTH, 'A', 5, &nbytes_read_DHTH); + DHTH[nbytes_read_DHTH - 1] = '\0'; + DHTHread = std::strtod(DHTH,NULL); + + // DHTT////////////////////////////////////////////////////////////////////////////////////////// + char DHTT[64] = {0}; + int nbytes_read_DHTT= 0; + tty_read_section(PortFD, DHTT, 'A', 5, &nbytes_read_DHTT); + DHTT[nbytes_read_DHTT - 1] = '\0'; + DHTTread = std::strtod(DHTT,NULL); + updateENV(temp1read,temp2read,temp3read,DHTHread,DHTTread); + + // Total current////////////////////////////////////////////////////////////////////////////////////////// + char Tcurrent[64] = {0}; + int nbytes_read_Tcurrent= 0; + tty_read_section(PortFD, Tcurrent, 'A', 5, &nbytes_read_Tcurrent); + Tcurrent[nbytes_read_Tcurrent - 1] = '\0'; + Tcurrentread = std::strtod(Tcurrent,NULL); + + // 19V current////////////////////////////////////////////////////////////////////////////////////////// + char V19current[64] = {0}; + int nbytes_read_V19current= 0; + tty_read_section(PortFD, V19current, 'A', 5, &nbytes_read_V19current); + V19current[nbytes_read_V19current - 1] = '\0'; + V19currentread = std::strtod(V19current,NULL); + + + // Adjustable Regulator current////////////////////////////////////////////////////////////////////////////////////////// + char ARcurrent[64] = {0}; + int nbytes_read_ARcurrent= 0; + tty_read_section(PortFD, ARcurrent, 'A', 5, &nbytes_read_ARcurrent); + ARcurrent[nbytes_read_ARcurrent - 1] = '\0'; + ARcurrentread = std::strtod(ARcurrent,NULL); + + + // Voltage////////////////////////////////////////////////////////////////////////////////////////// + char voltage[64] = {0}; + int nbytes_read_voltage= 0; + tty_read_section(PortFD, voltage, 'A', 5, &nbytes_read_voltage); + voltage[nbytes_read_voltage - 1] = '\0'; + voltageread = std::strtod(voltage,NULL); + updatePower(Tcurrentread,V19currentread,ARcurrentread,voltageread); + + // USB31////////////////////////////////////////////////////////////////////////////////////////// + char USB31[64] = {0}; + int nbytes_read_USB31= 0; + tty_read_section(PortFD, USB31, 'A', 5, &nbytes_read_USB31); + USB31[nbytes_read_USB31 - 1] = '\0'; + USB31read = std::stoi(USB31); + updateUSB31(USB31read); + + // USB32////////////////////////////////////////////////////////////////////////////////////////// + char USB32[64] = {0}; + int nbytes_read_USB32= 0; + tty_read_section(PortFD, USB32, 'A', 5, &nbytes_read_USB32); + USB32[nbytes_read_USB32 - 1] = '\0'; + USB32read = std::stoi(USB32); + updateUSB32(USB32read); + + // USB33////////////////////////////////////////////////////////////////////////////////////////// + char USB33[64] = {0}; + int nbytes_read_USB33= 0; + tty_read_section(PortFD, USB33, 'A', 5, &nbytes_read_USB33); + USB33[nbytes_read_USB33 - 1] = '\0'; + USB33read = std::stoi(USB33); + updateUSB33(USB33read); + + // USB21////////////////////////////////////////////////////////////////////////////////////////// + char USB21[64] = {0}; + int nbytes_read_USB21= 0; + tty_read_section(PortFD, USB21, 'A', 5, &nbytes_read_USB21); + USB21[nbytes_read_USB21 - 1] = '\0'; + USB21read = std::stoi(USB21); + updateUSB21(USB21read); + + // USB22////////////////////////////////////////////////////////////////////////////////////////// + char USB22[64] = {0}; + int nbytes_read_USB22= 0; + tty_read_section(PortFD, USB22, 'A', 5, &nbytes_read_USB22); + USB22[nbytes_read_USB22 - 1] = '\0'; + USB22read = std::stoi(USB22); + updateUSB22(USB22read); + + // DC34////////////////////////////////////////////////////////////////////////////////////////// + char DC34[64] = {0}; + int nbytes_read_DC34= 0; + tty_read_section(PortFD, DC34, 'A', 5, &nbytes_read_DC34); + DC34[nbytes_read_DC34 - 1] = '\0'; + DC34read = std::stoi(DC34); + updateDC34(DC34read); + + // DC5////////////////////////////////////////////////////////////////////////////////////////// + char DC5[64] = {0}; + int nbytes_read_DC5= 0; + tty_read_section(PortFD, DC5, 'A', 5, &nbytes_read_DC5); + DC5[nbytes_read_DC5 - 1] = '\0'; + DC5read = std::stoi(DC5); + updateDC5(DC5read); + + // DC6////////////////////////////////////////////////////////////////////////////////////////// + char DC6[64] = {0}; + int nbytes_read_DC6= 0; + tty_read_section(PortFD, DC6, 'A', 5, &nbytes_read_DC6); + DC6[nbytes_read_DC6 - 1] = '\0'; + DC6read = std::stoi(DC6); + updateDC6(DC6read); + + // DC7////////////////////////////////////////////////////////////////////////////////////////// + char DC7[64] = {0}; + int nbytes_read_DC7= 0; + tty_read_section(PortFD, DC7, 'A', 5, &nbytes_read_DC7); + DC7[nbytes_read_DC7 - 1] = '\0'; + DC7read = std::stoi(DC7); + updateDC7(DC7read); + + // DC8_9////////////////////////////////////////////////////////////////////////////////////////// + char DC8_9[64] = {0}; + int nbytes_read_DC8_9= 0; + tty_read_section(PortFD, DC8_9, 'A', 5, &nbytes_read_DC8_9); + DC8_9[nbytes_read_DC8_9 - 1] = '\0'; + DC8_9read =std::stoi(DC8_9); + updateDC8_9(DC8_9read); + + // DC10_11////////////////////////////////////////////////////////////////////////////////////////// + char DC10_11[64] = {0}; + int nbytes_read_DC10_11= 0; + tty_read_section(PortFD, DC10_11, 'A', 5, &nbytes_read_DC10_11); + DC10_11[nbytes_read_DC10_11 - 1] = '\0'; + DC10_11read =std::stoi(DC10_11); + updateDC10_11(DC10_11read); + + // DC34SET////////////////////////////////////////////////////////////////////////////////////////// + char DC34SET[64] = {0}; + int nbytes_read_DC34SET= 0; + tty_read_section(PortFD, DC34SET, 'A', 5, &nbytes_read_DC34SET); + DC34SET[nbytes_read_DC34SET - 1] = '\0'; + //LOGF_INFO("All Data Updated","Updated"); + DC34SETread = std::stoi(DC34SET); + updateDC34SET(DC34SETread); + + //DC5 DEW CONTROL + if(DC5DIFFMODE==true ) + { + if(temp1read=20240216) + { + defineProperty(&CalibrateSP); + } + else + { + LOGF_INFO("The firmware is outdated, please upgrade to the latest firmware, or power reading calibration will be unavailable.","failed"); + } + defineProperty(&PowerMonitorNP); + + + defineProperty(&usb31ControlSP); + defineProperty(&usb32ControlSP); + defineProperty(&usb33ControlSP); + defineProperty(&usb21ControlSP); + defineProperty(&usb22ControlSP); + + defineProperty(&setDC34voltageNP); + defineProperty(&dc3_4ControlSP); + + defineProperty(&dc8_9ControlSP); + defineProperty(&dc10_11ControlSP); + + defineProperty(&dc5dewSP); + defineProperty(&dc6dewSP); + defineProperty(&dc7dewSP); + + + //DC5//////////////////// + if(dc5diffS[DC5_DPD_Mode].s == ISS_ON) + { + deleteProperty(dc5constSETNP.name); + deleteProperty(dc5ControlNP.name); + defineProperty(&dc5diffSETNP); + } + else if(dc5diffS[DC5_CT_Mode].s == ISS_ON) + { + deleteProperty(dc5ControlNP.name); + deleteProperty(dc5diffSETNP.name); + defineProperty(&dc5constSETNP); + } + else + { + defineProperty(&dc5ControlNP); + deleteProperty(dc5diffSETNP.name); + deleteProperty(dc5constSETNP.name); + } + //DC6//////////////// + if(dc6diffS[DC6_DPD_Mode].s == ISS_ON) + { + deleteProperty(dc6constSETNP.name); + deleteProperty(dc6ControlNP.name); + defineProperty(&dc6diffSETNP); + } + else if(dc6diffS[DC6_CT_Mode].s == ISS_ON) + { + deleteProperty(dc6ControlNP.name); + deleteProperty(dc6diffSETNP.name); + defineProperty(&dc6constSETNP); + } + else + { + defineProperty(&dc6ControlNP); + deleteProperty(dc6diffSETNP.name); + deleteProperty(dc6constSETNP.name); + } + //DC7//////////////// + if(dc7diffS[DC7_DPD_Mode].s == ISS_ON) + { + deleteProperty(dc7constSETNP.name); + deleteProperty(dc7ControlNP.name); + defineProperty(&dc7diffSETNP); + } + else if(dc7diffS[DC7_CT_Mode].s == ISS_ON) + { + deleteProperty(dc7ControlNP.name); + deleteProperty(dc7diffSETNP.name); + defineProperty(&dc7constSETNP); + } + else + { + defineProperty(&dc7ControlNP); + deleteProperty(dc7diffSETNP.name); + deleteProperty(dc7constSETNP.name); + } + + + defineProperty(&ENVMonitorNP); + + + } + else + { + + deleteProperty(FirmwareTP.name); + deleteProperty(CalibrateSP.name); + deleteProperty(PowerMonitorNP.name); + deleteProperty(ENVMonitorNP.name); + + deleteProperty(dc3_4ControlSP.name); + deleteProperty(setDC34voltageNP.name); + deleteProperty(dc8_9ControlSP.name); + deleteProperty(dc10_11ControlSP.name); + deleteProperty(usb31ControlSP.name); + deleteProperty(usb32ControlSP.name); + deleteProperty(usb33ControlSP.name); + deleteProperty(usb21ControlSP.name); + deleteProperty(usb22ControlSP.name); + + deleteProperty(dc5ControlNP.name); + deleteProperty(dc6ControlNP.name); + deleteProperty(dc7ControlNP.name); + + deleteProperty(dc5dewSP.name); + deleteProperty(dc5diffSETNP.name); + + deleteProperty(dc6dewSP.name); + deleteProperty(dc6diffSETNP.name); + + deleteProperty(dc7dewSP.name); + deleteProperty(dc7diffSETNP.name); + + + } + return true; +} + +bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) +{ + // Calibrate + if (!strcmp(name, CalibrateSP.name)) + { + CalibrateSP.s = sendCommand("66300744") ? IPS_OK : IPS_ALERT; + IDSetSwitch(&CalibrateSP, nullptr); + LOG_INFO("Calibrating Current Readings..."); + return true; + } + + + // DC3-4 Control + if (!strcmp(name, dc3_4ControlSP.name)) + { + IUUpdateSwitch(&dc3_4ControlSP, states, names, n); + dc3_4ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "10%d", (dc3_4ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + dc3_4ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&dc3_4ControlSP, nullptr); + + return true; + } + // DC8-9 Control + if (!strcmp(name, dc8_9ControlSP.name)) + { + IUUpdateSwitch(&dc8_9ControlSP, states, names, n); + dc8_9ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "20%d", (dc8_9ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + dc8_9ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&dc8_9ControlSP, nullptr); + + return true; + } + // DC10-11 Control + if (!strcmp(name, dc10_11ControlSP.name)) + { + IUUpdateSwitch(&dc10_11ControlSP, states, names, n); + dc10_11ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "21%d", (dc10_11ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + dc10_11ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&dc10_11ControlSP, nullptr); + + return true; + } + + // USB31 Control + if (!strcmp(name, usb31ControlSP.name)) + { + IUUpdateSwitch(&usb31ControlSP, states, names, n); + usb31ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "11%d", (usb31ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + usb31ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + + return true; + } + // USB32 Control + if (!strcmp(name, usb32ControlSP.name)) + { + IUUpdateSwitch(&usb32ControlSP, states, names, n); + usb32ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "12%d", (usb32ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + usb32ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&usb32ControlSP, nullptr); + + return true; + } + // USB33 Control + if (!strcmp(name, usb33ControlSP.name)) + { + IUUpdateSwitch(&usb33ControlSP, states, names, n); + usb33ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "13%d", (usb33ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + usb33ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&usb33ControlSP, nullptr); + + return true; + } + // USB21 Control + if (!strcmp(name, usb21ControlSP.name)) + { + IUUpdateSwitch(&usb21ControlSP, states, names, n); + usb21ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "14%d", (usb21ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + usb21ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&usb21ControlSP, nullptr); + + return true; + } + // USB22 Control + if (!strcmp(name, usb22ControlSP.name)) + { + IUUpdateSwitch(&usb22ControlSP, states, names, n); + usb22ControlSP.s = IPS_ALERT; + char cmd[128] = {0}; + snprintf(cmd, 128, "15%d", (usb22ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); + usb22ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + IDSetSwitch(&usb22ControlSP, nullptr); + + return true; + } + + // DC5 DEW + if (!strcmp(name, dc5dewSP.name)) + { + IUUpdateSwitch(&dc5dewSP, states, names, n); + dc5dewSP.s = IPS_ALERT; + if(dc5diffS[DC5_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + { + DC5DIFFMODE=true; + DC5CONSTMODE=false; + deleteProperty(dc5ControlNP.name); + deleteProperty(dc5constSETNP.name); + defineProperty(&dc5diffSETNP); + + dc5diffSETNP.s = IPS_OK; + IDSetNumber(&dc5diffSETNP, nullptr); + dc5dewSP.s = IPS_OK ; + IDSetSwitch(&dc5dewSP, nullptr); + LOGF_INFO("Dew Point Difference Mode for DC5 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); + return true; + } + else if(dc5diffS[DC5_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe1_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + { + DC5DIFFMODE=false; + DC5CONSTMODE=false; + dc5diffS[DC5_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); + IDSetSwitch(&dc5dewSP, nullptr); + } + else if(dc5diffS[DC5_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value!=-127) + { + DC5CONSTMODE=true; + DC5DIFFMODE=false; + deleteProperty(dc5diffSETNP.name); + deleteProperty(dc5ControlNP.name); + defineProperty(&dc5constSETNP); + + dc5constSETNP.s = IPS_OK; + IDSetNumber(&dc5constSETNP, nullptr); + dc5dewSP.s = IPS_OK ; + IDSetSwitch(&dc5dewSP, nullptr); + LOGF_INFO("Constant Temperature Mode for DC5 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); + return true; + } + else if(dc5diffS[DC5_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value==-127) + { + DC5DIFFMODE=false; + DC5CONSTMODE=false; + dc5diffS[DC5_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); + IDSetSwitch(&dc5dewSP, nullptr); + } + else + { + DC5DIFFMODE=false; + DC5CONSTMODE=false; + defineProperty(&dc5ControlNP); + deleteProperty(dc5diffSETNP.name); + deleteProperty(dc5constSETNP.name); + dc5dewSP.s = IPS_OK ; + IDSetSwitch(&dc5dewSP, nullptr); + LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); + return true; + } + + } + + // DC6 DEW + if (!strcmp(name, dc6dewSP.name)) + { + IUUpdateSwitch(&dc6dewSP, states, names, n); + dc6dewSP.s = IPS_ALERT; + if(dc6diffS[DC6_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + { + DC6DIFFMODE=true; + DC6CONSTMODE=false; + deleteProperty(dc6ControlNP.name); + deleteProperty(dc6constSETNP.name); + defineProperty(&dc6diffSETNP); + + dc6diffSETNP.s = IPS_OK; + IDSetNumber(&dc6diffSETNP, nullptr); + dc6dewSP.s = IPS_OK ; + IDSetSwitch(&dc6dewSP, nullptr); + LOGF_INFO("Dew Point Difference Mode for DC6 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); + return true; + } + else if(dc6diffS[DC6_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe2_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + { + DC6DIFFMODE=false; + DC6CONSTMODE=false; + dc6diffS[DC6_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); + IDSetSwitch(&dc6dewSP, nullptr); + } + else if(dc6diffS[DC6_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value!=-127) + { + DC6CONSTMODE=true; + DC6DIFFMODE=false; + deleteProperty(dc6diffSETNP.name); + deleteProperty(dc6ControlNP.name); + defineProperty(&dc6constSETNP); + + dc6constSETNP.s = IPS_OK; + IDSetNumber(&dc6constSETNP, nullptr); + dc6dewSP.s = IPS_OK ; + IDSetSwitch(&dc6dewSP, nullptr); + LOGF_INFO("Constant Temperature Mode for DC6 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); + return true; + } + else if(dc6diffS[DC6_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value==-127) + { + DC6DIFFMODE=false; + DC6CONSTMODE=false; + dc6diffS[DC6_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); + IDSetSwitch(&dc6dewSP, nullptr); + } + else + { + DC6DIFFMODE=false; + DC6CONSTMODE=false; + defineProperty(&dc6ControlNP); + deleteProperty(dc6diffSETNP.name); + deleteProperty(dc6constSETNP.name); + dc6dewSP.s = IPS_OK ; + IDSetSwitch(&dc6dewSP, nullptr); + LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); + return true; + } + + } + + // DC7 DEW + if (!strcmp(name, dc7dewSP.name)) + { + IUUpdateSwitch(&dc7dewSP, states, names, n); + dc7dewSP.s = IPS_ALERT; + if(dc7diffS[DC7_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + { + DC7DIFFMODE=true; + DC7CONSTMODE=false; + deleteProperty(dc7ControlNP.name); + deleteProperty(dc7constSETNP.name); + defineProperty(&dc7diffSETNP); + + dc7diffSETNP.s = IPS_OK; + IDSetNumber(&dc7diffSETNP, nullptr); + dc7dewSP.s = IPS_OK ; + IDSetSwitch(&dc7dewSP, nullptr); + LOGF_INFO("Dew Point Difference Mode for DC7 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); + return true; + } + else if(dc7diffS[DC7_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe3_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + { + DC7DIFFMODE=false; + DC7CONSTMODE=false; + dc7diffS[DC7_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); + IDSetSwitch(&dc7dewSP, nullptr); + } + else if(dc7diffS[DC7_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value!=-127) + { + DC7CONSTMODE=true; + DC7DIFFMODE=false; + deleteProperty(dc7diffSETNP.name); + deleteProperty(dc7ControlNP.name); + defineProperty(&dc7constSETNP); + + dc7constSETNP.s = IPS_OK; + IDSetNumber(&dc7constSETNP, nullptr); + dc7dewSP.s = IPS_OK ; + IDSetSwitch(&dc7dewSP, nullptr); + LOGF_INFO("Constant Temperature Mode for DC7 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); + return true; + } + else if(dc7diffS[DC7_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value==-127) + { + DC7DIFFMODE=false; + DC7CONSTMODE=false; + dc7diffS[DC7_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); + IDSetSwitch(&dc7dewSP, nullptr); + } + else + { + DC7DIFFMODE=false; + DC7CONSTMODE=false; + defineProperty(&dc7ControlNP); + deleteProperty(dc7diffSETNP.name); + deleteProperty(dc7constSETNP.name); + dc7dewSP.s = IPS_OK ; + IDSetSwitch(&dc7dewSP, nullptr); + LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); + return true; + } + + } + + return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); +} + +bool WandererBoxProV3::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) +{ + if (dev && !strcmp(dev, getDeviceName())) + { + // DC5 + if (!strcmp(name, dc5ControlNP.name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + if (!strcmp(names[i], dc5ControlN[DC5].name)) + rc1 = setDewPWM(5, static_cast(values[i])); + } + + dc5ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (dc5ControlNP.s == IPS_OK) + IUUpdateNumber(&dc5ControlNP, values, names, n); + IDSetNumber(&dc5ControlNP, nullptr); + return true; + } + if (!strcmp(name, dc5diffSETNP.name)) + { + + dc5diffSETNP.s = IPS_OK ; + if (dc5diffSETNP.s == IPS_OK) + IUUpdateNumber(&dc5diffSETNP, values, names, n); + IDSetNumber(&dc5diffSETNP, nullptr); + return true; + } + if (!strcmp(name, dc5constSETNP.name)) + { + + dc5constSETNP.s = IPS_OK ; + if (dc5constSETNP.s == IPS_OK) + IUUpdateNumber(&dc5constSETNP, values, names, n); + IDSetNumber(&dc5constSETNP, nullptr); + return true; + } + // DC6 + if (!strcmp(name, dc6ControlNP.name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + if (!strcmp(names[i], dc6ControlN[DC6].name)) + rc1 = setDewPWM(6, static_cast(values[i])); + } + + dc6ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (dc6ControlNP.s == IPS_OK) + IUUpdateNumber(&dc6ControlNP, values, names, n); + IDSetNumber(&dc6ControlNP, nullptr); + return true; + } + if (!strcmp(name, dc6diffSETNP.name)) + { + + dc6diffSETNP.s = IPS_OK ; + if (dc6diffSETNP.s == IPS_OK) + IUUpdateNumber(&dc6diffSETNP, values, names, n); + IDSetNumber(&dc6diffSETNP, nullptr); + return true; + } + if (!strcmp(name, dc6constSETNP.name)) + { + + dc6constSETNP.s = IPS_OK ; + if (dc6constSETNP.s == IPS_OK) + IUUpdateNumber(&dc6constSETNP, values, names, n); + IDSetNumber(&dc6constSETNP, nullptr); + return true; + } + // DC7 + if (!strcmp(name, dc7ControlNP.name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + if (!strcmp(names[i], dc7ControlN[DC6].name)) + rc1 = setDewPWM(7, static_cast(values[i])); + } + + dc7ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (dc7ControlNP.s == IPS_OK) + IUUpdateNumber(&dc7ControlNP, values, names, n); + IDSetNumber(&dc7ControlNP, nullptr); + return true; + } + if (!strcmp(name, dc7diffSETNP.name)) + { + + dc7diffSETNP.s = IPS_OK ; + if (dc7diffSETNP.s == IPS_OK) + IUUpdateNumber(&dc7diffSETNP, values, names, n); + IDSetNumber(&dc7diffSETNP, nullptr); + return true; + } + if (!strcmp(name, dc7constSETNP.name)) + { + + dc7constSETNP.s = IPS_OK ; + if (dc7constSETNP.s == IPS_OK) + IUUpdateNumber(&dc7constSETNP, values, names, n); + IDSetNumber(&dc7constSETNP, nullptr); + return true; + } + // DC34voltageSET + if (!strcmp(name, setDC34voltageNP.name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + if (!strcmp(names[i], setDC34voltageN[setDC34voltage].name)) + rc1 = setDewPWM(20, static_cast(10*values[i])); + } + + setDC34voltageNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (setDC34voltageNP.s == IPS_OK) + IUUpdateNumber(&setDC34voltageNP, values, names, n); + IDSetNumber(&setDC34voltageNP, nullptr); + return true; + } + + + } + return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); +} + +bool WandererBoxProV3::setDewPWM(uint8_t id, uint8_t value) +{ + char cmd[64] = {0}; + snprintf(cmd, 64, "%d%03d", id, value); + if (sendCommand(cmd)) + { + return true; + } + + return false; +} + +const char *WandererBoxProV3::getDefaultName() +{ + return "WandererBox Pro V3"; +} + + +bool WandererBoxProV3::sendCommand(std::string command) +{ + int nbytes_written = 0, rc = -1; + std::string command_termination = "\n"; + LOGF_DEBUG("CMD: %s", command.c_str()); + if ((rc = tty_write_string(PortFD, (command + command_termination).c_str(), &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + return true; +} + +void WandererBoxProV3::TimerHit() +{ + if (!isConnected()) + { + SetTimer(2500); + return; + } + + getData(); + SetTimer(2500); +} + +bool WandererBoxProV3::saveConfigItems(FILE * fp) +{ + INDI::DefaultDevice::saveConfigItems(fp); + + IUSaveConfigSwitch(fp, &dc5dewSP); + IUSaveConfigNumber(fp, &dc5diffSETNP); + IUSaveConfigNumber(fp, &dc5constSETNP); + IUSaveConfigNumber(fp, &dc5ControlNP); + + IUSaveConfigSwitch(fp, &dc6dewSP); + IUSaveConfigNumber(fp, &dc6diffSETNP); + IUSaveConfigNumber(fp, &dc6constSETNP); + IUSaveConfigNumber(fp, &dc6ControlNP); + + IUSaveConfigSwitch(fp, &dc7dewSP); + IUSaveConfigNumber(fp, &dc7diffSETNP); + IUSaveConfigNumber(fp, &dc7constSETNP); + IUSaveConfigNumber(fp, &dc7ControlNP); + + IUSaveConfigNumber(fp, &setDC34voltageNP); + return true; +} + + diff --git a/drivers/auxiliary/wandererbox_pro_v3.h b/drivers/auxiliary/wandererbox_pro_v3.h new file mode 100644 index 0000000000..447ab4e006 --- /dev/null +++ b/drivers/auxiliary/wandererbox_pro_v3.h @@ -0,0 +1,281 @@ +/******************************************************************************* + Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + + Simple GPS Simulator + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#pragma once + +#include "defaultdevice.h" +#include +#include + +namespace Connection +{ +class Serial; +} + +class WandererBoxProV3 : public INDI::DefaultDevice +{ + public: + WandererBoxProV3(); + virtual ~WandererBoxProV3() = default; + + virtual bool initProperties() override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool updateProperties() override; + + + + protected: + const char *getDefaultName() override; + virtual bool saveConfigItems(FILE *fp) override; + virtual void TimerHit() override; + + + private: + + char version[64] = {0}; + bool sendCommand(std::string command); + bool DC5DIFFMODE=false; + bool DC5CONSTMODE=false; + bool DC6DIFFMODE=false; + bool DC6CONSTMODE=false; + bool DC7DIFFMODE=false; + bool DC7CONSTMODE=false; + bool getData(); + static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; + static constexpr const char *DC5_TAB {"DC5"}; + static constexpr const char *DC6_TAB {"DC6"}; + static constexpr const char *DC7_TAB {"DC7"}; + //Current Calibrate + ISwitch CalibrateS[1]; + ISwitchVectorProperty CalibrateSP; + + // Firmware version + ITextVectorProperty FirmwareTP; + IText FirmwareT[1] {}; + //Temp1 + double temp1read = 0; + //Temp2 + double temp2read = 0; + //Temp3 + double temp3read = 0; + //DHTH + double DHTHread = 0; + //DHTT + void updateENV(double temp1,double temp2,double temp3,double DHTH,double DHTT); + double DHTTread = 0; + //Total Current + double Tcurrentread = 0; + //19V Current + double V19currentread = 0; + //Adjustable Regulator Current + double ARcurrentread = 0; + //Power Monitor + void updatePower(double Tcurrent,double V19_current,double AR_current,double voltage); + double voltageread = 0; + //USB31 + void updateUSB31(int value); + int USB31read = 0; + //USB32 + void updateUSB32(int value); + int USB32read = 0; + //USB33 + void updateUSB33(int value); + int USB33read = 0; + //USB21 + void updateUSB21(int value); + int USB21read = 0; + //USB22 + void updateUSB22(int value); + int USB22read = 0; + //DC34 + void updateDC34(int value); + int DC34read = 0; + //DC5 + void updateDC5(int value); + int DC5read = 0; + //DC6 + void updateDC6(int value); + int DC6read = 0; + //DC7 + void updateDC7(int value); + int DC7read = 0; + //DC8_9 + void updateDC8_9(int value); + int DC8_9read = 0; + //DC10_11 + void updateDC10_11(int value); + int DC10_11read = 0; + //DC34set + void updateDC34SET(double value); + int DC34SETread = 0; + + bool setDewPWM(uint8_t id, uint8_t value); + + //DC Control////////////////////////////////////////////////////////////////////////////////// + ISwitchVectorProperty dc3_4ControlSP; + ISwitch dc3_4ControlS[2]; + ISwitchVectorProperty dc8_9ControlSP; + ISwitch dc8_9ControlS[2]; + ISwitchVectorProperty dc10_11ControlSP; + ISwitch dc10_11ControlS[2]; + //USB Control////////////////////////////////////////////////////////////////////////////////// + ISwitchVectorProperty usb31ControlSP; + ISwitch usb31ControlS[2]; + ISwitchVectorProperty usb32ControlSP; + ISwitch usb32ControlS[2]; + ISwitchVectorProperty usb33ControlSP; + ISwitch usb33ControlS[2]; + ISwitchVectorProperty usb21ControlSP; + ISwitch usb21ControlS[2]; + ISwitchVectorProperty usb22ControlSP; + ISwitch usb22ControlS[2]; + //DC5 Control//////////////////////////////////////////////////////////////// + INumber dc5ControlN[1]; + INumberVectorProperty dc5ControlNP; + enum + { + DC5, + }; + //DC6 Control//////////////////////////////////////////////////////////////// + INumber dc6ControlN[1]; + INumberVectorProperty dc6ControlNP; + enum + { + DC6, + }; + //DC7 Control//////////////////////////////////////////////////////////////// + INumber dc7ControlN[1]; + INumberVectorProperty dc7ControlNP; + enum + { + DC7, + }; + //DC5 DIFF//////////////////////////////////////////////////////////////// + ISwitchVectorProperty dc5dewSP; + ISwitch dc5diffS[3]; + enum + { + DC5_Manual, + DC5_DPD_Mode, + DC5_CT_Mode, + }; + + INumber dc5diffSETN[1]; + INumberVectorProperty dc5diffSETNP; + enum + { + DC5DIFFSET, + }; + INumber dc5constSETN[1]; + INumberVectorProperty dc5constSETNP; + enum + { + DC5CONSTSET, + }; + + //DC6 DIFF//////////////////////////////////////////////////////////////// + ISwitchVectorProperty dc6dewSP; + ISwitch dc6diffS[3]; + enum + { + DC6_Manual, + DC6_DPD_Mode, + DC6_CT_Mode, + }; + + INumber dc6diffSETN[1]; + INumberVectorProperty dc6diffSETNP; + enum + { + DC6DIFFSET, + }; + INumber dc6constSETN[1]; + INumberVectorProperty dc6constSETNP; + enum + { + DC6CONSTSET, + }; + + //DC7 DIFF//////////////////////////////////////////////////////////////// + ISwitchVectorProperty dc7dewSP; + ISwitch dc7diffS[3]; + enum + { + DC7_Manual, + DC7_DPD_Mode, + DC7_CT_Mode, + }; + + INumber dc7diffSETN[1]; + INumberVectorProperty dc7diffSETNP; + enum + { + DC7DIFFSET, + }; + INumber dc7constSETN[1]; + INumberVectorProperty dc7constSETNP; + enum + { + DC7CONSTSET, + }; + + //DC34 Voltage Control//////////////////////////////////////////////////////////////// + INumber setDC34voltageN[1]; + INumberVectorProperty setDC34voltageNP; + enum + { + setDC34voltage, + }; + + // Power Monitor + INumber PowerMonitorN[4]; + INumberVectorProperty PowerMonitorNP; + enum + { + VOLTAGE, + TOTAL_CURRENT, + V19_CURRENT, + AR_CURRENT, + }; + + // ENV Monitor + INumber ENVMonitorN[6]; + INumberVectorProperty ENVMonitorNP; + enum + { + Probe1_Temp, + Probe2_Temp, + Probe3_Temp, + ENV_Humidity, + ENV_Temp, + DEW_Point, + }; + + + + int PortFD{ -1 }; + + Connection::Serial *serialConnection{ nullptr }; +}; From 78477e3391c2f03a2128baf93bae4706b596901a Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 01:05:02 +0800 Subject: [PATCH 2/9] Driver for WandererBox Pro V3 added --- drivers/auxiliary/wandererbox_pro_v3.cpp | 17 +++++++---------- drivers/auxiliary/wandererbox_pro_v3.h | 1 - 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp index bc0839bfa1..199c16ab4d 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.cpp +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -208,13 +208,16 @@ bool WandererBoxProV3::getData() throw std::exception(); // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// int nbytes_read_version = 0; - version[64] = {0}; + char version[64] = {0}; tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); version[nbytes_read_version - 1] = '\0'; IUSaveText(&FirmwareT[0], version); IDSetText(&FirmwareTP, nullptr); - + if(std::stoi(version)<=20240216) + { + deleteProperty(CalibrateSP.name); + } // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// char temp1[64] = {0}; @@ -699,14 +702,8 @@ bool WandererBoxProV3::updateProperties() { defineProperty(&FirmwareTP); - if(std::stoi(version)>=20240216) - { - defineProperty(&CalibrateSP); - } - else - { - LOGF_INFO("The firmware is outdated, please upgrade to the latest firmware, or power reading calibration will be unavailable.","failed"); - } + defineProperty(&CalibrateSP); + defineProperty(&PowerMonitorNP); diff --git a/drivers/auxiliary/wandererbox_pro_v3.h b/drivers/auxiliary/wandererbox_pro_v3.h index 447ab4e006..149a6654ff 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.h +++ b/drivers/auxiliary/wandererbox_pro_v3.h @@ -54,7 +54,6 @@ class WandererBoxProV3 : public INDI::DefaultDevice private: - char version[64] = {0}; bool sendCommand(std::string command); bool DC5DIFFMODE=false; bool DC5CONSTMODE=false; From 73f3940a0815bf9a39c7cbeac95ebdd87fa1a523 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 07:32:42 +0800 Subject: [PATCH 3/9] Driver for WandererBox Pro V3 updated --- drivers.xml | 4 + drivers/auxiliary/CMakeLists.txt | 8 + drivers/auxiliary/wandererbox_plus_v3.cpp | 692 +++++++++ drivers/auxiliary/wandererbox_plus_v3.h | 170 +++ drivers/auxiliary/wandererbox_pro_v3.cpp | 1596 ++++++++++----------- drivers/auxiliary/wandererbox_pro_v3.h | 463 +++--- 6 files changed, 1890 insertions(+), 1043 deletions(-) create mode 100644 drivers/auxiliary/wandererbox_plus_v3.cpp create mode 100644 drivers/auxiliary/wandererbox_plus_v3.h diff --git a/drivers.xml b/drivers.xml index da691c0579..6ccf58b079 100644 --- a/drivers.xml +++ b/drivers.xml @@ -753,6 +753,10 @@ indi_wandererbox_pro_v3 1.0 + + indi_wandererbox_plus_v3 + 1.0 + diff --git a/drivers/auxiliary/CMakeLists.txt b/drivers/auxiliary/CMakeLists.txt index 95b9781a3d..dfb862db22 100644 --- a/drivers/auxiliary/CMakeLists.txt +++ b/drivers/auxiliary/CMakeLists.txt @@ -1,6 +1,14 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") INSTALL(FILES 99-indi_auxiliary.rules DESTINATION ${UDEVRULES_INSTALL_DIR}) ENDIF() +# ########## Wanderer Box Plus V3 ############### +SET(indi_wandererbox_plus_v3_SRC + wandererbox_plus_v3.cpp) + +add_executable(indi_wandererbox_plus_v3 ${indi_wandererbox_plus_v3_SRC}) +target_link_libraries(indi_wandererbox_plus_v3 indidriver) +install(TARGETS indi_wandererbox_plus_v3 RUNTIME DESTINATION bin) + # ########## Wanderer Box Pro V3 ############### SET(indi_wandererbox_pro_v3_SRC diff --git a/drivers/auxiliary/wandererbox_plus_v3.cpp b/drivers/auxiliary/wandererbox_plus_v3.cpp new file mode 100644 index 0000000000..83ac7e3713 --- /dev/null +++ b/drivers/auxiliary/wandererbox_plus_v3.cpp @@ -0,0 +1,692 @@ +/******************************************************************************* + Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + + WandererBox Plus V3 + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#include "wandererbox_plus_v3.h" +#include "indicom.h" +#include "connectionplugins/connectionserial.h" +#include +#include +#include +#include +#include +#include +#include +#include + +// We declare an auto pointer to WandererBoxPlusV3. +static std::unique_ptr wandererboxplusv3(new WandererBoxPlusV3()); + + + +WandererBoxPlusV3::WandererBoxPlusV3() +{ + setVersion(1, 0); +} + +bool WandererBoxPlusV3::initProperties() +{ + + INDI::DefaultDevice::initProperties(); + setDriverInterface(AUX_INTERFACE); + + + addAuxControls(); + + + // Calibrate + IUFillSwitch(&CalibrateS[0], "Calibrate", "Calibrate Current", ISS_OFF); + IUFillSwitchVector(&CalibrateSP, CalibrateS, 1, getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + + // Power Monitor + IUFillNumber(&PowerMonitorN[VOLTAGE], "VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&PowerMonitorN[TOTAL_CURRENT], "TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); + IUFillNumberVector(&PowerMonitorNP, PowerMonitorN, 2, getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); + + + + // Firmware version + IUFillText(&FirmwareT[0], "Version", "Version", nullptr); + + + // USB Control + IUFillSwitch(&USBControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&USBControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&USBControlSP, USBControlS, 2, getDeviceName(), "USB3.0_1", "USB3.0_1", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + + // DC3 + IUFillNumber(&DC3ControlN[DC3], "DC3", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + IUFillNumberVector(&DC3ControlNP, DC3ControlN, 1, getDeviceName(), "PWM", "DC3", DC3_TAB, IP_RW, 60, IPS_IDLE); + + // DC2SET + IUFillNumber(&setDC2voltageN[setDC2voltage], "DC2SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); + IUFillNumberVector(&setDC2voltageNP, setDC2voltageN, 1, getDeviceName(), "DC2voltageSET", "Set DC2", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + // DC2 Control + IUFillSwitch(&DC2ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&DC2ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&DC2ControlSP, DC2ControlS, 2, getDeviceName(), "DC2", "DC2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC4-6 Control + IUFillSwitch(&DC4_6ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); + IUFillSwitch(&DC4_6ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); + IUFillSwitchVector(&DC4_6ControlSP, DC4_6ControlS, 2, getDeviceName(), "DC4-6", "DC4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC3 TEMP Difference Control + IUFillSwitch(&DC3diffS[DC3_Manual], "Manual", "Manual", ISS_ON); + IUFillSwitch(&DC3diffS[DC3_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); + IUFillSwitch(&DC3diffS[DC3_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); + IUFillSwitchVector(&DC3dewSP, DC3diffS, 3, getDeviceName(), "DC3_DIFF", "DC3 Dew Mode", DC3_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + IUFillNumber(&DC3diffSETN[DC3DIFFSET], "DC3 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + IUFillNumberVector(&DC3diffSETNP, DC3diffSETN, 1, getDeviceName(), "DC3_DIFF_SET", "DPD Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); + + IUFillNumber(&DC3constSETN[DC3CONSTSET], "DC3 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + IUFillNumberVector(&DC3constSETNP, DC3constSETN, 1, getDeviceName(), "DC3_CONST_SET", "CT Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); + + //ENV + IUFillNumber(&ENVMonitorN[Probe1_Temp], "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[ENV_Humidity], "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[ENV_Temp], "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumber(&ENVMonitorN[DEW_Point], "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); + IUFillNumberVector(&ENVMonitorNP, ENVMonitorN, 4, getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); + serialConnection = new Connection::Serial(this); + serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); + serialConnection->registerHandshake([&]() + { + return getData(); + }); + registerConnection(serialConnection); + + return true; +} + +bool WandererBoxPlusV3::getData() +{ + try + { + PortFD = serialConnection->getPortFD(); + tcflush(PortFD, TCIOFLUSH); + int nbytes_read_name = 0,rc=-1; + char name[64] = {0}; + + //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_INFO("No data received, the device may not be WandererBox Pro V3, please check the serial port!","Updated"); + LOGF_ERROR("Device read error: %s", errorMessage); + return false; + } + name[nbytes_read_name - 1] = '\0'; + if(strcmp(name, "ZXWBProV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) + { + LOGF_INFO("The device is not WandererBox Pro V3!","Updated"); + return false; + } + if(strcmp(name, "ZXWBPlusV3")!=0) + throw std::exception(); + // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// + int nbytes_read_version = 0; + char version[64] = {0}; + tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); + + version[nbytes_read_version - 1] = '\0'; + IUSaveText(&FirmwareT[0], version); + IDSetText(&FirmwareTP, nullptr); + if(std::stoi(version)<=20240216) + { + deleteProperty(CalibrateSP.name); + } + + // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// + char temp1[64] = {0}; + int nbytes_read_temp1= 0; + tty_read_section(PortFD, temp1, 'A', 5, &nbytes_read_temp1); + temp1[nbytes_read_temp1 - 1] = '\0'; + temp1read = std::strtod(temp1,NULL); + + // DHTH////////////////////////////////////////////////////////////////////////////////////////// + char DHTH[64] = {0}; + int nbytes_read_DHTH= 0; + tty_read_section(PortFD, DHTH, 'A', 5, &nbytes_read_DHTH); + DHTH[nbytes_read_DHTH - 1] = '\0'; + DHTHread = std::strtod(DHTH,NULL); + + // DHTT////////////////////////////////////////////////////////////////////////////////////////// + char DHTT[64] = {0}; + int nbytes_read_DHTT= 0; + tty_read_section(PortFD, DHTT, 'A', 5, &nbytes_read_DHTT); + DHTT[nbytes_read_DHTT - 1] = '\0'; + DHTTread = std::strtod(DHTT,NULL); + updateENV(temp1read,DHTHread,DHTTread); + + // Total current////////////////////////////////////////////////////////////////////////////////////////// + char Tcurrent[64] = {0}; + int nbytes_read_Tcurrent= 0; + tty_read_section(PortFD, Tcurrent, 'A', 5, &nbytes_read_Tcurrent); + Tcurrent[nbytes_read_Tcurrent - 1] = '\0'; + Tcurrentread = std::strtod(Tcurrent,NULL); + + + // Voltage////////////////////////////////////////////////////////////////////////////////////////// + char voltage[64] = {0}; + int nbytes_read_voltage= 0; + tty_read_section(PortFD, voltage, 'A', 5, &nbytes_read_voltage); + voltage[nbytes_read_voltage - 1] = '\0'; + voltageread = std::strtod(voltage,NULL); + updatePower(Tcurrentread,voltageread); + + // USB////////////////////////////////////////////////////////////////////////////////////////// + char USB[64] = {0}; + int nbytes_read_USB= 0; + tty_read_section(PortFD, USB, 'A', 5, &nbytes_read_USB); + USB[nbytes_read_USB - 1] = '\0'; + USBread = std::stoi(USB); + updateUSB(USBread); + + // DC2////////////////////////////////////////////////////////////////////////////////////////// + char DC2[64] = {0}; + int nbytes_read_DC2= 0; + tty_read_section(PortFD, DC2, 'A', 5, &nbytes_read_DC2); + DC2[nbytes_read_DC2 - 1] = '\0'; + DC2read = std::stoi(DC2); + updateDC2(DC2read); + + // DC3////////////////////////////////////////////////////////////////////////////////////////// + char DC3[64] = {0}; + int nbytes_read_DC3= 0; + tty_read_section(PortFD, DC3, 'A', 5, &nbytes_read_DC3); + DC3[nbytes_read_DC3 - 1] = '\0'; + DC3read = std::stoi(DC3); + updateDC3(DC3read); + + + // DC4_6////////////////////////////////////////////////////////////////////////////////////////// + char DC4_6[64] = {0}; + int nbytes_read_DC4_6= 0; + tty_read_section(PortFD, DC4_6, 'A', 5, &nbytes_read_DC4_6); + DC4_6[nbytes_read_DC4_6 - 1] = '\0'; + DC4_6read =std::stoi(DC4_6); + updateDC4_6(DC4_6read); + + // DC2SET////////////////////////////////////////////////////////////////////////////////////////// + char DC2SET[64] = {0}; + int nbytes_read_DC2SET= 0; + tty_read_section(PortFD, DC2SET, 'A', 5, &nbytes_read_DC2SET); + DC2SET[nbytes_read_DC2SET - 1] = '\0'; + //LOGF_INFO("All Data Updated","Updated"); + DC2SETread = std::stoi(DC2SET); + updateDC2SET(DC2SETread); + + //DC3 DEW CONTROL + if(DC3DIFFMODE==true ) + { + if(temp1read(values[i])); + } + + DC3ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (DC3ControlNP.s == IPS_OK) + IUUpdateNumber(&DC3ControlNP, values, names, n); + IDSetNumber(&DC3ControlNP, nullptr); + return true; + } + if (!strcmp(name, DC3diffSETNP.name)) + { + + DC3diffSETNP.s = IPS_OK ; + if (DC3diffSETNP.s == IPS_OK) + IUUpdateNumber(&DC3diffSETNP, values, names, n); + IDSetNumber(&DC3diffSETNP, nullptr); + return true; + } + if (!strcmp(name, DC3constSETNP.name)) + { + + DC3constSETNP.s = IPS_OK ; + if (DC3constSETNP.s == IPS_OK) + IUUpdateNumber(&DC3constSETNP, values, names, n); + IDSetNumber(&DC3constSETNP, nullptr); + return true; + } + + // DC2voltageSET + if (!strcmp(name, setDC2voltageNP.name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + if (!strcmp(names[i], setDC2voltageN[setDC2voltage].name)) + rc1 = setDewPWM(20, static_cast(10*values[i])); + } + + setDC2voltageNP.s = (rc1) ? IPS_OK : IPS_ALERT; + if (setDC2voltageNP.s == IPS_OK) + IUUpdateNumber(&setDC2voltageNP, values, names, n); + IDSetNumber(&setDC2voltageNP, nullptr); + return true; + } + + + } + return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); +} + +bool WandererBoxPlusV3::setDewPWM(uint8_t id, uint8_t value) +{ + char cmd[64] = {0}; + snprintf(cmd, 64, "%d%03d", id, value); + if (sendCommand(cmd)) + { + return true; + } + + return false; +} + +const char *WandererBoxPlusV3::getDefaultName() +{ + return "WandererBox Pro V3"; +} + + +bool WandererBoxPlusV3::sendCommand(std::string command) +{ + int nbytes_written = 0, rc = -1; + std::string command_termination = "\n"; + LOGF_DEBUG("CMD: %s", command.c_str()); + if ((rc = tty_write_string(PortFD, (command + command_termination).c_str(), &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + return true; +} + +void WandererBoxPlusV3::TimerHit() +{ + if (!isConnected()) + { + SetTimer(2500); + return; + } + + getData(); + SetTimer(2500); +} + +bool WandererBoxPlusV3::saveConfigItems(FILE * fp) +{ + INDI::DefaultDevice::saveConfigItems(fp); + + IUSaveConfigSwitch(fp, &DC3dewSP); + IUSaveConfigNumber(fp, &DC3diffSETNP); + IUSaveConfigNumber(fp, &DC3constSETNP); + IUSaveConfigNumber(fp, &DC3ControlNP); + + + IUSaveConfigNumber(fp, &setDC2voltageNP); + return true; +} + + diff --git a/drivers/auxiliary/wandererbox_plus_v3.h b/drivers/auxiliary/wandererbox_plus_v3.h new file mode 100644 index 0000000000..3f1194be7e --- /dev/null +++ b/drivers/auxiliary/wandererbox_plus_v3.h @@ -0,0 +1,170 @@ +/******************************************************************************* + Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + +WandererBox Plus V3 + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#pragma once + +#include "defaultdevice.h" +#include +#include + +namespace Connection +{ +class Serial; +} + +class WandererBoxPlusV3 : public INDI::DefaultDevice +{ + public: + WandererBoxPlusV3(); + virtual ~WandererBoxPlusV3() = default; + + virtual bool initProperties() override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool updateProperties() override; + + + + protected: + const char *getDefaultName() override; + virtual bool saveConfigItems(FILE *fp) override; + virtual void TimerHit() override; + + + private: + + bool sendCommand(std::string command); + bool DC3DIFFMODE=false; + bool DC3CONSTMODE=false; + bool getData(); + static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; + static constexpr const char *DC3_TAB {"DC3"}; + //Current Calibrate + ISwitch CalibrateS[1]; + ISwitchVectorProperty CalibrateSP; + + // Firmware version + ITextVectorProperty FirmwareTP; + IText FirmwareT[1] {}; + //Temp1 + double temp1read = 0; + //DHTH + double DHTHread = 0; + //DHTT + void updateENV(double temp1,double DHTH,double DHTT); + double DHTTread = 0; + //Total Current + double Tcurrentread = 0; + //Power Monitor + void updatePower(double Tcurrent,double voltage); + double voltageread = 0; + //USB + void updateUSB(int value); + int USBread = 0; + //DC2 + void updateDC2(int value); + int DC2read = 0; + //DC3 + void updateDC3(int value); + int DC3read = 0; + //DC4_6 + void updateDC4_6(int value); + int DC4_6read = 0; + //DC2set + void updateDC2SET(double value); + int DC2SETread = 0; + + bool setDewPWM(uint8_t id, uint8_t value); + + //DC Control////////////////////////////////////////////////////////////////////////////////// + ISwitchVectorProperty DC2ControlSP; + ISwitch DC2ControlS[2]; + ISwitchVectorProperty DC4_6ControlSP; + ISwitch DC4_6ControlS[2]; + //USB Control////////////////////////////////////////////////////////////////////////////////// + ISwitchVectorProperty USBControlSP; + ISwitch USBControlS[2]; + //DC3 Control//////////////////////////////////////////////////////////////// + INumber DC3ControlN[1]; + INumberVectorProperty DC3ControlNP; + enum + { + DC3, + }; + ISwitchVectorProperty DC3dewSP; + ISwitch DC3diffS[3]; + enum + { + DC3_Manual, + DC3_DPD_Mode, + DC3_CT_Mode, + }; + + INumber DC3diffSETN[1]; + INumberVectorProperty DC3diffSETNP; + enum + { + DC3DIFFSET, + }; + INumber DC3constSETN[1]; + INumberVectorProperty DC3constSETNP; + enum + { + DC3CONSTSET, + }; + + //DC2 Voltage Control//////////////////////////////////////////////////////////////// + INumber setDC2voltageN[1]; + INumberVectorProperty setDC2voltageNP; + enum + { + setDC2voltage, + }; + + // Power Monitor + INumber PowerMonitorN[2]; + INumberVectorProperty PowerMonitorNP; + enum + { + VOLTAGE, + TOTAL_CURRENT, + }; + + // ENV Monitor + INumber ENVMonitorN[4]; + INumberVectorProperty ENVMonitorNP; + enum + { + Probe1_Temp, + ENV_Humidity, + ENV_Temp, + DEW_Point, + }; + + + + int PortFD{ -1 }; + + Connection::Serial *serialConnection{ nullptr }; +}; diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp index 199c16ab4d..06055fa30b 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.cpp +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -55,126 +55,123 @@ bool WandererBoxProV3::initProperties() // Calibrate - IUFillSwitch(&CalibrateS[0], "Calibrate", "Calibrate Current", ISS_OFF); - IUFillSwitchVector(&CalibrateSP, CalibrateS, 1, getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + CalibrateSP[0].fill("Calibrate", "Calibrate Current", ISS_OFF); + CalibrateSP.fill(getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); // Power Monitor - IUFillNumber(&PowerMonitorN[VOLTAGE], "VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerMonitorN[TOTAL_CURRENT], "TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerMonitorN[V19_CURRENT], "V19_CURRENT", "DC2 Current (A))", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerMonitorN[AR_CURRENT], "AR_CURRENT", "DC3-4 Current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumberVector(&PowerMonitorNP, PowerMonitorN, 4, getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); - - - - // Firmware version - IUFillText(&FirmwareT[0], "Version", "Version", nullptr); + PowerMonitorNP[VOLTAGE].fill("VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP[TOTAL_CURRENT].fill("TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP[V19_CURRENT].fill("V19_CURRENT", "DC2 Current (A))", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP[AR_CURRENT].fill("AR_CURRENT", "DC3-4 Current (A)", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP.fill(getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); // USB31 Control - IUFillSwitch(&usb31ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&usb31ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&usb31ControlSP, usb31ControlS, 2, getDeviceName(), "USB3.0_1", "USB3.0_1", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + usb31ControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + usb31ControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_OFF); + usb31ControlSP.fill(getDeviceName(), "USB3.0_1", "USB3.0_1", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // USB32 Control - IUFillSwitch(&usb32ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&usb32ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&usb32ControlSP, usb32ControlS, 2, getDeviceName(), "USB3.0_2", "USB3.0_2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + usb32ControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + usb32ControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_OFF); + usb32ControlSP.fill(getDeviceName(), "USB3.0_2", "USB3.0_2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // USB33 Control - IUFillSwitch(&usb33ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&usb33ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&usb33ControlSP, usb33ControlS, 2, getDeviceName(), "USB3.0_3", "USB3.0_3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + usb33ControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + usb33ControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_OFF); + usb33ControlSP.fill(getDeviceName(), "USB3.0_3", "USB3.0_3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // USB21 Control - IUFillSwitch(&usb21ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&usb21ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&usb21ControlSP, usb21ControlS, 2, getDeviceName(), "USB2.0_1-3", "USB2.0_1-3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + usb21ControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + usb21ControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_OFF); + usb21ControlSP.fill(getDeviceName(), "USB2.0_1-3", "USB2.0_1-3", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // USB22 Control - IUFillSwitch(&usb22ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&usb22ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&usb22ControlSP, usb22ControlS, 2, getDeviceName(), "USB2.0_4-6", "USB2.0_4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + usb22ControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + usb22ControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_ON); + usb22ControlSP.fill(getDeviceName(), "USB2.0_4-6", "USB2.0_4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // DC567 - IUFillNumber(&dc5ControlN[DC5], "DC5", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); - IUFillNumberVector(&dc5ControlNP, dc5ControlN, 1, getDeviceName(), "PWM", "DC5", DC5_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&dc6ControlN[DC6], "DC6", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); - IUFillNumberVector(&dc6ControlNP, dc6ControlN, 1, getDeviceName(), "DC6", "DC6", DC6_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&dc7ControlN[DC7], "DC7", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); - IUFillNumberVector(&dc7ControlNP, dc7ControlN, 1, getDeviceName(), "DC7", "DC7", DC7_TAB, IP_RW, 60, IPS_IDLE); + dc5ControlNP[DC5].fill( "DC5", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + dc5ControlNP.fill(getDeviceName(), "PWM", "DC5", DC5_TAB, IP_RW, 60, IPS_IDLE); + + dc6ControlNP[DC6].fill( "DC6", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + dc6ControlNP.fill( getDeviceName(), "DC6", "DC6", DC6_TAB, IP_RW, 60, IPS_IDLE); + + dc7ControlNP[DC7].fill( "DC7", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + dc7ControlNP.fill(getDeviceName(), "DC7", "DC7", DC7_TAB, IP_RW, 60, IPS_IDLE); // DC34SET - IUFillNumber(&setDC34voltageN[setDC34voltage], "DC34SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); - IUFillNumberVector(&setDC34voltageNP, setDC34voltageN, 1, getDeviceName(), "DC34voltageSET", "Set DC3-4", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + setDC34voltageNP[setDC34voltage].fill( "DC34SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); + setDC34voltageNP.fill(getDeviceName(), "DC34voltageSET", "Set DC3-4", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); // DC3-4 Control - IUFillSwitch(&dc3_4ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&dc3_4ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&dc3_4ControlSP, dc3_4ControlS, 2, getDeviceName(), "DC3-4", "DC3-4", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc3_4ControlSP[INDI_ENABLED].fill( "INDI_ENABLED", "On", ISS_OFF); + dc3_4ControlSP[INDI_DISABLED].fill( "INDI_DISABLED", "Off", ISS_ON); + dc3_4ControlSP.fill(getDeviceName(), "DC3-4", "DC3-4", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // DC8-9 Control - IUFillSwitch(&dc8_9ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&dc8_9ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&dc8_9ControlSP, dc8_9ControlS, 2, getDeviceName(), "DC8-9", "DC8-9", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc8_9ControlSP[INDI_ENABLED].fill( "INDI_ENABLED", "On", ISS_OFF); + dc8_9ControlSP[INDI_DISABLED].fill( "INDI_DISABLED", "Off", ISS_ON); + dc8_9ControlSP.fill(getDeviceName(), "DC8-9", "DC8-9", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // DC10-11 Control - IUFillSwitch(&dc10_11ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&dc10_11ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&dc10_11ControlSP, dc10_11ControlS, 2, getDeviceName(), "DC10-11", "DC10-11", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc10_11ControlSP[INDI_ENABLED].fill( "INDI_ENABLED", "On", ISS_OFF); + dc10_11ControlSP[INDI_DISABLED].fill( "INDI_DISABLED", "Off", ISS_ON); + dc10_11ControlSP.fill(getDeviceName(), "DC10-11", "DC10-11", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); // DC5 TEMP Difference Control - IUFillSwitch(&dc5diffS[DC5_Manual], "Manual", "Manual", ISS_ON); - IUFillSwitch(&dc5diffS[DC5_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); - IUFillSwitch(&dc5diffS[DC5_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); - IUFillSwitchVector(&dc5dewSP, dc5diffS, 3, getDeviceName(), "DC5_DIFF", "DC5 Dew Mode", DC5_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc5diffSP[DC5_Manual].fill( "Manual", "Manual", ISS_ON); + dc5diffSP[DC5_DPD_Mode].fill( "DPD_Mode", "DPD Mode", ISS_OFF); + dc5diffSP[DC5_CT_Mode].fill( "CT_Mode", "CT Mode", ISS_OFF); + dc5diffSP.fill(getDeviceName(), "DC5_DIFF", "DC5 Dew Mode", DC5_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - IUFillNumber(&dc5diffSETN[DC5DIFFSET], "DC5 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); - IUFillNumberVector(&dc5diffSETNP, dc5diffSETN, 1, getDeviceName(), "DC5_DIFF_SET", "DPD Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); + dc5diffSETNP[DC5DIFFSET].fill( "DC5 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + dc5diffSETNP.fill(getDeviceName(), "DC5_DIFF_SET", "DPD Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&dc5constSETN[DC5CONSTSET], "DC5 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); - IUFillNumberVector(&dc5constSETNP, dc5constSETN, 1, getDeviceName(), "DC5_CONST_SET", "CT Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); + dc5constSETNP[DC5CONSTSET].fill( "DC5 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + dc5constSETNP.fill(getDeviceName(), "DC5_CONST_SET", "CT Mode", DC5_TAB, IP_RW, 60, IPS_IDLE); // DC6 TEMP Difference Control - IUFillSwitch(&dc6diffS[DC6_Manual], "Manual", "Manual", ISS_ON); - IUFillSwitch(&dc6diffS[DC6_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); - IUFillSwitch(&dc6diffS[DC6_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); - IUFillSwitchVector(&dc6dewSP, dc6diffS, 3, getDeviceName(), "DC6_DIFF", "DC6 Dew Mode", DC6_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc6diffSP[DC6_Manual].fill( "Manual", "Manual", ISS_ON); + dc6diffSP[DC6_DPD_Mode].fill( "DPD_Mode", "DPD Mode", ISS_OFF); + dc6diffSP[DC6_CT_Mode].fill( "CT_Mode", "CT Mode", ISS_OFF); + dc6diffSP.fill(getDeviceName(), "DC6_DIFF", "DC6 Dew Mode", DC6_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - IUFillNumber(&dc6diffSETN[DC6DIFFSET], "DC6 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); - IUFillNumberVector(&dc6diffSETNP, dc6diffSETN, 1, getDeviceName(), "DC6_DIFF_SET", "DPD Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); + dc6diffSETNP[DC6DIFFSET].fill( "DC6 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + dc6diffSETNP.fill(getDeviceName(), "DC6_DIFF_SET", "DPD Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&dc6constSETN[DC6CONSTSET], "DC6 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); - IUFillNumberVector(&dc6constSETNP, dc6constSETN, 1, getDeviceName(), "DC6_CONST_SET", "CT Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); + dc6constSETNP[DC6CONSTSET].fill( "DC6 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + dc6constSETNP.fill(getDeviceName(), "DC6_CONST_SET", "CT Mode", DC6_TAB, IP_RW, 60, IPS_IDLE); // DC7 TEMP Difference Control - IUFillSwitch(&dc7diffS[DC7_Manual], "Manual", "Manual", ISS_ON); - IUFillSwitch(&dc7diffS[DC7_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); - IUFillSwitch(&dc7diffS[DC7_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); - IUFillSwitchVector(&dc7dewSP, dc7diffS, 3, getDeviceName(), "DC7_DIFF", "DC7 Dew Mode", DC7_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + dc7diffSP[DC7_Manual].fill( "Manual", "Manual", ISS_ON); + dc7diffSP[DC7_DPD_Mode].fill( "DPD_Mode", "DPD Mode", ISS_OFF); + dc7diffSP[DC7_CT_Mode].fill( "CT_Mode", "CT Mode", ISS_OFF); + dc7diffSP.fill(getDeviceName(), "DC7_DIFF", "DC7 Dew Mode", DC7_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - IUFillNumber(&dc7diffSETN[DC7DIFFSET], "DC7 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); - IUFillNumberVector(&dc7diffSETNP, dc7diffSETN, 1, getDeviceName(), "DC7_DIFF_SET", "DPD Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); + dc7diffSETNP[DC7DIFFSET].fill( "DC7 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + dc7diffSETNP.fill(getDeviceName(), "DC7_DIFF_SET", "DPD Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); - IUFillNumber(&dc7constSETN[DC7CONSTSET], "DC7 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); - IUFillNumberVector(&dc7constSETNP, dc7constSETN, 1, getDeviceName(), "DC7_CONST_SET", "CT Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); + dc7constSETNP[DC7CONSTSET].fill( "DC7 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + dc7constSETNP.fill(getDeviceName(), "DC7_CONST_SET", "CT Mode", DC7_TAB, IP_RW, 60, IPS_IDLE); //ENV - IUFillNumber(&ENVMonitorN[Probe1_Temp], "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[Probe2_Temp], "Probe2_Temp", "Probe2 Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[Probe3_Temp], "Probe3_Temp", "Probe3 Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[ENV_Humidity], "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[ENV_Temp], "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[DEW_Point], "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumberVector(&ENVMonitorNP, ENVMonitorN, 6, getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); + ENVMonitorNP[Probe1_Temp].fill( "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[Probe2_Temp].fill( "Probe2_Temp", "Probe2 Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[Probe3_Temp].fill( "Probe3_Temp", "Probe3 Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[ENV_Humidity].fill( "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[ENV_Temp].fill( "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[DEW_Point].fill( "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP.fill(getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); serialConnection = new Connection::Serial(this); serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); serialConnection->registerHandshake([&]() - { - return getData(); - }); + { + return getData(); + }); registerConnection(serialConnection); return true; @@ -184,391 +181,390 @@ bool WandererBoxProV3::getData() { try { - PortFD = serialConnection->getPortFD(); - tcflush(PortFD, TCIOFLUSH); - int nbytes_read_name = 0,rc=-1; - char name[64] = {0}; + PortFD = serialConnection->getPortFD(); + tcflush(PortFD, TCIOFLUSH); + int nbytes_read_name = 0,rc=-1; + char name[64] = {0}; - //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// - if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) - { - char errorMessage[MAXRBUF]; - tty_error_msg(rc, errorMessage, MAXRBUF); - LOGF_INFO("No data received, the device may not be WandererBox Pro V3, please check the serial port!","Updated"); - LOGF_ERROR("Device read error: %s", errorMessage); - return false; - } - name[nbytes_read_name - 1] = '\0'; - if(strcmp(name, "ZXWBPlusV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) - { - LOGF_INFO("The device is not WandererBox Pro V3!","Updated"); - return false; - } - if(strcmp(name, "ZXWBProV3")!=0) + //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_INFO("No data received, the device may not be WandererBox Pro V3, please check the serial port!","Updated"); + LOGF_ERROR("Device read error: %s", errorMessage); + return false; + } + name[nbytes_read_name - 1] = '\0'; + if(strcmp(name, "ZXWBPlusV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) + { + LOGF_INFO("The device is not WandererBox Pro V3!","Updated"); + return false; + } + if(strcmp(name, "ZXWBProV3")!=0) throw std::exception(); - // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// - int nbytes_read_version = 0; - char version[64] = {0}; - tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); - - version[nbytes_read_version - 1] = '\0'; - IUSaveText(&FirmwareT[0], version); - IDSetText(&FirmwareTP, nullptr); - if(std::stoi(version)<=20240216) - { - deleteProperty(CalibrateSP.name); - } + // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// + int nbytes_read_version = 0; + version[64] = {0}; + tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); + + version[nbytes_read_version - 1] = '\0'; + + + + // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// + char temp1[64] = {0}; + int nbytes_read_temp1= 0; + tty_read_section(PortFD, temp1, 'A', 5, &nbytes_read_temp1); + temp1[nbytes_read_temp1 - 1] = '\0'; + temp1read = std::strtod(temp1,NULL); + + // Temp probe 2////////////////////////////////////////////////////////////////////////////////////////// + char temp2[64] = {0}; + int nbytes_read_temp2= 0; + tty_read_section(PortFD, temp2, 'A', 5, &nbytes_read_temp2); + temp2[nbytes_read_temp2 - 1] = '\0'; + temp2read = std::strtod(temp2,NULL); + + // Temp probe 3////////////////////////////////////////////////////////////////////////////////////////// + char temp3[64] = {0}; + int nbytes_read_temp3= 0; + tty_read_section(PortFD, temp3, 'A', 5, &nbytes_read_temp3); + temp3[nbytes_read_temp3 - 1] = '\0'; + temp3read = std::strtod(temp3,NULL); + + // DHTH////////////////////////////////////////////////////////////////////////////////////////// + char DHTH[64] = {0}; + int nbytes_read_DHTH= 0; + tty_read_section(PortFD, DHTH, 'A', 5, &nbytes_read_DHTH); + DHTH[nbytes_read_DHTH - 1] = '\0'; + DHTHread = std::strtod(DHTH,NULL); + + // DHTT////////////////////////////////////////////////////////////////////////////////////////// + char DHTT[64] = {0}; + int nbytes_read_DHTT= 0; + tty_read_section(PortFD, DHTT, 'A', 5, &nbytes_read_DHTT); + DHTT[nbytes_read_DHTT - 1] = '\0'; + DHTTread = std::strtod(DHTT,NULL); + updateENV(temp1read,temp2read,temp3read,DHTHread,DHTTread); + + // Total current////////////////////////////////////////////////////////////////////////////////////////// + char Tcurrent[64] = {0}; + int nbytes_read_Tcurrent= 0; + tty_read_section(PortFD, Tcurrent, 'A', 5, &nbytes_read_Tcurrent); + Tcurrent[nbytes_read_Tcurrent - 1] = '\0'; + Tcurrentread = std::strtod(Tcurrent,NULL); + + // 19V current////////////////////////////////////////////////////////////////////////////////////////// + char V19current[64] = {0}; + int nbytes_read_V19current= 0; + tty_read_section(PortFD, V19current, 'A', 5, &nbytes_read_V19current); + V19current[nbytes_read_V19current - 1] = '\0'; + V19currentread = std::strtod(V19current,NULL); + + + // Adjustable Regulator current////////////////////////////////////////////////////////////////////////////////////////// + char ARcurrent[64] = {0}; + int nbytes_read_ARcurrent= 0; + tty_read_section(PortFD, ARcurrent, 'A', 5, &nbytes_read_ARcurrent); + ARcurrent[nbytes_read_ARcurrent - 1] = '\0'; + ARcurrentread = std::strtod(ARcurrent,NULL); + + + // Voltage////////////////////////////////////////////////////////////////////////////////////////// + char voltage[64] = {0}; + int nbytes_read_voltage= 0; + tty_read_section(PortFD, voltage, 'A', 5, &nbytes_read_voltage); + voltage[nbytes_read_voltage - 1] = '\0'; + voltageread = std::strtod(voltage,NULL); + updatePower(Tcurrentread,V19currentread,ARcurrentread,voltageread); + + // USB31////////////////////////////////////////////////////////////////////////////////////////// + char USB31[64] = {0}; + int nbytes_read_USB31= 0; + tty_read_section(PortFD, USB31, 'A', 5, &nbytes_read_USB31); + USB31[nbytes_read_USB31 - 1] = '\0'; + USB31read = std::stoi(USB31); + updateUSB31(USB31read); + + // USB32////////////////////////////////////////////////////////////////////////////////////////// + char USB32[64] = {0}; + int nbytes_read_USB32= 0; + tty_read_section(PortFD, USB32, 'A', 5, &nbytes_read_USB32); + USB32[nbytes_read_USB32 - 1] = '\0'; + USB32read = std::stoi(USB32); + updateUSB32(USB32read); + + // USB33////////////////////////////////////////////////////////////////////////////////////////// + char USB33[64] = {0}; + int nbytes_read_USB33= 0; + tty_read_section(PortFD, USB33, 'A', 5, &nbytes_read_USB33); + USB33[nbytes_read_USB33 - 1] = '\0'; + USB33read = std::stoi(USB33); + updateUSB33(USB33read); + + // USB21////////////////////////////////////////////////////////////////////////////////////////// + char USB21[64] = {0}; + int nbytes_read_USB21= 0; + tty_read_section(PortFD, USB21, 'A', 5, &nbytes_read_USB21); + USB21[nbytes_read_USB21 - 1] = '\0'; + USB21read = std::stoi(USB21); + updateUSB21(USB21read); + + // USB22////////////////////////////////////////////////////////////////////////////////////////// + char USB22[64] = {0}; + int nbytes_read_USB22= 0; + tty_read_section(PortFD, USB22, 'A', 5, &nbytes_read_USB22); + USB22[nbytes_read_USB22 - 1] = '\0'; + USB22read = std::stoi(USB22); + updateUSB22(USB22read); + + // DC34////////////////////////////////////////////////////////////////////////////////////////// + char DC34[64] = {0}; + int nbytes_read_DC34= 0; + tty_read_section(PortFD, DC34, 'A', 5, &nbytes_read_DC34); + DC34[nbytes_read_DC34 - 1] = '\0'; + DC34read = std::stoi(DC34); + updateDC34(DC34read); + + // DC5////////////////////////////////////////////////////////////////////////////////////////// + char DC5[64] = {0}; + int nbytes_read_DC5= 0; + tty_read_section(PortFD, DC5, 'A', 5, &nbytes_read_DC5); + DC5[nbytes_read_DC5 - 1] = '\0'; + DC5read = std::stoi(DC5); + updateDC5(DC5read); + + // DC6////////////////////////////////////////////////////////////////////////////////////////// + char DC6[64] = {0}; + int nbytes_read_DC6= 0; + tty_read_section(PortFD, DC6, 'A', 5, &nbytes_read_DC6); + DC6[nbytes_read_DC6 - 1] = '\0'; + DC6read = std::stoi(DC6); + updateDC6(DC6read); + + // DC7////////////////////////////////////////////////////////////////////////////////////////// + char DC7[64] = {0}; + int nbytes_read_DC7= 0; + tty_read_section(PortFD, DC7, 'A', 5, &nbytes_read_DC7); + DC7[nbytes_read_DC7 - 1] = '\0'; + DC7read = std::stoi(DC7); + updateDC7(DC7read); + + // DC8_9////////////////////////////////////////////////////////////////////////////////////////// + char DC8_9[64] = {0}; + int nbytes_read_DC8_9= 0; + tty_read_section(PortFD, DC8_9, 'A', 5, &nbytes_read_DC8_9); + DC8_9[nbytes_read_DC8_9 - 1] = '\0'; + DC8_9read =std::stoi(DC8_9); + updateDC8_9(DC8_9read); + + // DC10_11////////////////////////////////////////////////////////////////////////////////////////// + char DC10_11[64] = {0}; + int nbytes_read_DC10_11= 0; + tty_read_section(PortFD, DC10_11, 'A', 5, &nbytes_read_DC10_11); + DC10_11[nbytes_read_DC10_11 - 1] = '\0'; + DC10_11read =std::stoi(DC10_11); + updateDC10_11(DC10_11read); + + // DC34SET////////////////////////////////////////////////////////////////////////////////////////// + char DC34SET[64] = {0}; + int nbytes_read_DC34SET= 0; + tty_read_section(PortFD, DC34SET, 'A', 5, &nbytes_read_DC34SET); + DC34SET[nbytes_read_DC34SET - 1] = '\0'; + //LOGF_INFO("All Data Updated","Updated"); + DC34SETread = std::stoi(DC34SET); + updateDC34SET(DC34SETread); + + + //DC5 DEW CONTROL + if(dc5diffSP[DC5_DPD_Mode].getState() == ISS_ON) + { + if(temp1read=20240216) + { + defineProperty(CalibrateSP); + LOGF_INFO("Firmware version: %s", version); + } + else + { + LOGF_INFO("The firmware is outdated, please upgrade to the latest firmware, or power reading calibration will be unavailable.","failed"); + } + defineProperty(PowerMonitorNP); - defineProperty(&usb31ControlSP); - defineProperty(&usb32ControlSP); - defineProperty(&usb33ControlSP); - defineProperty(&usb21ControlSP); - defineProperty(&usb22ControlSP); + defineProperty(usb31ControlSP); + defineProperty(usb32ControlSP); + defineProperty(usb33ControlSP); + defineProperty(usb21ControlSP); + defineProperty(usb22ControlSP); - defineProperty(&setDC34voltageNP); - defineProperty(&dc3_4ControlSP); + defineProperty(setDC34voltageNP); + defineProperty(dc3_4ControlSP); - defineProperty(&dc8_9ControlSP); - defineProperty(&dc10_11ControlSP); + defineProperty(dc8_9ControlSP); + defineProperty(dc10_11ControlSP); - defineProperty(&dc5dewSP); - defineProperty(&dc6dewSP); - defineProperty(&dc7dewSP); + defineProperty(dc5diffSP); + defineProperty(dc6diffSP); + defineProperty(dc7diffSP); - //DC5//////////////////// - if(dc5diffS[DC5_DPD_Mode].s == ISS_ON) + //DC5//////////////////// + if(dc5diffSP[DC5_DPD_Mode].getState() == ISS_ON) { - deleteProperty(dc5constSETNP.name); - deleteProperty(dc5ControlNP.name); - defineProperty(&dc5diffSETNP); + deleteProperty(dc5constSETNP); + deleteProperty(dc5ControlNP); + defineProperty(dc5diffSETNP); } - else if(dc5diffS[DC5_CT_Mode].s == ISS_ON) + else if(dc5diffSP[DC5_CT_Mode].getState() == ISS_ON) { - deleteProperty(dc5ControlNP.name); - deleteProperty(dc5diffSETNP.name); - defineProperty(&dc5constSETNP); + deleteProperty(dc5ControlNP); + deleteProperty(dc5diffSETNP); + defineProperty(dc5constSETNP); } else { - defineProperty(&dc5ControlNP); - deleteProperty(dc5diffSETNP.name); - deleteProperty(dc5constSETNP.name); + defineProperty(dc5ControlNP); + deleteProperty(dc5diffSETNP); + deleteProperty(dc5constSETNP); } //DC6//////////////// - if(dc6diffS[DC6_DPD_Mode].s == ISS_ON) + if(dc6diffSP[DC6_DPD_Mode].getState() == ISS_ON) { - deleteProperty(dc6constSETNP.name); - deleteProperty(dc6ControlNP.name); - defineProperty(&dc6diffSETNP); + deleteProperty(dc6constSETNP); + deleteProperty(dc6ControlNP); + defineProperty(dc6diffSETNP); } - else if(dc6diffS[DC6_CT_Mode].s == ISS_ON) + else if(dc6diffSP[DC6_CT_Mode].getState() == ISS_ON) { - deleteProperty(dc6ControlNP.name); - deleteProperty(dc6diffSETNP.name); - defineProperty(&dc6constSETNP); + deleteProperty(dc6ControlNP); + deleteProperty(dc6diffSETNP); + defineProperty(dc6constSETNP); } else { - defineProperty(&dc6ControlNP); - deleteProperty(dc6diffSETNP.name); - deleteProperty(dc6constSETNP.name); + defineProperty(dc6ControlNP); + deleteProperty(dc6diffSETNP); + deleteProperty(dc6constSETNP); } //DC7//////////////// - if(dc7diffS[DC7_DPD_Mode].s == ISS_ON) + if(dc7diffSP[DC7_DPD_Mode].getState() == ISS_ON) { - deleteProperty(dc7constSETNP.name); - deleteProperty(dc7ControlNP.name); - defineProperty(&dc7diffSETNP); + deleteProperty(dc7constSETNP); + deleteProperty(dc7ControlNP); + defineProperty(dc7diffSETNP); } - else if(dc7diffS[DC7_CT_Mode].s == ISS_ON) + else if(dc7diffSP[DC7_CT_Mode].getState() == ISS_ON) { - deleteProperty(dc7ControlNP.name); - deleteProperty(dc7diffSETNP.name); - defineProperty(&dc7constSETNP); + deleteProperty(dc7ControlNP); + deleteProperty(dc7diffSETNP); + defineProperty(dc7constSETNP); } else { - defineProperty(&dc7ControlNP); - deleteProperty(dc7diffSETNP.name); - deleteProperty(dc7constSETNP.name); + defineProperty(dc7ControlNP); + deleteProperty(dc7diffSETNP); + deleteProperty(dc7constSETNP); } - defineProperty(&ENVMonitorNP); + defineProperty(ENVMonitorNP); } else { - deleteProperty(FirmwareTP.name); - deleteProperty(CalibrateSP.name); - deleteProperty(PowerMonitorNP.name); - deleteProperty(ENVMonitorNP.name); + deleteProperty(CalibrateSP); + deleteProperty(PowerMonitorNP); + deleteProperty(ENVMonitorNP); - deleteProperty(dc3_4ControlSP.name); - deleteProperty(setDC34voltageNP.name); - deleteProperty(dc8_9ControlSP.name); - deleteProperty(dc10_11ControlSP.name); - deleteProperty(usb31ControlSP.name); - deleteProperty(usb32ControlSP.name); - deleteProperty(usb33ControlSP.name); - deleteProperty(usb21ControlSP.name); - deleteProperty(usb22ControlSP.name); + deleteProperty(dc3_4ControlSP); + deleteProperty(setDC34voltageNP); + deleteProperty(dc8_9ControlSP); + deleteProperty(dc10_11ControlSP); + deleteProperty(usb31ControlSP); + deleteProperty(usb32ControlSP); + deleteProperty(usb33ControlSP); + deleteProperty(usb21ControlSP); + deleteProperty(usb22ControlSP); - deleteProperty(dc5ControlNP.name); - deleteProperty(dc6ControlNP.name); - deleteProperty(dc7ControlNP.name); + deleteProperty(dc5ControlNP); + deleteProperty(dc6ControlNP); + deleteProperty(dc7ControlNP); - deleteProperty(dc5dewSP.name); - deleteProperty(dc5diffSETNP.name); + deleteProperty(dc5diffSP); + deleteProperty(dc5diffSETNP); - deleteProperty(dc6dewSP.name); - deleteProperty(dc6diffSETNP.name); + deleteProperty(dc6diffSP); + deleteProperty(dc6diffSETNP); - deleteProperty(dc7dewSP.name); - deleteProperty(dc7diffSETNP.name); + deleteProperty(dc7diffSP); + deleteProperty(dc7diffSETNP); } @@ -826,172 +827,172 @@ bool WandererBoxProV3::updateProperties() bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { // Calibrate - if (!strcmp(name, CalibrateSP.name)) + if (CalibrateSP.isNameMatch(name)) { - CalibrateSP.s = sendCommand("66300744") ? IPS_OK : IPS_ALERT; - IDSetSwitch(&CalibrateSP, nullptr); + CalibrateSP.setState(sendCommand("66300744") ? IPS_OK : IPS_ALERT); + CalibrateSP.apply(); LOG_INFO("Calibrating Current Readings..."); return true; } // DC3-4 Control - if (!strcmp(name, dc3_4ControlSP.name)) + if (dc3_4ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&dc3_4ControlSP, states, names, n); - dc3_4ControlSP.s = IPS_ALERT; + dc3_4ControlSP.update(states, names, n); + dc3_4ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "10%d", (dc3_4ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - dc3_4ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&dc3_4ControlSP, nullptr); + snprintf(cmd, 128, "10%d", (dc3_4ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + dc3_4ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + dc3_4ControlSP.apply(); return true; } // DC8-9 Control - if (!strcmp(name, dc8_9ControlSP.name)) + if (dc8_9ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&dc8_9ControlSP, states, names, n); - dc8_9ControlSP.s = IPS_ALERT; + dc8_9ControlSP.update(states, names, n); + dc8_9ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "20%d", (dc8_9ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - dc8_9ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&dc8_9ControlSP, nullptr); + snprintf(cmd, 128, "20%d", (dc8_9ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + dc8_9ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + dc8_9ControlSP.apply(); return true; } // DC10-11 Control - if (!strcmp(name, dc10_11ControlSP.name)) + if (dc10_11ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&dc10_11ControlSP, states, names, n); - dc10_11ControlSP.s = IPS_ALERT; + dc10_11ControlSP.update(states, names, n); + dc10_11ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "21%d", (dc10_11ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - dc10_11ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&dc10_11ControlSP, nullptr); + snprintf(cmd, 128, "21%d", (dc10_11ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + dc10_11ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + dc10_11ControlSP.apply(); return true; } // USB31 Control - if (!strcmp(name, usb31ControlSP.name)) + if (usb31ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&usb31ControlSP, states, names, n); - usb31ControlSP.s = IPS_ALERT; + usb31ControlSP.update(states, names, n); + usb31ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "11%d", (usb31ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - usb31ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; + snprintf(cmd, 128, "11%d", (usb31ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + usb31ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); return true; } // USB32 Control - if (!strcmp(name, usb32ControlSP.name)) + if (usb32ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&usb32ControlSP, states, names, n); - usb32ControlSP.s = IPS_ALERT; + usb32ControlSP.update(states, names, n); + usb32ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "12%d", (usb32ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - usb32ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&usb32ControlSP, nullptr); + snprintf(cmd, 128, "12%d", (usb32ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + usb32ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + usb32ControlSP.apply(); return true; } // USB33 Control - if (!strcmp(name, usb33ControlSP.name)) + if (usb33ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&usb33ControlSP, states, names, n); - usb33ControlSP.s = IPS_ALERT; + usb33ControlSP.update(states, names, n); + usb33ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "13%d", (usb33ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - usb33ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&usb33ControlSP, nullptr); + snprintf(cmd, 128, "13%d", (usb33ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + usb33ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + usb33ControlSP.apply(); return true; } // USB21 Control - if (!strcmp(name, usb21ControlSP.name)) + if (usb21ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&usb21ControlSP, states, names, n); - usb21ControlSP.s = IPS_ALERT; + usb21ControlSP.update(states, names, n); + usb21ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "14%d", (usb21ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - usb21ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&usb21ControlSP, nullptr); + snprintf(cmd, 128, "14%d", (usb21ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + usb21ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + usb21ControlSP.apply(); return true; } // USB22 Control - if (!strcmp(name, usb22ControlSP.name)) + if (usb22ControlSP.isNameMatch(name)) { - IUUpdateSwitch(&usb22ControlSP, states, names, n); - usb22ControlSP.s = IPS_ALERT; + usb22ControlSP.update(states, names, n); + usb22ControlSP.setState(IPS_ALERT); char cmd[128] = {0}; - snprintf(cmd, 128, "15%d", (usb22ControlS[INDI_ENABLED].s == ISS_ON) ? 1 : 0); - usb22ControlSP.s = sendCommand(cmd) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&usb22ControlSP, nullptr); + snprintf(cmd, 128, "15%d", (usb22ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + usb22ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + usb22ControlSP.apply(); return true; } // DC5 DEW - if (!strcmp(name, dc5dewSP.name)) + if (dc5diffSP.isNameMatch(name)) { - IUUpdateSwitch(&dc5dewSP, states, names, n); - dc5dewSP.s = IPS_ALERT; - if(dc5diffS[DC5_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + dc5diffSP.update(states, names, n); + dc5diffSP.setState(IPS_ALERT); + if(dc5diffSP[DC5_DPD_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value!=-127&&isnan(ENVMonitorNP[DEW_Point].value)==0) { DC5DIFFMODE=true; DC5CONSTMODE=false; - deleteProperty(dc5ControlNP.name); - deleteProperty(dc5constSETNP.name); - defineProperty(&dc5diffSETNP); - - dc5diffSETNP.s = IPS_OK; - IDSetNumber(&dc5diffSETNP, nullptr); - dc5dewSP.s = IPS_OK ; - IDSetSwitch(&dc5dewSP, nullptr); + deleteProperty(dc5ControlNP); + deleteProperty(dc5constSETNP); + defineProperty(dc5diffSETNP); + + dc5diffSETNP.setState(IPS_OK); + dc5diffSETNP.apply(); + dc5diffSP.setState(IPS_OK) ; + dc5diffSP.apply(); LOGF_INFO("Dew Point Difference Mode for DC5 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); return true; } - else if(dc5diffS[DC5_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe1_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + else if(dc5diffSP[DC5_DPD_Mode].getState() == ISS_ON&&(ENVMonitorNP[Probe1_Temp].value==-127||isnan(ENVMonitorNP[DEW_Point].value)==1)) { DC5DIFFMODE=false; DC5CONSTMODE=false; - dc5diffS[DC5_Manual].s = ISS_ON; - LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); - IDSetSwitch(&dc5dewSP, nullptr); + dc5diffSP[DC5_Manual].s = ISS_ON; + LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); + dc5diffSP.apply(); } - else if(dc5diffS[DC5_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value!=-127) + else if(dc5diffSP[DC5_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value!=-127) { DC5CONSTMODE=true; DC5DIFFMODE=false; - deleteProperty(dc5diffSETNP.name); - deleteProperty(dc5ControlNP.name); - defineProperty(&dc5constSETNP); - - dc5constSETNP.s = IPS_OK; - IDSetNumber(&dc5constSETNP, nullptr); - dc5dewSP.s = IPS_OK ; - IDSetSwitch(&dc5dewSP, nullptr); + deleteProperty(dc5diffSETNP); + deleteProperty(dc5ControlNP); + defineProperty(dc5constSETNP); + + dc5constSETNP.setState(IPS_OK); + dc5constSETNP.apply(); + dc5diffSP.setState(IPS_OK) ; + dc5diffSP.apply(); LOGF_INFO("Constant Temperature Mode for DC5 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); return true; } - else if(dc5diffS[DC5_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe1_Temp].value==-127) + else if(dc5diffSP[DC5_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value==-127) { DC5DIFFMODE=false; DC5CONSTMODE=false; - dc5diffS[DC5_Manual].s = ISS_ON; + dc5diffSP[DC5_Manual].s = ISS_ON; LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); - IDSetSwitch(&dc5dewSP, nullptr); + dc5diffSP.apply(); } else { DC5DIFFMODE=false; DC5CONSTMODE=false; - defineProperty(&dc5ControlNP); - deleteProperty(dc5diffSETNP.name); - deleteProperty(dc5constSETNP.name); - dc5dewSP.s = IPS_OK ; - IDSetSwitch(&dc5dewSP, nullptr); + defineProperty(dc5ControlNP); + deleteProperty(dc5diffSETNP); + deleteProperty(dc5constSETNP); + dc5diffSP.setState(IPS_OK) ; + dc5diffSP.apply(); LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); return true; } @@ -999,65 +1000,65 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s } // DC6 DEW - if (!strcmp(name, dc6dewSP.name)) + if (dc6diffSP.isNameMatch(name)) { - IUUpdateSwitch(&dc6dewSP, states, names, n); - dc6dewSP.s = IPS_ALERT; - if(dc6diffS[DC6_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + dc6diffSP.update(states, names, n); + dc6diffSP.setState(IPS_ALERT); + if(dc6diffSP[DC6_DPD_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe2_Temp].value!=-127&&isnan(ENVMonitorNP[DEW_Point].value)==0) { DC6DIFFMODE=true; DC6CONSTMODE=false; - deleteProperty(dc6ControlNP.name); - deleteProperty(dc6constSETNP.name); - defineProperty(&dc6diffSETNP); - - dc6diffSETNP.s = IPS_OK; - IDSetNumber(&dc6diffSETNP, nullptr); - dc6dewSP.s = IPS_OK ; - IDSetSwitch(&dc6dewSP, nullptr); + deleteProperty(dc6ControlNP); + deleteProperty(dc6constSETNP); + defineProperty(dc6diffSETNP); + + dc6diffSETNP.setState(IPS_OK); + dc6diffSETNP.apply(); + dc6diffSP.setState(IPS_OK) ; + dc6diffSP.apply(); LOGF_INFO("Dew Point Difference Mode for DC6 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); return true; } - else if(dc6diffS[DC6_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe2_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + else if(dc6diffSP[DC6_DPD_Mode].getState() == ISS_ON&&(ENVMonitorNP[Probe2_Temp].value==-127||isnan(ENVMonitorNP[DEW_Point].value)==1)) { DC6DIFFMODE=false; DC6CONSTMODE=false; - dc6diffS[DC6_Manual].s = ISS_ON; + dc6diffSP[DC6_Manual].s = ISS_ON; LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); - IDSetSwitch(&dc6dewSP, nullptr); + dc6diffSP.apply(); } - else if(dc6diffS[DC6_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value!=-127) + else if(dc6diffSP[DC6_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe2_Temp].value!=-127) { DC6CONSTMODE=true; DC6DIFFMODE=false; - deleteProperty(dc6diffSETNP.name); - deleteProperty(dc6ControlNP.name); - defineProperty(&dc6constSETNP); - - dc6constSETNP.s = IPS_OK; - IDSetNumber(&dc6constSETNP, nullptr); - dc6dewSP.s = IPS_OK ; - IDSetSwitch(&dc6dewSP, nullptr); + deleteProperty(dc6diffSETNP); + deleteProperty(dc6ControlNP); + defineProperty(dc6constSETNP); + + dc6constSETNP.setState(IPS_OK); + dc6constSETNP.apply(); + dc6diffSP.setState(IPS_OK) ; + dc6diffSP.apply(); LOGF_INFO("Constant Temperature Mode for DC6 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); return true; } - else if(dc6diffS[DC6_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe2_Temp].value==-127) + else if(dc6diffSP[DC6_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe2_Temp].value==-127) { DC6DIFFMODE=false; DC6CONSTMODE=false; - dc6diffS[DC6_Manual].s = ISS_ON; + dc6diffSP[DC6_Manual].s = ISS_ON; LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); - IDSetSwitch(&dc6dewSP, nullptr); + dc6diffSP.apply(); } else { DC6DIFFMODE=false; DC6CONSTMODE=false; - defineProperty(&dc6ControlNP); - deleteProperty(dc6diffSETNP.name); - deleteProperty(dc6constSETNP.name); - dc6dewSP.s = IPS_OK ; - IDSetSwitch(&dc6dewSP, nullptr); + defineProperty(dc6ControlNP); + deleteProperty(dc6diffSETNP); + deleteProperty(dc6constSETNP); + dc6diffSP.setState(IPS_OK) ; + dc6diffSP.apply(); LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); return true; } @@ -1065,72 +1066,72 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s } // DC7 DEW - if (!strcmp(name, dc7dewSP.name)) + if (dc7diffSP.isNameMatch(name)) { - IUUpdateSwitch(&dc7dewSP, states, names, n); - dc7dewSP.s = IPS_ALERT; - if(dc7diffS[DC7_DPD_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value!=-127&&isnan(ENVMonitorN[DEW_Point].value)==0) + dc7diffSP.update(states, names, n); + dc7diffSP.setState(IPS_ALERT); + if(dc7diffSP[DC7_DPD_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe3_Temp].value!=-127&&isnan(ENVMonitorNP[DEW_Point].value)==0) { DC7DIFFMODE=true; DC7CONSTMODE=false; - deleteProperty(dc7ControlNP.name); - deleteProperty(dc7constSETNP.name); - defineProperty(&dc7diffSETNP); - - dc7diffSETNP.s = IPS_OK; - IDSetNumber(&dc7diffSETNP, nullptr); - dc7dewSP.s = IPS_OK ; - IDSetSwitch(&dc7dewSP, nullptr); + deleteProperty(dc7ControlNP); + deleteProperty(dc7constSETNP); + defineProperty(dc7diffSETNP); + + dc7diffSETNP.setState(IPS_OK); + dc7diffSETNP.apply(); + dc7diffSP.setState(IPS_OK) ; + dc7diffSP.apply(); LOGF_INFO("Dew Point Difference Mode for DC7 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); return true; } - else if(dc7diffS[DC7_DPD_Mode].s == ISS_ON&&(ENVMonitorN[Probe3_Temp].value==-127||isnan(ENVMonitorN[DEW_Point].value)==1)) + else if(dc7diffSP[DC7_DPD_Mode].getState() == ISS_ON&&(ENVMonitorNP[Probe3_Temp].value==-127||isnan(ENVMonitorNP[DEW_Point].value)==1)) { DC7DIFFMODE=false; DC7CONSTMODE=false; - dc7diffS[DC7_Manual].s = ISS_ON; + dc7diffSP[DC7_Manual].s = ISS_ON; LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); - IDSetSwitch(&dc7dewSP, nullptr); + dc7diffSP.apply(); } - else if(dc7diffS[DC7_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value!=-127) + else if(dc7diffSP[DC7_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe3_Temp].value!=-127) { DC7CONSTMODE=true; DC7DIFFMODE=false; - deleteProperty(dc7diffSETNP.name); - deleteProperty(dc7ControlNP.name); - defineProperty(&dc7constSETNP); - - dc7constSETNP.s = IPS_OK; - IDSetNumber(&dc7constSETNP, nullptr); - dc7dewSP.s = IPS_OK ; - IDSetSwitch(&dc7dewSP, nullptr); + deleteProperty(dc7diffSETNP); + deleteProperty(dc7ControlNP); + defineProperty(dc7constSETNP); + + dc7constSETNP.setState(IPS_OK); + dc7constSETNP.apply(); + dc7diffSP.setState(IPS_OK) ; + dc7diffSP.apply(); LOGF_INFO("Constant Temperature Mode for DC7 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); return true; } - else if(dc7diffS[DC7_CT_Mode].s == ISS_ON&&ENVMonitorN[Probe3_Temp].value==-127) + else if(dc7diffSP[DC7_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe3_Temp].value==-127) { DC7DIFFMODE=false; DC7CONSTMODE=false; - dc7diffS[DC7_Manual].s = ISS_ON; + dc7diffSP[DC7_Manual].s = ISS_ON; LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); - IDSetSwitch(&dc7dewSP, nullptr); + dc7diffSP.apply(); } else { DC7DIFFMODE=false; DC7CONSTMODE=false; - defineProperty(&dc7ControlNP); - deleteProperty(dc7diffSETNP.name); - deleteProperty(dc7constSETNP.name); - dc7dewSP.s = IPS_OK ; - IDSetSwitch(&dc7dewSP, nullptr); + defineProperty(dc7ControlNP); + deleteProperty(dc7diffSETNP); + deleteProperty(dc7constSETNP); + dc7diffSP.setState(IPS_OK) ; + dc7diffSP.apply(); LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); return true; } } - return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); + return DefaultDevice::ISNewSwitch(dev, name, states, names, n); } bool WandererBoxProV3::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) @@ -1138,121 +1139,117 @@ bool WandererBoxProV3::ISNewNumber(const char * dev, const char * name, double v if (dev && !strcmp(dev, getDeviceName())) { // DC5 - if (!strcmp(name, dc5ControlNP.name)) + if (dc5ControlNP.isNameMatch(name)) { bool rc1 = false; for (int i = 0; i < n; i++) { - if (!strcmp(names[i], dc5ControlN[DC5].name)) - rc1 = setDewPWM(5, static_cast(values[i])); + rc1 = setDewPWM(5, static_cast(values[i])); } - dc5ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (dc5ControlNP.s == IPS_OK) - IUUpdateNumber(&dc5ControlNP, values, names, n); - IDSetNumber(&dc5ControlNP, nullptr); + dc5ControlNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (dc5ControlNP.getState() == IPS_OK) + dc5ControlNP.update(values, names, n); + dc5ControlNP.apply(); return true; } - if (!strcmp(name, dc5diffSETNP.name)) + if (dc5diffSETNP.isNameMatch(name)) { - dc5diffSETNP.s = IPS_OK ; - if (dc5diffSETNP.s == IPS_OK) - IUUpdateNumber(&dc5diffSETNP, values, names, n); - IDSetNumber(&dc5diffSETNP, nullptr); + dc5diffSETNP.setState(IPS_OK) ; + if (dc5diffSETNP.getState() == IPS_OK) + dc5diffSETNP.update(values, names, n); + dc5diffSETNP.apply(); return true; } - if (!strcmp(name, dc5constSETNP.name)) + if (dc5constSETNP.isNameMatch(name)) { - dc5constSETNP.s = IPS_OK ; - if (dc5constSETNP.s == IPS_OK) - IUUpdateNumber(&dc5constSETNP, values, names, n); - IDSetNumber(&dc5constSETNP, nullptr); + dc5constSETNP.setState(IPS_OK) ; + if (dc5constSETNP.getState() == IPS_OK) + dc5constSETNP.update(values, names, n); + dc5constSETNP.apply(); return true; } // DC6 - if (!strcmp(name, dc6ControlNP.name)) + if (dc6ControlNP.isNameMatch(name)) { bool rc1 = false; for (int i = 0; i < n; i++) { - if (!strcmp(names[i], dc6ControlN[DC6].name)) rc1 = setDewPWM(6, static_cast(values[i])); } - dc6ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (dc6ControlNP.s == IPS_OK) - IUUpdateNumber(&dc6ControlNP, values, names, n); - IDSetNumber(&dc6ControlNP, nullptr); + dc6ControlNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (dc6ControlNP.getState() == IPS_OK) + dc6ControlNP.update(values, names, n); + dc6ControlNP.apply(); return true; } - if (!strcmp(name, dc6diffSETNP.name)) + if (dc6diffSETNP.isNameMatch(name)) { - dc6diffSETNP.s = IPS_OK ; - if (dc6diffSETNP.s == IPS_OK) - IUUpdateNumber(&dc6diffSETNP, values, names, n); - IDSetNumber(&dc6diffSETNP, nullptr); + dc6diffSETNP.setState(IPS_OK) ; + if (dc6diffSETNP.getState() == IPS_OK) + dc6diffSETNP.update(values, names, n); + dc6diffSETNP.apply(); return true; } - if (!strcmp(name, dc6constSETNP.name)) + if (dc6constSETNP.isNameMatch(name)) { - dc6constSETNP.s = IPS_OK ; - if (dc6constSETNP.s == IPS_OK) - IUUpdateNumber(&dc6constSETNP, values, names, n); - IDSetNumber(&dc6constSETNP, nullptr); + dc6constSETNP.setState(IPS_OK) ; + if (dc6constSETNP.getState() == IPS_OK) + dc6constSETNP.update(values, names, n); + dc6constSETNP.apply(); return true; } // DC7 - if (!strcmp(name, dc7ControlNP.name)) + if (dc7ControlNP.isNameMatch(name)) { bool rc1 = false; for (int i = 0; i < n; i++) { - if (!strcmp(names[i], dc7ControlN[DC6].name)) rc1 = setDewPWM(7, static_cast(values[i])); } - dc7ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (dc7ControlNP.s == IPS_OK) - IUUpdateNumber(&dc7ControlNP, values, names, n); - IDSetNumber(&dc7ControlNP, nullptr); + dc7ControlNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (dc7ControlNP.getState() == IPS_OK) + dc7ControlNP.update(values, names, n); + dc7ControlNP.apply(); return true; } - if (!strcmp(name, dc7diffSETNP.name)) + if (dc7diffSETNP.isNameMatch(name)) { - dc7diffSETNP.s = IPS_OK ; - if (dc7diffSETNP.s == IPS_OK) - IUUpdateNumber(&dc7diffSETNP, values, names, n); - IDSetNumber(&dc7diffSETNP, nullptr); + dc7diffSETNP.setState(IPS_OK) ; + if (dc7diffSETNP.getState() == IPS_OK) + dc7diffSETNP.update(values, names, n); + dc7diffSETNP.apply(); return true; } - if (!strcmp(name, dc7constSETNP.name)) + if (dc7constSETNP.isNameMatch(name)) { - dc7constSETNP.s = IPS_OK ; - if (dc7constSETNP.s == IPS_OK) - IUUpdateNumber(&dc7constSETNP, values, names, n); - IDSetNumber(&dc7constSETNP, nullptr); + dc7constSETNP.setState(IPS_OK) ; + if (dc7constSETNP.getState() == IPS_OK) + dc7constSETNP.update(values, names, n); + dc7constSETNP.apply(); return true; } // DC34voltageSET - if (!strcmp(name, setDC34voltageNP.name)) + if (setDC34voltageNP.isNameMatch(name)) { bool rc1 = false; for (int i = 0; i < n; i++) { - if (!strcmp(names[i], setDC34voltageN[setDC34voltage].name)) rc1 = setDewPWM(20, static_cast(10*values[i])); } - setDC34voltageNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (setDC34voltageNP.s == IPS_OK) - IUUpdateNumber(&setDC34voltageNP, values, names, n); - IDSetNumber(&setDC34voltageNP, nullptr); + setDC34voltageNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (setDC34voltageNP.getState() == IPS_OK) + setDC34voltageNP.update(values, names, n); + setDC34voltageNP.apply(); return true; } @@ -1310,23 +1307,22 @@ bool WandererBoxProV3::saveConfigItems(FILE * fp) { INDI::DefaultDevice::saveConfigItems(fp); - IUSaveConfigSwitch(fp, &dc5dewSP); - IUSaveConfigNumber(fp, &dc5diffSETNP); - IUSaveConfigNumber(fp, &dc5constSETNP); - IUSaveConfigNumber(fp, &dc5ControlNP); + dc5diffSP.save(fp); + dc5diffSETNP.save(fp); + dc5constSETNP.save(fp); + dc5ControlNP.save(fp); - IUSaveConfigSwitch(fp, &dc6dewSP); - IUSaveConfigNumber(fp, &dc6diffSETNP); - IUSaveConfigNumber(fp, &dc6constSETNP); - IUSaveConfigNumber(fp, &dc6ControlNP); + dc6diffSP.save(fp); + dc6diffSETNP.save(fp); + dc6constSETNP.save(fp); + dc6ControlNP.save(fp); - IUSaveConfigSwitch(fp, &dc7dewSP); - IUSaveConfigNumber(fp, &dc7diffSETNP); - IUSaveConfigNumber(fp, &dc7constSETNP); - IUSaveConfigNumber(fp, &dc7ControlNP); + dc7diffSP.save(fp); + dc7diffSETNP.save(fp); + dc7constSETNP.save(fp); + dc7ControlNP.save(fp); - IUSaveConfigNumber(fp, &setDC34voltageNP); + setDC34voltageNP.save(fp); return true; } - diff --git a/drivers/auxiliary/wandererbox_pro_v3.h b/drivers/auxiliary/wandererbox_pro_v3.h index 149a6654ff..f5aaf9247c 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.h +++ b/drivers/auxiliary/wandererbox_pro_v3.h @@ -1,7 +1,7 @@ /******************************************************************************* Copyright(c) 2015 Jasem Mutlaq. All rights reserved. - Simple GPS Simulator + WandererBox Pro V3 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -35,246 +35,223 @@ class Serial; class WandererBoxProV3 : public INDI::DefaultDevice { - public: - WandererBoxProV3(); - virtual ~WandererBoxProV3() = default; - - virtual bool initProperties() override; - virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; - virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; - virtual bool updateProperties() override; - - - - protected: - const char *getDefaultName() override; - virtual bool saveConfigItems(FILE *fp) override; - virtual void TimerHit() override; - - - private: - - bool sendCommand(std::string command); - bool DC5DIFFMODE=false; - bool DC5CONSTMODE=false; - bool DC6DIFFMODE=false; - bool DC6CONSTMODE=false; - bool DC7DIFFMODE=false; - bool DC7CONSTMODE=false; - bool getData(); - static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; - static constexpr const char *DC5_TAB {"DC5"}; - static constexpr const char *DC6_TAB {"DC6"}; - static constexpr const char *DC7_TAB {"DC7"}; - //Current Calibrate - ISwitch CalibrateS[1]; - ISwitchVectorProperty CalibrateSP; - - // Firmware version - ITextVectorProperty FirmwareTP; - IText FirmwareT[1] {}; - //Temp1 - double temp1read = 0; - //Temp2 - double temp2read = 0; - //Temp3 - double temp3read = 0; - //DHTH - double DHTHread = 0; - //DHTT - void updateENV(double temp1,double temp2,double temp3,double DHTH,double DHTT); - double DHTTread = 0; - //Total Current - double Tcurrentread = 0; - //19V Current - double V19currentread = 0; - //Adjustable Regulator Current - double ARcurrentread = 0; - //Power Monitor - void updatePower(double Tcurrent,double V19_current,double AR_current,double voltage); - double voltageread = 0; - //USB31 - void updateUSB31(int value); - int USB31read = 0; - //USB32 - void updateUSB32(int value); - int USB32read = 0; - //USB33 - void updateUSB33(int value); - int USB33read = 0; - //USB21 - void updateUSB21(int value); - int USB21read = 0; - //USB22 - void updateUSB22(int value); - int USB22read = 0; - //DC34 - void updateDC34(int value); - int DC34read = 0; - //DC5 - void updateDC5(int value); - int DC5read = 0; - //DC6 - void updateDC6(int value); - int DC6read = 0; - //DC7 - void updateDC7(int value); - int DC7read = 0; - //DC8_9 - void updateDC8_9(int value); - int DC8_9read = 0; - //DC10_11 - void updateDC10_11(int value); - int DC10_11read = 0; - //DC34set - void updateDC34SET(double value); - int DC34SETread = 0; - - bool setDewPWM(uint8_t id, uint8_t value); - - //DC Control////////////////////////////////////////////////////////////////////////////////// - ISwitchVectorProperty dc3_4ControlSP; - ISwitch dc3_4ControlS[2]; - ISwitchVectorProperty dc8_9ControlSP; - ISwitch dc8_9ControlS[2]; - ISwitchVectorProperty dc10_11ControlSP; - ISwitch dc10_11ControlS[2]; - //USB Control////////////////////////////////////////////////////////////////////////////////// - ISwitchVectorProperty usb31ControlSP; - ISwitch usb31ControlS[2]; - ISwitchVectorProperty usb32ControlSP; - ISwitch usb32ControlS[2]; - ISwitchVectorProperty usb33ControlSP; - ISwitch usb33ControlS[2]; - ISwitchVectorProperty usb21ControlSP; - ISwitch usb21ControlS[2]; - ISwitchVectorProperty usb22ControlSP; - ISwitch usb22ControlS[2]; - //DC5 Control//////////////////////////////////////////////////////////////// - INumber dc5ControlN[1]; - INumberVectorProperty dc5ControlNP; - enum - { - DC5, - }; - //DC6 Control//////////////////////////////////////////////////////////////// - INumber dc6ControlN[1]; - INumberVectorProperty dc6ControlNP; - enum - { - DC6, - }; - //DC7 Control//////////////////////////////////////////////////////////////// - INumber dc7ControlN[1]; - INumberVectorProperty dc7ControlNP; - enum - { - DC7, - }; - //DC5 DIFF//////////////////////////////////////////////////////////////// - ISwitchVectorProperty dc5dewSP; - ISwitch dc5diffS[3]; - enum - { - DC5_Manual, - DC5_DPD_Mode, - DC5_CT_Mode, - }; - - INumber dc5diffSETN[1]; - INumberVectorProperty dc5diffSETNP; - enum - { - DC5DIFFSET, - }; - INumber dc5constSETN[1]; - INumberVectorProperty dc5constSETNP; - enum - { - DC5CONSTSET, - }; - - //DC6 DIFF//////////////////////////////////////////////////////////////// - ISwitchVectorProperty dc6dewSP; - ISwitch dc6diffS[3]; - enum - { - DC6_Manual, - DC6_DPD_Mode, - DC6_CT_Mode, - }; - - INumber dc6diffSETN[1]; - INumberVectorProperty dc6diffSETNP; - enum - { - DC6DIFFSET, - }; - INumber dc6constSETN[1]; - INumberVectorProperty dc6constSETNP; - enum - { - DC6CONSTSET, - }; - - //DC7 DIFF//////////////////////////////////////////////////////////////// - ISwitchVectorProperty dc7dewSP; - ISwitch dc7diffS[3]; - enum - { - DC7_Manual, - DC7_DPD_Mode, - DC7_CT_Mode, - }; - - INumber dc7diffSETN[1]; - INumberVectorProperty dc7diffSETNP; - enum - { - DC7DIFFSET, - }; - INumber dc7constSETN[1]; - INumberVectorProperty dc7constSETNP; - enum - { - DC7CONSTSET, - }; - - //DC34 Voltage Control//////////////////////////////////////////////////////////////// - INumber setDC34voltageN[1]; - INumberVectorProperty setDC34voltageNP; - enum - { - setDC34voltage, - }; - - // Power Monitor - INumber PowerMonitorN[4]; - INumberVectorProperty PowerMonitorNP; - enum - { - VOLTAGE, - TOTAL_CURRENT, - V19_CURRENT, - AR_CURRENT, - }; - - // ENV Monitor - INumber ENVMonitorN[6]; - INumberVectorProperty ENVMonitorNP; - enum - { - Probe1_Temp, - Probe2_Temp, - Probe3_Temp, - ENV_Humidity, - ENV_Temp, - DEW_Point, - }; - - - - int PortFD{ -1 }; - - Connection::Serial *serialConnection{ nullptr }; +public: + WandererBoxProV3(); + virtual ~WandererBoxProV3() = default; + + virtual bool initProperties() override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool updateProperties() override; + + + +protected: + const char *getDefaultName() override; + virtual bool saveConfigItems(FILE *fp) override; + virtual void TimerHit() override; + + +private: + + char version[64] = {0}; + bool sendCommand(std::string command); + bool DC5DIFFMODE=false; + bool DC5CONSTMODE=false; + bool DC6DIFFMODE=false; + bool DC6CONSTMODE=false; + bool DC7DIFFMODE=false; + bool DC7CONSTMODE=false; + bool getData(); + static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; + static constexpr const char *DC5_TAB {"DC5"}; + static constexpr const char *DC6_TAB {"DC6"}; + static constexpr const char *DC7_TAB {"DC7"}; + //Current Calibrate + INDI::PropertySwitch CalibrateSP{1}; + + + //Temp1 + double temp1read = 0; + //Temp2 + double temp2read = 0; + //Temp3 + double temp3read = 0; + //DHTH + double DHTHread = 0; + //DHTT + void updateENV(double temp1,double temp2,double temp3,double DHTH,double DHTT); + double DHTTread = 0; + //Total Current + double Tcurrentread = 0; + //19V Current + double V19currentread = 0; + //Adjustable Regulator Current + double ARcurrentread = 0; + //Power Monitor + void updatePower(double Tcurrent,double V19_current,double AR_current,double voltage); + double voltageread = 0; + //USB31 + void updateUSB31(int value); + int USB31read = 0; + //USB32 + void updateUSB32(int value); + int USB32read = 0; + //USB33 + void updateUSB33(int value); + int USB33read = 0; + //USB21 + void updateUSB21(int value); + int USB21read = 0; + //USB22 + void updateUSB22(int value); + int USB22read = 0; + //DC34 + void updateDC34(int value); + int DC34read = 0; + //DC5 + void updateDC5(int value); + int DC5read = 0; + //DC6 + void updateDC6(int value); + int DC6read = 0; + //DC7 + void updateDC7(int value); + int DC7read = 0; + //DC8_9 + void updateDC8_9(int value); + int DC8_9read = 0; + //DC10_11 + void updateDC10_11(int value); + int DC10_11read = 0; + //DC34set + void updateDC34SET(double value); + int DC34SETread = 0; + + bool setDewPWM(uint8_t id, uint8_t value); + + //DC Control////////////////////////////////////////////////////////////////////////////////// + INDI::PropertySwitch dc3_4ControlSP{2}; + INDI::PropertySwitch dc8_9ControlSP{2}; + INDI::PropertySwitch dc10_11ControlSP{2}; + //USB Control////////////////////////////////////////////////////////////////////////////////// + INDI::PropertySwitch usb31ControlSP{2}; + INDI::PropertySwitch usb32ControlSP{2}; + INDI::PropertySwitch usb33ControlSP{2}; + INDI::PropertySwitch usb21ControlSP{2}; + INDI::PropertySwitch usb22ControlSP{2}; + //DC5 Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber dc5ControlNP{1}; + enum + { + DC5, + }; + //DC6 Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber dc6ControlNP{1}; + enum + { + DC6, + }; + //DC7 Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber dc7ControlNP{1}; + enum + { + DC7, + }; + //DC5 DIFF//////////////////////////////////////////////////////////////// + INDI::PropertySwitch dc5diffSP{3}; + enum + { + DC5_Manual, + DC5_DPD_Mode, + DC5_CT_Mode, + }; + + INDI::PropertyNumber dc5diffSETNP{1}; + enum + { + DC5DIFFSET, + }; + INDI::PropertyNumber dc5constSETNP{1}; + enum + { + DC5CONSTSET, + }; + + //DC6 DIFF//////////////////////////////////////////////////////////////// + INDI::PropertySwitch dc6diffSP{3}; + enum + { + DC6_Manual, + DC6_DPD_Mode, + DC6_CT_Mode, + }; + + INDI::PropertyNumber dc6diffSETNP{1}; + enum + { + DC6DIFFSET, + }; + INDI::PropertyNumber dc6constSETNP{1}; + enum + { + DC6CONSTSET, + }; + + //DC7 DIFF//////////////////////////////////////////////////////////////// + INDI::PropertySwitch dc7diffSP{3}; + enum + { + DC7_Manual, + DC7_DPD_Mode, + DC7_CT_Mode, + }; + + INDI::PropertyNumber dc7diffSETNP{1}; + enum + { + DC7DIFFSET, + }; + INDI::PropertyNumber dc7constSETNP{1}; + enum + { + DC7CONSTSET, + }; + + //DC34 Voltage Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber setDC34voltageNP{1}; + enum + { + setDC34voltage, + }; + + // Power Monitor + + INDI::PropertyNumber PowerMonitorNP{4}; + enum + { + VOLTAGE, + TOTAL_CURRENT, + V19_CURRENT, + AR_CURRENT, + }; + + // ENV Monitor + + INDI::PropertyNumber ENVMonitorNP{6}; + enum + { + Probe1_Temp, + Probe2_Temp, + Probe3_Temp, + ENV_Humidity, + ENV_Temp, + DEW_Point, + }; + + + + int PortFD{ -1 }; + + Connection::Serial *serialConnection{ nullptr }; }; From 6db03ab5bea722dfe5968aa6f36a338d513a4fd5 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 07:51:07 +0800 Subject: [PATCH 4/9] Driver for WandererBox Pro V3 updated --- drivers.xml | 4 - drivers/auxiliary/CMakeLists.txt | 9 - drivers/auxiliary/wandererbox_plus_v3.cpp | 692 ---------------------- drivers/auxiliary/wandererbox_plus_v3.h | 170 ------ 4 files changed, 875 deletions(-) delete mode 100644 drivers/auxiliary/wandererbox_plus_v3.cpp delete mode 100644 drivers/auxiliary/wandererbox_plus_v3.h diff --git a/drivers.xml b/drivers.xml index 6ccf58b079..da691c0579 100644 --- a/drivers.xml +++ b/drivers.xml @@ -753,10 +753,6 @@ indi_wandererbox_pro_v3 1.0 - - indi_wandererbox_plus_v3 - 1.0 - diff --git a/drivers/auxiliary/CMakeLists.txt b/drivers/auxiliary/CMakeLists.txt index dfb862db22..b68e845325 100644 --- a/drivers/auxiliary/CMakeLists.txt +++ b/drivers/auxiliary/CMakeLists.txt @@ -1,15 +1,6 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") INSTALL(FILES 99-indi_auxiliary.rules DESTINATION ${UDEVRULES_INSTALL_DIR}) ENDIF() -# ########## Wanderer Box Plus V3 ############### -SET(indi_wandererbox_plus_v3_SRC - wandererbox_plus_v3.cpp) - -add_executable(indi_wandererbox_plus_v3 ${indi_wandererbox_plus_v3_SRC}) -target_link_libraries(indi_wandererbox_plus_v3 indidriver) -install(TARGETS indi_wandererbox_plus_v3 RUNTIME DESTINATION bin) - - # ########## Wanderer Box Pro V3 ############### SET(indi_wandererbox_pro_v3_SRC wandererbox_pro_v3.cpp) diff --git a/drivers/auxiliary/wandererbox_plus_v3.cpp b/drivers/auxiliary/wandererbox_plus_v3.cpp deleted file mode 100644 index 83ac7e3713..0000000000 --- a/drivers/auxiliary/wandererbox_plus_v3.cpp +++ /dev/null @@ -1,692 +0,0 @@ -/******************************************************************************* - Copyright(c) 2015 Jasem Mutlaq. All rights reserved. - - WandererBox Plus V3 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - The full GNU General Public License is included in this distribution in the - file called LICENSE. -*******************************************************************************/ - -#include "wandererbox_plus_v3.h" -#include "indicom.h" -#include "connectionplugins/connectionserial.h" -#include -#include -#include -#include -#include -#include -#include -#include - -// We declare an auto pointer to WandererBoxPlusV3. -static std::unique_ptr wandererboxplusv3(new WandererBoxPlusV3()); - - - -WandererBoxPlusV3::WandererBoxPlusV3() -{ - setVersion(1, 0); -} - -bool WandererBoxPlusV3::initProperties() -{ - - INDI::DefaultDevice::initProperties(); - setDriverInterface(AUX_INTERFACE); - - - addAuxControls(); - - - // Calibrate - IUFillSwitch(&CalibrateS[0], "Calibrate", "Calibrate Current", ISS_OFF); - IUFillSwitchVector(&CalibrateSP, CalibrateS, 1, getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); - - // Power Monitor - IUFillNumber(&PowerMonitorN[VOLTAGE], "VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerMonitorN[TOTAL_CURRENT], "TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumberVector(&PowerMonitorNP, PowerMonitorN, 2, getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); - - - - // Firmware version - IUFillText(&FirmwareT[0], "Version", "Version", nullptr); - - - // USB Control - IUFillSwitch(&USBControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&USBControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&USBControlSP, USBControlS, 2, getDeviceName(), "USB3.0_1", "USB3.0_1", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - - - // DC3 - IUFillNumber(&DC3ControlN[DC3], "DC3", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); - IUFillNumberVector(&DC3ControlNP, DC3ControlN, 1, getDeviceName(), "PWM", "DC3", DC3_TAB, IP_RW, 60, IPS_IDLE); - - // DC2SET - IUFillNumber(&setDC2voltageN[setDC2voltage], "DC2SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); - IUFillNumberVector(&setDC2voltageNP, setDC2voltageN, 1, getDeviceName(), "DC2voltageSET", "Set DC2", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); - // DC2 Control - IUFillSwitch(&DC2ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&DC2ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&DC2ControlSP, DC2ControlS, 2, getDeviceName(), "DC2", "DC2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - - // DC4-6 Control - IUFillSwitch(&DC4_6ControlS[INDI_ENABLED], "INDI_ENABLED", "On", ISS_OFF); - IUFillSwitch(&DC4_6ControlS[INDI_DISABLED], "INDI_DISABLED", "Off", ISS_ON); - IUFillSwitchVector(&DC4_6ControlSP, DC4_6ControlS, 2, getDeviceName(), "DC4-6", "DC4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - - // DC3 TEMP Difference Control - IUFillSwitch(&DC3diffS[DC3_Manual], "Manual", "Manual", ISS_ON); - IUFillSwitch(&DC3diffS[DC3_DPD_Mode], "DPD_Mode", "DPD Mode", ISS_OFF); - IUFillSwitch(&DC3diffS[DC3_CT_Mode], "CT_Mode", "CT Mode", ISS_OFF); - IUFillSwitchVector(&DC3dewSP, DC3diffS, 3, getDeviceName(), "DC3_DIFF", "DC3 Dew Mode", DC3_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); - - IUFillNumber(&DC3diffSETN[DC3DIFFSET], "DC3 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); - IUFillNumberVector(&DC3diffSETNP, DC3diffSETN, 1, getDeviceName(), "DC3_DIFF_SET", "DPD Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); - - IUFillNumber(&DC3constSETN[DC3CONSTSET], "DC3 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); - IUFillNumberVector(&DC3constSETNP, DC3constSETN, 1, getDeviceName(), "DC3_CONST_SET", "CT Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); - - //ENV - IUFillNumber(&ENVMonitorN[Probe1_Temp], "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[ENV_Humidity], "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[ENV_Temp], "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&ENVMonitorN[DEW_Point], "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); - IUFillNumberVector(&ENVMonitorNP, ENVMonitorN, 4, getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); - serialConnection = new Connection::Serial(this); - serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); - serialConnection->registerHandshake([&]() - { - return getData(); - }); - registerConnection(serialConnection); - - return true; -} - -bool WandererBoxPlusV3::getData() -{ - try - { - PortFD = serialConnection->getPortFD(); - tcflush(PortFD, TCIOFLUSH); - int nbytes_read_name = 0,rc=-1; - char name[64] = {0}; - - //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// - if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) - { - char errorMessage[MAXRBUF]; - tty_error_msg(rc, errorMessage, MAXRBUF); - LOGF_INFO("No data received, the device may not be WandererBox Pro V3, please check the serial port!","Updated"); - LOGF_ERROR("Device read error: %s", errorMessage); - return false; - } - name[nbytes_read_name - 1] = '\0'; - if(strcmp(name, "ZXWBProV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) - { - LOGF_INFO("The device is not WandererBox Pro V3!","Updated"); - return false; - } - if(strcmp(name, "ZXWBPlusV3")!=0) - throw std::exception(); - // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// - int nbytes_read_version = 0; - char version[64] = {0}; - tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); - - version[nbytes_read_version - 1] = '\0'; - IUSaveText(&FirmwareT[0], version); - IDSetText(&FirmwareTP, nullptr); - if(std::stoi(version)<=20240216) - { - deleteProperty(CalibrateSP.name); - } - - // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// - char temp1[64] = {0}; - int nbytes_read_temp1= 0; - tty_read_section(PortFD, temp1, 'A', 5, &nbytes_read_temp1); - temp1[nbytes_read_temp1 - 1] = '\0'; - temp1read = std::strtod(temp1,NULL); - - // DHTH////////////////////////////////////////////////////////////////////////////////////////// - char DHTH[64] = {0}; - int nbytes_read_DHTH= 0; - tty_read_section(PortFD, DHTH, 'A', 5, &nbytes_read_DHTH); - DHTH[nbytes_read_DHTH - 1] = '\0'; - DHTHread = std::strtod(DHTH,NULL); - - // DHTT////////////////////////////////////////////////////////////////////////////////////////// - char DHTT[64] = {0}; - int nbytes_read_DHTT= 0; - tty_read_section(PortFD, DHTT, 'A', 5, &nbytes_read_DHTT); - DHTT[nbytes_read_DHTT - 1] = '\0'; - DHTTread = std::strtod(DHTT,NULL); - updateENV(temp1read,DHTHread,DHTTread); - - // Total current////////////////////////////////////////////////////////////////////////////////////////// - char Tcurrent[64] = {0}; - int nbytes_read_Tcurrent= 0; - tty_read_section(PortFD, Tcurrent, 'A', 5, &nbytes_read_Tcurrent); - Tcurrent[nbytes_read_Tcurrent - 1] = '\0'; - Tcurrentread = std::strtod(Tcurrent,NULL); - - - // Voltage////////////////////////////////////////////////////////////////////////////////////////// - char voltage[64] = {0}; - int nbytes_read_voltage= 0; - tty_read_section(PortFD, voltage, 'A', 5, &nbytes_read_voltage); - voltage[nbytes_read_voltage - 1] = '\0'; - voltageread = std::strtod(voltage,NULL); - updatePower(Tcurrentread,voltageread); - - // USB////////////////////////////////////////////////////////////////////////////////////////// - char USB[64] = {0}; - int nbytes_read_USB= 0; - tty_read_section(PortFD, USB, 'A', 5, &nbytes_read_USB); - USB[nbytes_read_USB - 1] = '\0'; - USBread = std::stoi(USB); - updateUSB(USBread); - - // DC2////////////////////////////////////////////////////////////////////////////////////////// - char DC2[64] = {0}; - int nbytes_read_DC2= 0; - tty_read_section(PortFD, DC2, 'A', 5, &nbytes_read_DC2); - DC2[nbytes_read_DC2 - 1] = '\0'; - DC2read = std::stoi(DC2); - updateDC2(DC2read); - - // DC3////////////////////////////////////////////////////////////////////////////////////////// - char DC3[64] = {0}; - int nbytes_read_DC3= 0; - tty_read_section(PortFD, DC3, 'A', 5, &nbytes_read_DC3); - DC3[nbytes_read_DC3 - 1] = '\0'; - DC3read = std::stoi(DC3); - updateDC3(DC3read); - - - // DC4_6////////////////////////////////////////////////////////////////////////////////////////// - char DC4_6[64] = {0}; - int nbytes_read_DC4_6= 0; - tty_read_section(PortFD, DC4_6, 'A', 5, &nbytes_read_DC4_6); - DC4_6[nbytes_read_DC4_6 - 1] = '\0'; - DC4_6read =std::stoi(DC4_6); - updateDC4_6(DC4_6read); - - // DC2SET////////////////////////////////////////////////////////////////////////////////////////// - char DC2SET[64] = {0}; - int nbytes_read_DC2SET= 0; - tty_read_section(PortFD, DC2SET, 'A', 5, &nbytes_read_DC2SET); - DC2SET[nbytes_read_DC2SET - 1] = '\0'; - //LOGF_INFO("All Data Updated","Updated"); - DC2SETread = std::stoi(DC2SET); - updateDC2SET(DC2SETread); - - //DC3 DEW CONTROL - if(DC3DIFFMODE==true ) - { - if(temp1read(values[i])); - } - - DC3ControlNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (DC3ControlNP.s == IPS_OK) - IUUpdateNumber(&DC3ControlNP, values, names, n); - IDSetNumber(&DC3ControlNP, nullptr); - return true; - } - if (!strcmp(name, DC3diffSETNP.name)) - { - - DC3diffSETNP.s = IPS_OK ; - if (DC3diffSETNP.s == IPS_OK) - IUUpdateNumber(&DC3diffSETNP, values, names, n); - IDSetNumber(&DC3diffSETNP, nullptr); - return true; - } - if (!strcmp(name, DC3constSETNP.name)) - { - - DC3constSETNP.s = IPS_OK ; - if (DC3constSETNP.s == IPS_OK) - IUUpdateNumber(&DC3constSETNP, values, names, n); - IDSetNumber(&DC3constSETNP, nullptr); - return true; - } - - // DC2voltageSET - if (!strcmp(name, setDC2voltageNP.name)) - { - bool rc1 = false; - for (int i = 0; i < n; i++) - { - if (!strcmp(names[i], setDC2voltageN[setDC2voltage].name)) - rc1 = setDewPWM(20, static_cast(10*values[i])); - } - - setDC2voltageNP.s = (rc1) ? IPS_OK : IPS_ALERT; - if (setDC2voltageNP.s == IPS_OK) - IUUpdateNumber(&setDC2voltageNP, values, names, n); - IDSetNumber(&setDC2voltageNP, nullptr); - return true; - } - - - } - return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); -} - -bool WandererBoxPlusV3::setDewPWM(uint8_t id, uint8_t value) -{ - char cmd[64] = {0}; - snprintf(cmd, 64, "%d%03d", id, value); - if (sendCommand(cmd)) - { - return true; - } - - return false; -} - -const char *WandererBoxPlusV3::getDefaultName() -{ - return "WandererBox Pro V3"; -} - - -bool WandererBoxPlusV3::sendCommand(std::string command) -{ - int nbytes_written = 0, rc = -1; - std::string command_termination = "\n"; - LOGF_DEBUG("CMD: %s", command.c_str()); - if ((rc = tty_write_string(PortFD, (command + command_termination).c_str(), &nbytes_written)) != TTY_OK) - { - char errorMessage[MAXRBUF]; - tty_error_msg(rc, errorMessage, MAXRBUF); - LOGF_ERROR("Serial write error: %s", errorMessage); - return false; - } - return true; -} - -void WandererBoxPlusV3::TimerHit() -{ - if (!isConnected()) - { - SetTimer(2500); - return; - } - - getData(); - SetTimer(2500); -} - -bool WandererBoxPlusV3::saveConfigItems(FILE * fp) -{ - INDI::DefaultDevice::saveConfigItems(fp); - - IUSaveConfigSwitch(fp, &DC3dewSP); - IUSaveConfigNumber(fp, &DC3diffSETNP); - IUSaveConfigNumber(fp, &DC3constSETNP); - IUSaveConfigNumber(fp, &DC3ControlNP); - - - IUSaveConfigNumber(fp, &setDC2voltageNP); - return true; -} - - diff --git a/drivers/auxiliary/wandererbox_plus_v3.h b/drivers/auxiliary/wandererbox_plus_v3.h deleted file mode 100644 index 3f1194be7e..0000000000 --- a/drivers/auxiliary/wandererbox_plus_v3.h +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - Copyright(c) 2015 Jasem Mutlaq. All rights reserved. - -WandererBox Plus V3 - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - The full GNU General Public License is included in this distribution in the - file called LICENSE. -*******************************************************************************/ - -#pragma once - -#include "defaultdevice.h" -#include -#include - -namespace Connection -{ -class Serial; -} - -class WandererBoxPlusV3 : public INDI::DefaultDevice -{ - public: - WandererBoxPlusV3(); - virtual ~WandererBoxPlusV3() = default; - - virtual bool initProperties() override; - virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; - virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; - virtual bool updateProperties() override; - - - - protected: - const char *getDefaultName() override; - virtual bool saveConfigItems(FILE *fp) override; - virtual void TimerHit() override; - - - private: - - bool sendCommand(std::string command); - bool DC3DIFFMODE=false; - bool DC3CONSTMODE=false; - bool getData(); - static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; - static constexpr const char *DC3_TAB {"DC3"}; - //Current Calibrate - ISwitch CalibrateS[1]; - ISwitchVectorProperty CalibrateSP; - - // Firmware version - ITextVectorProperty FirmwareTP; - IText FirmwareT[1] {}; - //Temp1 - double temp1read = 0; - //DHTH - double DHTHread = 0; - //DHTT - void updateENV(double temp1,double DHTH,double DHTT); - double DHTTread = 0; - //Total Current - double Tcurrentread = 0; - //Power Monitor - void updatePower(double Tcurrent,double voltage); - double voltageread = 0; - //USB - void updateUSB(int value); - int USBread = 0; - //DC2 - void updateDC2(int value); - int DC2read = 0; - //DC3 - void updateDC3(int value); - int DC3read = 0; - //DC4_6 - void updateDC4_6(int value); - int DC4_6read = 0; - //DC2set - void updateDC2SET(double value); - int DC2SETread = 0; - - bool setDewPWM(uint8_t id, uint8_t value); - - //DC Control////////////////////////////////////////////////////////////////////////////////// - ISwitchVectorProperty DC2ControlSP; - ISwitch DC2ControlS[2]; - ISwitchVectorProperty DC4_6ControlSP; - ISwitch DC4_6ControlS[2]; - //USB Control////////////////////////////////////////////////////////////////////////////////// - ISwitchVectorProperty USBControlSP; - ISwitch USBControlS[2]; - //DC3 Control//////////////////////////////////////////////////////////////// - INumber DC3ControlN[1]; - INumberVectorProperty DC3ControlNP; - enum - { - DC3, - }; - ISwitchVectorProperty DC3dewSP; - ISwitch DC3diffS[3]; - enum - { - DC3_Manual, - DC3_DPD_Mode, - DC3_CT_Mode, - }; - - INumber DC3diffSETN[1]; - INumberVectorProperty DC3diffSETNP; - enum - { - DC3DIFFSET, - }; - INumber DC3constSETN[1]; - INumberVectorProperty DC3constSETNP; - enum - { - DC3CONSTSET, - }; - - //DC2 Voltage Control//////////////////////////////////////////////////////////////// - INumber setDC2voltageN[1]; - INumberVectorProperty setDC2voltageNP; - enum - { - setDC2voltage, - }; - - // Power Monitor - INumber PowerMonitorN[2]; - INumberVectorProperty PowerMonitorNP; - enum - { - VOLTAGE, - TOTAL_CURRENT, - }; - - // ENV Monitor - INumber ENVMonitorN[4]; - INumberVectorProperty ENVMonitorNP; - enum - { - Probe1_Temp, - ENV_Humidity, - ENV_Temp, - DEW_Point, - }; - - - - int PortFD{ -1 }; - - Connection::Serial *serialConnection{ nullptr }; -}; From 033d6b43878cdf8a2a28d922746e7a791d140e4c Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 08:17:31 +0800 Subject: [PATCH 5/9] Driver for WandererBox Pro V3 updated --- drivers/auxiliary/wandererbox_pro_v3.cpp | 8 ++++---- drivers/auxiliary/wandererbox_pro_v3.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp index 06055fa30b..e535ca7f81 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.cpp +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -205,11 +205,11 @@ bool WandererBoxProV3::getData() throw std::exception(); // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// int nbytes_read_version = 0; - version[64] = {0}; + char version[64] = {0}; tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); version[nbytes_read_version - 1] = '\0'; - + firmware=std::atoi(version); // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// @@ -697,10 +697,10 @@ bool WandererBoxProV3::updateProperties() if (isConnected()) { - if(std::stoi(version)>=20240216) + if(firmware>=20240216) { defineProperty(CalibrateSP); - LOGF_INFO("Firmware version: %s", version); + LOGF_INFO("Firmware version: %d", firmware); } else { diff --git a/drivers/auxiliary/wandererbox_pro_v3.h b/drivers/auxiliary/wandererbox_pro_v3.h index f5aaf9247c..5a0e26315a 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.h +++ b/drivers/auxiliary/wandererbox_pro_v3.h @@ -54,7 +54,7 @@ class WandererBoxProV3 : public INDI::DefaultDevice private: - char version[64] = {0}; + int firmware=0; bool sendCommand(std::string command); bool DC5DIFFMODE=false; bool DC5CONSTMODE=false; From fc429bcbf79e7c18ce7c95aedd8145132692cb26 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 15:09:20 +0800 Subject: [PATCH 6/9] Driver for WandererBox Pro V3 updated --- drivers/auxiliary/wandererbox_pro_v3.cpp | 138 +++++++++++------------ drivers/auxiliary/wandererbox_pro_v3.h | 4 +- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp index e535ca7f81..aba4077d54 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.cpp +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + Copyright(c) 2024 Frank Wang. All rights reserved. WandererBox Pro V3 @@ -400,11 +400,11 @@ bool WandererBoxProV3::getData() defineProperty(dc5ControlNP); deleteProperty(dc5diffSETNP); deleteProperty(dc5constSETNP); - LOGF_INFO("Temp probe 1 not connected, Dew Point Difference Mode for DC5 has exited!","Updated"); + LOGF_ERROR("Temp probe 1 not connected, Dew Point Difference Mode for DC5 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc5diffSP[DC5_Manual].s = ISS_ON; - dc5diffSP[DC5_DPD_Mode].s = ISS_OFF; - dc5diffSP[DC5_CT_Mode].s = ISS_OFF; + dc5diffSP[DC5_Manual].setState( ISS_ON); + dc5diffSP[DC5_DPD_Mode].setState( ISS_OFF); + dc5diffSP[DC5_CT_Mode].setState( ISS_OFF); dc5diffSP.setState(IPS_OK); dc5diffSP.apply(); } @@ -415,10 +415,10 @@ bool WandererBoxProV3::getData() defineProperty(dc5ControlNP); deleteProperty(dc5diffSETNP); deleteProperty(dc5constSETNP); - LOGF_INFO("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC5 has exited!","Updated"); - dc5diffSP[DC5_Manual].s = ISS_ON; - dc5diffSP[DC5_DPD_Mode].s = ISS_OFF; - dc5diffSP[DC5_CT_Mode].s = ISS_OFF; + LOGF_ERROR("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC5 has exited!","Updated"); + dc5diffSP[DC5_Manual].setState( ISS_ON); + dc5diffSP[DC5_DPD_Mode].setState( ISS_OFF); + dc5diffSP[DC5_CT_Mode].setState( ISS_OFF); dc5diffSP.setState(IPS_OK); dc5diffSP.apply(); } @@ -429,11 +429,11 @@ bool WandererBoxProV3::getData() defineProperty(dc5ControlNP); deleteProperty(dc5diffSETNP); deleteProperty(dc5constSETNP); - LOGF_INFO("Temp probe 1 not connected, Constant Temperature Mode for DC5 has exited!","Updated"); + LOGF_ERROR("Temp probe 1 not connected, Constant Temperature Mode for DC5 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc5diffSP[DC5_Manual].s = ISS_ON; - dc5diffSP[DC5_DPD_Mode].s = ISS_OFF; - dc5diffSP[DC5_CT_Mode].s = ISS_OFF; + dc5diffSP[DC5_Manual].setState( ISS_ON); + dc5diffSP[DC5_DPD_Mode].setState( ISS_OFF); + dc5diffSP[DC5_CT_Mode].setState( ISS_OFF); dc5diffSP.setState(IPS_OK); dc5diffSP.apply(); } @@ -462,11 +462,11 @@ bool WandererBoxProV3::getData() defineProperty(dc6ControlNP); deleteProperty(dc6diffSETNP); deleteProperty(dc6constSETNP); - LOGF_INFO("Temp probe 2 not connected, Dew Point Difference Mode for DC6 has exited!","Updated"); + LOGF_ERROR("Temp probe 2 not connected, Dew Point Difference Mode for DC6 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc6diffSP[DC6_Manual].s = ISS_ON; - dc6diffSP[DC6_DPD_Mode].s = ISS_OFF; - dc6diffSP[DC6_CT_Mode].s = ISS_OFF; + dc6diffSP[DC6_Manual].setState( ISS_ON); + dc6diffSP[DC6_DPD_Mode].setState( ISS_OFF); + dc6diffSP[DC6_CT_Mode].setState( ISS_OFF); dc6diffSP.setState(IPS_OK); dc6diffSP.apply(); } @@ -477,10 +477,10 @@ bool WandererBoxProV3::getData() defineProperty(dc6ControlNP); deleteProperty(dc6diffSETNP); deleteProperty(dc6constSETNP); - LOGF_INFO("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC6 has exited!","Updated"); - dc6diffSP[DC6_Manual].s = ISS_ON; - dc6diffSP[DC6_DPD_Mode].s = ISS_OFF; - dc6diffSP[DC6_CT_Mode].s = ISS_OFF; + LOGF_ERROR("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC6 has exited!","Updated"); + dc6diffSP[DC6_Manual].setState( ISS_ON); + dc6diffSP[DC6_DPD_Mode].setState( ISS_OFF); + dc6diffSP[DC6_CT_Mode].setState( ISS_OFF); dc6diffSP.setState(IPS_OK); dc6diffSP.apply(); } @@ -491,11 +491,11 @@ bool WandererBoxProV3::getData() defineProperty(dc6ControlNP); deleteProperty(dc6diffSETNP); deleteProperty(dc6constSETNP); - LOGF_INFO("Temp probe 2 not connected, Constant Temperature Mode for DC6 has exited!","Updated"); + LOGF_ERROR("Temp probe 2 not connected, Constant Temperature Mode for DC6 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc6diffSP[DC6_Manual].s = ISS_ON; - dc6diffSP[DC6_DPD_Mode].s = ISS_OFF; - dc6diffSP[DC6_CT_Mode].s = ISS_OFF; + dc6diffSP[DC6_Manual].setState( ISS_ON); + dc6diffSP[DC6_DPD_Mode].setState( ISS_OFF); + dc6diffSP[DC6_CT_Mode].setState( ISS_OFF); dc6diffSP.setState(IPS_OK); dc6diffSP.apply(); } @@ -523,11 +523,11 @@ bool WandererBoxProV3::getData() defineProperty(dc7ControlNP); deleteProperty(dc7diffSETNP); deleteProperty(dc7constSETNP); - LOGF_INFO("Temp probe 3 not connected, Dew Point Difference Mode for DC7 has exited!","Updated"); + LOGF_ERROR("Temp probe 3 not connected, Dew Point Difference Mode for DC7 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc7diffSP[DC7_Manual].s = ISS_ON; - dc7diffSP[DC7_DPD_Mode].s = ISS_OFF; - dc7diffSP[DC7_CT_Mode].s = ISS_OFF; + dc7diffSP[DC7_Manual].setState( ISS_ON); + dc7diffSP[DC7_DPD_Mode].setState( ISS_OFF); + dc7diffSP[DC7_CT_Mode].setState( ISS_OFF); dc7diffSP.setState(IPS_OK); dc7diffSP.apply(); } @@ -538,10 +538,10 @@ bool WandererBoxProV3::getData() defineProperty(dc7ControlNP); deleteProperty(dc7diffSETNP); deleteProperty(dc7constSETNP); - LOGF_INFO("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC7 has exited!","Updated"); - dc7diffSP[DC7_Manual].s = ISS_ON; - dc7diffSP[DC7_DPD_Mode].s = ISS_OFF; - dc7diffSP[DC7_CT_Mode].s = ISS_OFF; + LOGF_ERROR("DHT22 Humidity&Temperature sensor not connected, Dew Point Difference Mode for DC7 has exited!","Updated"); + dc7diffSP[DC7_Manual].setState( ISS_ON); + dc7diffSP[DC7_DPD_Mode].setState( ISS_OFF); + dc7diffSP[DC7_CT_Mode].setState( ISS_OFF); dc7diffSP.setState(IPS_OK); dc7diffSP.apply(); } @@ -552,11 +552,11 @@ bool WandererBoxProV3::getData() defineProperty(dc7ControlNP); deleteProperty(dc7diffSETNP); deleteProperty(dc7constSETNP); - LOGF_INFO("Temp probe 3 not connected, Constant Temperature Mode for DC7 has exited!","Updated"); + LOGF_ERROR("Temp probe 3 not connected, Constant Temperature Mode for DC7 has exited!","Updated"); LOGF_INFO("You need to insert the probe firmly to the end!","Updated"); - dc7diffSP[DC7_Manual].s = ISS_ON; - dc7diffSP[DC7_DPD_Mode].s = ISS_OFF; - dc7diffSP[DC7_CT_Mode].s = ISS_OFF; + dc7diffSP[DC7_Manual].setState( ISS_ON); + dc7diffSP[DC7_DPD_Mode].setState( ISS_OFF); + dc7diffSP[DC7_CT_Mode].setState( ISS_OFF); dc7diffSP.setState(IPS_OK); dc7diffSP.apply(); } @@ -573,12 +573,12 @@ bool WandererBoxProV3::getData() void WandererBoxProV3::updateENV(double temp1,double temp2,double temp3,double DHTH,double DHTT) { - ENVMonitorNP[Probe1_Temp].value = temp1; - ENVMonitorNP[Probe2_Temp].value = temp2; - ENVMonitorNP[Probe3_Temp].value = temp3; - ENVMonitorNP[ENV_Humidity].value = DHTH; - ENVMonitorNP[ENV_Temp].value = DHTT; - ENVMonitorNP[DEW_Point].value = (237.7 * ((17.27 * DHTT) / (237.7 + DHTT) + log((DHTH / 100)))) / (17.27 - ((17.27 * DHTT) / (237.7 + DHTT) + log((DHTH / 100))));; + ENVMonitorNP[Probe1_Temp].setValue(temp1); + ENVMonitorNP[Probe2_Temp].setValue(temp2); + ENVMonitorNP[Probe3_Temp].setValue(temp3); + ENVMonitorNP[ENV_Humidity].setValue(DHTH); + ENVMonitorNP[ENV_Temp].setValue(DHTT); + ENVMonitorNP[DEW_Point].setValue((237.7 * ((17.27 * DHTT) / (237.7 + DHTT) + log((DHTH / 100)))) / (17.27 - ((17.27 * DHTT) / (237.7 + DHTT) + log((DHTH / 100)))));; ENVMonitorNP.setState(IPS_OK); ENVMonitorNP.apply(); @@ -588,58 +588,58 @@ void WandererBoxProV3::updateENV(double temp1,double temp2,double temp3,double D void WandererBoxProV3::updatePower(double Tcurrent,double V19_current,double AR_current,double voltage) { // Power Monitor - PowerMonitorNP[VOLTAGE].value = voltage; - PowerMonitorNP[TOTAL_CURRENT].value = Tcurrent; - PowerMonitorNP[V19_CURRENT].value = V19_current; - PowerMonitorNP[AR_CURRENT].value = AR_current; + PowerMonitorNP[VOLTAGE].setValue(voltage); + PowerMonitorNP[TOTAL_CURRENT].setValue(Tcurrent); + PowerMonitorNP[V19_CURRENT].setValue(V19_current); + PowerMonitorNP[AR_CURRENT].setValue(AR_current); PowerMonitorNP.setState(IPS_OK); PowerMonitorNP.apply(); } void WandererBoxProV3::updateUSB31(int res) { - usb31ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - usb31ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + usb31ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + usb31ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); usb31ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); usb31ControlSP.apply(); } void WandererBoxProV3::updateUSB32(int res) { - usb32ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - usb32ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + usb32ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + usb32ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); usb32ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); usb32ControlSP.apply(); } void WandererBoxProV3::updateUSB33(int res) { - usb33ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - usb33ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + usb33ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + usb33ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); usb33ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); usb33ControlSP.apply(); } void WandererBoxProV3::updateUSB21(int res) { - usb21ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - usb21ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + usb21ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + usb21ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); usb21ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); usb21ControlSP.apply(); } void WandererBoxProV3::updateUSB22(int res) { - usb22ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - usb22ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + usb22ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + usb22ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); usb22ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); usb22ControlSP.apply(); } void WandererBoxProV3::updateDC34(int res) { - dc3_4ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - dc3_4ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + dc3_4ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + dc3_4ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); dc3_4ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); dc3_4ControlSP.apply(); } @@ -667,16 +667,16 @@ void WandererBoxProV3::updateDC7(int res) void WandererBoxProV3::updateDC8_9(int res) { - dc8_9ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - dc8_9ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + dc8_9ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + dc8_9ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); dc8_9ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); dc8_9ControlSP.apply(); } void WandererBoxProV3::updateDC10_11(int res) { - dc10_11ControlSP[INDI_ENABLED].s = (res== 1) ? ISS_ON : ISS_OFF; - dc10_11ControlSP[INDI_DISABLED].s = (res== 0) ? ISS_ON : ISS_OFF; + dc10_11ControlSP[INDI_ENABLED].setState( (res== 1) ? ISS_ON : ISS_OFF); + dc10_11ControlSP[INDI_DISABLED].setState( (res== 0) ? ISS_ON : ISS_OFF); dc10_11ControlSP.setState((res== 1) ? IPS_OK : IPS_IDLE); dc10_11ControlSP.apply(); } @@ -957,7 +957,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC5DIFFMODE=false; DC5CONSTMODE=false; - dc5diffSP[DC5_Manual].s = ISS_ON; + dc5diffSP[DC5_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); dc5diffSP.apply(); } @@ -980,7 +980,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC5DIFFMODE=false; DC5CONSTMODE=false; - dc5diffSP[DC5_Manual].s = ISS_ON; + dc5diffSP[DC5_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC5 activated! Please adjust the duty cycle manually, you can also use DC5 as an ordinary switch.","Updated"); dc5diffSP.apply(); } @@ -1023,7 +1023,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC6DIFFMODE=false; DC6CONSTMODE=false; - dc6diffSP[DC6_Manual].s = ISS_ON; + dc6diffSP[DC6_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); dc6diffSP.apply(); } @@ -1046,7 +1046,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC6DIFFMODE=false; DC6CONSTMODE=false; - dc6diffSP[DC6_Manual].s = ISS_ON; + dc6diffSP[DC6_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC6 activated! Please adjust the duty cycle manually, you can also use DC6 as an ordinary switch.","Updated"); dc6diffSP.apply(); } @@ -1089,7 +1089,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC7DIFFMODE=false; DC7CONSTMODE=false; - dc7diffSP[DC7_Manual].s = ISS_ON; + dc7diffSP[DC7_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); dc7diffSP.apply(); } @@ -1112,7 +1112,7 @@ bool WandererBoxProV3::ISNewSwitch(const char *dev, const char *name, ISState *s { DC7DIFFMODE=false; DC7CONSTMODE=false; - dc7diffSP[DC7_Manual].s = ISS_ON; + dc7diffSP[DC7_Manual].setState( ISS_ON); LOGF_INFO("Manual Mode for DC7 activated! Please adjust the duty cycle manually, you can also use DC7 as an ordinary switch.","Updated"); dc7diffSP.apply(); } diff --git a/drivers/auxiliary/wandererbox_pro_v3.h b/drivers/auxiliary/wandererbox_pro_v3.h index 5a0e26315a..12d87d27be 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.h +++ b/drivers/auxiliary/wandererbox_pro_v3.h @@ -1,7 +1,7 @@ /******************************************************************************* - Copyright(c) 2015 Jasem Mutlaq. All rights reserved. + Copyright(c) 2024 Frank Wang. All rights reserved. - WandererBox Pro V3 + WandererBox Pro V3 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free From 66b5e8ab7f24826bd5d2b06c0e6338cecd025015 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 15:23:09 +0800 Subject: [PATCH 7/9] Driver for WandererBox Pro V3 updated --- drivers/auxiliary/wandererbox_pro_v3.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/auxiliary/wandererbox_pro_v3.cpp b/drivers/auxiliary/wandererbox_pro_v3.cpp index aba4077d54..2755253eb1 100644 --- a/drivers/auxiliary/wandererbox_pro_v3.cpp +++ b/drivers/auxiliary/wandererbox_pro_v3.cpp @@ -646,21 +646,21 @@ void WandererBoxProV3::updateDC34(int res) void WandererBoxProV3::updateDC5(int res) { - dc5ControlNP[0].value = res; + dc5ControlNP[0].setValue(res); dc5ControlNP.setState(IPS_OK); dc5ControlNP.apply(); } void WandererBoxProV3::updateDC6(int res) { - dc6ControlNP[0].value = res; + dc6ControlNP[0].setValue(res); dc6ControlNP.setState(IPS_OK); dc6ControlNP.apply(); } void WandererBoxProV3::updateDC7(int res) { - dc7ControlNP[0].value = res; + dc7ControlNP[0].setValue(res); dc7ControlNP.setState(IPS_OK); dc7ControlNP.apply(); } @@ -683,7 +683,7 @@ void WandererBoxProV3::updateDC10_11(int res) void WandererBoxProV3::updateDC34SET(double res) { - setDC34voltageNP[setDC34voltage].value = res/10.0; + setDC34voltageNP[setDC34voltage].setValue(res/10); setDC34voltageNP.setState(IPS_OK); setDC34voltageNP.apply(); } From caf30b3f94a4009095492b8c36f96ad211e64486 Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 17:25:23 +0800 Subject: [PATCH 8/9] Driver for WandererBox Plus V3 added --- drivers.xml | 8 + drivers/auxiliary/CMakeLists.txt | 8 + drivers/auxiliary/wandererbox_plus_v3.cpp | 686 ++++++++++++++++++++++ drivers/auxiliary/wandererbox_plus_v3.h | 163 +++++ 4 files changed, 865 insertions(+) create mode 100644 drivers/auxiliary/wandererbox_plus_v3.cpp create mode 100644 drivers/auxiliary/wandererbox_plus_v3.h diff --git a/drivers.xml b/drivers.xml index 22471bcfef..6ccf58b079 100644 --- a/drivers.xml +++ b/drivers.xml @@ -75,6 +75,10 @@ indi_lx200ap_v2 1.1 + + indi_lx200autostar + 2.1 + indi_lx200_pegasus_nyx101 2.1 @@ -749,6 +753,10 @@ indi_wandererbox_pro_v3 1.0 + + indi_wandererbox_plus_v3 + 1.0 + diff --git a/drivers/auxiliary/CMakeLists.txt b/drivers/auxiliary/CMakeLists.txt index b68e845325..6bf1480ad9 100644 --- a/drivers/auxiliary/CMakeLists.txt +++ b/drivers/auxiliary/CMakeLists.txt @@ -1,6 +1,14 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") INSTALL(FILES 99-indi_auxiliary.rules DESTINATION ${UDEVRULES_INSTALL_DIR}) ENDIF() +# ########## Wanderer Box Plus V3 ############### +SET(indi_wandererbox_plus_v3_SRC + wandererbox_plus_v3.cpp) + +add_executable(indi_wandererbox_plus_v3 ${indi_wandererbox_plus_v3_SRC}) +target_link_libraries(indi_wandererbox_plus_v3 indidriver) +install(TARGETS indi_wandererbox_plus_v3 RUNTIME DESTINATION bin) + # ########## Wanderer Box Pro V3 ############### SET(indi_wandererbox_pro_v3_SRC wandererbox_pro_v3.cpp) diff --git a/drivers/auxiliary/wandererbox_plus_v3.cpp b/drivers/auxiliary/wandererbox_plus_v3.cpp new file mode 100644 index 0000000000..0cc1ba1e9f --- /dev/null +++ b/drivers/auxiliary/wandererbox_plus_v3.cpp @@ -0,0 +1,686 @@ +/******************************************************************************* + Copyright(c) 2024 Frank Wang. All rights reserved. + + WandererBox Plus V3 + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#include "wandererbox_plus_v3.h" +#include "indicom.h" +#include "connectionplugins/connectionserial.h" +#include +#include +#include +#include +#include +#include +#include +#include + +// We declare an auto pointer to WandererBoxPlusV3. +static std::unique_ptr WandererBoxplusv3(new WandererBoxPlusV3()); + + + +WandererBoxPlusV3::WandererBoxPlusV3() +{ + setVersion(1, 0); +} + +bool WandererBoxPlusV3::initProperties() +{ + + INDI::DefaultDevice::initProperties(); + setDriverInterface(AUX_INTERFACE); + + + addAuxControls(); + + + // Calibrate + CalibrateSP[0].fill("Calibrate", "Calibrate Current", ISS_OFF); + CalibrateSP.fill(getDeviceName(), "Calibrate_DEVICE", "Calibrate Current", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1,60, IPS_IDLE); + + // Power Monitor + PowerMonitorNP[VOLTAGE].fill("VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP[TOTAL_CURRENT].fill("TOTAL_CURRENT", "Total Current (A)", "%4.2f", 0, 999, 100, 0); + PowerMonitorNP.fill(getDeviceName(), "POWER_Monitor", "Power Monitor", MAIN_CONTROL_TAB, IP_RO,60, IPS_IDLE); + + + // USB Control + USBControlSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF); + USBControlSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_OFF); + USBControlSP.fill(getDeviceName(), "USB", "USB", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + + // DC3 + DC3ControlNP[DC3].fill( "DC3", "Dew Heater (PWM)", "%.2f", 0, 255, 5, 0); + DC3ControlNP.fill(getDeviceName(), "PWM", "DC3", DC3_TAB, IP_RW, 60, IPS_IDLE); + + // DC2SET + setDC2voltageNP[setDC2voltage].fill( "DC2SET", "Adjustable Voltage", "%.2f", 5, 13.2, 0.1, 0); + setDC2voltageNP.fill(getDeviceName(), "DC2voltageSET", "Set DC2", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE); + // DC2 Control + dc2ControlSP[INDI_ENABLED].fill( "INDI_ENABLED", "On", ISS_OFF); + dc2ControlSP[INDI_DISABLED].fill( "INDI_DISABLED", "Off", ISS_ON); + dc2ControlSP.fill(getDeviceName(), "DC2", "DC2", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC4-6 Control + DC4_6ControlSP[INDI_ENABLED].fill( "INDI_ENABLED", "On", ISS_OFF); + DC4_6ControlSP[INDI_DISABLED].fill( "INDI_DISABLED", "Off", ISS_ON); + DC4_6ControlSP.fill(getDeviceName(), "DC4-6", "DC4-6", MAIN_CONTROL_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + // DC3 TEMP Difference Control + DC3diffSP[DC3_Manual].fill( "Manual", "Manual", ISS_ON); + DC3diffSP[DC3_DPD_Mode].fill( "DPD_Mode", "DPD Mode", ISS_OFF); + DC3diffSP[DC3_CT_Mode].fill( "CT_Mode", "CT Mode", ISS_OFF); + DC3diffSP.fill(getDeviceName(), "DC3_DIFF", "DC3 Dew Mode", DC3_TAB, IP_RW,ISR_1OFMANY, 60, IPS_IDLE); + + DC3diffSETNP[DC3DIFFSET].fill( "DC3 Auto Control", "Dew Point Difference(C)", "%.2f", 10, 30, 1, 0); + DC3diffSETNP.fill(getDeviceName(), "DC3_DIFF_SET", "DPD Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); + + DC3constSETNP[DC3CONSTSET].fill( "DC3 Auto Control", "Temperature(C)", "%.2f", 0, 40, 1, 0); + DC3constSETNP.fill(getDeviceName(), "DC3_CONST_SET", "CT Mode", DC3_TAB, IP_RW, 60, IPS_IDLE); + + //ENV + ENVMonitorNP[Probe1_Temp].fill( "Probe1_Temp", "Probe1 Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[ENV_Humidity].fill( "ENV_Humidity", "Ambient Humidity %", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[ENV_Temp].fill( "ENV_Temp", "Ambient Temperature (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP[DEW_Point].fill( "DEW_Point", "Dew Point (C)", "%4.2f", 0, 999, 100, 0); + ENVMonitorNP.fill(getDeviceName(), "ENV_Monitor", "Environment",ENVIRONMENT_TAB, IP_RO,60, IPS_IDLE); + serialConnection = new Connection::Serial(this); + serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); + serialConnection->registerHandshake([&]() + { + return getData(); + }); + registerConnection(serialConnection); + + return true; +} + +bool WandererBoxPlusV3::getData() +{ + try + { + PortFD = serialConnection->getPortFD(); + tcflush(PortFD, TCIOFLUSH); + int nbytes_read_name = 0,rc=-1; + char name[64] = {0}; + + //Device Model////////////////////////////////////////////////////////////////////////////////////////////////////// + if ((rc = tty_read_section(PortFD, name, 'A', 3, &nbytes_read_name)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_INFO("No data received, the device may not be WandererBox Plus V3, please check the serial port!","Updated"); + LOGF_ERROR("Device read error: %s", errorMessage); + return false; + } + name[nbytes_read_name - 1] = '\0'; + if(strcmp(name, "ZXWBProV3")==0||strcmp(name, "WandererCoverV4")==0||strcmp(name, "UltimateV2")==0||strcmp(name, "PlusV2")==0) + { + LOGF_INFO("The device is not WandererBox Plus V3!","Updated"); + return false; + } + if(strcmp(name, "ZXWBPlusV3")!=0) + throw std::exception(); + // Frimware version///////////////////////////////////////////////////////////////////////////////////////////// + int nbytes_read_version = 0; + char version[64] = {0}; + tty_read_section(PortFD, version, 'A', 5, &nbytes_read_version); + + version[nbytes_read_version - 1] = '\0'; + firmware=std::atoi(version); + + + // Temp probe 1////////////////////////////////////////////////////////////////////////////////////////// + char temp1[64] = {0}; + int nbytes_read_temp1= 0; + tty_read_section(PortFD, temp1, 'A', 5, &nbytes_read_temp1); + temp1[nbytes_read_temp1 - 1] = '\0'; + temp1read = std::strtod(temp1,NULL); + + // DHTH////////////////////////////////////////////////////////////////////////////////////////// + char DHTH[64] = {0}; + int nbytes_read_DHTH= 0; + tty_read_section(PortFD, DHTH, 'A', 5, &nbytes_read_DHTH); + DHTH[nbytes_read_DHTH - 1] = '\0'; + DHTHread = std::strtod(DHTH,NULL); + + // DHTT////////////////////////////////////////////////////////////////////////////////////////// + char DHTT[64] = {0}; + int nbytes_read_DHTT= 0; + tty_read_section(PortFD, DHTT, 'A', 5, &nbytes_read_DHTT); + DHTT[nbytes_read_DHTT - 1] = '\0'; + DHTTread = std::strtod(DHTT,NULL); + updateENV(temp1read,DHTHread,DHTTread); + + // Total current////////////////////////////////////////////////////////////////////////////////////////// + char Tcurrent[64] = {0}; + int nbytes_read_Tcurrent= 0; + tty_read_section(PortFD, Tcurrent, 'A', 5, &nbytes_read_Tcurrent); + Tcurrent[nbytes_read_Tcurrent - 1] = '\0'; + Tcurrentread = std::strtod(Tcurrent,NULL); + + // Voltage////////////////////////////////////////////////////////////////////////////////////////// + char voltage[64] = {0}; + int nbytes_read_voltage= 0; + tty_read_section(PortFD, voltage, 'A', 5, &nbytes_read_voltage); + voltage[nbytes_read_voltage - 1] = '\0'; + voltageread = std::strtod(voltage,NULL); + updatePower(Tcurrentread,voltageread); + + // USB////////////////////////////////////////////////////////////////////////////////////////// + char USB[64] = {0}; + int nbytes_read_USB= 0; + tty_read_section(PortFD, USB, 'A', 5, &nbytes_read_USB); + USB[nbytes_read_USB - 1] = '\0'; + USBread = std::stoi(USB); + updateUSB(USBread); + + + // DC2////////////////////////////////////////////////////////////////////////////////////////// + char DC2[64] = {0}; + int nbytes_read_DC2= 0; + tty_read_section(PortFD, DC2, 'A', 5, &nbytes_read_DC2); + DC2[nbytes_read_DC2 - 1] = '\0'; + DC2read = std::stoi(DC2); + updateDC2(DC2read); + + // DC3////////////////////////////////////////////////////////////////////////////////////////// + char DC3[64] = {0}; + int nbytes_read_DC3= 0; + tty_read_section(PortFD, DC3, 'A', 5, &nbytes_read_DC3); + DC3[nbytes_read_DC3 - 1] = '\0'; + DC3read = std::stoi(DC3); + updateDC3(DC3read); + + + // DC4_6////////////////////////////////////////////////////////////////////////////////////////// + char DC4_6[64] = {0}; + int nbytes_read_DC4_6= 0; + tty_read_section(PortFD, DC4_6, 'A', 5, &nbytes_read_DC4_6); + DC4_6[nbytes_read_DC4_6 - 1] = '\0'; + DC4_6read =std::stoi(DC4_6); + updateDC4_6(DC4_6read); + + + // DC2SET////////////////////////////////////////////////////////////////////////////////////////// + char DC2SET[64] = {0}; + int nbytes_read_DC2SET= 0; + tty_read_section(PortFD, DC2SET, 'A', 5, &nbytes_read_DC2SET); + DC2SET[nbytes_read_DC2SET - 1] = '\0'; + //LOGF_INFO("All Data Updated","Updated"); + DC2SETread = std::stoi(DC2SET); + updateDC2SET(DC2SETread); + + + //DC3 DEW CONTROL + if(DC3diffSP[DC3_DPD_Mode].getState() == ISS_ON) + { + if(temp1read=20240216) + { + defineProperty(CalibrateSP); + LOGF_INFO("Firmware version: %d", firmware); + } + else + { + LOGF_INFO("The firmware is outdated, please upgrade to the latest firmware, or power reading calibration will be unavailable.","failed"); + } + defineProperty(PowerMonitorNP); + + + defineProperty(USBControlSP); + + defineProperty(setDC2voltageNP); + defineProperty(dc2ControlSP); + + defineProperty(DC4_6ControlSP); + + + defineProperty(DC3diffSP); + + + + //DC3//////////////////// + if(DC3diffSP[DC3_DPD_Mode].getState() == ISS_ON) + { + deleteProperty(DC3constSETNP); + deleteProperty(DC3ControlNP); + defineProperty(DC3diffSETNP); + } + else if(DC3diffSP[DC3_CT_Mode].getState() == ISS_ON) + { + deleteProperty(DC3ControlNP); + deleteProperty(DC3diffSETNP); + defineProperty(DC3constSETNP); + } + else + { + defineProperty(DC3ControlNP); + deleteProperty(DC3diffSETNP); + deleteProperty(DC3constSETNP); + } + defineProperty(ENVMonitorNP); + + + } + else + { + + deleteProperty(CalibrateSP); + deleteProperty(PowerMonitorNP); + deleteProperty(ENVMonitorNP); + + deleteProperty(dc2ControlSP); + deleteProperty(setDC2voltageNP); + deleteProperty(DC4_6ControlSP); + + deleteProperty(USBControlSP); + + + deleteProperty(DC3ControlNP); + + + deleteProperty(DC3diffSP); + deleteProperty(DC3diffSETNP); + + + + } + return true; +} + +bool WandererBoxPlusV3::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) +{ + // Calibrate + if (CalibrateSP.isNameMatch(name)) + { + CalibrateSP.setState(sendCommand("66300744") ? IPS_OK : IPS_ALERT); + CalibrateSP.apply(); + LOG_INFO("Calibrating Current Readings..."); + return true; + } + + + // DC2 Control + if (dc2ControlSP.isNameMatch(name)) + { + dc2ControlSP.update(states, names, n); + dc2ControlSP.setState(IPS_ALERT); + char cmd[128] = {0}; + snprintf(cmd, 128, "12%d", (dc2ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + dc2ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + dc2ControlSP.apply(); + + return true; + } + // DC4-6 Control + if (DC4_6ControlSP.isNameMatch(name)) + { + DC4_6ControlSP.update(states, names, n); + DC4_6ControlSP.setState(IPS_ALERT); + char cmd[128] = {0}; + snprintf(cmd, 128, "10%d", (DC4_6ControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + DC4_6ControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + DC4_6ControlSP.apply(); + + return true; + } + + // USB Control + if (USBControlSP.isNameMatch(name)) + { + USBControlSP.update(states, names, n); + USBControlSP.setState(IPS_ALERT); + char cmd[128] = {0}; + snprintf(cmd, 128, "11%d", (USBControlSP[INDI_ENABLED].getState() == ISS_ON) ? 1 : 0); + USBControlSP.setState( sendCommand(cmd) ? IPS_OK : IPS_ALERT); + + return true; + } + + // DC3 DEW + if (DC3diffSP.isNameMatch(name)) + { + DC3diffSP.update(states, names, n); + DC3diffSP.setState(IPS_ALERT); + if(DC3diffSP[DC3_DPD_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value!=-127&&isnan(ENVMonitorNP[DEW_Point].value)==0) + { + DC3DIFFMODE=true; + DC3CONSTMODE=false; + deleteProperty(DC3ControlNP); + deleteProperty(DC3constSETNP); + defineProperty(DC3diffSETNP); + + DC3diffSETNP.setState(IPS_OK); + DC3diffSETNP.apply(); + DC3diffSP.setState(IPS_OK) ; + DC3diffSP.apply(); + LOGF_INFO("Dew Point Difference Mode for DC3 activated! WandererBox will keep the dew heater at the temperature higher than the dew point by the set value.","Updated"); + return true; + } + else if(DC3diffSP[DC3_DPD_Mode].getState() == ISS_ON&&(ENVMonitorNP[Probe1_Temp].value==-127||isnan(ENVMonitorNP[DEW_Point].value)==1)) + { + DC3DIFFMODE=false; + DC3CONSTMODE=false; + DC3diffSP[DC3_Manual].setState( ISS_ON); + LOGF_INFO("Manual Mode for DC3 activated! Please adjust the duty cycle manually, you can also use DC3 as an ordinary switch.","Updated"); + DC3diffSP.apply(); + } + else if(DC3diffSP[DC3_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value!=-127) + { + DC3CONSTMODE=true; + DC3DIFFMODE=false; + deleteProperty(DC3diffSETNP); + deleteProperty(DC3ControlNP); + defineProperty(DC3constSETNP); + + DC3constSETNP.setState(IPS_OK); + DC3constSETNP.apply(); + DC3diffSP.setState(IPS_OK) ; + DC3diffSP.apply(); + LOGF_INFO("Constant Temperature Mode for DC3 activated! WandererBox will keep the dew heater at the set temperature.","Updated"); + return true; + } + else if(DC3diffSP[DC3_CT_Mode].getState() == ISS_ON&&ENVMonitorNP[Probe1_Temp].value==-127) + { + DC3DIFFMODE=false; + DC3CONSTMODE=false; + DC3diffSP[DC3_Manual].setState( ISS_ON); + LOGF_INFO("Manual Mode for DC3 activated! Please adjust the duty cycle manually, you can also use DC3 as an ordinary switch.","Updated"); + DC3diffSP.apply(); + } + else + { + DC3DIFFMODE=false; + DC3CONSTMODE=false; + defineProperty(DC3ControlNP); + deleteProperty(DC3diffSETNP); + deleteProperty(DC3constSETNP); + DC3diffSP.setState(IPS_OK) ; + DC3diffSP.apply(); + LOGF_INFO("Manual Mode for DC3 activated! Please adjust the duty cycle manually, you can also use DC3 as an ordinary switch.","Updated"); + return true; + } + + } + + + return DefaultDevice::ISNewSwitch(dev, name, states, names, n); +} + +bool WandererBoxPlusV3::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) +{ + if (dev && !strcmp(dev, getDeviceName())) + { + // DC3 + if (DC3ControlNP.isNameMatch(name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + rc1 = setDewPWM(3, static_cast(values[i])); + } + + DC3ControlNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (DC3ControlNP.getState() == IPS_OK) + DC3ControlNP.update(values, names, n); + DC3ControlNP.apply(); + return true; + } + if (DC3diffSETNP.isNameMatch(name)) + { + + DC3diffSETNP.setState(IPS_OK) ; + if (DC3diffSETNP.getState() == IPS_OK) + DC3diffSETNP.update(values, names, n); + DC3diffSETNP.apply(); + return true; + } + if (DC3constSETNP.isNameMatch(name)) + { + + DC3constSETNP.setState(IPS_OK) ; + if (DC3constSETNP.getState() == IPS_OK) + DC3constSETNP.update(values, names, n); + DC3constSETNP.apply(); + return true; + } + + // DC2voltageSET + if (setDC2voltageNP.isNameMatch(name)) + { + bool rc1 = false; + for (int i = 0; i < n; i++) + { + rc1 = setDewPWM(20, static_cast(10*values[i])); + } + + setDC2voltageNP.setState( (rc1) ? IPS_OK : IPS_ALERT); + if (setDC2voltageNP.getState() == IPS_OK) + setDC2voltageNP.update(values, names, n); + setDC2voltageNP.apply(); + return true; + } + + + } + return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); +} + +bool WandererBoxPlusV3::setDewPWM(uint8_t id, uint8_t value) +{ + char cmd[64] = {0}; + snprintf(cmd, 64, "%d%03d", id, value); + if (sendCommand(cmd)) + { + return true; + } + + return false; +} + +const char *WandererBoxPlusV3::getDefaultName() +{ + return "WandererBox Pro V3"; +} + + +bool WandererBoxPlusV3::sendCommand(std::string command) +{ + int nbytes_written = 0, rc = -1; + std::string command_termination = "\n"; + LOGF_DEBUG("CMD: %s", command.c_str()); + if ((rc = tty_write_string(PortFD, (command + command_termination).c_str(), &nbytes_written)) != TTY_OK) + { + char errorMessage[MAXRBUF]; + tty_error_msg(rc, errorMessage, MAXRBUF); + LOGF_ERROR("Serial write error: %s", errorMessage); + return false; + } + return true; +} + +void WandererBoxPlusV3::TimerHit() +{ + if (!isConnected()) + { + SetTimer(2500); + return; + } + + getData(); + SetTimer(2500); +} + +bool WandererBoxPlusV3::saveConfigItems(FILE * fp) +{ + INDI::DefaultDevice::saveConfigItems(fp); + + DC3diffSP.save(fp); + DC3diffSETNP.save(fp); + DC3constSETNP.save(fp); + DC3ControlNP.save(fp); + + setDC2voltageNP.save(fp); + return true; +} + diff --git a/drivers/auxiliary/wandererbox_plus_v3.h b/drivers/auxiliary/wandererbox_plus_v3.h new file mode 100644 index 0000000000..53ccc5d551 --- /dev/null +++ b/drivers/auxiliary/wandererbox_plus_v3.h @@ -0,0 +1,163 @@ +/******************************************************************************* + Copyright(c) 2024 Frank Wang. All rights reserved. + + WandererBox Plus V3 + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + The full GNU General Public License is included in this distribution in the + file called LICENSE. +*******************************************************************************/ + +#pragma once + +#include "defaultdevice.h" +#include +#include + +namespace Connection +{ +class Serial; +} + +class WandererBoxPlusV3 : public INDI::DefaultDevice +{ +public: + WandererBoxPlusV3(); + virtual ~WandererBoxPlusV3() = default; + + virtual bool initProperties() override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool updateProperties() override; + + + +protected: + const char *getDefaultName() override; + virtual bool saveConfigItems(FILE *fp) override; + virtual void TimerHit() override; + + +private: + + int firmware=0; + bool sendCommand(std::string command); + bool DC3DIFFMODE=false; + bool DC3CONSTMODE=false; + bool getData(); + static constexpr const char *ENVIRONMENT_TAB {"Sensors"}; + static constexpr const char *DC3_TAB {"DC3"}; + //Current Calibrate + INDI::PropertySwitch CalibrateSP{1}; + + + //Temp1 + double temp1read = 0; + //DHTH + double DHTHread = 0; + //DHTT + void updateENV(double temp1,double DHTH,double DHTT); + double DHTTread = 0; + //Total Current + double Tcurrentread = 0; + //Power Monitor + void updatePower(double Tcurrent,double voltage); + double voltageread = 0; + //USB + void updateUSB(int value); + int USBread = 0; + //DC2 + void updateDC2(int value); + int DC2read = 0; + //DC3 + void updateDC3(int value); + int DC3read = 0; + //DC4_6 + void updateDC4_6(int value); + int DC4_6read = 0; + //DC2set + void updateDC2SET(double value); + int DC2SETread = 0; + + bool setDewPWM(uint8_t id, uint8_t value); + + //DC Control////////////////////////////////////////////////////////////////////////////////// + INDI::PropertySwitch dc2ControlSP{2}; + INDI::PropertySwitch DC4_6ControlSP{2}; + //USB Control////////////////////////////////////////////////////////////////////////////////// + INDI::PropertySwitch USBControlSP{2}; + //DC3 Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber DC3ControlNP{1}; + enum + { + DC3, + }; + //DC3 DIFF//////////////////////////////////////////////////////////////// + INDI::PropertySwitch DC3diffSP{3}; + enum + { + DC3_Manual, + DC3_DPD_Mode, + DC3_CT_Mode, + }; + + INDI::PropertyNumber DC3diffSETNP{1}; + enum + { + DC3DIFFSET, + }; + INDI::PropertyNumber DC3constSETNP{1}; + enum + { + DC3CONSTSET, + }; + + + + //DC2 Voltage Control//////////////////////////////////////////////////////////////// + INDI::PropertyNumber setDC2voltageNP{1}; + enum + { + setDC2voltage, + }; + + // Power Monitor + + INDI::PropertyNumber PowerMonitorNP{2}; + enum + { + VOLTAGE, + TOTAL_CURRENT, + }; + + // ENV Monitor + + INDI::PropertyNumber ENVMonitorNP{4}; + enum + { + Probe1_Temp, + ENV_Humidity, + ENV_Temp, + DEW_Point, + }; + + + + int PortFD{ -1 }; + + Connection::Serial *serialConnection{ nullptr }; +}; From 003b6718fb2fbb07d2755bee6c26d9ed3893358d Mon Sep 17 00:00:00 2001 From: WandererAstro Date: Sat, 17 Feb 2024 17:43:15 +0800 Subject: [PATCH 9/9] Driver for WandererBox Plus V3 updated --- drivers.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers.xml b/drivers.xml index 6ccf58b079..7a1f10f910 100644 --- a/drivers.xml +++ b/drivers.xml @@ -75,10 +75,6 @@ indi_lx200ap_v2 1.1 - - indi_lx200autostar - 2.1 - indi_lx200_pegasus_nyx101 2.1