36 : sendTimeoutMultiplier(multiplier), conf{}, gammaSwitch{}
39 fd = open(serialPath, O_RDWR);
42 LOG_ERR(logger,
"Cannot open {}", serialPath);
52 const uint16_t multiplier)
55 gammaSwitch = learnModePin;
58 gammaSwitch->mode(Mode::OUTPUT);
69 bool ret = (write(fd, pkt, packetLength) > 0);
70 Thread::sleep(sendTimeoutMultiplier * packetLength);
80 return read(fd, pkt, 1);
98 bool ok = updateConfig();
122 memcpy(&oldConf, &conf,
sizeof(
GammaConf));
125 LOG_DEBUG(logger,
"Writing new configuration...");
126 writeConfig(newConf);
129 bool ok = updateConfig();
131 if (ok && conf == newConf)
138 LOG_ERR(logger,
"Config error");
139 memcpy(&conf, &oldConf,
sizeof(
GammaConf));
151void Gamma868::enterLearnMode()
156 LOG_DEBUG(logger,
"Entering learn mode...");
168void Gamma868::exitLearnMode()
179void Gamma868::writeConfig(
const GammaConf& newConf)
181 uint8_t confAddress[8] =
"#A";
182 memcpy(confAddress + 2, &(newConf.localAddress), 3);
183 memcpy(confAddress + 5, &(newConf.destinationAddress), 3);
185 write(fd, confAddress, 8);
188 char confBaud[3] =
"#B";
189 confBaud[2] = (uint8_t)newConf.baudrate;
190 write(fd, confBaud, 3);
193 char confHandshake[3] =
"#H";
194 confHandshake[2] = (uint8_t)newConf.handshake;
195 write(fd, confHandshake, 3);
198 char confLora[4] =
"#C";
199 confLora[2] = (uint8_t)newConf.loraSf;
200 confLora[3] = (uint8_t)newConf.loraPower;
201 write(fd, confLora, 4);
204 memcpy(&conf, &newConf,
sizeof(GammaConf));
211bool Gamma868::updateConfig()
220 read(fd, &(msg.buf),
sizeof(GammaMessage));
241 conf.
handshake = (msg.conf.handshake > 0) ?
true : false;
249void Gamma868::waitForOk()
253 LOG_DEBUG(logger,
"Device replied: {}", reply);
#define LOG_ERR(logger,...)
#define LOG_DEBUG(logger,...)
Gamma868(const char *serialPath, const uint16_t multiplier=0)
const int LEARN_MODE_TIMEOUT
bool configure(const GammaConf &newConf)
bool send(uint8_t *pkt, size_t packetLength) override
Send a packet.
ssize_t receive(uint8_t *pkt, size_t packetLength) override
Wait until a new packet is received.
This file includes all the types the logdecoder script will decode.
std::array< uint8_t, 3 > destinationAddress
std::array< uint8_t, 3 > localAddress