@libs-scripts-mep/grav-fw-pvi 2.1.2 → 2.2.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.
Files changed (2) hide show
  1. package/grav-fw-pvi.js +88 -3
  2. package/package.json +1 -1
package/grav-fw-pvi.js CHANGED
@@ -2,7 +2,7 @@ class GravaFW {
2
2
 
3
3
  /**
4
4
  * Realiza gravacao nos microcontroladores ST atraves do PVI, via STVP command line
5
- * @param {string} dirFirm formato esperado: "I:\\\Documentos\\\Softwares\\\STM8\\\STM8S003F3\\\INV-173\\\173v01\\\173v01_1.50_Com.stp"
5
+ * @param {string} dirFirm formato esperado: "I:\\\\Documentos\\\Softwares\\\STM8\\\STM8S003F3\\\INV-173\\\173v01\\\173v01_1.50_Com.stp"
6
6
  * @param {string} dirOpt formato esperado: "I:\\\Documentos\\\Softwares\\\STM8\\\STM8S003F3\\\INV-173\\\173v01\\\173v01_1.50_Com.stp"
7
7
  * @param {string} modelo_uC formato esperado: "STM8S003F3"
8
8
  */
@@ -121,7 +121,7 @@ class GravaFW {
121
121
  * @param {string} dirProject Formato esperado: "I:\\\Documentos\\\Softwares\\\RENESAS\\\R5F51303ADFL\\\INV-301\\\301v06\\\301v06.rpj"
122
122
  * @param {number} timeOut
123
123
  */
124
- static Renesas(dirProject = null, timeOut = 5000) {
124
+ static async Renesas(dirProject = null, timeOut = 5000) {
125
125
 
126
126
  return new Promise((resolve) => {
127
127
 
@@ -186,7 +186,7 @@ class GravaFW {
186
186
  * @param {string} device modelo do micrcontrolador
187
187
  * @param {number} timeOut
188
188
  */
189
- static JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
189
+ static async JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
190
190
 
191
191
  let logGravacao = ""
192
192
 
@@ -224,4 +224,89 @@ class GravaFW {
224
224
  }, timeOut)
225
225
 
226
226
  }
227
+
228
+
229
+ /**
230
+ * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
231
+ * @param {string} sessionStorageTag nome que sera utilizado para armazenar a porta COM encontrada
232
+ * @param {string} appPath formato esperado: "I:\\Documentos\\Softwares\\ESP32\\INV-161\\31L\\INV-161_INV-161_HW2-31-FW-v1.bat" ou "I:\\Documentos\\Softwares\\ESP32\\INV-161\\31L\\INV-161_INV-161_HW2-31-FW-v1.bin"
233
+ * @param {boolean} isBatFile true = firmware esta em .bat / false = firmware esta em .bin
234
+ * @param {number} betweenMsgTimeout timeout maximo para inatividade na comunicação com o ESP32
235
+ */
236
+ static async ESP32(sessionStorageTag, appPath, isBatFile, betweenMsgTimeout) {
237
+
238
+ return new Promise((resolve) => {
239
+
240
+ console.time("WriteFirmware")
241
+
242
+ if (!appPath) {
243
+ resolve({ sucess: false, msg: "Caminho de arquivo para gravação não especificado" }); return
244
+ }
245
+
246
+ let portsFound = null, tryingPorts = [], lastTimeMsg = new Date().getTime()
247
+
248
+ const betweenMsgMonitor = setInterval(() => {
249
+
250
+ if (new Date().getTime() - lastTimeMsg > betweenMsgTimeout) {
251
+ clearInterval(betweenMsgMonitor)
252
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
253
+ resolve({ sucess: false, msg: "esptool.py encontrou um problema e teve que ser finalizado." }); return
254
+ }
255
+
256
+ }, 1000)
257
+
258
+ const id = PVI.FWLink.globalDaqMessagesObservers.add((filter, message) => {
259
+
260
+ const info = message[0]
261
+ lastTimeMsg = new Date().getTime()
262
+ console.log(`%cLog Program: ${message}`, ' color: #87CEEB')
263
+
264
+ if (info.includes("Found")) {
265
+ const splittedInfo = info.split(" ")
266
+ portsFound = parseInt(splittedInfo[1])
267
+
268
+ } else if (info.includes("Serial port")) {
269
+ const splittedInfo = info.split(" ")
270
+ tryingPorts.push(splittedInfo[2])
271
+ UI.setMsg(`Tentando gravar na porta ${splittedInfo[2]}`)
272
+
273
+ } else if (info.includes("failed to connect")) {
274
+ if (tryingPorts.length >= portsFound) {
275
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
276
+ resolve({ sucess: false, msg: "Gravador não conseguiu se conectar com o ESP32" }); return
277
+ }
278
+
279
+ } else if (info.includes("%")) {
280
+ UI.setMsg(info)
281
+
282
+ } else if (info.includes("Hard resetting via RTS pin...")) {
283
+ sessionStorage.getItem(sessionStorageTag) == null ? sessionStorage.setItem(sessionStorageTag, tryingPorts.pop()) : null
284
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
285
+ resolve({ sucess: true, msg: "Gravação bem sucedida" })
286
+ console.timeEnd("WriteFirmware")
287
+ }
288
+
289
+ }, "PVI.Sniffer.sniffer.exec_return.data")
290
+
291
+ console.log("writeFirmware ID", id)
292
+
293
+ let pythonPath = "C:/esp-idf/Python/python.exe"
294
+ let espToolPath = "C:/esp-idf/components/esptool_py/esptool/esptool.py"
295
+ let port = ""
296
+
297
+ sessionStorage.getItem(sessionStorageTag) != null ? port = `-p${sessionStorage.getItem(sessionStorageTag)}` : null
298
+
299
+ 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 0x0000 ${appPath}`
300
+
301
+ if (isBatFile) {
302
+ console.log(`Executando batch: ${appPath} args: ${port}`)
303
+ pvi.runInstructionS("EXEC", [appPath, port, "true", "true", "true"])
304
+ } else {
305
+ console.log(`Executando python: ${pythonPath} args: ${args}`)
306
+ pvi.runInstructionS("EXEC", [pythonPath, args, "true", "true", "true"])
307
+ }
308
+
309
+ })
310
+ }
311
+
227
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
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": {