-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloWorldUDP.js
70 lines (59 loc) · 3.18 KB
/
helloWorldUDP.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var dgram = require("dgram"),
parser = new require('packet').createParser();
var server = dgram.createSocket("udp4");
var structure = [
'b32 => Magic', // is always 0x526F6455
'b8 => Version', // Version of message
'b8 => Alive', // Alivecounter
'b8 => VehicleType', // Vehicle type
'b32 => MileageTotal', // Overall milage in km
'b16 => SpeedWheelRear', // Speed @rear wheel in km/h
'b16 => SpeedWheelFront', // Speed @front wheel in km/h
'-b16 => Temperature', // Outside temperature
'b8 => RockerSwitchRightUp', // Rocker switch (left handle) right up
'b8 => RockerSwitchRightDown', // Rocker switch (left handle) right down
'b8 => PushButtonLeftHand', // Push button left hand
'b8 => PushButtonRightHand', // Push button right hand
'b8 => CruiseControlOn', // Cruise control on
'b8 => CruiseControlAccelerate', // Cruise control accelerate
'b8 => CruiseControlDecelerator', // Cruise control decelerate
'b8 => IndicatorSwitchLeft', // Indicator switch left
'b8 => IndicatorSwitchRight', // Indicator switch right
'b8 => IndicatorSwitchReset', // Indicator switch reset
'b8 => Horn', // Horn
'b8 => HighBeam', // High beam
'b8 => RockerSwitchLeftUp', // Rocker switch (left handle) left up
'b8 => RockerSwitchLeftDown', // Rocker switch (left handle) left down
'b8 => MMCLeft', // Multimedia controller left
'b8 => MMCRight', // Multimedia contoller right
'b8 => MMCPosition', // Multimedia controller position
'b8 => ReadinessDriving', // Ready to ride
'b8 => ChargingCondition', // Charging condition
'b16 => ChargingDurationExpected', // expected charging duration in min.
'b8 => ChargingWirePluggedIn', // charging wire plugged
'b8 => StateOfCharge', // SOC – state of charge in %
'b8 => Range', // Range in km
'b16 => EnergyDischarged', // HV battery energy discharged by consumption
'b16 => EnergyChargedByRecuperation', // HV battery energy charged by recuperation
'b16 => HighVoltageStorageVoltage', // High voltage storage voltage
'b16 => HighVoltageStorageCurrent', // High voltage storage current
'b8 => ECOPoints' // Economic points
].join(', ');
// Here the magic happens
server.on("message", function (msg, rinfo) {
parser.extract(structure, function (record) {
console.log(record);
});
parser.parse(msg);
});
// Who cares LOL
server.on("error", function (err) {
console.log("server error:\n" + err.stack);
server.close();
});
server.on("listening", function () {
var address = server.address();
console.log("server listening " +
address.address + ":" + address.port);
});
server.bind(30002);