Skip to content

Commit 92edb2c

Browse files
authored
Merge pull request #11 from duinoapp/develop
v3.3.1
2 parents fb4a192 + 4356e7c commit 92edb2c

File tree

7 files changed

+114
-41
lines changed

7 files changed

+114
-41
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ RUN mkdir -p /mnt/duino-data
77
RUN chmod 0777 /mnt/duino-data
88

99
COPY setup /home/duino/setup
10+
COPY src/utils /home/duino/src/utils
1011
RUN chmod +x /home/duino/setup/*.sh
1112
# COPY Arduino /home/duino/Arduino
1213

1314
# RUN mkdir /home/duino
1415
RUN chown duino:duino /home/duino -R
15-
RUN apt-get update && apt-get install build-essential -y
16+
RUN apt-get update && apt-get install build-essential python-pip -y
17+
RUN pip install pyserial
1618

1719
WORKDIR /home/duino
1820
USER duino
1921

2022
COPY package*.json /home/duino/
2123
RUN npm ci
2224

23-
COPY src /home/duino/src
24-
2525
RUN node ./setup/docker-install.js
2626

27+
COPY src /home/duino/src
28+
2729
EXPOSE 3030
2830
CMD [ "node", "src/index.js" ]

package-lock.json

Lines changed: 25 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"properties": "^1.2.1",
2424
"serverless-http": "^2.7.0",
2525
"socket.io": "^2.4.1",
26-
"tar": "^6.1.0",
26+
"tar": "^6.1.8",
2727
"tmp-promise": "^2.0.2",
2828
"uuid": "^8.3.2",
2929
"yaml": "^1.10.2"

setup/process-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = async (supportedCores) => {
1717
if (!line.includes('=')) return line;
1818
const key = line.replace(/=.*/, '');
1919
let newLine = line;
20-
if (!/\.(upload\.|build\.mcu)/.test(key)) newLine = '';
20+
if (!/\.(upload\.|build\.(mcu|bootloader_addr|boot|flash_freq))/.test(key)) newLine = '';
2121
return newLine;
2222
}).join('\n');
2323
return properties.parse(file, { namespaces: true });

src/actions/info.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const loadBoards = () => json.loadLargeData('boards');
66
const loadLegacyBoards = () => json.parse('/mnt/duino-data/legacy-boards-processed.json');
77

88
const searchRegex = (search = '') => new RegExp(`(${search.replace(/[^\w-\s]/g, '.').split(/\s+/g).join(')|(')})`, 'i');
9+
const exactSearchRegex = (search = '') => new RegExp(`^${search.replace(/[^\w-\s]/g, '.?')}$`, 'i');
910

