Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
RFID TEST
var stdin = process.openStdin(); stdin.addListener("data", function(d) { var message = d.toString().trim(); processTimeIntervalReport(message); }); console.log(__filename); var WRONG_RFID = [ "00000001" ,00000001 ,"00000000" ,00000000 ,0 ,1 ,"0" ,"1" ,"" ,null ]; var readRFID = function(rfid){ var pattern = [ /%\s+\^(.*)\$(.*)\$(.*)\^(.*)\^\?\;(\d+)\=(\d+)\=\?\+\s+(.*)\?/ ,/%\s+\^(.*)\$(.*)\$(.*)\^(.*)\^\?\;(\d+)\=(\d+)\=\?\+(.*)\?/ ,/%\s+\^(.*)\$(.*)\$(.*)\^(.*)\^\?\r?\n\;(\d+)\=(\d+)\=\?\r?\n\+\s+(.*)\?/ ,/%\s+\^(.*)\$(.*)\$(.*)\^(.*)\^\?\r?\n\;(\d+)\=(\d+)\=\?\r?\n\+(.*)\?/ ,/%\s+(\w+)\s+(\w+)\s+(.*)\s+(\?)\r?\n\;(\d+)\=(\d+)\=\?\r?\n\+(.*)\?/ ,/%\s+(\w+)\s+(\w+)\s+(.*)\s+(\?)\;(\d+)\=(\d+)\=\?\+(.*)\?/ ,/%\s+\^(\w+)\s+(\w+)\s+(.*)\^(.*)\?\;(\d+)\=(\d+)\=\?\+\s+(.*)\?/ ]; console.log("READ RFID DATA ",rfid); for(var i in pattern){ var regx =new RegExp(pattern[i]); var rfidData = regx.exec(rfid); //console.log(rfidData); //console.log("READ RFID DATA WITH PATTERN "+i+" result = ",(rfidData)?rfidData.length : null); if(rfidData && rfidData.length >=7){ return rfidData; } } return null; } var processAndUpdatelicense = function(log_row,license,driver,client){ var engine_state = parseStatusMeitrack(log_row,client.box_id); var isLicense = checkRFIDIsLicense(license); console.log("IMEI =>" + log_row.log_IMEI + " BOX_ID ==> " + client.box_id +" ENGINE_STATE ==> " + engine_state + " RFID=>" + license + " IS LICENSE => "+isLicense); if(engine_state == 0 || engine_state == '0'){ console.log("update license to null"); } else if(isLicense){ console.log("update license to "+license); } } checkRFIDIsLicense = function(rfid){ if(rfid == undefined || rfid == null || rfid == ''){ return false; } var rfidUnspace = rfid.replace(new RegExp(' ', 'g'), ''); var isLicense = rfidUnspace.match('^[0-9]{15,}$'); if(isLicense == null){ return false; } else if(rfid.length < 15){ return false; }else{ var split = rfid.split(/\s+/); if(split[3] != undefined && split[3].length < 3){ return false; } return true; } } parseStatusMeitrack = function(log,box_id){ var state = log['log_value']; var engine_state = ['0','1']; // 0 => STOP , 1 => START if(box_id == 6){ return engine_state[state[3]]; }else if(box_id == 8 || box_id == 4 || box_id == 16 || box_id == 24 ){ return engine_state[state[5]]; } } function processTimeIntervalReport(gps_data){ var client = {}; client.username = "test"; client.imei = "test"; client.box_id = '8'; var log_row = { log_rfid : gps_data ,log_value : 000001000000000 ,log_IMEI : client.imei } if(log_row.log_rfid && WRONG_RFID.indexOf(log_row.log_rfid) == -1){ var rfidData = readRFID(log_row.log_rfid); var license = (rfidData)? rfidData[7].trim() : null; console.log("CHECK RFID DATA : correct : ",(rfidData!=null && license!=null)); if(rfidData && license){ var prefixName = ""; var licenseArr = license.match(/\d+/g); if(licenseArr[1] == 1){ prefixName= "MR."; }else if(licenseArr[1] == 2){ prefixName= "MS."; }else{ prefixName = rfidData[3]; } var driverData = { driver_first_name : prefixName + rfidData[2] ,driver_last_name : rfidData[1] ,driver_gender : (prefixName)?(prefixName.toLowerCase() == "mr.")? "Male" : "Female" : null ,driver_address : rfidData[4] ,driver_citizen_id : (rfidData[5] && rfidData[5].length > 13)? rfidData[5].substr(-13) : rfidData[5] ,driver_birth_day : (rfidData[6] && rfidData[6].length>=8)? rfidData[6].substr(-8) : null ,driver_card_expired : (rfidData[6] && rfidData[6].length>=4)? "20"+rfidData[6].substr(0,4) : null ,driver_rfid : license.replace(/\s+/g, '') ,driver_user_username : client.username ,driver_add_by : "PROTOCOL" ,driver_dateadded : new Date() }; console.log(driverData); processAndUpdatelicense(log_row,license,0,client); }else if(!rfidData && !license){ console.log(" RFID WRONG PATTERN"); processAndUpdatelicense(log_row,license,0,client); } } }
run
|
edit
|
history
|
help
0
AVL-GO-FLAT
localhost:8080/?name=2017&lname=July
Compare 2 arrays and fill 1 or 2
Get stack from error
find all prime factors of a number
lodash
Funny stuff
Rest Params
neural spam network
Include object in a query string