var com,com_rx=[];function mcu_connect(){log("Connecting to MCU at "+COM_PORT),(com=new SerialPort.SerialPort(COM_PORT,{baudrate:9600})).on("error",log),com.on("open",function(){com.on("data",function(c){for(var o=0;o<c.length;o++)com_rx.push(c[o]);for(;4<=com_rx.length;)if(255!=com_rx[0]||254!=com_rx[1]||253!=com_rx[2])com_rx.shift();else{var n=com_rx[3];if(com_rx.length<n+4)return;n=com_rx.splice(0,n+4).splice(4,n);mcu_process_message(n)}}),setTimeout(mcu_reconnect,WINDOWS?5e3:1e3)})}function mcu_write(c){com.write([255,254,253].concat(c))}var mcu_ping_timer=0;function mcu_reconnect(){log("mcu connecting..."),com.write([255,254,253,7,100]),clearInterval(mcu_ping_timer),mcu_ping_timer=setInterval(mcu_ping,1e3)}function mcu_ping(){com.write([255,254,253,100])}