@libs-scripts-mep/grav-fw-pvi 4.0.4 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat.py +66 -0
- package/grav-fw-pvi.js +56 -11
- package/package.json +1 -1
package/compat.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
from importlib.metadata import version as get_version, PackageNotFoundError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Detecta se há um ambiente virtual na pasta atual
|
|
8
|
+
def detect_venv_python():
|
|
9
|
+
venv_path = os.path.join(os.getcwd(), ".venv", "Scripts", "python.exe")
|
|
10
|
+
if os.path.exists(venv_path):
|
|
11
|
+
return venv_path
|
|
12
|
+
return sys.executable # Fallback para o Python atual (global ou outro venv)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
PYTHON_EXEC = detect_venv_python()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_installed_version(package):
|
|
19
|
+
try:
|
|
20
|
+
return get_version(package)
|
|
21
|
+
except PackageNotFoundError as e:
|
|
22
|
+
print(e)
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def uninstall_package(package):
|
|
27
|
+
try:
|
|
28
|
+
print(f"[ESP DEP]Uninstalling {package}...")
|
|
29
|
+
subprocess.check_call([PYTHON_EXEC, "-m", "pip", "uninstall", "-y", package])
|
|
30
|
+
except subprocess.CalledProcessError as e:
|
|
31
|
+
print(f"[ESP DEP]Failed to uninstall {package}. Error: {e}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def install_package(package, version):
|
|
35
|
+
try:
|
|
36
|
+
print(f"[ESP DEP]Installing {package} version {version}...")
|
|
37
|
+
subprocess.check_call([PYTHON_EXEC, "-m", "pip", "install", f"{package}=={version}"])
|
|
38
|
+
except subprocess.CalledProcessError as e:
|
|
39
|
+
print(f"[ESP DEP]Failed to install {package} version {version}. Error: {e}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def check_and_fix_package(package, module, expected_version):
|
|
43
|
+
installed_version = get_installed_version(package)
|
|
44
|
+
|
|
45
|
+
if installed_version:
|
|
46
|
+
print(f"[ESP DEP]{package} is installed with version {installed_version}.")
|
|
47
|
+
if installed_version != expected_version:
|
|
48
|
+
print(f"[ESP DEP]Version mismatch! Expected: {expected_version}, Installed: {installed_version}.")
|
|
49
|
+
uninstall_package(package)
|
|
50
|
+
install_package(package, expected_version)
|
|
51
|
+
else:
|
|
52
|
+
print(f"[ESP DEP]{package} is already at the expected version ({expected_version}).")
|
|
53
|
+
else:
|
|
54
|
+
print(f"[ESP DEP]{package} is not installed.")
|
|
55
|
+
install_package(package, expected_version)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
packages = {
|
|
59
|
+
"esptool": ("esptool", "4.10")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Check and fix packages
|
|
63
|
+
for package, (module, expected_version) in packages.items():
|
|
64
|
+
check_and_fix_package(package, module, expected_version)
|
|
65
|
+
|
|
66
|
+
print("[ESP DEP]Package version check and update completed.")
|
package/grav-fw-pvi.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import FWLink from "../daq-fwlink/FWLink.js"
|
|
2
|
+
import Log from "../script-loader/utils-script.js"
|
|
2
3
|
|
|
3
4
|
export default class GravaFW {
|
|
4
5
|
|
|
6
|
+
static progress
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
*
|
|
7
10
|
* @param {String} dirFirm
|
|
@@ -45,6 +48,7 @@ export default class GravaFW {
|
|
|
45
48
|
|
|
46
49
|
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
47
50
|
logGravacao = logGravacao + param[0]
|
|
51
|
+
this.progress = param[0]
|
|
48
52
|
|
|
49
53
|
if (param[0] != undefined) {
|
|
50
54
|
|
|
@@ -89,7 +93,7 @@ export default class GravaFW {
|
|
|
89
93
|
resolve({ success: false, msg: `Nenhum diretório de firmware ou option byte informado` })
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
FWLink.runInstructionS("EXEC", [
|
|
96
|
+
FWLink.runInstructionS("EXEC", [`I:/Teste_Producao/Resources/stvp/STVP_CmdLine.exe`, ObjWriteSTM8.commandLineArguments, "true", "true"])
|
|
93
97
|
|
|
94
98
|
})
|
|
95
99
|
|
|
@@ -172,6 +176,7 @@ export default class GravaFW {
|
|
|
172
176
|
|
|
173
177
|
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
174
178
|
logGravacao = logGravacao + param[0]
|
|
179
|
+
this.progress = param[0]
|
|
175
180
|
|
|
176
181
|
if (param[0] != undefined) {
|
|
177
182
|
|
|
@@ -203,13 +208,20 @@ export default class GravaFW {
|
|
|
203
208
|
|
|
204
209
|
resolve({ success: false, msg: `Falha ao receber dados do microcontrolador`, dirProject: dirProject })
|
|
205
210
|
|
|
211
|
+
} else if (param[0].includes(`The device is not responding`)) {
|
|
212
|
+
|
|
213
|
+
FWLink.PVIEventObserver.remove(id)
|
|
214
|
+
clearTimeout(timeOutGravacao)
|
|
215
|
+
|
|
216
|
+
resolve({ success: false, msg: `Controlador nao responde ao gravador`, dirProject: dirProject })
|
|
217
|
+
|
|
206
218
|
}
|
|
207
219
|
|
|
208
220
|
}
|
|
209
221
|
|
|
210
222
|
}, "sniffer.exec")
|
|
211
223
|
|
|
212
|
-
FWLink.runInstructionS("EXEC", [
|
|
224
|
+
FWLink.runInstructionS("EXEC", [`I:/Teste_Producao/Resources/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
|
|
213
225
|
|
|
214
226
|
let timeOutGravacao = setTimeout(() => {
|
|
215
227
|
|
|
@@ -256,13 +268,14 @@ export default class GravaFW {
|
|
|
256
268
|
return new Promise((resolve) => {
|
|
257
269
|
|
|
258
270
|
FWLink.runInstructionS("JLINK7.init", []) // Inicializa o JLink
|
|
259
|
-
|
|
271
|
+
|
|
260
272
|
let logGravacao = ""
|
|
261
273
|
|
|
262
274
|
const id = FWLink.PVIEventObserver.add((msg, param) => {
|
|
263
275
|
|
|
264
276
|
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
265
277
|
logGravacao = logGravacao + param[0]
|
|
278
|
+
this.progress = param[0]
|
|
266
279
|
|
|
267
280
|
if (param == "Script processing completed.") {
|
|
268
281
|
|
|
@@ -284,7 +297,7 @@ export default class GravaFW {
|
|
|
284
297
|
}, "sniffer.exec")
|
|
285
298
|
|
|
286
299
|
const commandFile = commandJlink(nameFile, speed, dirProject)
|
|
287
|
-
FWLink.runInstructionS("EXEC", [
|
|
300
|
+
FWLink.runInstructionS("EXEC", [`I:/Teste_Producao/Resources/JLink7/JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
|
|
288
301
|
|
|
289
302
|
let timeOutGravacao = setTimeout(() => {
|
|
290
303
|
FWLink.PVIEventObserver.remove(id)
|
|
@@ -329,9 +342,10 @@ export default class GravaFW {
|
|
|
329
342
|
* { success: Boolean, msg: String }
|
|
330
343
|
* ```
|
|
331
344
|
*/
|
|
332
|
-
static async ESP32(sessionStorageTag, AddressFilePath, isBatFile, betweenMsgTimeout) {
|
|
345
|
+
static async ESP32(sessionStorageTag, AddressFilePath, isBatFile, betweenMsgTimeout = 10000, chip = "esp32") {
|
|
333
346
|
|
|
334
|
-
return new Promise((resolve) => {
|
|
347
|
+
return new Promise(async (resolve) => {
|
|
348
|
+
await this.checkDependenciesPython()
|
|
335
349
|
|
|
336
350
|
if (!AddressFilePath) {
|
|
337
351
|
resolve({ success: false, msg: "Caminho de arquivo para gravação não especificado", AddressFilePath: AddressFilePath }); return
|
|
@@ -370,6 +384,7 @@ export default class GravaFW {
|
|
|
370
384
|
}
|
|
371
385
|
|
|
372
386
|
} else if (info.includes("%")) {
|
|
387
|
+
this.progress = info
|
|
373
388
|
|
|
374
389
|
} else if (info.includes("Hard resetting via RTS pin...")) {
|
|
375
390
|
sessionStorage.getItem(sessionStorageTag) == null ? sessionStorage.setItem(sessionStorageTag, tryingPorts.pop()) : null
|
|
@@ -382,25 +397,55 @@ export default class GravaFW {
|
|
|
382
397
|
|
|
383
398
|
console.log("writeFirmware ID", id)
|
|
384
399
|
|
|
385
|
-
let pythonPath = "C:/esp-idf/Python/python.exe"
|
|
386
|
-
let espToolPath = "C:/esp-idf/components/esptool_py/esptool/esptool.py"
|
|
387
400
|
let port = ""
|
|
388
401
|
|
|
389
402
|
sessionStorage.getItem(sessionStorageTag) != null ? port = `-p${sessionStorage.getItem(sessionStorageTag)}` : null
|
|
390
403
|
|
|
391
|
-
const args = `${
|
|
404
|
+
const args = `${port} -b 480600 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size detect --flash_freq 40m ${AddressFilePath}`
|
|
392
405
|
|
|
393
406
|
if (isBatFile) {
|
|
394
407
|
console.log(`Executando batch: ${AddressFilePath} args: ${port}`)
|
|
395
408
|
FWLink.runInstructionS("EXEC", [AddressFilePath, port, "true", "true", "true"])
|
|
396
409
|
} else {
|
|
397
|
-
console.log(`Executando
|
|
398
|
-
FWLink.runInstructionS("EXEC", [
|
|
410
|
+
console.log(`Executando esptoll, args: ${args}`)
|
|
411
|
+
FWLink.runInstructionS("EXEC", ["esptool", args, "true", "true", "true"])
|
|
399
412
|
}
|
|
400
413
|
|
|
401
414
|
})
|
|
402
415
|
}
|
|
403
416
|
|
|
417
|
+
static getScriptPath() {
|
|
418
|
+
const pathC = location.pathname.slice(location.pathname.indexOf("C:/"), location.pathname.lastIndexOf("/"))
|
|
419
|
+
const pathI = location.pathname.slice(location.pathname.indexOf("I:/"), location.pathname.lastIndexOf("/"))
|
|
420
|
+
|
|
421
|
+
if (pathC.length > 0) {
|
|
422
|
+
return pathC
|
|
423
|
+
} else if (pathI.length > 0) {
|
|
424
|
+
return pathI
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
static async checkDependenciesPython(pyFilePath = this.getScriptPath() + '/node_modules/@libs-scripts-mep/grav-fw-pvi/compat.py') {
|
|
429
|
+
return new Promise((resolve) => {
|
|
430
|
+
const id = FWLink.PVIEventObserver.add((message, params) => {
|
|
431
|
+
const msg = params?.[0]
|
|
432
|
+
|
|
433
|
+
if (msg.includes("[ESP DEP]")) { Log.warn(msg, Log.Colors.Brown.SandyBrown) }
|
|
434
|
+
|
|
435
|
+
if (msg.includes("[ESP DEP]") && msg.includes("Package version check and update completed.")) {
|
|
436
|
+
FWLink.PVIEventObserver.remove(id)
|
|
437
|
+
Log.console("ESP: Dependências instaladas com sucesso.", Log.Colors.Green.SpringGreen)
|
|
438
|
+
resolve({ success: true, msg: msg, })
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
}, "PVI.Sniffer.sniffer.PID_")
|
|
442
|
+
|
|
443
|
+
setTimeout(() => {
|
|
444
|
+
FWLink.runInstructionS("EXEC", ["Python", pyFilePath, "true", "true"])
|
|
445
|
+
}, 300)
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
404
449
|
static { window.GravaFW = GravaFW }
|
|
405
450
|
|
|
406
451
|
}
|