@libs-scripts-mep/grav-fw-pvi 1.1.0 → 2.0.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/README.md +62 -0
  2. package/grav-fw-pvi.js +141 -110
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -24,6 +24,7 @@ npm uninstall @libs-scripts-mep/grav-fw-pvi
24
24
  | ---------- | ------------------------ | ------- |
25
25
  | ST | STVP | ✔️ |
26
26
  | Renesas | Renesas Flash Programmer | ✔️ |
27
+ | Nuvoton | JLink v7.82 | ✔️ |
27
28
 
28
29
  ## Resumo da Classe
29
30
 
@@ -82,5 +83,66 @@ static Renesas(params, callback, timeOut = 5000) {
82
83
  callback(false, `Falha na gravação do firmware final`)
83
84
  }
84
85
  }
86
+
87
+ /**
88
+ * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via Jlink v7 command line
89
+ * @param {string} dirProject Formato esperado: "C:\\Users\\eduardo.rezzadori\\Desktop\\Farmwar\\193M3PL3v01_3.02.hex"
90
+ * @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
91
+ * @param {string} device modelo do micrcontrolador
92
+ * @param {function} callback
93
+ * @param {number} timeOut
94
+ */
95
+ static JLink_v7(dirProject = null, commandFile = null, device, callback = () => { }, timeOut = 10000) {
96
+ // inicia as variaveis locais utilizadas
97
+ let error = null, observer = null, logGravacao = [], controleGravacao = null
98
+ const pathPVI = pvi.runInstructionS("GETPVIPATH", [])
99
+
100
+ // start do obsever para o retorno do cmd
101
+ observer = pvi.FWLink.globalDaqMessagesObservers.add((m, data) => {
102
+ console.log(m, data)
103
+
104
+ // monta um array para validar a gravação
105
+ logGravacao.push(data)
106
+
107
+ // aguarda a string final do processo de gravação
108
+ if (data == "Script processing completed.") {
109
+ pvi.FWLink.globalDaqMessagesObservers.clear()
110
+ pvi.daq.init()
111
+ logGravacao.forEach((e) => {
112
+
113
+ // mensagem que valida a gravação
114
+ if (e == "O.K.") {
115
+ observer = () => { }
116
+ controleGravacao = true
117
+ // erro conhecido
118
+ } else if (e == "Cannot connect to target.") {
119
+ error = e
120
+ }
121
+ })
122
+
123
+ // retorno convencional do script
124
+ if (controleGravacao) {
125
+ clearTimeout(timeOutGravacao)
126
+ callback(true, `Gravado com sucesso, caminho: ${dirProject}`)
127
+ } else if (error) {
128
+ clearTimeout(timeOutGravacao)
129
+ callback(false, `Falha na gravação, ${error}`)
130
+ } else {
131
+ clearTimeout(timeOutGravacao)
132
+ callback(false, `Falha na gravação, caminho: ${dirProject}`)
133
+ }
134
+ }
135
+ }, "sniffer.exec")
136
+
137
+ // execução do comando de gravação
138
+ pvi.runInstructionS("EXEC", [`${pathPVI}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
139
+
140
+ // timeout para setar erro caso ocorra algum tipo de erro inesperado
141
+ let timeOutGravacao = setTimeout(() => {
142
+ pvi.FWLink.globalDaqMessagesObservers.clear()
143
+ pvi.daq.init()
144
+ callback(false, `Falha na gravação, verifique a conexão USB do gravador`)
145
+ }, timeOut)
146
+ }
85
147
  ```
86
148
 
package/grav-fw-pvi.js CHANGED
@@ -5,181 +5,212 @@ class GravaFW {
5
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
- * @param {function} callback
9
- * @param {number} timeOut
10
8
  */
11
- static STM8(dirFirm = null, dirOpt = null, modelo_uC = null, callback = () => { }, timeOut = 5000) {
12
-
13
- if (dirFirm != null && dirOpt != null) {
14
-
15
- let result = pvi.runInstructionS(`ST.writefirmwarestm8_stlink`, [
16
- dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
17
- dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
18
- modelo_uC
19
- ])
9
+ static async STM8(dirFirm = null, dirOpt = null, modelo_uC = null, timeOut = 5000) {
20
10
 
21
- let monitor = setInterval(() => {
11
+ return new Promise(async (resolve) => {
22
12
 
23
- if (result != null) {
13
+ let ObjWriteSTM8 = await defineWriteSTM8(dirFirm, dirOpt, modelo_uC)
24
14
 
25
- clearInterval(monitor)
26
- clearTimeout(timeoutMonitor)
15
+ let logGravacao = ""
27
16
 
28
- if (result.includes(`Verify OPTION BYTE succeeds`)) {
17
+ if (ObjWriteSTM8.sucess) {
29
18
 
30
- console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
31
- callback(true, result)
19
+ const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
32
20
 
33
- } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
21
+ console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
22
+ logGravacao = logGravacao + param[0]
34
23
 
35
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
36
- callback(null, `Gravador não respondeu`)
24
+ if (param[0] != undefined) {
37
25
 
38
- } else {
26
+ if (param[0].includes(`Verify OPTION BYTE succeeds`)) {
39
27
 
40
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
41
- callback(false, `Falha na gravação do firmware final`)
28
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
29
+ clearTimeout(timeOutGravacao)
42
30
 
43
- }
44
- }
45
- }, 100)
31
+ resolve({ sucess: true, msg: logGravacao })
46
32
 
47
- let timeoutMonitor = setTimeout(() => {
48
- clearInterval(monitor)
49
- callback(false, `Tempo de gravação excedido`)
50
- }, timeOut)
33
+ } else if (param[0].includes(`ERROR : Cannot communicate with the tool`)) {
51
34
 
52
- } else if (dirFirm != null) {
35
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
36
+ clearTimeout(timeOutGravacao)
53
37
 
54
- let result = pvi.runInstructionS(`ST.writeprogramstm8_stlink`, [
55
- dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
56
- modelo_uC
57
- ])
38
+ resolve({ sucess: null, msg: `Gravador não respondeu` })
58
39
 
59
- let monitor = setInterval(() => {
40
+ }
60
41
 
61
- clearInterval(monitor)
62
- clearTimeout(timeoutMonitor)
42
+ }
63
43
 
64
- if (result != null) {
44
+ }, "sniffer.exec")
65
45
 
66
- if (result.includes(`Verifying PROGRAM MEMORY succeeds`)) {
46
+ } else {
47
+ console.log(`%cNenhum diretório de firmware ou option byte informado`, ' color: #EE0033')
48
+ resolve({ sucess: false, msg: `Nenhum diretório de firmware ou option byte informado` })
49
+ }
67
50
 
68
- console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
69
- callback(true)
51
+ pvi.runInstructionS("EXEC", [`C:/Program Files (x86)/STMicroelectronics/st_toolset/stvp/STVP_CmdLine.exe`, ObjWriteSTM8.commandLineArguments, "true", "true"])
70
52
 
71
- } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
53
+ let timeOutGravacao = setTimeout(() => {
72
54
 
73
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
74
- callback(null, `Gravador não respondeu`)
55
+ console.log(`%cLog Program:\n\n${logGravacao}`, ' color: #EE0033')
56
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
75
57
 
76
- } else {
58
+ resolve({ sucess: false, msg: `Falha na gravação do firmware final` })
77
59
 
78
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
79
- callback(false, `Falha na gravação do firmware`)
60
+ }, timeOut)
80
61
 
81
- }
82
- }
83
- }, 100)
62
+ })
84
63
 
85
- let timeoutMonitor = setTimeout(() => {
86
- clearInterval(monitor)
87
- callback(false, `Tempo de gravação excedido`)
88
- }, timeOut)
89
64
 
90
- } else if (dirOpt != null) {
65
+ async function defineWriteSTM8(dirFirm, dirOpt, modelo_uC) {
91
66
 
92
- let result = pvi.runInstructionS(`ST.writeoptionstm8_stlink`, [
93
- dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
94
- modelo_uC
95
- ])
67
+ return new Promise((resolve) => {
96
68
 
97
- let monitor = setInterval(() => {
69
+ if (dirFirm != null && dirOpt != null) {
98
70
 
99
- clearInterval(monitor)
100
- clearTimeout(timeoutMonitor)
71
+ dirFirm = dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
72
+ dirOpt = dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
101
73
 
102
- if (result != null) {
74
+ resolve({
75
+ sucess: true,
76
+ commandLineArguments: `-BoardName=ST-LINK -Tool_ID=0 -NbTools=1 -Port=USB -ProgMode=SWIM -Device=${modelo_uC} -verbose -no_loop -no_warn_protect -FileProg=${dirFirm} -FileOption=${dirOpt}`,
77
+ })
103
78
 
104
- if (result.includes(`Verify OPTION BYTE succeeds`)) {
79
+ } else if (dirFirm != null) {
105
80
 
106
- console.log(`%cLog Desprotect:\n\n${result}`, ' color: #00EE66')
107
- callback(true, result)
81
+ dirFirm = dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
108
82
 
109
- } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
83
+ resolve({
84
+ sucess: true,
85
+ commandLineArguments: `-BoardName=ST-LINK -Tool_ID=0 -NbTools=1 -Port=USB -ProgMode=SWIM -Device=${modelo_uC} -verbose -no_loop -no_warn_protect -FileProg=${dirFirm}`,
86
+ })
110
87
 
111
- console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
112
- callback(null, `Gravador não respondeu`)
88
+ } else if (dirOpt != null) {
113
89
 
114
- } else {
90
+ dirOpt = dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
115
91
 
116
- console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
117
- callback(false, `Falha na gravação do option byte`)
92
+ resolve({
93
+ sucess: true,
94
+ commandLineArguments: `-BoardName=ST-LINK -Tool_ID=0 -NbTools=1 -Port=USB -ProgMode=SWIM -Device=${modelo_uC} -verbose -no_loop -no_warn_protect -FileOption=${dirOpt}`,
95
+ })
118
96
 
119
- }
97
+ } else {
98
+ resolve({
99
+ sucess: false,
100
+ })
120
101
  }
121
- }, 100)
122
102
 
123
- let timeoutMonitor = setTimeout(() => {
124
- clearInterval(monitor)
125
- callback(false, `Tempo de gravação excedido`)
126
- }, timeOut)
103
+ })
127
104
 
128
- } else {
129
- callback(false, `Nenhum diretório de firmware ou option byte informado.`)
130
105
  }
131
106
  }
132
107
 
133
108
  /**
134
109
  * Realiza gravacao nos microcontroladores renesas atraves do PVI, via renesas flash programmer command line
135
110
  * @param {string} dirProject Formato esperado: "I:\\\Documentos\\\Softwares\\\RENESAS\\\R5F51303ADFL\\\INV-301\\\301v06\\\301v06.rpj"
136
- * @param {function} callback
137
111
  * @param {number} timeOut
138
112
  */
139
- static Renesas(dirProject = null, callback = () => { }, timeOut = 5000) {
113
+ static Renesas(dirProject = null, timeOut = 5000) {
114
+
115
+ return new Promise((resolve) => {
140
116
 
141
- if (dirProject != null) {
117
+ if (dirProject != null) {
142
118
 
143
- let result = pvi.runInstructionS(`RENESAS.gravafw`, [dirProject])
119
+ let logGravacao = ""
144
120
 
145
- let monitor = setInterval(() => {
121
+ const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
146
122
 
147
- if (result != null) {
123
+ console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
124
+ logGravacao = logGravacao + param[0]
148
125
 
149
- clearInterval(monitor)
150
- clearTimeout(timeoutMonitor)
126
+ if (param[0] != undefined) {
151
127
 
152
- if (result.includes(`Operation completed.`)) {
128
+ if (param[0].includes(`Operation completed.`)) {
153
129
 
154
- console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
155
- callback(true, result)
130
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
131
+ clearTimeout(timeOutGravacao)
156
132
 
157
- } else if (result.includes(`Cannot find the specified tool.`)) {
133
+ resolve({ sucess: true, msg: logGravacao })
158
134
 
159
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
160
- callback(null, `Gravador não respondeu`)
135
+ } else if (param[0].includes(`Cannot find the specified tool.`)) {
161
136
 
162
- } else if (result.includes(`Error: No project file specifed.`)) {
137
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
138
+ clearTimeout(timeOutGravacao)
163
139
 
164
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
165
- callback(false, `Projeto informado é inválido`)
140
+ resolve({ sucess: null, msg: `Gravador não respondeu` })
166
141
 
167
- } else {
142
+ } else if (param[0].includes(`Error: No project file specifed.`)) {
168
143
 
169
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
170
- callback(false, `Falha na gravação do firmware final`)
144
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
145
+ clearTimeout(timeOutGravacao)
146
+
147
+ resolve({ sucess: false, msg: `Projeto informado é inválido` })
148
+
149
+ }
171
150
 
172
151
  }
152
+
153
+ }, "sniffer.exec")
154
+
155
+ pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETPVIPATH", [])}/Resources/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
156
+
157
+ let timeOutGravacao = setTimeout(() => {
158
+
159
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
160
+ resolve({ sucess: false, msg: `Tempo de gravação excedido` })
161
+
162
+ }, timeOut)
163
+
164
+ } else {
165
+ resolve({ sucess: false, msg: `Caminho do firmware não informado` })
166
+ }
167
+
168
+ })
169
+ }
170
+
171
+ /**
172
+ * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
173
+ * @param {string} dirProject Formato esperado: "C:\\Users\\eduardo.rezzadori\\Desktop\\Farmwar\\193M3PL3v01_3.02.hex"
174
+ * @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
175
+ * @param {string} device modelo do micrcontrolador
176
+ * @param {number} timeOut
177
+ */
178
+ static JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
179
+
180
+ let logGravacao = ""
181
+
182
+ const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
183
+
184
+ console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
185
+ logGravacao = logGravacao + param[0]
186
+
187
+ if (data == "Script processing completed.") {
188
+
189
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
190
+
191
+ if (logGravacao.includes(`O.K.`)) {
192
+
193
+ clearTimeout(timeOutGravacao)
194
+ resolve({ sucess: true, msg: `Gravado com sucesso, caminho: ${dirProject}` })
195
+
196
+ } else if (logGravacao.includes(`Cannot connect to target.`)) {
197
+
198
+ clearTimeout(timeOutGravacao)
199
+ resolve({ sucess: false, msg: `Cannot connect to target.` })
200
+
173
201
  }
174
- }, 100)
175
202
 
176
- let timeoutMonitor = setTimeout(() => {
177
- clearInterval(monitor)
178
- callback(false, `Tempo de gravação excedido`)
179
- }, timeOut)
203
+ }
204
+ }, "sniffer.exec")
205
+
206
+ pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
207
+
208
+ let timeOutGravacao = setTimeout(() => {
209
+
210
+ PVI.FWLink.globalDaqMessagesObservers.remove(id)
211
+ resolve({ sucess: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
212
+
213
+ }, timeOut)
180
214
 
181
- } else {
182
- callback(false, `Caminho do firmware não informado`)
183
- }
184
215
  }
185
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "1.1.0",
3
+ "version": "2.0.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": {