@libs-scripts-mep/grav-fw-pvi 2.3.2 → 3.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 (3) hide show
  1. package/README.md +9 -97
  2. package/grav-fw-pvi.js +104 -62
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,108 +18,20 @@ Abra o terminal, e na pasta do script, execute:
18
18
  npm uninstall @libs-scripts-mep/grav-fw-pvi
19
19
  ```
20
20
 
21
- <br>
21
+ ## Atualizando
22
22
 
23
- | Fabricante | Ferramenta | Suporte |
24
- | ---------- | ------------------------ | ------- |
25
- | ST | STVP | ✔️ |
26
- | Renesas | Renesas Flash Programmer | ✔️ |
27
- | Nuvoton | JLink v7.82 | ✔️ |
28
-
29
- ## Exemplo de Utilização do Modulo
30
-
31
- ### STM8
32
- ```js
33
-
34
- static async GravaFirmware(dirFirm, dirOpt) {
35
-
36
- const ObjParams = {
37
-
38
- objArguments: {
39
- verbose: true,
40
- Device: "STM8S003F3",
41
- },
42
- timeOut : 4000
43
-
44
- }
45
-
46
- return new Promise(async (resolve) => {
47
-
48
- let RetornoGravacao = await GravaFW.STM8(dirFirm, dirOpt, ObjParams.objArguments, ObjParams.timeOut)
49
-
50
- if (RetornoGravacao.sucess) {
51
-
52
- console.log("GRAVOU")
53
-
54
- } else {
55
-
56
- console.log("NÃO GRAVOU")
57
- }
58
-
59
- })
60
-
61
- }
23
+ Abra o terminal, e na pasta raíz do script, execute:
62
24
 
25
+ ```
26
+ npm uninstall @libs-scripts-mep/daq-fwlink
63
27
  ```
64
28
 
65
- #### <h3> Possíveis valores para os argumentos da gravação <h3>
29
+ ## Como utilizar
66
30
 
31
+ Realize a importação:
67
32
 
68
33
  ```js
69
- [-BoardName=STxxx] ==========> Programming Tool name (ST-LINK, RLINK, STICE, ...)
70
- [-Tool_ID=x] ================> ST-LINK Programming Tool ID (0, 1, 2...)
71
- [-NbTools=x] ================> Number of ST-LINK Tools with same device connected (Tool_ID is automatically incremented)
72
- [-Port=xxx] =================> Communication Port (USB, LPT1)
73
- [-ProgMode=xxx] =============> Programming mode or protocol (SWIM, JTAG, SWD)
74
- [-Device=STxxx] =============> Device name (exact same name as in STVP)
75
- [-version] ==================> Display version of this application
76
- [-verbose] ==================> Display messages, warnings, errors
77
- [-log] ======================> Generate or append Result.log log file
78
- [-loop] =====================> Loop on actions until 'Space' key hit
79
- [-progress] =================> Display progress of each action
80
- [-warn_protect] =============> Message Box if programming Option Byte protection
81
- [-no_progProg] ==============> Do not program PROGRAM MEMORY (used to verify device from a file)
82
- [-no_progData] ==============> Do not program DATA MEMORY (used to verify device from a file)
83
- [-no_progOption] ============> Do not program OPTION BYTE (used to verify device from a file)
84
- [-readProg] =================> Read PROGRAM MEMORY
85
- [-readData] =================> Read DATA MEMORY
86
- [-readOption] ===============> Read OPTION BYTE
87
- [-erase] ====================> Erase the device (before programming)
88
- [-blank] ====================> Blank Check the device (before programming)
89
- [-verif] ====================> Verify the device after programming
90
- [-FileProg=fname.hex/s19] ===> File name to program PROGRAM MEMORY area (hex or s19)
91
- [-FileData=fname.hex/s19] ===> File name to program DATA MEMORY area (hex or s19)
92
- [-FileOption=fname.hex/s19] => File name to program OPTION BYTE area (hex or s19)
93
-
94
-
95
-
96
- objArguments = {
97
-
98
- log: true or false
99
- loop: true or false
100
- erase: true or false
101
- blank: true or false
102
- verif: true or false
103
- verbose: true or false
104
- version: true or false
105
- progress: true or false
106
- readProg: true or false
107
- readData: true or false
108
- readOption: true or false
109
- no_progProg: true or false
110
- warn_protect: true or false
111
- no_progOption: true or false
112
- verbose: true or false,
113
-
114
- Port:"USB",
115
- ProgMode:"SWIM",
116
- NbTools:"1",
117
- Tool_ID:"0",
118
- BoardName:"ST-LINK",
119
- Device: "STM8S003F3",
120
- FileData: ""
121
-
122
- },
123
-
124
-
34
+ import GravaFW from "./module_path/grav-fw-pvi.js"
125
35
  ```
