44#define TAB_INFO "Status"
84 IUFillNumber(&MCUTempN[0],
"MCU_Temp",
"MCU Temperature (C)",
"%.2f", 0, 200, 0.01, 0);
90 addParameter(
"WEATHER_TEMPERATURE",
"Temperature (C)", -15, 35, 15);
91 addParameter(
"WEATHER_HUMIDITY",
"Humidity %", 0, 100, 15);
92 addParameter(
"WEATHER_DEWPOINT",
"Dew Point (C)", 0, 100, 15);
117 setupComplete =
true;
124 setupComplete =
false;
137bool TerransPowerBoxProV2::Handshake()
150 for(
int HS = 0 ; HS < 3 ; HS++)
152 if (sendCommand(
">VR#", res))
154 if(!strcmp(res,
"*TPPNNN"))
156 if (sendCommand(
">VN#", res))
158 if(!strcmp(res,
"*V001"))
160 LOG_INFO(
"Handshake successfully!");
169 LOG_INFO(
"The firmware version does not match the driver. Please use the latest firmware and driver!");
189 return "TerransPowerBoxProV2";
200 if (processButtonSwitch(dev, name, states, names, n))
228bool TerransPowerBoxProV2::sendCommand(
const char *
cmd,
char * res)
231 int nbytes_read = 0, nbytes_written = 0, tty_rc = 0;
236 for (
int i = 0; i < 2; i++)
238 tcflush(PortFD, TCIOFLUSH);
245 tcflush(PortFD, TCIOFLUSH);
252 tcflush(PortFD, TCIOFLUSH);
253 res[nbytes_read - 1] =
'\0';
280void TerransPowerBoxProV2::Get_State()
283 static bool powerChanged =
false;
284 static bool usbChanged =
false;
288 powerChanged =
false;
289 if (sendCommand(
">GDA#", res))
302 if (sendCommand(
">GDB#", res))
315 if (sendCommand(
">GDC#", res))
328 if (sendCommand(
">GDD#", res))
341 if (sendCommand(
">GDE#", res))
354 if (sendCommand(
">GDF#", res))
367 if (sendCommand(
">GDG#", res))
385 if (sendCommand(
">GUA#", res))
398 if (sendCommand(
">GUB#", res))
411 if (sendCommand(
">GUC#", res))
424 if (sendCommand(
">GUD#", res))
437 if (sendCommand(
">GUE#", res))
450 if (sendCommand(
">GUF#", res))
467 if (sendCommand(
">GS#", res))
475 if (sendCommand(
">GPF#", res))
477 ch3_bus = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
493 if (sendCommand(
">GPE#", res))
495 ch3_shuntv = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
514 if (sendCommand(
">GPC#", res))
516 ch2_shuntv = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
531 if (sendCommand(
">GPA#", res))
533 ch1_shuntv = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
549 if (sendCommand(
">GTC#", res))
551 mcu_temp = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
554 MCUTempN[0].value = 0;
564 else if (res[2] ==
'B')
578 if (sendCommand(
">GTH#", res))
580 humidity = (res[5] - 0x30) + ((res[4] - 0x30) * 10) + ((res[3] - 0x30) * 100) + ((res[2] - 0x30) * 1000);
596 if (sendCommand(
">GTT#", res))
598 temperature = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
610 else if (res[2] ==
'B')
623 if (sendCommand(
">GTD#", res))
625 dewPoint = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
637 else if (res[2] ==
'B')
667bool TerransPowerBoxProV2::processButtonSwitch(
const char *dev,
const char *name,
ISState * states,
char *names[],
int n)
683 const char* commands[][2] =
685 {
">SDA1#",
">SDA0#"},
686 {
">SDB1#",
">SDB0#"},
687 {
">SDC1#",
">SDC0#"},
688 {
">SDD1#",
">SDD0#"},
689 {
">SDE1#",
">SDE0#"},
690 {
">SDF1#",
">SDF0#"},
697 const char*
cmd = enabled ? commands[port][0] : commands[port][1];
699 if (sendCommand(
cmd, res))
723 sendCommand(
">SA10#",
nullptr);
730 sendCommand(
">SA20#",
nullptr);
732 else if (voltage < 10.5)
734 sendCommand(
">SA40#",
nullptr);
738 sendCommand(
">SA550#",
nullptr);
768 const char* commands[][2] =
770 {
">SUA1A#",
">SUA0A#"},
771 {
">SUB1A#",
">SUB0A#"},
772 {
">SUC1A#",
">SUC0A#"},
773 {
">SUD1A#",
">SUD0A#"},
774 {
">SUE1A#",
">SUE0A#"},
775 {
">SUF1A#",
">SUF0A#"}
781 const char*
cmd = enabled ? commands[port][0] : commands[port][1];
783 if (sendCommand(
cmd, res))
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
const char * getDeviceName() const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
bool saveConfigItems(FILE *fp)
saveConfigItems Save power properties in config file
void SetCapability(uint32_t cap)
SetPowerCapability sets the Power capabilities. All capabilities must be initialized.
@ POWER_HAS_VOLTAGE_SENSOR
@ POWER_HAS_OVERALL_CURRENT
@ POWER_HAS_PER_PORT_CURRENT
INDI::PropertyNumber PowerSensorsNP
INDI::PropertyNumber PowerChannelCurrentNP
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process Power number properties.
void initProperties(const char *groupName, size_t nPowerPorts=0, size_t nDewPorts=0, size_t nVariablePorts=0, size_t nAutoDewPorts=0, size_t nUSBPorts=0)
Initialize Power properties. It is recommended to call this function within initProperties() of your ...
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process Power text properties.
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process Power switch properties.
INDI::PropertySwitch PowerChannelsSP
INDI::PropertySwitch USBPortSP
bool updateProperties()
updateProperties Define or Delete Power properties based on the connection status of the base device
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning, bool flipWarning=false)
Add a physical weather measurable parameter to the weather driver.
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
INDI::PropertyNumber ParametersNP
void initProperties(const char *statusGroup, const char *paramsGroup)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool SetPowerPort(size_t port, bool enabled) override
SetPowerPort Set power port on/off.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual const char * getDefaultName() override
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
Namespace to encapsulate INDI client, drivers, and mediator classes.