31 #define SHORT_TIMEOUT 2
41 int sz = (int)data.size();
44 for (
int i = 0; i < sz; i++)
46 snprintf(&
debugStr[i * 3], 301,
"%02X ", data[i]);
59 this->
length = data.size() + 3;
64 buff.resize(this->
length + 3);
70 for (uint32_t i = 0; i <
data.size(); i++)
72 buff[5 + i] =
data[i];
75 buff.back() = checksum(buff);
82 if (packet.size() < 6)
95 if (packet.size() !=
length + 3)
98 packet.size(),
length + 3);
105 data =
buffer(packet.begin() + 5, packet.end() - 1);
107 uint8_t cs = checksum(packet);
108 uint8_t cb = packet[
length + 2];
117 uint8_t Packet::checksum(
buffer packet)
120 for (
int i = 1; i < packet[1] + 2; i++)
146 pkt.FillBuffer(txbuff);
150 tcflush(portFD, TCIOFLUSH);
151 if ( (ttyrc =
tty_write(portFD,
reinterpret_cast<const char *
>(txbuff.data()), txbuff.size(), &ns)) !=
TTY_OK)
161 bool Communicator::readPacket(
int portFD, Packet &reply)
164 int nr = 0, ttyrc = 0;
173 "readPacket fail read hdr tty %i %s, nr %i", ttyrc, errmsg, nr);
203 packet.insert(packet.end(), rxdata, rxdata + len + 1);
207 return reply.Parse(packet);
215 while (num_tries++ < 3)
217 if (!sendPacket(portFD, dest,
cmd, data))
221 if (!readPacket(portFD, pkt))
228 "sendCommand pkt.command %i cmd %i, pkt.destination %i pkt.source %i dest %i",
static std::string Device
bool commandBlind(int port, Target dest, Command cmd, buffer data)
bool sendCommand(int port, Target dest, Command cmd, buffer data, buffer &reply)
The Packet class handles low-level communication with the Celestron devices.
static const uint8_t AUX_HDR
void FillBuffer(buffer &buf)
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Implementations for common driver routines.
#define DEBUGDEVICE(device, priority, msg)
#define DEBUGFDEVICE(device, priority, msg,...)
Command
The Command enum includes all the command types sent to the various devices (motor,...
std::vector< uint8_t > buffer
Target
The Target enum Specifies the target device of the command.
char * toHexStr(buffer data)