forked from Apollon77/smartmeter-obis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
91 lines (81 loc) · 3.08 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
var D0Protocol = require('./lib/protocols/D0Protocol');
var JsonEfrProtocol = require('./lib/protocols/JsonEfrProtocol');
var SmlProtocol = require('./lib/protocols/SmlProtocol');
var SmlUnits = require('./lib/protocols/SmlUnits');
var HttpRequestTransport = require('./lib/transports/HttpRequestTransport');
var LocalFileTransport = require('./lib/transports/LocalFileTransport');
var SerialRequestResponseTransport = require('./lib/transports/SerialRequestResponseTransport');
var SerialResponseTransport = require('./lib/transports/SerialResponseTransport');
var StdInTransport = require('./lib/transports/StdInTransport');
var TCPTransport = require('./lib/transports/TCPTransport');
var ObisMeasurement = require('./lib/ObisMeasurement');
var ObisNames = require('./lib/ObisNames');
function init(options, writeDataCallback) {
if (!options.logger || typeof options.logger !== 'function') {
options.logger = console.log;
}
if (options.debug === undefined) {
options.debug = 0;
}
if (options.requestInterval === undefined) {
options.requestInterval = 300;
}
var smProtocol;
switch(options.protocol) {
case 'D0Protocol':
smProtocol = new D0Protocol(options, writeDataCallback);
break;
case 'JsonEfrProtocol':
smProtocol = new JsonEfrProtocol(options, writeDataCallback);
break;
case 'SmlProtocol':
smProtocol = new SmlProtocol(options, writeDataCallback);
break;
default:
throw Error('Unsupported Protocol ' + options.protocol);
}
var smTransport;
switch(options.transport) {
case 'HttpRequestTransport':
smTransport = new HttpRequestTransport(options, smProtocol);
break;
case 'LocalFileTransport':
smTransport = new LocalFileTransport(options, smProtocol);
break;
case 'SerialRequestResponseTransport':
smTransport = new SerialRequestResponseTransport(options, smProtocol);
break;
case 'SerialResponseTransport':
smTransport = new SerialResponseTransport(options, smProtocol);
break;
case 'StdInTransport':
smTransport = new StdInTransport(options, smProtocol);
break;
case 'TCPTransport':
smTransport = new TCPTransport(options, smProtocol);
break;
default:
throw Error('Unsupported Transport ' + options.transport);
}
smTransport.init();
return smTransport;
}
module.exports = {
D0Protocol: D0Protocol,
JsonEfrProtocol: JsonEfrProtocol,
SmlProtocol: SmlProtocol,
SmlUnits: SmlUnits,
HttpRequestTransport: HttpRequestTransport,
LocalFileTransport: LocalFileTransport,
SerialRequestResponseTransport: SerialRequestResponseTransport,
SerialResponseTransport: SerialResponseTransport,
TCPTransport: TCPTransport,
ObisMeasurement: ObisMeasurement,
ObisNames: ObisNames,
init: init
};