36
+
37
+ As demais informações e instruções estarão disponíveis via `JSDocs`.
package/grav-fw-pvi.js CHANGED
@@ -1,10 +1,28 @@
1
- class GravaFW {
1
+ import FWLink from "../daq-fwlink/FWLink.js"
2
+
3
+ export default class GravaFW {
2
4
 
3
5
  /**
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"
6
- * @param {string} dirOpt formato esperado: "I:\\\Documentos\\\Softwares\\\STM8\\\STM8S003F3\\\INV-173\\\173v01\\\173v01_1.50_Com.stp"
7
- * @param {string} modelo_uC formato esperado: "STM8S003F3"
6
+ *
7
+ * @param {String} dirFirm
8
+ * @param {String} dirOpt
9
+ * @param {Object} objArguments
10
+ * @param {Number} timeOut
11
+ * @returns
12
+ *
13
+ * # Exemplos
14
+ *
15
+ * ```js
16
+ * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.hex"
17
+ * const optionPath = "I:/script_repo/fw_repo/opt.hex"
18
+ * const writeFirmware = await GravaFW.STM8(programPath, optionPath, { Device: "STM8S003F3" })
19
+ * ```
20
+ *
21
+ * # Retorno
22
+ *
23
+ * ```js
24
+ * { success: Boolean, msg: String }
25
+ * ```
8
26
  */
9
27
  static async STM8(dirFirm = null, dirOpt = null, objArguments = {}, timeOut = 5000) {
10
28
 
@@ -20,9 +38,9 @@ class GravaFW {
20
38
 
21
39
  let logGravacao = ""
22
40
 
23
- if (ObjWriteSTM8.sucess) {
41
+ if (ObjWriteSTM8.success) {
24
42
 
25
- const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
43
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
26
44
 
27
45
  console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
28
46
  logGravacao = logGravacao + param[0]
@@ -31,24 +49,24 @@ class GravaFW {
31
49
 
32
50
  if (param[0].includes(validationMsg)) {
33
51
 
34
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
52
+ FWLink.PVIEventObserver.remove(id)
35
53
  clearTimeout(timeOutGravacao)
36
54
 
37
- resolve({ sucess: true, msg: logGravacao })
55
+ resolve({ success: true, msg: "Gravação bem sucedida", dirFirm: dirFirm })
38
56
 
39
57
  } else if (param[0].includes(`ERROR : Cannot communicate with the tool`)) {
40
58
 
41
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
59
+ FWLink.PVIEventObserver.remove(id)
42
60
  clearTimeout(timeOutGravacao)
43
61
 
44
- resolve({ sucess: null, msg: `Gravador não respondeu` })
62
+ resolve({ success: null, msg: `Gravador não respondeu`, dirFirm: dirFirm })
45
63
 
46
64
  } else if (param[0].includes(`(API) ERROR`)) {
47
65
 
48
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
66
+ FWLink.PVIEventObserver.remove(id)
49
67
  clearTimeout(timeOutGravacao)
50
68
 
51
- resolve({ sucess: null, msg: `Não foi possível realizar a gravação` })
69
+ resolve({ success: null, msg: `Não foi possível realizar a gravação`, dirFirm: dirFirm })
52
70
 
53
71
  }
54
72
 
@@ -59,26 +77,26 @@ class GravaFW {
59
77
  let timeOutGravacao = setTimeout(() => {
60
78
 
61
79
  console.log(`%cLog Program:\n\n${logGravacao}`, ' color: #EE0033')
62
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
80
+ FWLink.PVIEventObserver.remove(id)
63
81
 
64
- resolve({ sucess: false, msg: `Falha na gravação do firmware final` })
82
+ resolve({ success: false, msg: `Falha na gravação do firmware final` })
65
83
 
66
84
  }, timeOut)
67
85
 
68
86
  } else {
69
87
  console.log(`%cNenhum diretório de firmware ou option byte informado`, ' color: #EE0033')
70
- resolve({ sucess: false, msg: `Nenhum diretório de firmware ou option byte informado` })
88
+ resolve({ success: false, msg: `Nenhum diretório de firmware ou option byte informado` })
71
89
  }
72
90
 
73
- pvi.runInstructionS("EXEC", [`C:/Program Files (x86)/STMicroelectronics/st_toolset/stvp/STVP_CmdLine.exe`, ObjWriteSTM8.commandLineArguments, "true", "true"])
91
+ FWLink.runInstructionS("EXEC", [`C:/Program Files (x86)/STMicroelectronics/st_toolset/stvp/STVP_CmdLine.exe`, ObjWriteSTM8.commandLineArguments, "true", "true"])
74
92
 
75
93
  })
76
94
 
77
95
  /**
78
96
  *
79
- * @param {string} dirFirm
80
- * @param {string} dirOpt
81
- * @param {object} objArguments
97
+ * @param {String} dirFirm
98
+ * @param {String} dirOpt
99
+ * @param {Object} objArguments
82
100
  * @returns
83
101
  */
84
102
  async function defineWriteSTM8(dirFirm, dirOpt, objArguments) {
@@ -112,7 +130,7 @@ class GravaFW {
112
130
  const FileOption = dirOpt != null ? `-FileOption=${dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)} ` : ""
113
131
 
114
132
  resolve({
115
- sucess: true,
133
+ success: true,
116
134
  commandLineArguments: `${BoardName}${Tool_ID}${NbTools}${Port}${ProgMode}${verbose}` +
117
135
  `${loop}${warn_protect}${erase}${blank}${verif}${FileProg}${FileOption}${FileData}` +
118
136
  `${readProg}${readData}${readOption}${log}${progress}${no_progOption}${no_progProg}${version}${version}${Device}`,
@@ -123,9 +141,24 @@ class GravaFW {
123
141
  }
124
142
 
125
143
  /**
126
- * Realiza gravacao nos microcontroladores renesas atraves do PVI, via renesas flash programmer command line
127
- * @param {string} dirProject Formato esperado: "I:\\\Documentos\\\Softwares\\\RENESAS\\\R5F51303ADFL\\\INV-301\\\301v06\\\301v06.rpj"
128
- * @param {number} timeOut
144
+ *
145
+ * @param {String} dirProject
146
+ * @param {Number} timeOut
147
+ * @returns
148
+ *
149
+ * # Exemplos
150
+ *
151
+ * ```js
152
+ * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.rpj"
153
+ * const optionPath = "I:/script_repo/fw_repo/opt.hex"
154
+ * const writeFirmware = await GravaFW.Renesas(programPath)
155
+ * ```
156
+ *
157
+ * # Retorno
158
+ *
159
+ * ```js
160
+ * { success: Boolean, msg: String }
161
+ * ```
129
162
  */
130
163
  static async Renesas(dirProject = null, timeOut = 5000) {
131
164
 
@@ -135,7 +168,7 @@ class GravaFW {
135
168
 
136
169
  let logGravacao = ""
137
170
 
138
- const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
171
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
139
172
 
140
173
  console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
141
174
  logGravacao = logGravacao + param[0]
@@ -144,24 +177,24 @@ class GravaFW {
144
177
 
145
178
  if (param[0].includes(`Operation completed.`)) {
146
179
 
147
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
180
+ FWLink.PVIEventObserver.remove(id)
148
181
  clearTimeout(timeOutGravacao)
149
182
 
150
- resolve({ sucess: true, msg: logGravacao })
183
+ resolve({ success: true, msg: "Gravação bem sucedida", dirProject: dirProject })
151
184
 
152
185
  } else if (param[0].includes(`Cannot find the specified tool.`)) {
153
186
 
154
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
187
+ FWLink.PVIEventObserver.remove(id)
155
188
  clearTimeout(timeOutGravacao)
156
189
 
157
- resolve({ sucess: null, msg: `Gravador não respondeu` })
190
+ resolve({ success: null, msg: `Gravador não respondeu`, dirProject: dirProject })
158
191
 
159
192
  } else if (param[0].includes(`Error: No project file specifed.`)) {
160
193
 
161
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
194
+ FWLink.PVIEventObserver.remove(id)
162
195
  clearTimeout(timeOutGravacao)
163
196
 
164
- resolve({ sucess: false, msg: `Projeto informado é inválido` })
197
+ resolve({ success: false, msg: `Projeto informado é inválido`, dirProject: dirProject })
165
198
 
166
199
  }
167
200
 
@@ -169,17 +202,17 @@ class GravaFW {
169
202
 
170
203
  }, "sniffer.exec")
171
204
 
172
- pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETPVIPATH", [])}/Resources/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
205
+ FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}/Resources/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
173
206
 
174
207
  let timeOutGravacao = setTimeout(() => {
175
208
 
176
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
177
- resolve({ sucess: false, msg: `Tempo de gravação excedido` })
209
+ FWLink.PVIEventObserver.remove(id)
210
+ resolve({ success: false, msg: `Tempo de gravação excedido` })
178
211
 
179
212
  }, timeOut)
180
213
 
181
214
  } else {
182
- resolve({ sucess: false, msg: `Caminho do firmware não informado` })
215
+ resolve({ success: false, msg: `Caminho do firmware não informado` })
183
216
  }
184
217
 
185
218
  })
@@ -187,7 +220,7 @@ class GravaFW {
187
220
 
188
221
  /**
189
222
  * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
190
- * @param {string} dirProject Formato esperado: "C:\\Users\\eduardo.rezzadori\\Desktop\\Farmwar\\193M3PL3v01_3.02.hex"
223
+ * @param {string} dirProject caminho do firmware
191
224
  * @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
192
225
  * @param {string} device modelo do micrcontrolador
193
226
  * @param {number} timeOut
@@ -196,37 +229,35 @@ class GravaFW {
196
229
 
197
230
  let logGravacao = ""
198
231
 
199
- const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
232
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
200
233
 
201
234
  console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
202
235
  logGravacao = logGravacao + param[0]
203
236
 
204
237
  if (data == "Script processing completed.") {
205
238
 
206
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
239
+ FWLink.PVIEventObserver.remove(id)
207
240
 
208
241
  if (logGravacao.includes(`O.K.`)) {
209
242
 
210
243
  clearTimeout(timeOutGravacao)
211
- resolve({ sucess: true, msg: `Gravado com sucesso, caminho: ${dirProject}` })
244
+ resolve({ success: true, msg: dirProject })
212
245
 
213
246
  } else if (logGravacao.includes(`Cannot connect to target.`)) {
214
247
 
215
248
  clearTimeout(timeOutGravacao)
216
- resolve({ sucess: false, msg: `Cannot connect to target.` })
249
+ resolve({ success: false, msg: `Cannot connect to target.` })
217
250
 
218
251
  }
219
252
 
220
253
  }
221
254
  }, "sniffer.exec")
222
255
 
223
- pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
256
+ FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
224
257
 
225
258
  let timeOutGravacao = setTimeout(() => {
226
-
227
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
228
- resolve({ sucess: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
229
-
259
+ FWLink.PVIEventObserver.remove(id)
260
+ resolve({ success: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
230
261
  }, timeOut)
231
262
 
232
263
  }
@@ -234,19 +265,30 @@ class GravaFW {
234
265
 
235
266
  /**
236
267
  * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
237
- * @param {string} sessionStorageTag nome que sera utilizado para armazenar a porta COM encontrada
268
+ * @param {string} sessionStorageTag tag para armazenar e acessar o numero da porta COM
238
269
  * @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"
239
- * @param {boolean} isBatFile true = firmware esta em .bat / false = firmware esta em .bin
270
+ * @param {boolean} isBatFile distingue extensão entre .bat e .bin
240
271
  * @param {number} betweenMsgTimeout timeout maximo para inatividade na comunicação com o ESP32
272
+ *
273
+ * # Exemplos
274
+ *
275
+ * ```js
276
+ * const AddressFilePath = "I:/firmware/path/FW-v1.bin"
277
+ * const result = await GravaFW.ESP32("Controlador", AddressFilePath, false, 5000)
278
+ * ```
279
+ *
280
+ * # Result
281
+ *
282
+ * ```js
283
+ * { success: Boolean, msg: String }
284
+ * ```
241
285
  */
242
286
  static async ESP32(sessionStorageTag, AddressFilePath, isBatFile, betweenMsgTimeout) {
243
287
 
244
288
  return new Promise((resolve) => {
245
289
 
246
- console.time("WriteFirmware")
247
-
248
290
  if (!AddressFilePath) {
249
- resolve({ sucess: false, msg: "Caminho de arquivo para gravação não especificado" }); return
291
+ resolve({ success: false, msg: "Caminho de arquivo para gravação não especificado", AddressFilePath: AddressFilePath }); return
250
292
  }
251
293
 
252
294
  let portsFound = null, tryingPorts = [], lastTimeMsg = new Date().getTime()
@@ -255,17 +297,17 @@ class GravaFW {
255
297
 
256
298
  if (new Date().getTime() - lastTimeMsg > betweenMsgTimeout) {
257
299
  clearInterval(betweenMsgMonitor)
258
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
259
- resolve({ sucess: false, msg: "esptool.py encontrou um problema e teve que ser finalizado." }); return
300
+ FWLink.PVIEventObserver.remove(id)
301
+ resolve({ success: false, msg: "esptool.py encontrou um problema e teve que ser finalizado.", AddressFilePath: AddressFilePath }); return
260
302
  }
261
303
 
262
304
  }, 1000)
263
305
 
264
- const id = PVI.FWLink.globalDaqMessagesObservers.add((filter, message) => {
306
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
265
307
 
266
- const info = message[0]
308
+ const info = param[0]
267
309
  lastTimeMsg = new Date().getTime()
268
- console.log(`%cLog Program: ${message}`, ' color: #87CEEB')
310
+ console.log(`%cLog Program: ${param}`, ' color: #87CEEB')
269
311
 
270
312
  if (info.includes("Found")) {
271
313
  const splittedInfo = info.split(" ")
@@ -276,10 +318,10 @@ class GravaFW {
276
318
  tryingPorts.push(splittedInfo[2])
277
319
  UI.setMsg(`Tentando gravar na porta ${splittedInfo[2]}`)
278
320
 
279
- } else if (info.includes("failed to connect") || info.includes("Timed out waiting for packet header")) {
321
+ } else if (info.includes("failed to connect")) {
280
322
  if (tryingPorts.length >= portsFound) {
281
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
282
- resolve({ sucess: false, msg: "Gravador não conseguiu se conectar com o ESP32" }); return
323
+ FWLink.PVIEventObserver.remove(id)
324
+ resolve({ success: false, msg: "Gravador não conseguiu se conectar com o ESP32", AddressFilePath: AddressFilePath }); return
283
325
  }
284
326
 
285
327
  } else if (info.includes("%")) {
@@ -287,8 +329,8 @@ class GravaFW {
287
329
 
288
330
  } else if (info.includes("Hard resetting via RTS pin...")) {
289
331
  sessionStorage.getItem(sessionStorageTag) == null ? sessionStorage.setItem(sessionStorageTag, tryingPorts.pop()) : null
290
- PVI.FWLink.globalDaqMessagesObservers.remove(id)
291
- resolve({ sucess: true, msg: "Gravação bem sucedida" })
332
+ FWLink.PVIEventObserver.remove(id)
333
+ resolve({ success: true, msg: "Gravação bem sucedida", AddressFilePath: AddressFilePath })
292
334
  console.timeEnd("WriteFirmware")
293
335
  }
294
336
 
@@ -306,10 +348,10 @@ class GravaFW {
306
348
 
307
349
  if (isBatFile) {
308
350
  console.log(`Executando batch: ${AddressFilePath} args: ${port}`)
309
- pvi.runInstructionS("EXEC", [AddressFilePath, port, "true", "true", "true"])
351
+ FWLink.runInstructionS("EXEC", [AddressFilePath, port, "true", "true", "true"])
310
352
  } else {
311
353
  console.log(`Executando python: ${pythonPath} args: ${args}`)
312
- pvi.runInstructionS("EXEC", [pythonPath, args, "true", "true", "true"])
354
+ FWLink.runInstructionS("EXEC", [pythonPath, args, "true", "true", "true"])
313
355
  }
314
356
 
315
357
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "2.3.2",
3
+ "version": "3.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": {