-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·132 lines (98 loc) · 4.24 KB
/
build.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var config = require('./config');
// Paths
var templatesPath = "./templates";
var outputPath = "./build";
// Filepaths
var projectTemplateFile = path.join(templatesPath, "project.template.bgproj"),
projectOutputFile = path.join(outputPath, "project.bgproj"),
configTemplateFile = path.join(templatesPath, "config.template.xml"),
configOutputFile = path.join(outputPath, "config.xml"),
hardwareTemplateFile = path.join(templatesPath, "hardware.template.xml"),
hardwareOutputFile = path.join(outputPath, "hardware.xml"),
gattTemplateFile = path.join(templatesPath, "gatt.template.xml"),
gattOutputFile = path.join(outputPath, "gatt.xml"),
scriptTemplateFile = path.join(templatesPath, "script.template.bgs"),
scriptOutputFile = path.join(outputPath, "script.bgs");
// Check for deviceName length
if (config.deviceName.length > 13) {
throw new Error("deviceName is too long. Maximun lenght is 13 characters");
} else {
config.deviceName += ' '; // Add a blank space
}
// Generate device name code
var deviceNameGeneratedCode = '';
var index = 0;
for (var i in config.deviceName) {
deviceNameGeneratedCode += 'devicename('+i+':1) = '+config.deviceName.charCodeAt(i)+' \t # '+config.deviceName[i]+'\n';
index++;
}
deviceNameGeneratedCode += 'devicename('+(index+0)+':1) = (mac_address(2:1)/$10) + 48 + ((mac_address(2:1)/$10)/10*7) # MAC byte 4 10th digit\n';
deviceNameGeneratedCode += 'devicename('+(index+1)+':1) = (mac_address(2:1)&$f) + 48 + ((mac_address(2:1)&$f )/10*7) # MAC byte 4 1st digit\n';
deviceNameGeneratedCode += 'devicename('+(index+2)+':1) = (mac_address(1:1)/$10) + 48 + ((mac_address(1:1)/$10)/10*7) # MAC byte 5 10th digit\n';
deviceNameGeneratedCode += 'devicename('+(index+3)+':1) = (mac_address(1:1)&$f) + 48 + ((mac_address(1:1)&$f )/10*7) # MAC byte 5 1st digit\n';
deviceNameGeneratedCode += 'devicename('+(index+4)+':1) = (mac_address(0:1)/$10) + 48 + ((mac_address(0:1)/$10)/10*7) # MAC byte 6 10th digit\n';
deviceNameGeneratedCode += 'devicename('+(index+5)+':1) = (mac_address(0:1)&$f) + 48 + ((mac_address(0:1)&$f )/10*7) # MAC byte 6 1st digit\n';
/**
* script.bgs templating
*/
fs.readFile(scriptTemplateFile, 'utf8', function(err, data) {
if (err) throw err;
var content = data;
content = content.replace(/{{deviceNameGeneratedCode}}+/g, deviceNameGeneratedCode);
fs.writeFile(scriptOutputFile, content, function(err) {
if (err) throw err;
console.log("The "+scriptOutputFile+" file was saved!");
});
});
/**
* config.xml templating
*/
fs.readFile(configTemplateFile, 'utf8', function(err, data) {
if (err) throw err;
var content = data;
fs.writeFile(configOutputFile, content, function(err) {
if (err) throw err;
console.log("The "+configOutputFile+" file was saved!");
});
});
/**
* hardware.xml templating
*/
fs.readFile(hardwareTemplateFile, 'utf8', function(err, data) {
if (err) throw err;
var content = data;
fs.writeFile(hardwareOutputFile, content, function(err) {
if (err) throw err;
console.log("The "+hardwareOutputFile+" file was saved!");
});
});
/**
* Gatt.xml templating
*/
fs.readFile(gattTemplateFile, 'utf8', function(err, data) {
if (err) throw err;
var content = data;
content = content.replace(/{{manufacturerName}}+/g, config.manufacturerName);
content = content.replace(/{{modelNumberString}}+/g, config.modelNumberString);
content = content.replace(/{{firmwareRevisionString}}+/g, config.firmwareRevisionString);
content = content.replace(/{{hardwareRevisionString}}+/g, config.hardwareRevisionString);
fs.writeFile(gattOutputFile, content, function(err) {
if (err) throw err;
console.log("The "+gattOutputFile+" file was saved!");
});
});
/**
* project.bgproj templating
*/
fs.readFile(projectTemplateFile, 'utf8', function(err, data) {
if (err) throw err;
var content = data;
content = content.replace(/{{bluegigaModel}}+/g, config.bluegigaModel);
fs.writeFile(projectOutputFile, content, function(err) {
if (err) throw err;
console.log("The "+projectOutputFile+" file was saved!");
});
});