Skip to content

Commit

Permalink
Added decoding of report answer to command "X"
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Verbraak committed Jan 20, 2022
1 parent 96bd39c commit 92f8645
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cul.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const Cul = function (options) {
options.networkTimeout = options.networkTimeout || true;
options.logger = options.logger || console.log;

that.getReport = 0;

if (options.coc) {
options.baudrate = options.baudrate || 38400;
options.serialport = options.serialport || '/dev/ttyACM0';
Expand Down Expand Up @@ -179,6 +181,9 @@ const Cul = function (options) {
options.logger('->', data);
}

if (data == "X")
that.getReport++;

serialPort.write(data + '\r\n');
serialPort.drain(callback);
};
Expand Down Expand Up @@ -320,6 +325,23 @@ const Cul = function (options) {
message = protocol[p].parse(data);
}
}
else {
if (that.getReport > 0) {
let reportData = Number.parseInt(data.substr(0,2), 16);
message.report = {
knownMessages: (reportData & 0x01) == 0x01,
eachPacket: (reportData & 0x02) == 0x02,
detailedData: (reportData & 0x04) == 0x04,
monitorMode: (reportData & 0x08) == 0x08,
timing: (reportData & 0x10) == 0x10,
rssi: (reportData & 0x20) == 0x20,
FHTprotocolMessage: (reportData & 0x40) == 0x40,
rawRssi: (reportData & 0x80) == 0x80
}
message.availableTime = Number.parseInt(data.substr(2).replace(" ",""));
that.report--;
}
}

if (options.rssi) {
rssi = Number.parseInt(data.slice(-2), 16);
Expand Down

0 comments on commit 92f8645

Please sign in to comment.