Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liuwenzheng committed Jul 2, 2024
1 parent 79e849c commit 30ab405
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 37 deletions.
16 changes: 8 additions & 8 deletions LW003-B/LW003-V3 Frimware/LW003-B V3 on Chirpstack_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function decodeUplink(input) {
// port 1:Turn on info/port 3:Device info
data.battery_charging_status = bytes[0] & 0x80 ? "in charging" : "no charging";
data.battery_level = (bytes[0] & 0x7F) + "%";
data.battery_voltage = bytesToInt(bytes, 1, 2) + "mV";
data.battery_voltage = (bytesToInt(bytes, 1, 2) / 1000).toFixed(1) + "V";
var firmware_ver_major = (bytes[3] >> 6) & 0x03;
var firmware_ver_minor = (bytes[3] >> 4) & 0x03;
var firmware_ver_patch = bytes[3] & 0x0f;
Expand Down Expand Up @@ -82,7 +82,7 @@ function decodeUplink(input) {
// Turn off info
data.battery_charging_status = bytes[0] & 0x80 ? "in charging" : "no charging";
data.battery_level = (bytes[0] & 0x7F) + "%";
data.battery_voltage = bytesToInt(bytes, 1, 2) + "mV";
data.battery_voltage = (bytesToInt(bytes, 1, 2) / 1000).toFixed(1) + "V";
data.time = parse_time(bytesToInt(bytes, 3, 4), bytes[7] * 0.5);
data.timestamp = bytesToInt(bytes, 3, 4);
data.timezone = timezone_decode(bytes[7]);
Expand Down Expand Up @@ -873,7 +873,7 @@ function decodeUplink(input) {
item.raw_data = bytesToHexString(bytes, parse_len, item.raw_data_length).toUpperCase();
parse_len += item.raw_data_length;
}
datas.push(item);
datas.push(JSON.stringify(item));
}
}
data.scan_data = datas;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ String.prototype.format = function () {
function getData(hex) {
var length = hex.length;
var datas = [];
for (var i = 0; i < length; i += 3) {
for (var i = 0; i < length; i += 2) {
var start = i;
var end = i + 2;
var data = parseInt("0x" + hex.substring(start, end));
Expand All @@ -1029,7 +1029,7 @@ function getData(hex) {
// var datas = [17, 100, 145, 120, 51, 16, 9, 8, 1, 2, 1, 6, 5, 34, 0, 0, 0, 0];

// console.log(getData("11 64 91 78 33 10 09 08 01 02 01 06 05 22 00 00 00 00"));
// var input = {};
// input.fPort = 5;
// input.bytes = getData("03 65 70 2e c9 10 01 65 08 dc 68 be fc 35 c4 cf 65 70 2e c1 20 03 00 34 03 00 00 01 00 09 4d 4b 20 42 75 74 74 6f 6e 00 00 10 ff c8 00 10 fc 1c 00 67 00 0b dc 00 02 01 06 0c 16 e0 fe 20 03 00 34 00 00 01 00 00 0a 09 4d 4b 20 42 75 74 74 6f 6e 18 16 00 ea 00 00 00 10 ff c8 00 10 fc 1c 00 67 00 0b dc dc 68 be fc 35 c4 02 0a 00");
// console.log(decodeUplink(input));
var input = {};
input.fPort = 5;
input.bytes = getData("0066503f2010013f0ae75e188a22e5cb66503f1b000201041aff0a6202151900e75e188a22e5160412101b190e0a00cf1f9ad9020af810094d6b69426561636f6e5f3938373635");
console.log(decodeUplink(input));
38 changes: 19 additions & 19 deletions LW004-PB/V3 Version/LW004-PB V3 on Chirpstack_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ var auxiliaryOperationArray = [
, "Alert alarm"
, "SOS alarm"];
var eventTypeArray = [
"Start of movement"
, "In movement"
, "End of movement"
, "Start SOS alarm"
, "SOS alarm exit"
, "Start Alert alarm"
, "Alert alarm exit"
, "Come into Man Down status"
, "Exit Man Down status"
"Motion On Start"
, "Motion In Trip"
, "Motion On End"
, "SOS Start"
, "SOS End"
, "Alert Start"
, "Alert End"
, "Man Down Start"
, "Man Down End"
];
var shutdownTypeArray = ["Bluetooth command or App", "LoRaWAN Command", "Power button", "Battery run out"];
var posFailedReasonArray = [
Expand Down Expand Up @@ -84,7 +84,7 @@ function decodeUplink(input) {
data.event_type = eventTypeArray[eventTypeCode]; //event
data.payload_type = "Event info"
} else if (fPort == 2) {
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.firmware_version = "V" + bytes[2] + "." + bytes[3] + "." + bytes[4];
data.hardware_version = "V" + bytes[5] + "." + bytes[6];
Expand All @@ -96,20 +96,20 @@ function decodeUplink(input) {
data.payload_type = "Device info"
data.time = parse_time(data.timestamp, bytes[7] * 0.5);
} else if (fPort == 3) {
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.timezone = timezone_decode(bytes[2]); //timezone
data.timestamp = bytesToInt(bytes, 3, 4); //timestamp
data.shutdown_type = shutdownTypeArray[bytes[7]];
data.payload_type = "Turn off info"
data.time = parse_time(data.timestamp, bytes[2] * 0.5);
} else if (fPort == 4) {
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.timezone = timezone_decode(bytes[2]); //timezone
data.timestamp = bytesToInt(bytes, 3, 4); //timestamp
} else if (fPort == 5) {
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.timezone = timezone_decode(bytes[2]); //timezone
data.timestamp = bytesToInt(bytes, 3, 4); //timestamp
Expand All @@ -121,8 +121,8 @@ function decodeUplink(input) {
data.timestamp = timestamp;
data.time = parse_time(timestamp, offsetHours);
data.timezone = timezone_decode(offsetHours * 2);
data.device_mode = deviceModeArray[(bytes[1] >> 5) & 0x07]; //work mode

data.device_mode = deviceModeArray[((bytes[1] >> 5) & 0x07) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] >> 2 & 0x07]; //device status

age = (bytes[1] & 0x01) << 8 | bytes[2];
Expand All @@ -140,9 +140,9 @@ function decodeUplink(input) {
data.longitude = lon / 10000000;
} else if (fPort == 7 || fPort == 11) {
var gps_fix_false_reason = ["hardware_error", "down_request_fix_interrupt", "mandown_fix_interrupt", "alarm_fix_interrupt", "gps_fix_tech_timeout", "gps_fix_timeout", "alert_short_time", "sos_short_time", "pdop_limit", "motion_start_interrupt", "motion_stop_interrupt"];
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.reasons_for_positioning_failure = posFailedReasonArray[bytes[2]];
data.reasons_for_positioning_failure = posFailedReasonArray[bytes[2] - 1];
data.location_failure_cn0 = bytes[3];
data.location_failure_cn1 = bytes[4];
data.location_failure_cn2 = bytes[5];
Expand All @@ -155,7 +155,7 @@ function decodeUplink(input) {
data.time = parse_time(timestamp, offsetHours);
data.timezone = timezone_decode(offsetHours * 2);

data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
var age = (bytes[2]) << 8 | bytes[3];
data.age = age + "s"; //age
Expand All @@ -172,7 +172,7 @@ function decodeUplink(input) {

} else if (fPort == 9 || fPort == 13) {
var ble_fix_false_reason = ["none", "hardware_error", "down_request_fix_interrupt", "mandown_fix_interrupt", "alarm_fix_interrupt", "ble_fix_timeout", "ble_adv", "motion_start_interrupt", "motion_stop_interrupt"];
data.device_mode = deviceModeArray[(bytes[1] >> 4) & 0x0F]; //work mode
data.device_mode = deviceModeArray[((bytes[1] >> 4) & 0x0F) - 1]; //work mode
data.auxiliary_operation = auxiliaryOperationArray[bytes[1] & 0x0F]; //device status
data.reasons_for_positioning_failure = posFailedReasonArray2[bytes[2]];

Expand Down
23 changes: 19 additions & 4 deletions LW006/LW006_Decoder_ChirpStack_V4.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ function decodeUplink(input) {
}
if (fPort == 1) {
// Device info
var date = new Date();
var timestamp = Math.trunc(date.getTime() / 1000);
var offsetHours = Math.abs(Math.floor(date.getTimezoneOffset() / 60));
data.timestamp = timestamp;
data.time = parse_time(timestamp, offsetHours);
data.timezone = timezone_decode(offsetHours * 2);
data.payload_type = 'Device info';
var temperature = bytes[1];
if (temperature > 0x80)
Expand All @@ -62,7 +68,8 @@ function decodeUplink(input) {
var hardware_ver_patch = bytes[3] & 0x0f;
data.hardware_version = "V" + hardware_ver_major + "." + hardware_ver_patch;
data.device_mode = deviceMode[bytes[4]];
data.device_status = deviceStatus[bytes[5]];
data.device_status_code = bytes[5];
data.device_status = deviceStatus[data.device_status_code];
data.vibration_status = bytes[6] > 0 ? "Abnormal" : "Normal";

} else if (fPort == 2 || fPort == 3 || fPort == 4) {
Expand All @@ -76,7 +83,7 @@ function decodeUplink(input) {
data.timestamp = bytesToInt(bytes, 2, 4);
data.timezone = timezone_decode(bytes[6]);
data.device_mode = deviceMode[bytes[7]];
data.device_status_code = bytes[8] & 0x0F;
data.device_status_code = bytes[8];
data.device_status = deviceStatus[data.device_status_code];
if (fPort == 2) {
data.payload_type = 'Turn off info';
Expand All @@ -91,6 +98,7 @@ function decodeUplink(input) {
data.time = parse_time(bytesToInt(bytes, 1, 4), bytes[5] * 0.5);
data.timestamp = bytesToInt(bytes, 1, 4);
data.timezone = timezone_decode(bytes[5]);
data.event_type_code = bytes[6] & 0xFF;
data.event_type = eventType[bytes[6]];
} else if (fPort == 6) {
// L76_GPS data
Expand Down Expand Up @@ -131,7 +139,7 @@ function decodeUplink(input) {
data.payload_type = posDataSign[pos_data_sign];
data.pos_data_sign_code = pos_data_sign;
data.device_mode = deviceMode[bytes[4] >> 4];
data.device_status_code = bytes[4] & 0x0F;
data.device_status_code = bytes[4];
data.device_status = deviceStatus[data.device_status_code];
var pos_data_length = bytes[5] & 0xFF;
data.pos_data_length = pos_data_length;
Expand Down Expand Up @@ -173,11 +181,18 @@ function decodeUplink(input) {
data.pdop = pdop;
}
} else if (fPort == 9) {
var date = new Date();
var timestamp = Math.trunc(date.getTime() / 1000);
var offsetHours = Math.abs(Math.floor(date.getTimezoneOffset() / 60));
data.timestamp = timestamp;
data.time = parse_time(timestamp, offsetHours);
data.timezone = timezone_decode(offsetHours * 2);
// Pos Failed
data.payload_type = 'Pos Failed';
data.pos_type = posType[bytes[1]];
data.device_mode = deviceMode[bytes[2]];
data.device_status = deviceStatus[bytes[3]];
data.device_status_code = bytes[3];
data.device_status = deviceStatus[data.device_status_code];
var pos_data_sign = bytes[4] & 0x0F;
data.pos_data_sign = pos_data_sign;
data.failed_reason = fixFailedReason[pos_data_sign];
Expand Down
25 changes: 19 additions & 6 deletions LW008-MT/LW008-MT on ChirpStack_v4.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
var payloadTypeArray = [
"Heartbeat"
, "Location Fixed"
, "Location Failure"
, "Shutdown"
, "Shock"
, "Man Down detection"
, "Event Message"
, "Battery Consumption"
, "GPS Limit"];
var operationModeArray = ["Standby mode", "Periodic mode", "Timing mode", "Motion mode"];
var rebootReasonArray = ["Restart after power failure", "Bluetooth command request", "LoRaWAN command request", "Power on after normal power off"];
var positionTypeArray = [
Expand Down Expand Up @@ -111,35 +121,38 @@ function decodeUplink(input) {
data.ack = bytes[2] & 0x0f;

if (fPort == 1 && bytes.length == 9) {
data.payload_type = payloadTypeArray[0];
parse_port1_data(data, bytes.slice(3), fPort);
} else if (fPort == 2 && bytes.length >= 7) {
data.payload_type = "Pos success info"
data.payload_type = payloadTypeArray[1];
parse_port2_data(data, bytes.slice(3), fPort);
} else if (fPort == 4 && bytes.length >= 5) {
data.payload_type = payloadTypeArray[2];
parse_port4_data(data, bytes.slice(3), fPort);
} else if (fPort == 5 && bytes.length == 4) {
data.payload_type = payloadTypeArray[3];
var obj = {};
var shutdownTypeCode = bytesToInt(bytes, 3, 1);
// obj.shutdown_type_code = shutdownTypeCode;
obj.shutdown_type = shutdownTypeArray[shutdownTypeCode];
data.payload_type = "Turn off info"
data.obj = obj;
} else if (fPort == 6 && bytes.length == 5) {
data.payload_type = payloadTypeArray[4];
var obj = {};
obj.number_of_shocks = bytesToInt(bytes, 3, 2);
data.obj = obj;
} else if (fPort == 7 && bytes.length == 5) {
data.payload_type = payloadTypeArray[5];
var obj = {};
obj.total_idle_time = bytesToInt(bytes, 3, 2);
data.obj = obj;
} else if (fPort == 8 && bytes.length == 4) {
var obj = {};
data.payload_type = "Event info"
data.payload_type = payloadTypeArray[6];
var eventTypeCode = bytesToInt(bytes, 3, 1);
// obj.event_type_code = eventTypeCode;
obj.event_type = eventTypeArray[eventTypeCode];
data.obj = obj;
data.event_type = eventTypeArray[eventTypeCode];
} else if (fPort == 9 && bytes.length == 43) {
data.payload_type = payloadTypeArray[7];
parse_port9_data(data, bytes.slice(3), fPort);
}
// data.obj = data_dic;
Expand Down

0 comments on commit 30ab405

Please sign in to comment.