1011
module.exports.server = (socket, done) => done && done({
1112
name: process.env.SERVER_INFO_NAME || 'Test Compile Server',
@@ -24,17 +25,24 @@ module.exports.librariesSearch = async (data, socket, done) => {
2425
const reg = searchRegex(data.search);
2526
const { sortBy = 'name' } = data;
2627
const sortDesc = !(typeof data.sortDesc === 'undefined' || `${data.sortDesc}` === 'false');
28+
const exact = !(typeof data.exact === 'undefined' || `${data.exact}` === 'false');
2729
const eq = (a, b) => a.toLowerCase() === b.toLowerCase();
28-
const res = [
29-
...libs.filter((lib) => eq(lib.name, data.search)),
30-
...libs.filter((lib) => !eq(lib.name, data.search) && reg.test(lib.name))
31-
.sort((a, b) => {
32-
const ai = `${a[sortBy]}`.toLowerCase();
33-
const bi = `${b[sortBy]}`.toLowerCase();
34-
if (ai === bi) return 0;
35-
return (ai < bi ? -1 : 1) * (sortDesc ? -1 : 1);
36-
}),
37-
];
30+
let res;
31+
if (exact) {
32+
const nameRegs = data.search.split(/\s*,\s*/g).map(exactSearchRegex);
33+
res = libs.filter((lib) => nameRegs.some((nr) => nr.test(lib.name)));
34+
} else {
35+
res = [
36+
...libs.filter((lib) => eq(lib.name, data.search)),
37+
...libs.filter((lib) => !eq(lib.name, data.search) && reg.test(lib.name))
38+
.sort((a, b) => {
39+
const ai = `${a[sortBy]}`.toLowerCase();
40+
const bi = `${b[sortBy]}`.toLowerCase();
41+
if (ai === bi) return 0;
42+
return (ai < bi ? -1 : 1) * (sortDesc ? -1 : 1);
43+
}),
44+
];
45+
}
3846
const response = {
3947
limit, skip, total: res.length, data: res.slice(skip * limit, (skip + 1) * limit),
4048
};

src/actions/program.js

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ const fs = require('fs').promises;
33
const net = require('net');
44
const cli = require('../utils/arduino-exec');
55
const tmpFiles = require('../utils/files');
6+
const json = require('../utils/json');
7+
8+
const exists = async (path) => {
9+
try {
10+
await fs.access(path);
11+
return true;
12+
} catch (err) {
13+
Math.random(err);
14+
return false;
15+
}
16+
};
617

718
const program = {
819

@@ -35,11 +46,58 @@ const program = {
3546
const response = program.getError(res);
3647
if (!response.error && !noHex) {
3748
const ref = socket.sketchPath.split('/').pop();
38-
try {
39-
const hex = await fs.readFile(`${socket.sketchPath}/output/${ref}.ino.hex`, 'base64');
40-
response.hex = hex;
41-
} catch (err) {
42-
console.error(err);
49+
if (fqbn.indexOf('esp') !== 0) {
50+
try {
51+
const hex = await fs.readFile(`${socket.sketchPath}/output/${ref}.ino.hex`, 'base64');
52+
response.hex = hex;
53+
} catch (err) {
54+
console.error(err);
55+
}
56+
} else if (fqbn.indexOf('esp8266') === 0) {
57+
try {
58+
const bin = await fs.readFile(`${socket.sketchPath}/output/${ref}.ino.bin`, 'base64');
59+
response.files = [{ data: bin, address: 0 }];
60+
} catch (err) {
61+
console.error(err);
62+
}
63+
} else if (fqbn.indexOf('esp32') === 0) {
64+
const boards = await json.loadLargeData('boards');
65+
const baseFqbn = fqbn.split(':').slice(0, 4).join(':');
66+
const board = boards.find((b) => b.fqbn === baseFqbn);
67+
if (board) {
68+
const flashFreq = `${
69+
(fqbn.split(':').find((part) => part.includes('FlashFreq=')) || '').replace('FlashFreq=', '')
70+
|| (board.config_options.find((o) => o.option === 'FlashFreq')
71+
|| { values: [{ selected: true, value: '' }] }).values.find((v) => v.selected).value
72+
|| board.properties.build.flash_freq
73+
}m`.replace('mm', 'm');
74+
const flashMode = (fqbn.split(':').find((part) => part.includes('FlashMode=')) || '').replace('FlashMode=', '')
75+
|| (board.config_options.find((o) => o.option === 'FlashMode')
76+
|| { values: [{ selected: true, value: '' }] }).values.find((v) => v.selected).value
77+
|| board.properties.build.boot;
78+
const espToolsPath = '/mnt/duino-data/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools';
79+
let bootPath = `${espToolsPath}/sdk/bin/bootloader_${flashMode}_${flashFreq}.bin`;
80+
// account for the new path for the bin in the next arduino-esp32 release. (2021-07-18)
81+
if (!(await exists(bootPath))) {
82+
bootPath = `${espToolsPath}/sdk/${board.properties.build.mcu}/bin/bootloader_${flashMode}_${flashFreq}.bin`;
83+
}
84+
try {
85+
const appBin = await fs.readFile(`${socket.sketchPath}/output/${ref}.ino.bin`, 'base64');
86+
const partBin = await fs.readFile(`${socket.sketchPath}/output/${ref}.ino.partitions.bin`, 'base64');
87+
const app0Bin = await fs.readFile(`${espToolsPath}/partitions/boot_app0.bin`, 'base64');
88+
const bootBin = await fs.readFile(bootPath, 'base64');
89+
response.files = [
90+
{ data: app0Bin, address: 0xe000 },
91+
{ data: bootBin, address: Number(board.properties.build.bootloader_addr) || 0x1000 },
92+
{ data: appBin, address: 0x10000 },
93+
{ data: partBin, address: 0x8000 },
94+
];
95+
response.flash_freq = flashFreq;
96+
response.flash_mode = flashMode;
97+
} catch (err) {
98+
console.error(err);
99+
}
100+
}
43101
}
44102
}
45103
response.log = libRes + res;

src/utils/arduino-exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = (commands, args, socket, options) => new Promise((resolve) => {
1818
...(Array.isArray(commands) ? commands : commands.split('.')),
1919
...(Array.isArray(args) ? args : [args]).map((arg) => `${`${arg}`.replace(/"/g, '')}`),
2020
...(cliArgs).split(' '),
21-
], { cwd: socket ? socket.tmpDir.path : `${__dirname}/../../`, env: { HOME: '/mnt/duino-data' } });
21+
], { cwd: socket ? socket.tmpDir.path : `${__dirname}/../../`, env: { HOME: '/mnt/duino-data', PATH: process.env.PATH } });
2222
exec.stdout.on('data', (data) => log(data));
2323
exec.stderr.on('data', (data) => log(data));
2424

0 commit comments

Comments
 (0)