function decode_alert_concentrator(source,tinsec,month,day,year,hour,minute,second,len,data) { var i, j, control, version, TS, TF, cyclic, more ; var is, num ; var sensor = Array() ; var idata = Array() ; var pmsg = Array() ; var soffset ; var toffset = Array() ; var is_offset ; var i1, i2 ; var tmm = Array() ; var tdata = Array() ; var wtinsec ; control = data[0] ; version = control & 0x03 ; control = control >> 2 ; TS = control & 0x01 ; control = control >> 1 ; TF = control & 0x01 ; control = control >> 1 ; cyclic = control & 0x07 ; control = control >> 3 ; more = control ; is = 1 ; soffset = 0 ; is_offset = FALSE ; if ( TS ) { soffset = 256*data[is] + data[is+1] ; is += 2 ; is_offset = TRUE ; } num = (len - is) / 4 ; for ( i = 0 ; i < num ; i++ ) { j = is + 4*i ; toffset[i] = data[j+3] ; // Offset i1 = data[j] ; i2 = data[j+1] ; sensor[i] = i1 + 256*(i2 % 32) ; i1 = data[j+1] >> 5 ; i2 = data[j+2] ; idata[i] = 256*i1 + i2 ; } var d = new Date() ; var timezone = d.getTimezoneOffset() ; is_offset = 0 ; // Temporary 5/6/2014 if ( is_offset ) { if ( hour < 12 ) { hour = minute = second = 0 ; } else { hour = 12 ; minute = second = 0 ; } var dtemp = year ; dtemp = dtemp + "-"+ month ; dtemp = dtemp + "-" + mday ; dtemp = dtemp + " " + hour ; dtemp = dtemp + ":" + minute ; dtemp = dtemp + ":" + second ; var dateTime = new Date(dtemp).getTime() ; var tinsec = Math.floor(dateTime/1000) ; wtinsec = tinsec ; tinsec += soffset ; for ( i = 0 ; i < num ; i++ ) tdata[i] = tinsec - toffset[i] - timezone ; // + 3600*tmm.tm_isdst ; } else { for ( i = 0 ; i < num ; i++ ) { tdata[i] = tinsec - toffset[i] - timezone ; // + 3600*tmw.tm_isdst ; } } var d = new Date(tdata[i]*1000) ; var year = d.getFullYear() ; var month = d.getMonth() + 1; if ( month < 10 ) month = '0'+month ; var mday = d.getDate() ; if ( mday < 10 ) mday = '0' + mday ; var hour = d.getHours() ; if ( hour < 10 ) hour = '0'+hour ; var minute = d.getMinutes() ; if ( minute < 10 ) minute = '0' + minute ; var seconds = d.getSeconds() ; if ( seconds < 10 ) seconds = '0' + seconds ; var str = "Decoded ALERT Concentrator Message" ; for ( i = 0 ; i < num ; i++ ) { var stime = month+'/'+mday+'/'+year+' '+hour+':'+minute+':'+seconds ; str = str + "\n" + "Sensor " + sensor[i] " / data = "+idata[i] " / time = "+stime ; } alert(str) ; } function strtime(tinsec) { var d = new Date(tinsec) ; var year = d.gtFullYear() ; var month = d.getMonth() ; if ( month < 10 ) month = '0'+month ; var day = d.getDate() ; if ( day < 10 ) day = '0'+day ; var hour = d.getHours() ; if ( hour < 10 ) hour = '0'+hour ; var minute = d.getMinutes() ; if ( minute < 10 ) minute = '0'+minute ; var second = d.getSeconds() ; if ( second < 10 ) second = '0'+second ; str = month + '/' + day + '/' + year + ' ' + hour + ':' + minute + ':' + second ; return(str) ; } function decode_alert_concentrator(source,tinsec,month,day,year,hour,minute,second,len,data) { } function decodeC(msg) { var hop = Array() ; var msg = msg.substr(1) ; var str = msg.split(',') ; var indx = 0 ; var count = str.length ; var num = parseInt(str[indx]) ; indx++ ; for ( var i = 0 ; i < num ; i++ ) { hop[i] = parseInt(str[indx]) ; indx++ ; } var i = 0 ; var year = 0 ; var month = 0 ; var tinsec = Array() ; var sensor = Array() ; var data = Array() ; var dateTime ; var dtemp ; var nvalues ; while ( indx < count ) { console.log(indx + " / " +count) ; year = str[indx] ; indx++ ; if ( indx >= count ) break ; month = parseInt(str[indx]) ; if ( month < 10 ) month = '0'+month ; indx++ ; if ( indx >= count ) break ; mday = parseInt(str[indx]) ; if ( mday < 10 ) mday = '0' + mday ; indx++ ; if ( indx >= count ) break ; hour = parseInt(str[indx]) ; if ( hour < 10 ) hour = '0' + hour ; indx++ ; if ( indx >= count ) break ; minute = parseInt(str[indx]) ; if ( minute < 10 ) minute = '0' + minute ; indx++ ; if ( indx >= count ) break ; second = parseInt(str) ; if ( second < 10 ) second = '0' + second ; indx++ ; if ( indx >= count ) break ; dtemp = year ; dtemp = dtemp + "-"+ month ; dtemp = dtemp + "-" + mday ; dtemp = dtemp + " " + hour ; dtemp = dtemp + ":" + minute ; dtemp = dtemp + ":" + second ; dateTime = new Date(dtemp).getTime() ; tinsec[i] = Math.floor(dateTime/1000) ; sensor[i] = parseInt(str[indx]) ; indx++ ; if ( indx >= count ) break ; data[i] = parseInt(str[indx]) ; i++ ; } nvalues = i ; var str = "Hops:" ; for ( i = 0 ; i < num ; i++ ) { str = str + ' ' + hop[i] ; if ( i < (num-1) ) str = str + ',' ; console.log('hop['+i+'] = '+hop[i]) ; } alert(str) ; str = "Decoded C-message:\n" ; for ( i = 0 ; i < nvalues ; i++ ) { var date = new Date(tinsec[i]*1000) ; month = date.getMonth() + 1 ; if ( month < 10 ) month = '0'+month ; mday = date.getDate() ; if ( mday < 10 ) mday - '0'+mday ; year = date.getFullYear() ; hour = date.getHours() ; if ( hour < 10 ) hour = '0'+hour ; minute = date.getMinutes() ; if ( minute < 10 ) minute = '0'+minute ; second = date.getSeconds() ; if ( second < 10 ) second = '0'+second ; str = str + 'At '+month+'/'+mday+'/'+year+' '+hour+':'+minute+':'+second+' sensor '+sensor[i]+' data = '+data[i] + '\n' ; } alert(str) ; }