diff --git a/README.md b/README.md index 61e72ed..7bb6cf8 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,5 @@ - [XML](./dec/readme.md#xml) - [MessagePack](./dec/readme.md#messagepack) - [Protocol Buffers](./pbf) -- [LoRaWAN codec API](./lora) \ No newline at end of file +- [LoRaWAN codec API](./lora) +- [Taiga decoder](./taiga) \ No newline at end of file diff --git a/taiga/decoder.js b/taiga/decoder.js new file mode 100644 index 0000000..ab021be --- /dev/null +++ b/taiga/decoder.js @@ -0,0 +1 @@ +function parseTaiga(e){return void 0===e&&(e="9ae3d56878040f00d8c45c6401f5000f00d8c45c6402f80013004ac55c6401"),Decode(10,hexToBuffer(e))}export function Decode(e,r,t){var a={status_decode:!1,raw:r};if(10===e){var n=0;setpowerInformation(r,n,a),setProtocolInformation(r,++n,a),n++,a.is_sn&&(a.sn=toUInt32LE(r,n),n+=4),a.is_payload_size&&(a.payload_size=toUInt16LE(r,n),n+=2),delete a.is_sn,delete a.is_payload_size;var s=new Date;a.server_isotime=s.toISOString(),a.server_unixtime=Math.floor(s.getTime()/1e3),parseFrames(r,n,a),0==!!a.error&&(a.status_decode=!0)}return a};function decodeUplink(e){return{data:Decode(e.fPort,e.bytes)}}function parseFrames(e,r,t){if(void 0!==e[r]&&void 0!==e[r+1]){var a=e[r]|e[r+1]<<8,n=(4095&a)>>0,s=(61440&a)>>12;r+=2,void 0===t.frames&&(t.frames=[]),0==n?parseFramesDeviceInfo(e,r,t,s):3==n?parseFramesGNSS(e,r,t,s):4==n?parseFramesWiFiGeo(e,r,t,s):5==n?parseFramesMotionActivity(e,r,t,s):6==n?parseFramesShock(e,r,t,s):7==n?parseFramesWasteSensor(e,r,t,s):8==n?parseFramesModbus(e,r,t,s):9==n?parseFramesIBeacon(e,r,t,s):10==n?parseFrames4_20mA(e,r,t,s):11==n?parseFramesDigitalInput(e,r,t,s):12==n?parseFramesAnalogInput(e,r,t,s):13==n?parseFramesPulseCounter(e,r,t,s):14==n?parseFramesLbsGeo(e,r,t,s):16==n?parseFramesRs485(e,r,t,s):17==n?parseFramesSOS(e,r,t,s):18==n?parseFramesTurn(e,r,t,s):19==n?parseFramesMovement(e,r,t,s):20==n?parseFramesIMU(e,r,t,s):21==n?parseFramesODK(e,r,t,s):22==n?parseFramesMBUS(e,r,t,s):23==n?parseFramesModernState(e,r,t,s):24==n?parseFramesHumidity(e,r,t,s):25==n?parseFramesIlluminance(e,r,t,s):32==n?parseFramesAcceleration(e,r,t,s):33==n?parseFramesGuard(e,r,t,s):34==n?parseFramesInclination(e,r,t,s):36==n?parseFramesFallDetection(e,r,t,s):37==n?parseFramesHallDetection(e,r,t,s):15==n?parseFramestemperature(e,r,t,s):unknownFrame(t,n,r-2)}}function unknownFrame(e,r,t){e.error="unknown_frame",e.error_debug_info="type="+r+"|offset="+t}function parseFramesIMU(e,r,t,a){var n={type:"IMU"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.roll=toInt16LE(e,r),r+=2,n.pith=toInt16LE(e,r),r+=2,n.yaw=toInt16LE(e,r),r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramesMBUS(e,r,t,a){console.log("mbus");var n={type:"MBUS"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString();e[r+=4];var s=toHex(e,++r,4);(s<0||s>2576980377)&&(s="unknown");var o=e[r+=4],i=(3&e[++r])>>0,m="unknown";0===i?m="no_error":1===i?m="application_buse":2===i&&(m="any_application_error"),r++,n.medium=getTextMediumMBUS(o),n.status=m,n.meter_serial_number=s;var u=e[r];if(n.dif=parseDif(u),void 0===n.dif.type)n.error="unknown_dif_in_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+r;else if("selection_readout"===n.dif.type||"veriable_length"===n.dif.type||"special_function"===n.dif.type)n.error="unsupported_dif_in_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+r+"|dif_type="+n.dif.type;else{r++,1===n.dif.extension_bit&&setDife(e,r,n),n.dife_list&&n.dife_list.length>0&&(r+=n.dife_list.length);var _=e[r];n.vif=parseVif(_),r++,253===n.vif.value||251===n.vif.value?(n.vif.value=e[r],r++):124===n.vif.value?(n.error="unsupported_vif_in_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+(r-1)+"|vif_type=plain_text"):127===n.vif.value?(n.error="unsupported_vif_in_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+(r-1)+"|vif_type=manufacturer_specific_coding"):n.vif.data=findVife(n.vif.value),1===n.vif.extension_bit&&void 0===n.error&&(setVife(e,r,n,_),void 0!==n.countByteVife&&(r+=n.countByteVife)),n.vife_list&&n.vife_list.length>0?n.units=n.vife_list[n.vife_list.length-1].data:n.units=n.vif.data,isNaN(r)||void 0!==n.error||(n.measurement={},"no_data"==n.dif.type?n.measurement.value_raw="no_data":n.dif.countByte?(n.measurement.raw=e.slice(r,r+n.dif.countByte),r+=n.dif.countByte,"int"===n.dif.type?n.measurement.value_raw=toIntLE(n.measurement.raw,0,n.dif.countByte):"bcd"===n.dif.type?n.measurement.value_raw=toBcdLE(n.measurement.raw):"real"===n.dif.type?n.measurement.value_raw=to32Real(n.measurement.raw):(n.error="error_parse_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+r+"|unknown_type_data"),void 0===n.error&&void 0!==n.units&&(n.measurement.value=n.measurement.value_raw*n.units[1],n.measurement.desc=n.units[3],n.measurement.unit=n.units[2],n.measurement.dataType=n.dif.function_field_desc)):(n.error="error_parse_frame_mbus",n.error_debug_info="type="+n.type+"|offset="+r))}t.frames.push(n),void 0===t.error&&parseFrames(e,r,t)}function parseFramesDeviceInfo(e,r,t,a){var n={type:"device_info"};n.reason=0==a?"boot":1==a?"result_request":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.model_id=toUInt16LE(e,r),n.model_name=getModelNameById(n.model_id),setDeviceFirmwareVersion(e[r+=2],n),r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesODK(e,r,t,a){var n={type:"ODK"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.channel_number=toUInt8(e,r),0===e[++r]?n.state="NORMAL1":1===e[r]?n.state="NORMAL2":2===e[r]?n.state="NORMAL3":3===e[r]?n.state="NORMAL4":4===e[r]?n.state="NORMAL5":5===e[r]?n.state="WET":6===e[r]?n.state="BREAK":7===e[r]?n.state="WET_BREAK":8===e[r]?n.state="UNKNOWN":n.state="unknown",r++,n.current_resistance=toUInt32LE(e,r),r+=4,n.min_resistance=toUInt32LE(e,r),r+=4,n.max_resistance=toUInt32LE(e,r),r+=4,n.middle_resistance=toUInt32LE(e,r),r+=4,n.current_conduct_resistance=toUInt32LE(e,r),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesModernState(e,r,t,a){var n={type:"modern_state"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.iccid=toASCII(e,r,20),r+=20,n.rssi=toInt16LE(e,r),r+=2,n.iccid=toASCII(e,r,15),r+=15,t.frames.push(n),parseFrames(e,r,t)}function parseFramesHumidity(e,r,t,a){var n={type:"humidity"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.humidity_pct=toUInt16LE(e,r),n.humidity_pct>1e3||n.humidity_pct<0?n.humidity_pct="unknown":n.humidity_pct=n.humidity_pct/10,r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramesIlluminance(e,r,t,a){var n={type:"illuminance"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.illuminance_lex=toUInt16LE(e,r),r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramesAcceleration(e,r,t,a){var n={type:"acceleration"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.x_mG=toInt16LE(e,r),r+=2,n.y_mG=toInt16LE(e,r),r+=2,n.z_mG=toInt16LE(e,r),r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramesWasteSensor(e,r,t,a){var n={type:"waste_sensor"};n.reason=0==a?"regular":1==a?"waste_flush":2==a?"temperature_alarm":3==a?"open_alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),0==e[r+=4]?n.position="horizontally":1==e[r]?n.position="vertically":n.position="unknown",r++,n.distance_upper_sensor_cm=toUInt16LE(e,r),(n.distance_upper_sensor_cm<0||n.distance_upper_sensor_cm>300)&&(n.distance_upper_sensor_cm="unknown"),r+=2,n.distance_side_sensor_cm=toUInt16LE(e,r),(n.distance_side_sensor_cm<0||n.distance_side_sensor_cm>300)&&(n.distance_side_sensor_cm="unknown"),r+=2,n.temperature_cel=toInt8(e,r),r++,n.waste_pct=toUInt8(e,r),r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesRs485(e,r,t,a){var n={type:"rs485"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.measurement_row_number=toUInt8(e,r),r++,n.command_number_row=toUInt8(e,r),r++,n.size_answer=toUInt8(e,r),r++,n.answer=toHex(e,r,n.size_answer),r+=n.size_answer,t.frames.push(n),parseFrames(e,r,t)}function parseFramesModbus(e,r,t,a){var n={type:"modbus"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.name=toASCII(e,r,8),r+=8,n.slave_address=toUInt8(e,r),r++,n.register_address=toUInt16LE(e,r),r+=2,n.modbus_function=getNameModbusFunction(e[r]),r++,n.register_counter=toUInt8(e,r),(n.register_counter<0||n.register_counter>4)&&(n.register_counter="unknown"),0===e[++r]?n.signed_flag="unsigned":1===e[r]?n.signed_flag="signed":n.signed_flag="unknown",r++,n.register_value=toHex(e,r,8),r+=8,t.frames.push(n),parseFrames(e,r,t)}function parseFramesTurn(e,r,t,a){var n={type:"turn"};n.reason=1==a?"turn_detect":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesGuard(e,r,t,a){var n={type:"guard"};n.reason=0==a?"normal":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.pin_number=toUInt8(e,r),r++,n.pin_status=toUInt8(e,r),r++,1===n.pin_status?n.pin_status="open":0===n.pin_status?n.pin_status="close":n.pin_status="unknown",t.frames.push(n),parseFrames(e,r,t)}function parseFramesFallDetection(e,r,t,a){var n={type:"fall_detection"};n.reason=1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesHallDetection(e,r,t,a){var n={type:"hall_detection"};n.reason=1==a?"alarm":254==a?"malfunction":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesInclination(e,r,t,a){var n={type:"inclination"};n.reason=0==a?"normal":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.x_axis_angle_pct=toUInt16LE(e,r)/10,r+=2,n.y_axis_angle_pct=toUInt16LE(e,r)/10,r+=2,n.z_axis_angle_pct=toUInt16LE(e,r)/10,r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramestemperature(e,r,t,a){var n={type:"temperature"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.number_sensor=toUInt8(e,r),r++,n.temperature_cel=toInt16LE(e,r)/10,r+=2,t.frames.push(n),parseFrames(e,r,t)}function parseFramesMovement(e,r,t,a){var n={type:"movement"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString();var s=toUInt8(e,r+=4);n.is_movement=0!==s&&(1===s||"unknown"),r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesSOS(e,r,t,a){var n={type:"sos"};n.reason=1==a?"sos_1_detect":2==a?"sos_2_detect":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesShock(e,r,t,a){var n={type:"shock"};n.reason=1==a?"shock_detect":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesMotionActivity(e,r,t,a){var n={type:"motion_activity"};n.reason=0==a?"regular":1==a?"shock_detect":2==a?"stop_movement":3==a?"start_movement":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.period_duration_min=toUInt8(e,r),r++,n.avg_index=toUInt8(e,r),r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesIBeacon(e,r,t,a){var n={type:"ibeacon"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.ibeacons_list=[];var s=toUInt16LE(e,r),o=toUInt16LE(e,r+=2),i=toInt8(e,r+=2),m=toUInt16LE(e,++r),u=toUInt16LE(e,r+=2),_=toInt8(e,r+=2),d=toUInt16LE(e,++r),v=toUInt16LE(e,r+=2),l=toInt8(e,r+=2);r++,validIBeacon(s,o,i)&&n.ibeacons_list.push({major:s,minor:o,rssi:i}),validIBeacon(m,u,_)&&n.ibeacons_list.push({major:m,minor:u,rssi:_}),validIBeacon(d,v,l)&&n.ibeacons_list.push({major:d,minor:v,rssi:l}),setOldIBeaconByte(e[r],n),r++,t.frames.push(n),parseFrames(e,r,t)}function parseFrames4_20mA(e,r,t,a){var n={type:"4_20mA"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.number_sensor=toUInt8(e,r),r++,n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.mA=toUInt32LE(e,r),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesDigitalInput(e,r,t,a){var n={type:"digital_input"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.pin_number=toUInt8(e,r),0===e[++r]?n.pin_state="low":1===e[r]?n.pin_state="high":n.pin_state="unknown",r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesAnalogInput(e,r,t,a){var n={type:"analog_input"};n.reason=0==a?"regular":1==a?"alarm":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.pin_number=toUInt8(e,r),r++,n.mV=toUInt32LE(e,r),0===e[r+=4]?n.input_status="ok":1===e[r]?n.input_status="overvoltage":2===e[r]?n.input_status="no_sensor":3===e[r]?n.input_status="input_error":n.input_status="unknown",r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesPulseCounter(e,r,t,a){var n={type:"pulse_counter"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.pin_number=toUInt8(e,r),r++,n.counter=toUInt32LE(e,r),r+=4,t.frames.push(n),parseFrames(e,r,t)}function parseFramesLbsGeo(e,r,t,a){var n={type:"lbs_geolocation"};n.reason=0==a?"regular":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString();var s=toUInt16LE(e,r+=4),o=toUInt16LE(e,r+=2),i=toUInt16LE(e,r+=2),m=toUInt32LE(e,r+=2),u=toInt16LE(e,r+=4),_=toUInt16LE(e,r+=2),d=toUInt16LE(e,r+=2),v=toUInt16LE(e,r+=2),l=toUInt32LE(e,r+=2),f=toInt16LE(e,r+=4),p=toUInt16LE(e,r+=2),c=toUInt16LE(e,r+=2),g=toUInt16LE(e,r+=2),w=toUInt32LE(e,r+=2),I=toInt16LE(e,r+=4);r+=2,validLbsData(s,o,i,m,u)&&n.lbs_list.push({mcc:s,mnc:o,lac:i,cellid:m,power_dBm:u}),validLbsData(_,d,v,l,f)&&n.lbs_list.push({mcc:_,mnc:d,lac:v,cellid:l,power_dBm:f}),validLbsData(p,c,g,w,I)&&n.lbs_list.push({mcc:p,mnc:c,lac:g,cellid:w,power_dBm:I}),t.frames.push(n),parseFrames(e,r,t)}function parseFramesWiFiGeo(e,r,t,a){var n={type:"wifi"};n.reason=0==a?"regular":1==a?"change_mode":3==a?"result_request":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.wifi_ap_list=[];var s=e.slice(r,r+6),o=toMac(s),i=toInt8(e,r+=6);r++;var m=e.slice(r,r+6),u=toMac(m),_=toInt8(e,r+=6);r++;var d=e.slice(r,r+6),v=toMac(d),l=toInt8(e,r+=6);setOldWiFiGeoByte(e[++r],n),validBssid(s)&&n.wifi_ap_list.push({mac:o,rssi:i,is_home_network:n.is_home_network_1}),validBssid(m)&&n.wifi_ap_list.push({mac:u,rssi:_,is_home_network:n.is_home_network_2}),validBssid(d)&&n.wifi_ap_list.push({mac:v,rssi:l,is_home_network:n.is_home_network_3}),delete n.is_home_network_1,delete n.is_home_network_2,delete n.is_home_network_3,r++,t.frames.push(n),parseFrames(e,r,t)}function parseFramesGNSS(e,r,t,a){var n={type:"gnss"};n.reason=0==a?"regular":1==a?"change_mode":3==a?"result_request":"unknown",n.frame_unixtime=toUInt32LE(e,r),n.frame_isotime=new Date(1e3*n.frame_unixtime).toISOString(),r+=4,n.lat=toIntLE(e,r,4)/1e5,r+=4,n.lon=toIntLE(e,r,4)/1e5,r+=4,n.alt=toUInt16LE(e,r),r+=2,n.speed_kmh=toUInt16LE(e,r),r+=2,n.hdop=toUInt8(e,r)/10,setOldGnssByte(e[++r],n),r++,t.frames.push(n),parseFrames(e,r,t)}function hexToBuffer(e){for(var r=[],t=0;t>>=0]?-1*(255-e[r]+1):e[r]}function to32Real(e){var r=e[0]<<24|e[1]<<16|e[2]<<8|e[3],t=r>>>23&255;return(r>>>31==0?1:-1)*(0==t?(8388607&r)<<1:8388607&r|8388608)*Math.pow(2,t-150)}function toUInt8(e,r){return e[r>>>=0]}function toMac(e){for(var r="",t=0;t>>=0]|e[r+1]<<8}function toInt16LE(e,r){var t=e[r>>>=0]|e[r+1]<<8;return 32768&t?4294901760|t:t}function toUInt32LE(e,r){return(e[r>>>=0]|e[r+1]<<8|e[r+2]<<16)+16777216*e[r+3]}function toBcdLE(e){for(var r=0,t=0,a=0;a>4;t+=((15&e[a])>>0)*Math.pow(10,r),r++,t+=n*Math.pow(10,r),r++}return t}function toIntLE(e,r,t){t>>>=0;for(var a=e[r>>>=0],n=0,s=1;++n=(s*=128)&&(a-=Math.pow(2,8*t)),a}function toASCII(e,r,t){t>>>=0;for(var a="",n=r>>>=0;n>>=0;for(var a="",n=r>>>=0;n>0;t.type_power=0===a?"battery":"external";var n=(254&e[r])>>1;n>=0&&(t.battery_pct=n)}function setProtocolInformation(e,r,t){var a=(1&e[r])>>0,n=(14&e[r])>>1,s=(16&e[r])>>4;e[r];t.is_sn=!!a,t.version_protocol=n,t.is_payload_size=!!s}function setOldWiFiGeoByte(e,r){var t=(16&e)>>4,a=(32&e)>>5,n=(64&e)>>6,s=(128&e)>>7;r.in_movement=!!t,r.is_home_network_1=!!a,r.is_home_network_2=!!n,r.is_home_network_3=!!s}function setOldGnssByte(e,r){var t=(31&e)>>0,a=(32&e)>>5,n=(64&e)>>6,s=(128&e)>>7;r.used_sat=t,r.geofence1=a?"inside":"outside",r.geofence2=n?"inside":"outside",r.in_movement=!!s}function setDeviceFirmwareVersion(e,r){var t=(15&e)>>0,a=(240&e)>>4;r.version=t+"."+a}function setOldIBeaconByte(e,r){var t=(128&e)>>7;r.in_movement=!!t}function getNameModbusFunction(e){return 0==e?"read_coil_status":1==e?"read_discrete_inputs":2==e?"read_hlding_registers":3==e?"input_registers":"unknown"}function getModelNameById(e){return 1===(e=parseInt(e))?"Airbit light controller":200===e?"IXOCAT-LW-FULL":201===e?"IXOCAT-LW-LIGHT":3===e?"Betar LoRaWAN water meter LC":4===e?"Betar Nb-IoT water meter LC":500===e?"IXOCAT-NB-FULL":501===e?"IXOCAT-NB-LIGHT":7===e?"ERTX-L01":8===e?"Construtag":9===e?"MTBO-01-Nb":10===e?"TaigaBikeTracker":11===e?"MTBO-01-2G":12===e?"SST_GAS_radio_module":13===e?"NbIoT Button":14===e?"МКРС-02":15===e?"BS controller":16===e?"Airbit light controller NbIoT":17===e?"IoT node":18===e?"NIS_METER":19===e?"RoadsignTracker-LW-FULL":21===e?"Stels Smoke Sensor":22===e?"Betar LoRaWAN water meter HALL":23===e?"Betar Nb-IoT water meter HALL":24===e?"NodeG":25===e?"TaigaTracker LoRaWAN":26===e?"TaigaTracker Nb-IoT":27===e?"TaigaBeacon":28===e?"ERTX-ODK-2CH":29===e?"ERTX crypto kit":30===e?"TaigaPersonalTracker LW":31===e?"TaigaPersonalTracker NB":32===e?"TaigaPersonalTracker 2G":33===e?"TaigaNode Lw":34===e?"TaigaNode Nb":35===e?"TaigaTracker2G":36===e?"AirbitSensorHub-LW":37===e?"AuroraNodeODK":38===e?"TaigaBigTracker":39===e?"NhrsPersonalTracker":40===e?"WasteSensor-UKS":41===e?"TaigaBikeTrackerE":42===e?"ClickButton":43===e?"FannaConcentrator":44===e?"MyLogger":45===e?"TaigaCartTracker":46===e?"NtmPulseNB":47===e?"SoftControl-Pass":48===e?"TempButton":49===e?"Uveos":50===e?"McsmPulseNB":51===e?"FannaConcentrator IN PWR":52===e?"AuroraNodeOdkBoard":53===e?"Siltrack V1 EXT ANT":54===e?"RaceAnalyse":55===e?"MaximaContainerTracker":56===e?"FannaEframe":57===e?"MaximaWasteSensorV2":58===e?"модуль СГМБ-УСПД-NB-1":59===e?"AuroraNodeLTE":60===e?"AuroraNodeNB":61===e?"AuroraNodeETH":62===e?"TaigaPulseCounterNb":63===e?"FannaAnchor":64===e?"AuroraNodeExtBoards":65===e?"TaigaPersonalTracker LW_without GNSS":66===e?"TaigaPersonalTracker NB_without GNSS":67===e?"AuroraNodeGTS":68===e?"TetronTrackerLight":69===e?"SGMB-NB-2G":70===e?"TaigaPulseCounterLW":71===e?"AnalogPCBBoard":75===e?"ErtxTermologgerNb":"unknown"}function getTextMediumMBUS(e){return 0===e?"Other":1===e?"Oil":2===e?"Electricity":3===e?"Gas":4===e?"Heat (volume measured at return temperature: outlet)":5===e?"Steam":6===e?"Hot Water":7===e?"Water":8===e?"Heat Cost Allocator.":9===e?"Compressed Air":10===e?"Cooling load meter (volume measured at return temperature: outlet)":11===e?"Cooling load meter (volume measured at flow temperature: inlet)":12===e?"Heat (volume measured at flow temperature: inlet)":13===e?"Heat / Cooling load meter":14===e?"Bus / System":15===e?"Unknown Medium":e>=16&&e<=21?"Reserved":22===e?"Cold Water":23===e?"Dual Water":24===e?"Pressure":25===e?"A/D Converter":e>=32&&e<=255?"Reserved":"unknown"}function getTextFuncFieldDif(e){return 0===e?"instantaneous_value":2===e?"minimum_value":1===e?"maximum_value":3===e?"value_during_error_state":void 0}function parseVif(e){var r={raw:e},t=(127&e)>>0,a=(128&e)>>7;return r.extension_bit=a,r.value=t,r}function parseDif(e){var r={raw:e},t=(15&e)>>0,a=(48&e)>>4,n=(64&e)>>6,s=(128&e)>>7;return r.extension_bit=s,r.lsb_storage_number=n,r.function_field=a,r.function_field_desc=getTextFuncFieldDif(r.function_field),0===t?(r.type="no_data",r.countByte=0):1===t?(r.type="int",r.countByte=1):2===t?(r.type="int",r.countByte=2):3===t?(r.type="int",r.countByte=3):4===t?(r.type="int",r.countByte=4):5===t?(r.type="real",r.countByte=4):6===t?(r.type="int",r.countByte=6):7===t?(r.type="int",r.countByte=8):8===t?(r.type="selection_readout",r.countByte=void 0):9===t?(r.type="bcd",r.countByte=1):10===t?(r.type="bcd",r.countByte=2):11===t?(r.type="bcd",r.countByte=3):12===t?(r.type="bcd",r.countByte=4):13===t?(r.type="veriable_length",r.countByte=void 0):14===t?(r.type="bcd",r.countByte=12):15===t&&(r.type="special_function",r.countByte=void 0),r}function findVife(e){for(var r in mbus_variable_vif_table){var t=mbus_variable_vif_table[r];if(e===t[0])return t}return[e,1,"","unknown"]}function setVife(e,r,t,a){void 0===t.vife_list&&(t.vife_list=[]),void 0===t.countByteVife&&(t.countByteVife=0),t.countByteVife++;var n={raw:e[r]};n.value=(127&e[r])>>0,n.extension_bit=(128&e[r])>>7,253===n.value||251===n.value?(r++,t.countByteVife++,n.value=e[r]):n.data=findVife(253===a?n.value+256:251===a?n.value+512:n.value),t.vife_list.push(n),124===t.vif.value?(t.error="unsupported_vif_in_frame_mbus",t.error_debug_info="type="+t.type+"|offset="+(r-1)+"|vif_type=plain_text"):127===t.vif.value&&(t.error="unsupported_vif_in_frame_mbus",t.error_debug_info="type="+t.type+"|offset="+(r-1)+"|vif_type=manufacturer_specific_coding"),void 0===t.error&&1===n.extension_bit&&setVife(e,++r,t,n.raw)}function setDife(e,r,t){void 0===t.dife_list&&(t.dife_list=[]);var a={},n=(15&e[r])>>0,s=(48&e[r])>>4,o=(64&e[r])>>6,i=(128&e[r])>>7;a.storage_number=n,a.tarif=s,a.unit=o,a.extensionBit=i,t.dife_list.push(a),1===a.extensionBit&&setDife(e,++r,t)}function validIBeacon(e,r,t){return!(e<0||e>65535)&&(!(r<0||r>65535)&&!(t<-128||t>0))}function validLbsData(e,r,t,a,n){return!(e<0||e>65535)&&(!(r<0||r>65535)&&(!(t<0||t>65535)&&(!(a<0||a>4294967295)&&!(n<-32768||n>32768))))}function validBssid(e){for(var r=0,t=0,a=0;a