44#define TAB_INFO "Status"
45#define TAB_RENAME "Rename"
95 MCUTempNP[0].
fill(
"MCU_Temp",
"MCU Temperature (C)",
"%.2f", 0, 200, 0.01, 0);
98 StateSaveSP[0].
fill(
"SAVE_STATE",
"Save State",
ISS_ON);
99 StateSaveSP[1].
fill(
"DISABLE_SAVE",
"Disable Save",
ISS_OFF);
129 setupComplete =
true;
140 setupComplete =
false;
150 StateSaveSP.
save(fp);
154bool TerransPowerBoxGoV2::Handshake()
168 for(
int HS = 0 ; HS < 3 ; HS++)
170 if (sendCommand(
">VR#", res))
172 if(!strcmp(res,
"*TPGNNN"))
174 if (sendCommand(
">VN#", res))
176 if(!strcmp(res,
"*V001"))
178 LOG_INFO(
"Handshake successfully!");
188 LOG_INFO(
"The firmware version does not match the driver. Please use the latest firmware and driver!");
211 const char *portCmds[] = {
">SDA",
">SDB",
">SDC",
">SDD",
">SDE"};
212 if (port <
sizeof(portCmds) /
sizeof(portCmds[0]))
214 snprintf(
cmd,
CMD_LEN,
"%s%d#", portCmds[port], enabled ? 1 : 0);
215 if (sendCommand(
cmd, res))
218 char expectedRes[
CMD_LEN] = {0};
219 snprintf(expectedRes,
CMD_LEN,
"*D%c%dNNN",
static_cast<int>((
'A' + port)), enabled ? 1 : 0);
220 return !strcmp(res, expectedRes);
233 LOG_WARN(
"SetDewPort not implemented for TerransPowerBoxGoV2.");
244 LOG_WARN(
"SetVariablePort not implemented for TerransPowerBoxGoV2.");
253 LOG_WARN(
"SetLEDEnabled not implemented for TerransPowerBoxGoV2.");
263 LOG_WARN(
"SetAutoDewEnabled not implemented for TerransPowerBoxGoV2.");
271 LOG_WARN(
"CyclePower not implemented for TerransPowerBoxGoV2.");
282 const char *usbCmds[] = {
">SUA",
">SUB",
">SUE",
">SUF"};
283 if (port <
sizeof(usbCmds) /
sizeof(usbCmds[0]))
287 snprintf(
cmd,
CMD_LEN,
"%s%d%c#", usbCmds[port], enabled ? 1 : 0,
'A');
288 if (sendCommand(
cmd, res))
291 char expectedRes[
CMD_LEN] = {0};
292 if (port == 0 || port == 1)
293 snprintf(expectedRes,
CMD_LEN,
"*U%c%d11N",
static_cast<int>(
'A' + port), enabled ? 1 : 0);
295 snprintf(expectedRes,
CMD_LEN,
"*U%c%d1NN",
static_cast<int>(
'E' + (port - 2)), enabled ? 1 : 0);
296 return !strcmp(res, expectedRes);
306 return "TerransPowerBoxGoV2";
320 StateSaveSP.
update(states, names, n);
321 if (StateSaveSP[0].getState() ==
ISS_ON)
323 if (sendCommand(
">SS1#",
nullptr))
326 LOG_INFO(
"Save Switch State Enable");
331 LOG_INFO(
"Save Switch State Set Fail");
334 else if (StateSaveSP[1].getState() ==
ISS_ON)
336 if (sendCommand(
">SS0#",
nullptr))
339 LOG_INFO(
"Save Switch State Disable");
344 LOG_INFO(
"Save Switch State Set Fail");
374bool TerransPowerBoxGoV2::sendCommand(
const char *
cmd,
char * res)
377 int nbytes_read = 0, nbytes_written = 0, tty_rc = 0;
382 for (
int i = 0; i < 2; i++)
384 tcflush(PortFD, TCIOFLUSH);
391 tcflush(PortFD, TCIOFLUSH);
398 tcflush(PortFD, TCIOFLUSH);
399 res[nbytes_read - 1] =
'\0';
424 bool powerChanged =
false;
425 bool usbChanged =
false;
426 bool stateSaveChanged =
false;
427 bool sensorsChanged =
false;
428 bool mcuTempChanged =
false;
433 const char *portCmds[] = {
">GDA#",
">GDB#",
">GDC#",
">GDD#",
">GDE#"};
434 if (i <
sizeof(portCmds) /
sizeof(portCmds[0]))
436 if (sendCommand(portCmds[i], res))
441 char expectedChannel =
'A' + i;
442 if (strlen(res) >= 4 && res[2] == expectedChannel)
462 const char *usbCmds[] = {
">GUA#",
">GUB#",
">GUE#",
">GUF#"};
463 if (i <
sizeof(usbCmds) /
sizeof(usbCmds[0]))
465 if (sendCommand(usbCmds[i], res))
471 const char *portLetters =
"ABEF";
472 char expectedPort = portLetters[i];
473 if (strlen(res) >= 4 && res[2] == expectedPort)
491 if (sendCommand(
">GS#", res))
494 if (!strcmp(res,
"*SS1NNN"))
496 if (StateSaveSP[0].getState() !=
ISS_ON || StateSaveSP[1].getState() !=
ISS_OFF)
500 stateSaveChanged =
true;
503 else if (!strcmp(res,
"*SS0NNN"))
505 if (StateSaveSP[0].getState() !=
ISS_OFF || StateSaveSP[1].getState() !=
ISS_ON)
509 stateSaveChanged =
true;
513 if (stateSaveChanged)
523 if (sendCommand(
">GPA#", res))
525 ch1_bus = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
530 if (sendCommand(
">GPB#", res))
532 ch1_shuntv = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
546 sensorsChanged =
true;
554 if (sendCommand(
">GC#", res))
556 double newMcuTemp = MCUTempNP[0].getValue();
557 mcu_temp = (res[6] - 0x30) + ((res[5] - 0x30) * 10) + ((res[4] - 0x30) * 100) + ((res[3] - 0x30) * 1000);
569 else if (res[2] ==
'B')
577 if (MCUTempNP[0].getValue() != newMcuTemp)
579 MCUTempNP[0].setValue(newMcuTemp);
581 mcuTempChanged =
true;
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
INDI::PropertyNumber PowerSensorsNP
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 ...
INDI::PropertyText PowerChannelLabelsTP
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
INDI::PropertyText USBPortLabelsTP
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 save(FILE *f) const
save Save property to configuration file.
void setLabel(const char *label)
bool isNameMatch(const char *otherName) const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
bool update(const ISState states[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
virtual bool SetPowerPort(size_t port, bool enabled) override
SetPowerPort Set power port on/off.
virtual bool SetDewPort(size_t port, bool enabled, double dutyCycle) override
SetDewPort Set DEW/Dew port duty cycle.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool CyclePower() override
CyclePower Cycle power to all ports.
virtual const char * getDefaultName() override
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool SetVariablePort(size_t port, bool enabled, double voltage) override
SetVariablePort Set variable voltage port.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, 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 SetAutoDewEnabled(size_t port, bool enabled) override
SetAutoDewEnabled Enable/disable automatic dew control.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool SetLEDEnabled(bool enabled) override
SetLEDEnabled Enable/disable power LEDs.
virtual bool SetUSBPort(size_t port, bool enabled) override
SetUSBPort Set USB port on/off.
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.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
Namespace to encapsulate INDI client, drivers, and mediator classes.