Update: 更新socket工作模式
This commit is contained in:
@@ -1,20 +1,12 @@
|
||||
import os from 'node:os';
|
||||
import CONFIG from '../user/config.json';
|
||||
|
||||
export const DEBUG = true;
|
||||
export const ARDUINO = {
|
||||
path: {
|
||||
folder: 'D:/gitee/arduino-cli-win32/arduino-cli',
|
||||
cli: 'D:/gitee/arduino-cli-win32/arduino-cli/arduino-cli.exe',
|
||||
libraries: ['D:/gitee/arduino-cli-win32/arduino-cli/libraries'],
|
||||
cache: 'D:/gitee/arduino-cli-win32/arduino-cli/cache',
|
||||
config: 'D:/gitee/arduino-cli-win32/arduino-cli/arduino-cli.json',
|
||||
build: 'D:/gitee/mixly3-server/temp/web-socket',
|
||||
code: ''
|
||||
},
|
||||
key: '',
|
||||
port: '',
|
||||
code: ''
|
||||
};
|
||||
|
||||
export const DEBUG = CONFIG.debug;
|
||||
export const ARDUINO = CONFIG.arduino;
|
||||
export const MICROPYTHON = CONFIG.micropython;
|
||||
export const PYTHON = CONFIG.python;
|
||||
export const CURRENT_PLANTFORM = os.platform();
|
||||
export const WEB_SOCKT_TEMP_PATH = '';
|
||||
export const WEB_COMPILER_TEMP_PATH = '';
|
||||
export const WEB_SOCKT_TEMP_PATH = CONFIG.webSocketTempPath;
|
||||
export const WEB_COMPILER_TEMP_PATH = CONFIG.webSocketTempPath;
|
||||
export const CLIENT_PATH = CONFIG.clientPath;
|
||||
26
src/common/mstring.js
Normal file
26
src/common/mstring.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const MString = {};
|
||||
|
||||
|
||||
/**
|
||||
* @function 使用传入值替换字符串中{xxx}
|
||||
* @param str {string} 传入字符串
|
||||
* @param obj {object}
|
||||
* obj = {
|
||||
* xxx: value1,
|
||||
* xxx: value2
|
||||
* }
|
||||
* 使用value替换{xxx}
|
||||
* @return {string} 返回处理后的字符串
|
||||
**/
|
||||
MString.tpl = (str, obj) => {
|
||||
if (!(typeof str === 'string' && obj instanceof Object)) {
|
||||
return str;
|
||||
}
|
||||
for (let key in obj) {
|
||||
let re = new RegExp(`{*${key}*}`, 'gim');
|
||||
str = str.replace(re, obj[key]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
export default MString;
|
||||
@@ -79,7 +79,7 @@ export default class Serial extends EventsBase {
|
||||
});
|
||||
|
||||
this.#serialport_.on('error', (error) => {
|
||||
this.runEvent('error', error);
|
||||
this.runEvent('error', error.toString());
|
||||
});
|
||||
|
||||
this.#serialport_.on('open', () => {
|
||||
@@ -121,7 +121,7 @@ export default class Serial extends EventsBase {
|
||||
this.#addEventsListener_();
|
||||
this.#serialport_.open((error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
reject(error.toString());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@@ -137,7 +137,7 @@ export default class Serial extends EventsBase {
|
||||
}
|
||||
this.#serialport_.close((error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
reject(error.toString());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@@ -153,7 +153,7 @@ export default class Serial extends EventsBase {
|
||||
}
|
||||
this.#serialport_.update({ baudRate: baud }, (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
reject(error.toString());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@@ -169,7 +169,7 @@ export default class Serial extends EventsBase {
|
||||
}
|
||||
this.#serialport_.write(data, (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
reject(error.toString());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@@ -185,7 +185,7 @@ export default class Serial extends EventsBase {
|
||||
}
|
||||
this.#serialport_.set({ dtr, rts }, (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
reject(error.toString());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import path from 'node:path';
|
||||
import Shell from './shell';
|
||||
import MString from './mstring';
|
||||
import { MICROPYTHON, PYTHON, CLIENT_PATH } from './config';
|
||||
|
||||
|
||||
export default class ShellMicroPython extends Shell {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
async burn(config) {
|
||||
const info = {
|
||||
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
||||
esptool: `${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
|
||||
com: config.port
|
||||
};
|
||||
const command = MString.tpl(config.command, info);
|
||||
return this.exec(command);
|
||||
}
|
||||
|
||||
async upload(config) {
|
||||
const info = {
|
||||
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
||||
ampy: `${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
|
||||
com: config.port
|
||||
};
|
||||
const command = MString.tpl(config.command, info);
|
||||
return this.exec(command);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { execFile, exec } from 'node:child_process';
|
||||
import * as iconv_lite from 'iconv-lite';
|
||||
// import duration from 'dayjs/plugin/duration';
|
||||
import Debug from './debug';
|
||||
import EventsBase from './events-base';
|
||||
import { CURRENT_PLANTFORM } from './config';
|
||||
@@ -52,7 +51,7 @@ export default class Shell extends EventsBase {
|
||||
lines[i] = iconv_lite.decode(Buffer.from(lines[i], 'binary'), encoding);
|
||||
}
|
||||
data = lines.join('\n');
|
||||
data = this.#decode_(data);
|
||||
// data = this.#decode_(data);
|
||||
this.runEvent('error', data);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user