|
| 1 | +function decodeUplink(input) { |
| 2 | + return { |
| 3 | + data: Decode(input.fPort, input.bytes, input.variables) |
| 4 | + }; |
| 5 | +} |
| 6 | + |
| 7 | +function Decode(fPort, bytes, variables) { |
| 8 | +//LT33222-L or LT22222-L Decode |
| 9 | + if(fPort==0x02) |
| 10 | + { |
| 11 | + var hardware= (bytes[10] & 0xC0)>>6; |
| 12 | + var mode0= bytes[10] & 0xff; |
| 13 | + var mode= bytes[10] & 0x3f; |
| 14 | + var decode = {}; |
| 15 | + |
| 16 | + if(hardware=='0') |
| 17 | + { |
| 18 | + decode.Hardware_mode="LT33222"; |
| 19 | + decode.Node_type="LT-33222-L"; |
| 20 | + decode.DO3_status=(bytes[8] &0x04)? "Low":"High"; |
| 21 | + if(mode0=='1') |
| 22 | + { |
| 23 | + decode.DI3_status= (bytes[8] &0x20)?"High":"Low"; |
| 24 | + } |
| 25 | + } |
| 26 | + else if(hardware=='1') |
| 27 | + { |
| 28 | + decode.Node_type="LT-22222-L"; |
| 29 | + decode.Hardware_mode= "LT22222"; |
| 30 | + } |
| 31 | + |
| 32 | + if(mode!=6) |
| 33 | + { |
| 34 | + decode.DO1_status= (bytes[8] &0x01)? "Low":"High"; |
| 35 | + decode.DO2_status= (bytes[8] &0x02)? "Low":"High"; |
| 36 | + decode.RO1_status= (bytes[8] &0x80)? "ON":"OFF"; |
| 37 | + decode.RO2_status= (bytes[8] &0x40)? "ON":"OFF"; |
| 38 | + if(mode!=1) |
| 39 | + { |
| 40 | + if(mode!=5) |
| 41 | + { |
| 42 | + decode.Count1_times= (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3])>>>0; |
| 43 | + } |
| 44 | + decode.First_status= (bytes[8] &0x20)? "Yes":"No"; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + if(mode=='1') |
| 49 | + { |
| 50 | + decode.Work_mode= "2ACI+2AVI"; |
| 51 | + decode.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); |
| 52 | + decode.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); |
| 53 | + decode.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); |
| 54 | + decode.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); |
| 55 | + decode.DI1_status= (bytes[8] &0x08)? "High":"Low"; |
| 56 | + decode.DI2_status= (bytes[8] &0x10)? "High":"Low"; |
| 57 | + } |
| 58 | + else if(mode=='2') |
| 59 | + { |
| 60 | + decode.Work_mode= "Count mode 1"; |
| 61 | + decode.Count2_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]) >>>0; |
| 62 | + } |
| 63 | + else if(mode=='3') |
| 64 | + { |
| 65 | + decode.Work_mode= "2ACI+1Count"; |
| 66 | + decode.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); |
| 67 | + decode.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); |
| 68 | + } |
| 69 | + else if(mode=='4') |
| 70 | + { |
| 71 | + decode.Work_mode= "Count mode 2"; |
| 72 | + decode.Acount_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]) >>>0; |
| 73 | + } |
| 74 | + else if(mode=='5') |
| 75 | + { |
| 76 | + decode.Work_mode= " 1ACI+2AVI+1Count"; |
| 77 | + decode.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); |
| 78 | + decode.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); |
| 79 | + decode.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); |
| 80 | + decode.Count1_times= bytes[6]<<8 | bytes[7]; |
| 81 | + } |
| 82 | + else if(mode=='6') |
| 83 | + { |
| 84 | + decode.Work_mode= "Trigger mode"; |
| 85 | + decode.Mode_status= bytes[9] ? "True":"False"; |
| 86 | + decode.AV1L_flag= (bytes[0] &0x80)? "True":"False"; |
| 87 | + decode.AV1H_flag= (bytes[0] &0x40)? "True":"False"; |
| 88 | + decode.AV2L_flag= (bytes[0] &0x20)? "True":"False"; |
| 89 | + decode.AV2H_flag= (bytes[0] &0x10)? "True":"False"; |
| 90 | + decode.AC1L_flag= (bytes[0] &0x08)? "True":"False"; |
| 91 | + decode.AC1H_flag= (bytes[0] &0x04)? "True":"False"; |
| 92 | + decode.AC2L_flag= (bytes[0] &0x02)? "True":"False"; |
| 93 | + decode.AC2H_flag= (bytes[0] &0x01)? "True":"False"; |
| 94 | + decode.AV1L_status= (bytes[1] &0x80)? "True":"False"; |
| 95 | + decode.AV1H_status= (bytes[1] &0x40)? "True":"False"; |
| 96 | + decode.AV2L_status= (bytes[1] &0x20)? "True":"False"; |
| 97 | + decode.AV2H_status= (bytes[1] &0x10)? "True":"False"; |
| 98 | + decode.AC1L_status= (bytes[1] &0x08)? "True":"False"; |
| 99 | + decode.AC1H_status= (bytes[1] &0x04)? "True":"False"; |
| 100 | + decode.AC2L_status= (bytes[1] &0x02)? "True":"False"; |
| 101 | + decode.AC2H_status= (bytes[1] &0x01)? "True":"False"; |
| 102 | + decode.DI2_status= (bytes[2] &0x08)? "True":"False"; |
| 103 | + decode.DI2_flag= (bytes[2] &0x04)? "True":"False"; |
| 104 | + decode.DI1_status= (bytes[2] &0x02)? "True":"False"; |
| 105 | + decode.DI1_flag= (bytes[2] &0x01)? "True":"False"; |
| 106 | + } |
| 107 | + |
| 108 | + if(bytes.length!=1) |
| 109 | + return decode; |
| 110 | + } |
| 111 | + |
| 112 | + else if(fPort==5) |
| 113 | + { |
| 114 | + var freq_band; |
| 115 | + var sub_band; |
| 116 | + |
| 117 | + if(bytes[0]==0x01) |
| 118 | + freq_band="EU868"; |
| 119 | + else if(bytes[0]==0x02) |
| 120 | + freq_band="US915"; |
| 121 | + else if(bytes[0]==0x03) |
| 122 | + freq_band="IN865"; |
| 123 | + else if(bytes[0]==0x04) |
| 124 | + freq_band="AU915"; |
| 125 | + else if(bytes[0]==0x05) |
| 126 | + freq_band="KZ865"; |
| 127 | + else if(bytes[0]==0x06) |
| 128 | + freq_band="RU864"; |
| 129 | + else if(bytes[0]==0x07) |
| 130 | + freq_band="AS923"; |
| 131 | + else if(bytes[0]==0x08) |
| 132 | + freq_band="AS923_1"; |
| 133 | + else if(bytes[0]==0x09) |
| 134 | + freq_band="AS923_2"; |
| 135 | + else if(bytes[0]==0x0A) |
| 136 | + freq_band="AS923_3"; |
| 137 | + else if(bytes[0]==0x0F) |
| 138 | + freq_band="AS923_4"; |
| 139 | + else if(bytes[0]==0x0B) |
| 140 | + freq_band="CN470"; |
| 141 | + else if(bytes[0]==0x0C) |
| 142 | + freq_band="EU433"; |
| 143 | + else if(bytes[0]==0x0D) |
| 144 | + freq_band="KR920"; |
| 145 | + else if(bytes[0]==0x0E) |
| 146 | + freq_band="MA869"; |
| 147 | + |
| 148 | + if(bytes[1]==0xff) |
| 149 | + sub_band="NULL"; |
| 150 | + else |
| 151 | + sub_band=bytes[1]; |
| 152 | + |
| 153 | + var firm_ver= (bytes[2]&0x0f)+'.'+(bytes[3]>>4&0x0f)+'.'+(bytes[3]&0x0f); |
| 154 | + |
| 155 | + var tdc_time= bytes[4]<<16 | bytes[5]<<8 | bytes[6]; |
| 156 | + |
| 157 | + return { |
| 158 | + FIRMWARE_VERSION:firm_ver, |
| 159 | + FREQUENCY_BAND:freq_band, |
| 160 | + SUB_BAND:sub_band, |
| 161 | + TDC_sec:tdc_time, |
| 162 | + } |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +function encodeDownlink(input) { |
| 167 | + var command = input.data.command; |
| 168 | + var output = []; |
| 169 | + |
| 170 | + for (var i=0,j=0; i<command.length; i+=2,j++) { |
| 171 | + output[j]=parseInt(command.substr(i,2), 16); |
| 172 | + } |
| 173 | + |
| 174 | + return {bytes: output}; |
| 175 | +} |
0 commit comments