@libs-scripts-mep/grav-fw-pvi 4.0.0 → 4.0.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 +62 -27
  2. package/package.json +1 -1
package/grav-fw-pvi.js CHANGED
@@ -7,7 +7,7 @@ export default class GravaFW {
7
7
  * @param {String} dirFirm
8
8
  * @param {String} dirOpt
9
9
  * @param {Object} objArguments
10
- * @param {Number} timeOut
10
+ * @param {Number} [timeOut=5000]
11
11
  * @returns
12
12
  *
13
13
  * # Exemplos
@@ -144,14 +144,13 @@ export default class GravaFW {
144
144
  /**
145
145
  *
146
146
  * @param {String} dirProject
147
- * @param {Number} timeOut
147
+ * @param {Number} [timeOut=5000]
148
148
  * @returns
149
149
  *
150
150
  * # Exemplos
151
151
  *
152
152
  * ```js
153
153
  * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.rpj"
154
- * const optionPath = "I:/script_repo/fw_repo/opt.hex"
155
154
  * const writeFirmware = await GravaFW.Renesas(programPath)
156
155
  * ```
157
156
  *
@@ -226,48 +225,84 @@ export default class GravaFW {
226
225
  })
227
226
  }
228
227
 
228
+
229
229
  /**
230
- * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
230
+ * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line.
231
+ *
231
232
  * @param {string} dirProject caminho do firmware
232
- * @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
233
+ * @param {string} nameFile nome para o arquivo de comandos JLink que ficará na pasta 'C:/Temp/', sujestão: código effective
233
234
  * @param {string} device modelo do micrcontrolador
234
- * @param {number} timeOut
235
+ * @param {number} [speed=4000] velocidade de gravação
236
+ * @param {number} [timeOut=5000] tempo máximo de gravação
237
+ * @returns {Promise<{success: boolean, msg: string}>} - resultado da gravação
238
+ *
239
+ * # Exemplos
240
+ *
241
+ * ```js
242
+ * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.hex"
243
+ * const codigo_effective = "1234"
244
+ * const device = "STM32C031K6"
245
+ * const writeFirmware = await GravaFW.JLink_v7(programPath, codigo_effective, device)
246
+ * ```
247
+ *
248
+ * # Retorno
249
+ *
250
+ * ```js
251
+ * { success: Boolean, msg: String }
252
+ * ```
235
253
  */
236
- static async JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
254
+ static async JLink_v7(dirProject = null, nameFile, device, speed = 4000, timeOut = 5000) {
237
255
 
238
- let logGravacao = ""
256
+ return new Promise((resolve) => {
257
+ let logGravacao = ""
239
258
 
240
- const id = FWLink.PVIEventObserver.add((msg, param) => {
259
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
241
260
 
242
- console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
243
- logGravacao = logGravacao + param[0]
261
+ console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
262
+ logGravacao = logGravacao + param[0]
244
263
 
245
- if (data == "Script processing completed.") {
264
+ if (param == "Script processing completed.") {
246
265
 
247
- FWLink.PVIEventObserver.remove(id)
266
+ FWLink.PVIEventObserver.remove(id)
248
267
 
249
- if (logGravacao.includes(`O.K.`)) {
268
+ if (logGravacao.includes('Program & Verify speed')) {
250
269
 
251
- clearTimeout(timeOutGravacao)
252
- resolve({ success: true, msg: dirProject })
270
+ clearTimeout(timeOutGravacao)
271
+ resolve({ success: true, msg: dirProject })
253
272
 
254
- } else if (logGravacao.includes(`Cannot connect to target.`)) {
273
+ } else if (logGravacao.includes(`Cannot connect to target.`)) {
255
274
 
256
- clearTimeout(timeOutGravacao)
257
- resolve({ success: false, msg: `Cannot connect to target.` })
275
+ clearTimeout(timeOutGravacao)
276
+ resolve({ success: false, msg: `Cannot connect to target.` })
258
277
 
259
- }
278
+ }
260
279
 
261
- }
262
- }, "sniffer.exec")
280
+ }
281
+ }, "sniffer.exec")
263
282
 
264
- FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
283
+ const commandFile = commandJlink(nameFile, speed, dirProject)
284
+ FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
265
285
 
266
- let timeOutGravacao = setTimeout(() => {
267
- FWLink.PVIEventObserver.remove(id)
268
- resolve({ success: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
269
- }, timeOut)
286
+ let timeOutGravacao = setTimeout(() => {
287
+ FWLink.PVIEventObserver.remove(id)
288
+ resolve({ success: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
289
+ }, timeOut)
290
+ })
270
291
 
292
+ function commandJlink(nameFile, speed, dirProject) {
293
+ if (FWLink.runInstructionS("vfs.directoryexists", [`C:/Temp/`]) == '1') {
294
+ if (FWLink.runInstructionS("vfs.fileexists", [`C:/Temp/${nameFile}.txt`]) == '1') {
295
+ FWLink.runInstructionS("EXEC", ["cmd.exe", `/c (echo si 1 & echo speed ${speed} & echo r & echo h & echo erase & echo loadfile ${dirProject} & echo exit) > C:/Temp/${nameFile}.txt`, true, true])
296
+ return `C:/Temp/${nameFile}.txt`
297
+ } else {
298
+ FWLink.runInstructionS("EXEC", ["cmd.exe", `/c (echo texto invalido) > C:/Temp/${nameFile}.txt`, true, true])
299
+ return commandJlink(nameFile, speed, dirProject)
300
+ }
301
+ } else {
302
+ FWLink.runInstructionS("vfs.createdirectory", [`C:/Temp/`])
303
+ return commandJlink(nameFile, speed, dirProject)
304
+ }
305
+ }
271
306
  }
272
307
 
273
308
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "4.0.0",
3
+ "version": "4.0.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": {