Just as a heads up for anybody coming after me, I’ve needed to emulate some sensors coming from my computer so I could develop some signals, it wasn’t possible for me to have the device that will generate those signals with me all the time so I needed something that will emulate it on demand (just a simulation in my case won’t cut it). So I developed a TCP Server in Node.JS (Javascript, basically) so I can test and send signals to my RealDash application.
The previous examples posted here were using a CAN library when there is no need to, we only need to send the packets over WIFI in Hex format and whatever was designed on the XML definition.
So here’s the NodeJS code (there are some corrections I need to come up it for the RPM but the essentials are there, like turn signals, high beams, etc.
var socketGLO;
var net = require('net');
var readline = require('readline');
var serialBlockTag = Buffer.from([0x44,0x33,0x22,0x11]);
var BigEndian = Buffer.from([0x0C,0x80,0x00,0x00]);
// Each one of the following bytes represent the information used by RealDash for the values in the offset defined in the XML file. The left two bytes are RPM, next is Blinker Left, Blinker Right, High Beams, Fuel Level, Battery Voltage and last one (the one on the right) is Coolant Temperature.
var data = Buffer.from([0x04,0x01,0x01,0x01,0x11,0x11,0x11,0x11]);
try{
var server = net.createServer(function(socket) {
});
}
catch(e){
console.log(e);
}
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
if (key.ctrl && key.name === 'c') {
process.exit(0);
} else {
socketGLO.write(serialBlockTag);
socketGLO.write(BigEndian);
socketGLO.write(data);
console.log(serialBlockTag);
console.log(BigEndian);
console.log(data);
console.log('Sent now');
}
});
server.on('connection', function(socket) {
console.log('A new connection has been established, press any key to send RealDash CAN');
socketGLO = socket;
// Now that a TCP connection has been established, the server can send data to
// the client by writing to its socket.
socket.write(serialBlockTag);
socket.write(BigEndian);
socket.write(data);
socket.on('data', function(chunk) {
console.log('Data received from RealDash: ${chunk.toString()');
});
// When the client requests to end the TCP connection with the server, the server
// ends the connection.
// For some reason I was getting this a LOT, I need to investigate to see what is going on, server was on Mac RealDash client was Windows.
socket.on('end', function() {
console.log('Closing connection with the client');
});
// Don't forget to catch error, for your own sake.
socket.on('error', function(err) {
console.log('Error: ${err}');
});
});
server.listen(1337, 'your.IP.address.on.the.machine.running.it'); // it could be like 192.168.1.100 and you can also change the port if you need it.
If anybody needs help with this, please ask, I’ll gladly help. The XML definition for this particular command is the following:
<?xml version="1.0" encoding="utf-8"?>
<RealDashCAN version="2">
<frames>
<frame id="0x800C" endianess="big" signed="true">
<value name="RPM_Test" targetId="37" units=" " signed="true" offset="0" length="2"></value>
<value name="BLR_Test" targetId="160" units=" " signed="true" offset="1" length="1"></value>
<value name="BLL_Test" targetId="161" units=" " signed="true" offset="2" length="1"></value>
<value name="HB_Test" targetId="157" units=" " signed="true" offset="3" length="1"></value>
<value name="FL_Test" targetId="170" units=" " signed="true" offset="4" length="1"></value>
<value name="BV_Test" targetId="12" units=" " signed="true" offset="5" length="1"></value>
<value name="CT_Test" targetId="14" units=" " signed="true" offset="6" length="1"></value>
</frames>
While this is a work in progress it is already working so if you do find something wrong in your case and is not working, just ask, it could be something I copied wrong in here, do not assume that this isn’t working.
Hope this helps someone out there!
Juan