Commit e21c618a70717650154045bc3c177028e51be871

Authored by Eric
1 parent 60433c99f4
Exists in master

fix date

Showing 2 changed files with 2 additions and 1 deletions   Show diff stats
1 1
2 node_modules/ 2 node_modules/
3 3
4 package-lock\.json 4 package-lock\.json
5 config/config.json
5 6
1 //express 1 //express
2 const express = require('express'); 2 const express = require('express');
3 const app = express(); 3 const app = express();
4 const config = require('./config/config.json'); 4 const config = require('./config/config.json');
5 const socket = require('./socket/socket.js'); 5 const socket = require('./socket/socket.js');
6 6
7 const port = config.servidorveeder.port; 7 const port = config.servidorveeder.port;
8 const host = config.servidorveeder.direccion; 8 const host = config.servidorveeder.direccion;
9 var fecha; 9 var fecha;
10 10
11 app.listen(config.servidornode.port); 11 app.listen(config.servidornode.port);
12 12
13 app.get('/tank-info/:tank*?', function (req, res) { 13 app.get('/tank-info/:tank*?', function (req, res) {
14 14
15 socket.initConection(port, host); 15 socket.initConection(port, host);
16 16
17 var numberTank = req.params.tank ? req.params.tank : '00'; 17 var numberTank = req.params.tank ? req.params.tank : '00';
18 18
19 socket.getTank('i201' + numberTank).then(function (response) { 19 socket.getTank('i201' + numberTank).then(function (response) {
20 20
21 //obtengo una cadena de caracteres, los primeros 17 datos son de informacion de tanque 21 //obtengo una cadena de caracteres, los primeros 17 datos son de informacion de tanque
22 // e información de la fecha 22 // e información de la fecha
23 fecha = response.slice(7, 16); 23 fecha = response.slice(7, 17);
24 24
25 var dataTanks = getJson(response.slice(17, response.length)); 25 var dataTanks = getJson(response.slice(17, response.length));
26 26
27 res.status(200).send(dataTanks); 27 res.status(200).send(dataTanks);
28 28
29 socket.end(); 29 socket.end();
30 }); 30 });
31 }); 31 });
32 32
33 function getJson(tanks) { 33 function getJson(tanks) {
34 34
35 var json = { 35 var json = {
36 tanques: [] 36 tanques: []
37 }; 37 };
38 var arraysTanks = []; 38 var arraysTanks = [];
39 39
40 while (tanks.length > 10) { 40 while (tanks.length > 10) {
41 41
42 var stringTank = tanks.slice(0, 9); 42 var stringTank = tanks.slice(0, 9);
43 var cantOfProperties = stringTank.length + (parseInt(tanks.slice(7, 9)) * 8); 43 var cantOfProperties = stringTank.length + (parseInt(tanks.slice(7, 9)) * 8);
44 stringTank += tanks.slice(9, cantOfProperties) 44 stringTank += tanks.slice(9, cantOfProperties)
45 45
46 arraysTanks.push(stringTank); 46 arraysTanks.push(stringTank);
47 47
48 tanks = tanks.slice(stringTank.length, tanks.length); 48 tanks = tanks.slice(stringTank.length, tanks.length);
49 } 49 }
50 50
51 arraysTanks.forEach(function (tank) { 51 arraysTanks.forEach(function (tank) {
52 var objTank = { 52 var objTank = {
53 tank: tank.slice(0, 2), 53 tank: tank.slice(0, 2),
54 fecha: fecha, 54 fecha: fecha,
55 product: tank.slice(2, 3), 55 product: tank.slice(2, 3),
56 deliveryProgress: tank.slice(3, 4), 56 deliveryProgress: tank.slice(3, 4),
57 testProgress: tank.slice(4, 5), 57 testProgress: tank.slice(4, 5),
58 alarm: tank.slice(5, 6), 58 alarm: tank.slice(5, 6),
59 volume: getValue(tank.slice(9, 17)), 59 volume: getValue(tank.slice(9, 17)),
60 tCVolume: getValue(tank.slice(17, 25)), 60 tCVolume: getValue(tank.slice(17, 25)),
61 ullage: getValue(tank.slice(25, 33)), 61 ullage: getValue(tank.slice(25, 33)),
62 altura: getValue(tank.slice(33, 41)), 62 altura: getValue(tank.slice(33, 41)),
63 agua: getValue(tank.slice(41, 49)), 63 agua: getValue(tank.slice(41, 49)),
64 temperatura: getValue(tank.slice(49, 57)), 64 temperatura: getValue(tank.slice(49, 57)),
65 alturaAgua: getValue(tank.slice(57, 65)), 65 alturaAgua: getValue(tank.slice(57, 65)),
66 } 66 }
67 67
68 json.tanques.push(objTank); 68 json.tanques.push(objTank);
69 }); 69 });
70 70
71 json.cantidadTanques = json.tanques.length; 71 json.cantidadTanques = json.tanques.length;
72 72
73 return json; 73 return json;
74 } 74 }
75 75
76 function getValue(property) { 76 function getValue(property) {
77 77
78 var binary = parseInt(property, 16).toString(2); 78 var binary = parseInt(property, 16).toString(2);
79 79
80 if (binary.length < 32) { 80 if (binary.length < 32) {
81 81
82 var difence = 32 - binary.length; 82 var difence = 32 - binary.length;
83 83
84 var ceros = ''; 84 var ceros = '';
85 85
86 for (let i = 0; i < difence; i++) { 86 for (let i = 0; i < difence; i++) {
87 ceros += '0'; 87 ceros += '0';
88 } 88 }
89 89
90 binary = ceros + binary; 90 binary = ceros + binary;
91 } 91 }
92 92
93 var e = parseInt(binary.slice(1, 9), 2).toString(10); 93 var e = parseInt(binary.slice(1, 9), 2).toString(10);
94 94
95 var m = parseInt(binary.slice(9), 2).toString(10); 95 var m = parseInt(binary.slice(9), 2).toString(10);
96 96
97 var exponent = 2 ** (e - 127); 97 var exponent = 2 ** (e - 127);
98 98
99 99
100 if(parseInt(binary.slice(0, 1))) exponent = exponent * -1; 100 if(parseInt(binary.slice(0, 1))) exponent = exponent * -1;
101 101
102 var mantissa = 1.0 + (m / 8388608); 102 var mantissa = 1.0 + (m / 8388608);
103 103
104 return parseFloat(exponent * mantissa).toFixed(2); 104 return parseFloat(exponent * mantissa).toFixed(2);
105 } 105 }
106 106