use codebender to compile sketches
I had codebender username/password included originally but compiling works without. Codebender usage guidelines allow "usage via API".
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
const gwType = 'Ethernet';
|
//const gwType = 'Ethernet';
|
||||||
const gwAddress = '10.0.1.99';
|
//const gwAddress = '10.0.1.99';
|
||||||
const gwPort = 9999;
|
//const gwPort = 9999;
|
||||||
|
|
||||||
//const gwType = 'Serial';
|
const gwType = 'Serial';
|
||||||
//const gwPort = 'COM4';
|
//const gwPort = 'COM4';
|
||||||
//const gwPort = '/dev/ttyUSB0';
|
const gwPort = '/dev/ttyAMA0';
|
||||||
//const gwBaud = 115200;
|
const gwBaud = 115200;
|
||||||
|
|
||||||
const dbAddress = '127.0.0.1';
|
const dbAddress = '127.0.0.1';
|
||||||
const dbPort = 27017;
|
const dbPort = 27017;
|
||||||
const dbName = 'MySensorsDb';
|
const dbName = 'MySensorsDb';
|
||||||
|
|
||||||
const fwHexFiles = [ ];
|
const fwSketches = [ '../libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino' ];
|
||||||
const fwDefaultType = 0xFFFF; // index of hex file from array above (0xFFFF == none defined)
|
const fwDefaultType = 0; // index of hex file from array above
|
||||||
|
|
||||||
const FIRMWARE_BLOCK_SIZE = 16;
|
const FIRMWARE_BLOCK_SIZE = 16;
|
||||||
const BROADCAST_ADDRESS = 255;
|
const BROADCAST_ADDRESS = 255;
|
||||||
@@ -117,6 +117,8 @@ const P_ULONG32 = 5;
|
|||||||
const P_CUSTOM = 6;
|
const P_CUSTOM = 6;
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var requestify = require('requestify');
|
||||||
var appendedString="";
|
var appendedString="";
|
||||||
|
|
||||||
function crcUpdate(old, value) {
|
function crcUpdate(old, value) {
|
||||||
@@ -146,76 +148,99 @@ function pushDWord(arr, val) {
|
|||||||
arr.push((val >> 24) & 0x000000FF);
|
arr.push((val >> 24) & 0x000000FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFirmware(fwtype, fwversion, filename, db) {
|
function loadFirmware(fwtype, fwversion, sketch, db) {
|
||||||
console.log("loading firmware: " + filename);
|
var filename = path.basename(sketch);
|
||||||
fwdata = [];
|
console.log("compiling firmware: " + filename);
|
||||||
var start = 0;
|
var req = {
|
||||||
var end = 0;
|
files: [{
|
||||||
var pos = 0;
|
filename: filename,
|
||||||
var hex = fs.readFileSync(filename).toString().split("\n");
|
content: fs.readFileSync(sketch).toString()
|
||||||
for(l in hex) {
|
}],
|
||||||
line = hex[l].trim();
|
format: "hex",
|
||||||
if (line.length > 0) {
|
version: "105",
|
||||||
while (line.substring(0, 1) != ":")
|
build: {
|
||||||
line = line.substring(1);
|
mcu: "atmega328p",
|
||||||
var reclen = parseInt(line.substring(1, 3), 16);
|
f_cpu: "16000000L",
|
||||||
var offset = parseInt(line.substring(3, 7), 16);
|
core: "arduino",
|
||||||
var rectype = parseInt(line.substring(7, 9), 16);
|
variant: "standard"
|
||||||
var data = line.substring(9, 9 + 2 * reclen);
|
}
|
||||||
var chksum = parseInt(line.substring(9 + (2 * reclen), 9 + (2 * reclen) + 2), 16);
|
};
|
||||||
if (rectype == 0) {
|
requestify.post('https://codebender.cc/utilities/compile/', req).then(function(res) {
|
||||||
if ((start == 0) && (end == 0)) {
|
var body = JSON.parse(res.getBody());
|
||||||
if (offset % 128 > 0)
|
if (body.success) {
|
||||||
throw new Error("error loading hex file - offset can't be devided by 128");
|
console.log("loading firmware: " + filename);
|
||||||
start = offset;
|
fwdata = [];
|
||||||
end = offset;
|
var start = 0;
|
||||||
|
var end = 0;
|
||||||
|
var pos = 0;
|
||||||
|
var hex = body.output.split("\n");
|
||||||
|
for(l in hex) {
|
||||||
|
line = hex[l].trim();
|
||||||
|
if (line.length > 0) {
|
||||||
|
while (line.substring(0, 1) != ":")
|
||||||
|
line = line.substring(1);
|
||||||
|
var reclen = parseInt(line.substring(1, 3), 16);
|
||||||
|
var offset = parseInt(line.substring(3, 7), 16);
|
||||||
|
var rectype = parseInt(line.substring(7, 9), 16);
|
||||||
|
var data = line.substring(9, 9 + 2 * reclen);
|
||||||
|
var chksum = parseInt(line.substring(9 + (2 * reclen), 9 + (2 * reclen) + 2), 16);
|
||||||
|
if (rectype == 0) {
|
||||||
|
if ((start == 0) && (end == 0)) {
|
||||||
|
if (offset % 128 > 0)
|
||||||
|
throw new Error("error loading hex file - offset can't be devided by 128");
|
||||||
|
start = offset;
|
||||||
|
end = offset;
|
||||||
|
}
|
||||||
|
if (offset < end)
|
||||||
|
throw new Error("error loading hex file - offset lower than end");
|
||||||
|
while (offset > end) {
|
||||||
|
fwdata.push(255);
|
||||||
|
pos++;
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < reclen; i++) {
|
||||||
|
fwdata.push(parseInt(data.substring(i * 2, (i * 2) + 2), 16));
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
end += reclen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (offset < end)
|
}
|
||||||
throw new Error("error loading hex file - offset lower than end");
|
var pad = end % 128; // ATMega328 has 64 words per page / 128 bytes per page
|
||||||
while (offset > end) {
|
for (var i = 0; i < 128 - pad; i++) {
|
||||||
fwdata.push(255);
|
fwdata.push(255);
|
||||||
pos++;
|
pos++;
|
||||||
end++;
|
end++;
|
||||||
}
|
|
||||||
for (var i = 0; i < reclen; i++) {
|
|
||||||
fwdata.push(parseInt(data.substring(i * 2, (i * 2) + 2), 16));
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
end += reclen;
|
|
||||||
}
|
}
|
||||||
}
|
var blocks = (end - start) / FIRMWARE_BLOCK_SIZE;
|
||||||
}
|
var crc = 0xFFFF;
|
||||||
var pad = end % 128; // ATMega328 has 64 words per page / 128 bytes per page
|
for (var i = 0; i < blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
||||||
for (var i = 0; i < 128 - pad; i++) {
|
var v = crc;
|
||||||
fwdata.push(255);
|
crc = crcUpdate(crc, fwdata[i]);
|
||||||
pos++;
|
|
||||||
end++;
|
|
||||||
}
|
|
||||||
var blocks = (end - start) / FIRMWARE_BLOCK_SIZE;
|
|
||||||
var crc = 0xFFFF;
|
|
||||||
for (var i = 0; i < blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
|
||||||
var v = crc;
|
|
||||||
crc = crcUpdate(crc, fwdata[i]);
|
|
||||||
}
|
|
||||||
db.collection('firmware', function(err, c) {
|
|
||||||
c.update({
|
|
||||||
'type': fwtype,
|
|
||||||
'version': fwversion
|
|
||||||
}, {
|
|
||||||
$set: {
|
|
||||||
'filename': filename,
|
|
||||||
'blocks': blocks,
|
|
||||||
'crc': crc,
|
|
||||||
'data': fwdata
|
|
||||||
}
|
}
|
||||||
}, {
|
db.collection('firmware', function(err, c) {
|
||||||
upsert: true
|
c.update({
|
||||||
}, function(err, result) {
|
'type': fwtype,
|
||||||
if (err)
|
'version': fwversion
|
||||||
console.log('Error writing firmware to database');
|
}, {
|
||||||
});
|
$set: {
|
||||||
});
|
'filename': filename,
|
||||||
console.log("loading firmware done. blocks: " + blocks + " / crc: " + crc);
|
'blocks': blocks,
|
||||||
|
'crc': crc,
|
||||||
|
'data': fwdata
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
upsert: true
|
||||||
|
}, function(err, result) {
|
||||||
|
if (err)
|
||||||
|
console.log('Error writing firmware to database');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log("loading firmware done. blocks: " + blocks + " / crc: " + crc);
|
||||||
|
} else {
|
||||||
|
console.log("error: %j", res.body);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -645,8 +670,8 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err
|
|||||||
db.createCollection('firmware', function(err, collection) { });
|
db.createCollection('firmware', function(err, collection) { });
|
||||||
|
|
||||||
// ToDo : check for new hex files / only load if new / get type and version from filename
|
// ToDo : check for new hex files / only load if new / get type and version from filename
|
||||||
for (var i = 0; i < fwHexFiles.length; i++)
|
for (var i = 0; i < fwSketches.length; i++)
|
||||||
loadFirmware(i, 1, fwHexFiles[i], db);
|
loadFirmware(i, 1, fwSketches[i], db);
|
||||||
|
|
||||||
var gw;
|
var gw;
|
||||||
if (gwType == 'Ethernet') {
|
if (gwType == 'Ethernet') {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mongodb": "~1.4.7",
|
"mongodb": "~1.4.7",
|
||||||
"net": "~1.0.2",
|
"net": "~1.0.2",
|
||||||
|
"requestify": "^0.1.16",
|
||||||
"serialport": "^1.4.5"
|
"serialport": "^1.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user