@@ -58,11 +58,14 @@ function Module() {
5858 SONIC : 'SONIC' ,
5959 LINE1 : 'LINE1' ,
6060 LINE2 : 'LINE2' ,
61+
62+ TEMPERATURE : 'TEMPERATURE' ,
63+ HUMIDITY : 'HUMIDITY' ,
64+ WATER :'WATER' ,
6165 } ,
6266
6367
6468
65-
6669 this . localBuffer = new Array ( 14 ) ;
6770
6871 this . PacketState =
@@ -121,30 +124,40 @@ Module.prototype.addData = function(data, len)
121124 {
122125 if ( this . verifyCRC ( ) )
123126 {
124- console . log ( "CRC ok : " + this . buffer + "len : " + this . pos ) ;
125-
126127 this . buffer [ 0 ] ; //48 (udp)
127128 this . buffer [ 1 ] ; //2 (status)
128129
129- this . StatusData . DC1 = this . buffer [ 2 ] ;
130- this . StatusData . DC2 = this . buffer [ 3 ] ;
131-
132- this . StatusData . SV1 = this . buffer [ 4 ] ;
133- this . StatusData . SV2 = this . buffer [ 5 ] ;
130+ if ( this . buffer [ 1 ] == 0x02 ) {
131+ //console.log("CRC ok : 0x02 " +this.buffer + "len : " + this.pos);
132+ this . StatusData . DC1 = this . buffer [ 2 ] ;
133+ this . StatusData . DC2 = this . buffer [ 3 ] ;
134+
135+ this . StatusData . SV1 = this . buffer [ 4 ] ;
136+ this . StatusData . SV2 = this . buffer [ 5 ] ;
137+
138+ this . StatusData . V3 = this . buffer [ 6 ] ;
139+ this . StatusData . V5 = this . buffer [ 7 ] ;
140+
141+ this . StatusData . IO1 = this . buffer [ 8 ] ;
142+ this . StatusData . IO2 = this . buffer [ 9 ] ;
143+ this . StatusData . IO3 = this . buffer [ 10 ] ;
144+ this . StatusData . IO4 = this . buffer [ 11 ] ;
145+
146+
147+ this . StatusData . SONIC = ( this . buffer [ 12 ] | this . buffer [ 13 ] << 8 ) ;
148+ this . StatusData . LINE1 = ( this . buffer [ 14 ] | this . buffer [ 15 ] << 8 ) == 0 ? 1 : 0 ;
149+ this . StatusData . LINE2 = ( this . buffer [ 16 ] | this . buffer [ 17 ] << 8 ) == 0 ? 1 : 0 ;
150+ } else if ( this . buffer [ 1 ] == 0xb2 ) {
151+ //console.log("CRC ok : " +this.buffer);
152+
153+
154+ this . StatusData . TEMPERATURE = ( this . buffer [ 2 ] | this . buffer [ 3 ] << 8 ) ;
155+ this . StatusData . HUMIDITY = ( this . buffer [ 4 ] | this . buffer [ 5 ] << 8 ) ;
156+ this . StatusData . WATER = ( this . buffer [ 6 ] | this . buffer [ 7 ] << 8 ) ;
134157
135- this . StatusData . V3 = this . buffer [ 6 ] ;
136- this . StatusData . V5 = this . buffer [ 7 ] ;
137-
138- this . StatusData . IO1 = this . buffer [ 8 ] ;
139- this . StatusData . IO2 = this . buffer [ 9 ] ;
140- this . StatusData . IO3 = this . buffer [ 10 ] ;
141- this . StatusData . IO4 = this . buffer [ 11 ] ;
142-
143-
144- this . StatusData . SONIC = ( this . buffer [ 12 ] | this . buffer [ 13 ] << 8 ) ;
145- this . StatusData . LINE1 = ( this . buffer [ 14 ] | this . buffer [ 15 ] << 8 ) == 0 ? 1 : 0 ;
146- this . StatusData . LINE2 = ( this . buffer [ 16 ] | this . buffer [ 17 ] << 8 ) == 0 ? 1 : 0 ;
147-
158+ } else {
159+ //console.log("CRC other : " +this.buffer + "len : " + this.pos);
160+ }
148161
149162 }
150163 else
@@ -336,7 +349,7 @@ ff 55 idx size data a
336349*/
337350Module . prototype . handleLocalData = function ( data ) {
338351
339- console . log ( data ) ;
352+ // console.log(data);
340353 this . addData ( data , data . length ) ;
341354} ;
342355
0 commit comments