@libs-scripts-mep/grav-fw-pvi 4.0.4 → 4.1.0

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.
Files changed (3) hide show
  1. package/compat.py +66 -0
  2. package/grav-fw-pvi.js +48 -10
  3. 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", [`${FWLink.runInstructionS("GETRESOURCESPATH", [])}\\stvp\\STVP_CmdLine.exe`, ObjWriteSTM8.commandLineArguments, "true", "true"])
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
 
@@ -209,7 +214,7 @@ export default class GravaFW {
209
214
 
210
215
  }, "sniffer.exec")
211
216
 
212
- FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETRESOURCESPATH", [])}/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
217
+ FWLink.runInstructionS("EXEC", [`I:/Teste_Producao/Resources/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
213
218
 
214
219
  let timeOutGravacao = setTimeout(() => {
215
220
 
@@ -263,6 +268,7 @@ export default class GravaFW {
263
268
 
264
269
  console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
265
270
  logGravacao = logGravacao + param[0]
271
+ this.progress = param[0]
266
272
 
267
273
  if (param == "Script processing completed.") {
268
274
 
@@ -284,7 +290,7 @@ export default class GravaFW {
284
290
  }, "sniffer.exec")
285
291
 
286
292
  const commandFile = commandJlink(nameFile, speed, dirProject)
287
- FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
293
+ FWLink.runInstructionS("EXEC", [`I:/Teste_Producao/Resources/JLink7/JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
288
294
 
289
295
  let timeOutGravacao = setTimeout(() => {
290
296
  FWLink.PVIEventObserver.remove(id)
@@ -329,9 +335,10 @@ export default class GravaFW {
329
335
  * { success: Boolean, msg: String }
330
336
  * ```
331
337
  */
332
- static async ESP32(sessionStorageTag, AddressFilePath, isBatFile, betweenMsgTimeout) {
338
+ static async ESP32(sessionStorageTag, AddressFilePath, isBatFile, betweenMsgTimeout = 10000, chip = "esp32") {
333
339
 
334
- return new Promise((resolve) => {
340
+ return new Promise(async (resolve) => {
341
+ await this.checkDependenciesPython()
335
342
 
336
343
  if (!AddressFilePath) {
337
344
  resolve({ success: false, msg: "Caminho de arquivo para gravação não especificado", AddressFilePath: AddressFilePath }); return
@@ -370,6 +377,7 @@ export default class GravaFW {
370
377
  }
371
378
 
372
379
  } else if (info.includes("%")) {
380
+ this.progress = info
373
381
 
374
382
  } else if (info.includes("Hard resetting via RTS pin...")) {
375
383
  sessionStorage.getItem(sessionStorageTag) == null ? sessionStorage.setItem(sessionStorageTag, tryingPorts.pop()) : null
@@ -382,25 +390,55 @@ export default class GravaFW {
382
390
 
383
391
  console.log("writeFirmware ID", id)
384
392
 
385
- let pythonPath = "C:/esp-idf/Python/python.exe"
386
- let espToolPath = "C:/esp-idf/components/esptool_py/esptool/esptool.py"
387
393
  let port = ""
388
394
 
389
395
  sessionStorage.getItem(sessionStorageTag) != null ? port = `-p${sessionStorage.getItem(sessionStorageTag)}` : null
390
396
 
391
- const args = `${espToolPath} ${port} -b 480600 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size detect --flash_freq 40m ${AddressFilePath}`
397
+ 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
398
 
393
399
  if (isBatFile) {
394
400
  console.log(`Executando batch: ${AddressFilePath} args: ${port}`)
395
401
  FWLink.runInstructionS("EXEC", [AddressFilePath, port, "true", "true", "true"])
396
402
  } else {
397
- console.log(`Executando python: ${pythonPath} args: ${args}`)
398
- FWLink.runInstructionS("EXEC", [pythonPath, args, "true", "true", "true"])
403
+ console.log(`Executando esptoll, args: ${args}`)
404
+ FWLink.runInstructionS("EXEC", ["esptool", args, "true", "true", "true"])
399
405
  }
400
406
 
401
407
  })
402
408
  }
403
409
 
410
+ static getScriptPath() {
411
+ const pathC = location.pathname.slice(location.pathname.indexOf("C:/"), location.pathname.lastIndexOf("/"))
412
+ const pathI = location.pathname.slice(location.pathname.indexOf("I:/"), location.pathname.lastIndexOf("/"))
413
+
414
+ if (pathC.length > 0) {
415
+ return pathC
416
+ } else if (pathI.length > 0) {
417
+ return pathI
418
+ }
419
+ }
420
+
421
+ static async checkDependenciesPython(pyFilePath = this.getScriptPath() + '/node_modules/@libs-scripts-mep/grav-fw-pvi/compat.py') {
422
+ return new Promise((resolve) => {
423
+ const id = FWLink.PVIEventObserver.add((message, params) => {
424
+ const msg = params?.[0]
425
+
426
+ if (msg.includes("[ESP DEP]")) { Log.warn(msg, Log.Colors.Brown.SandyBrown) }
427
+
428
+ if (msg.includes("[ESP DEP]") && msg.includes("Package version check and update completed.")) {
429
+ FWLink.PVIEventObserver.remove(id)
430
+ Log.console("ESP: Dependências instaladas com sucesso.", Log.Colors.Green.SpringGreen)
431
+ resolve({ success: true, msg: msg, })
432
+ }
433
+
434
+ }, "PVI.Sniffer.sniffer.PID_")
435
+
436
+ setTimeout(() => {
437
+ FWLink.runInstructionS("EXEC", ["Python", pyFilePath, "true", "true"])
438
+ }, 300)
439
+ })
440
+ }
441
+
404
442
  static { window.GravaFW = GravaFW }
405
443
 
406
444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Auxilia na gravação de microcontroladores por linha de comando através do PVI",
5
5
  "main": "grav-fw-pvi.js",
6
6
  "scripts": {