Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the dev-esp32-idf4 branch #94

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/connector/check-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const _virtualTerminal = require('../transport/scriptable-serial-terminal');
const _luaCommandBuilder = require('../lua/command-builder');
const _logger = require('logging-facility').getLogger('connector');

_luaCommandBuilder.command = _luaCommandBuilder.espCommands();

// checks the node-mcu connection
function checkConnection(){

Expand Down
3 changes: 3 additions & 0 deletions lib/connector/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ async function connect(devicename, baudrate, applyConnectionCheck=true, connectD
// fetch device info
const data = await _deviceInfo();

_luaCommandBuilder.setArch(data.arch);
_luaCommandBuilder.command = _luaCommandBuilder.espCommands();

return 'Arch: ' + data.arch + ' | Version: ' + data.version + ' | ChipID: 0x' + data.chipID + ' | FlashID: 0x' + data.flashID;
}

Expand Down
9 changes: 6 additions & 3 deletions lib/connector/list-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const knownVendorIDs = [
'10C4',

// NodeMCU v3 - CH340G Adapter | 0x1A86 Nanjing QinHeng Electronics Co., Ltd.
'1A86'
'1A86',

// FTDI232 adapter | Product ID 6001
'0403',
];

// show connected serial devices
Expand All @@ -23,10 +26,10 @@ async function listDevices(showAll){
// filter by vendorIDs
}else{
return ports.filter(function(item){
//
//
return knownVendorIDs.includes(item.vendorId && item.vendorId.toUpperCase());
});
}
}

module.exports = listDevices;
module.exports = listDevices;
21 changes: 17 additions & 4 deletions lib/lua/command-builder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const _esp8266_commands = require('./esp8266-commands');
const _esp32Commands = require('./esp32-commands');
const _esp8266Commands = require('./esp8266-commands');

let arch = null;

// select a set of commands, depending on arch
function luaEspCommands(){

return arch === "esp32" ? _esp32Commands : _esp8266Commands;
}

// prepare command be escaping args
function luaPrepare(commandName, args){

const esp_commands = luaEspCommands();

// get command by name
let command = _esp8266_commands[commandName] || null;
let command = esp_commands[commandName] || null;

// valid command name provided ?
if (command == null){
Expand All @@ -23,6 +35,7 @@ function luaPrepare(commandName, args){
}

module.exports = {
command: _esp8266_commands,
prepare: luaPrepare
espCommands: luaEspCommands,
prepare: luaPrepare,
setArch: (a) => {arch = a}
};
56 changes: 56 additions & 0 deletions lib/lua/esp32-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// lua command templates - central location for easier debugging
const lua_commands = {
// connection info echo command,
echo: 'print("echo1337")',

// info command (flash id)
// v2 => v3 changed from list to table!
nodeInfoLegacy: 'print(node.info("hw"));',

// nodemcu >=3x info command
nodeInfo3: 'for k,v in pairs(node.info("?")) do print(k,v) end;',

// chipid info
chipid: 'print(node.chipid());',

// file system info
fsInfo: 'print(file.fsinfo())',

// format the file system
fsFormat: 'file.format()',

// compile a remote file
compile: 'node.compile("?")',

// run a file
run: 'dofile("?")',

// soft-reset
reset: 'node.restart()',

// list files on SPIFFS
listFiles: 'local l = file.list();for k,v in pairs(l) do uart.write(0,k..":"..v..";") end print("")',

// file open
fileOpen: '__f=io.open("?", "?") print(__f)',

// close a opened file
fileClose: '__f:close() __f=nil',

// remove file
fileRemove: 'file.remove("?")',

// file close & flush
fileCloseFlush: '__f:flush(f) __f:close() __f=nil',

// read file content
fileRead: '__nmtread()',

// helper function to write hex/base64 encoded content to file @see docs/TransferEncoding.md
transferWriteHelper: "if encoder and encoder.fromBase64 then _G.__nmtwrite = function(s) __f:write(encoder.fromBase64(s)) end print('b') else _G.__nmtwrite = function(s) for c in s:gmatch('..') do __f:write(string.char(tonumber(c, 16))) end end print('h') end",

// helper function to read hex/base64 encoded content from file @see docs/TransferEncoding.md
transferReadHelper: "function __nmtread()local b = encoder and encoder.toBase64 while true do c = __f:read(b and 240 or 1) if c==nil then print('')break end uart.write(0, b and encoder.toBase64(c) or string.format('%02X', string.byte(c)))end print('') end"
};

module.exports = lua_commands;