Browse Source

Can send LLAP messages from web interface.

master
flabbergast 9 years ago
parent
commit
32b6452380
  1. 39
      modules/llap_helper.js
  2. 14
      modules/serial_node.js
  3. 6
      modules/socket_server.js
  4. 7
      public/js/index.js

39
modules/llap_helper.js

@ -0,0 +1,39 @@
/*
LLAP helper functions: Public API
*/
exports.fixSignature = function(msg){
if(! /^a/.test(msg) ) { msg = 'a'+msg; }
return msg;
}
exports.padMessage = function(msg,filler) {
if(!filler) { var filler = '-'; }
for (var i=0; i<12; i++) { msg += filler; }
return msg.substring(0,12);
}
exports.deviceName = function(msg) {
return msg.substring(1,3);
}
exports.isValid = function(msg) {
return msg.length == 12 &&
msg.charAt(0) == 'a' &&
isAllowedID(exports.deviceName(msg)) &&
isAllowedData(msg.substring(3));
}
/*
Private
*/
var isAllowedID = function(str) {
return str.length == 2 &&
/[A-Z-#@?\\*]{2}/.test(str);
}
var isAllowedData = function(str) {
return str.length == 9 &&
/[0-9A-Z !"#$%&'()*+,\-.\/:;<=>?@[\\\]^_]{9}/.test(str);
}

14
modules/serial_node.js

@ -1,3 +1,5 @@
var lhelper = require('./llap_helper');
/*
Public API
*/
@ -21,6 +23,16 @@ exports.getPath = function()
}
}
exports.sendLLAPmsg = function(msg)
{
msg = lhelper.padMessage(lhelper.fixSignature(msg));
if(lhelper.isValid(msg)) {
sendDataOverSerial(msg);
} else {
console.log('error :: the message "'+msg+'" is not valid.');
}
}
/*
Private Methods
*/
@ -78,7 +90,7 @@ var detectSerialOnRaspberryPI = function()
var attemptConnection = function(port)
{
console.log('* attempting to connect to serial at :', port, ' *');
serport = new serialport.SerialPort(port, { baudrate: 9600, parser: serialport.parsers.readline("\n") });
serport = new serialport.SerialPort(port, { baudrate: 9600 });
serport.on("open", function () {
console.log('* connection to a serial port successful ! *');
serport.on('data', function(data){

6
modules/socket_server.js

@ -26,11 +26,15 @@ exports.init = function(io){
socket.on('request-server-info', function (data) {
socket.emit('server-info-response', { serialPort: serport.getPath() });
});
// send an LLAP message over serial
socket.on('send-llap-msg', function(data){
serport.sendLLAPmsg(data.content);
});
});
};
exports.onDataOverSerial = function(data){
console.log('onDataOverSerial', data);
console.log('onDataOverSerial', data.toString());
// process data received
};

7
public/js/index.js

@ -8,5 +8,12 @@ $(document).ready(function(){
socket.emit('animation-selected', { id:n });
}
*/
if( socket && socket_connected ){
socket.emit('send-llap-msg', {
content:$('#wrapper #serialtalk #serialtalk-text').val()
});
} else {
// socket unavailable: can't send
}
});
});
Loading…
Cancel
Save