@libs-scripts-mep/grav-fw-pvi 1.2.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.
- package/grav-fw-pvi.js +123 -139
- package/package.json +1 -1
package/grav-fw-pvi.js
CHANGED
|
@@ -5,182 +5,167 @@ 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,
|
|
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
|
-
|
|
11
|
+
return new Promise(async (resolve) => {
|
|
22
12
|
|
|
23
|
-
|
|
13
|
+
let ObjWriteSTM8 = await defineWriteSTM8(dirFirm, dirOpt, modelo_uC)
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
clearTimeout(timeoutMonitor)
|
|
15
|
+
let logGravacao = ""
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
if (ObjWriteSTM8.sucess) {
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
callback(true, result)
|
|
19
|
+
const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
|
|
32
20
|
|
|
33
|
-
|
|
21
|
+
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
22
|
+
logGravacao = logGravacao + param[0]
|
|
34
23
|
|
|
35
|
-
|
|
36
|
-
callback(null, `Gravador não respondeu`)
|
|
24
|
+
if (param[0] != undefined) {
|
|
37
25
|
|
|
38
|
-
|
|
26
|
+
if (param[0].includes(`Verify OPTION BYTE succeeds`)) {
|
|
39
27
|
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
29
|
+
clearTimeout(timeOutGravacao)
|
|
42
30
|
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}, 100)
|
|
31
|
+
resolve({ sucess: true, msg: logGravacao })
|
|
46
32
|
|
|
47
|
-
|
|
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
|
-
|
|
35
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
36
|
+
clearTimeout(timeOutGravacao)
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
|
|
56
|
-
modelo_uC
|
|
57
|
-
])
|
|
38
|
+
resolve({ sucess: null, msg: `Gravador não respondeu` })
|
|
58
39
|
|
|
59
|
-
|
|
40
|
+
}
|
|
60
41
|
|
|
61
|
-
|
|
62
|
-
clearTimeout(timeoutMonitor)
|
|
42
|
+
}
|
|
63
43
|
|
|
64
|
-
|
|
44
|
+
}, "sniffer.exec")
|
|
65
45
|
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
+
let timeOutGravacao = setTimeout(() => {
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
console.log(`%cLog Program:\n\n${logGravacao}`, ' color: #EE0033')
|
|
56
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
75
57
|
|
|
76
|
-
|
|
58
|
+
resolve({ sucess: false, msg: `Falha na gravação do firmware final` })
|
|
77
59
|
|
|
78
|
-
|
|
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
|
-
|
|
65
|
+
async function defineWriteSTM8(dirFirm, dirOpt, modelo_uC) {
|
|
91
66
|
|
|
92
|
-
|
|
93
|
-
dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
|
|
94
|
-
modelo_uC
|
|
95
|
-
])
|
|
67
|
+
return new Promise((resolve) => {
|
|
96
68
|
|
|
97
|
-
|
|
69
|
+
if (dirFirm != null && dirOpt != null) {
|
|
98
70
|
|
|
99
|
-
|
|
100
|
-
|
|
71
|
+
dirFirm = dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
|
|
72
|
+
dirOpt = dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
|
|
101
73
|
|
|
102
|
-
|
|
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
|
-
|
|
79
|
+
} else if (dirFirm != null) {
|
|
105
80
|
|
|
106
|
-
|
|
107
|
-
callback(true, result)
|
|
81
|
+
dirFirm = dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
|
|
108
82
|
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
callback(null, `Gravador não respondeu`)
|
|
88
|
+
} else if (dirOpt != null) {
|
|
113
89
|
|
|
114
|
-
|
|
90
|
+
dirOpt = dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)
|
|
115
91
|
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
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,
|
|
113
|
+
static Renesas(dirProject = null, timeOut = 5000) {
|
|
114
|
+
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
|
|
117
|
+
if (dirProject != null) {
|
|
140
118
|
|
|
141
|
-
|
|
119
|
+
let logGravacao = ""
|
|
142
120
|
|
|
143
|
-
|
|
121
|
+
const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
|
|
144
122
|
|
|
145
|
-
|
|
123
|
+
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
124
|
+
logGravacao = logGravacao + param[0]
|
|
146
125
|
|
|
147
|
-
|
|
126
|
+
if (param[0] != undefined) {
|
|
148
127
|
|
|
149
|
-
|
|
150
|
-
clearTimeout(timeoutMonitor)
|
|
128
|
+
if (param[0].includes(`Operation completed.`)) {
|
|
151
129
|
|
|
152
|
-
|
|
130
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
131
|
+
clearTimeout(timeOutGravacao)
|
|
153
132
|
|
|
154
|
-
|
|
155
|
-
callback(true, result)
|
|
133
|
+
resolve({ sucess: true, msg: logGravacao })
|
|
156
134
|
|
|
157
|
-
|
|
135
|
+
} else if (param[0].includes(`Cannot find the specified tool.`)) {
|
|
158
136
|
|
|
159
|
-
|
|
160
|
-
|
|
137
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
138
|
+
clearTimeout(timeOutGravacao)
|
|
161
139
|
|
|
162
|
-
|
|
140
|
+
resolve({ sucess: null, msg: `Gravador não respondeu` })
|
|
163
141
|
|
|
164
|
-
|
|
165
|
-
callback(false, `Projeto informado é inválido`)
|
|
142
|
+
} else if (param[0].includes(`Error: No project file specifed.`)) {
|
|
166
143
|
|
|
167
|
-
|
|
144
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
145
|
+
clearTimeout(timeOutGravacao)
|
|
168
146
|
|
|
169
|
-
|
|
170
|
-
|
|
147
|
+
resolve({ sucess: false, msg: `Projeto informado é inválido` })
|
|
148
|
+
|
|
149
|
+
}
|
|
171
150
|
|
|
172
151
|
}
|
|
173
|
-
}
|
|
174
|
-
}, 100)
|
|
175
152
|
|
|
176
|
-
|
|
177
|
-
clearInterval(monitor)
|
|
178
|
-
callback(false, `Tempo de gravação excedido`)
|
|
179
|
-
}, timeOut)
|
|
153
|
+
}, "sniffer.exec")
|
|
180
154
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
+
})
|
|
184
169
|
}
|
|
185
170
|
|
|
186
171
|
/**
|
|
@@ -188,45 +173,44 @@ class GravaFW {
|
|
|
188
173
|
* @param {string} dirProject Formato esperado: "C:\\Users\\eduardo.rezzadori\\Desktop\\Farmwar\\193M3PL3v01_3.02.hex"
|
|
189
174
|
* @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
|
|
190
175
|
* @param {string} device modelo do micrcontrolador
|
|
191
|
-
* @param {function} callback
|
|
192
176
|
* @param {number} timeOut
|
|
193
177
|
*/
|
|
194
|
-
static JLink_v7(dirProject = null, commandFile = null, device,
|
|
178
|
+
static JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
|
|
179
|
+
|
|
180
|
+
let logGravacao = ""
|
|
195
181
|
|
|
196
|
-
|
|
197
|
-
|
|
182
|
+
const id = PVI.FWLink.globalDaqMessagesObservers.add((msg, param) => {
|
|
183
|
+
|
|
184
|
+
console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
|
|
185
|
+
logGravacao = logGravacao + param[0]
|
|
198
186
|
|
|
199
|
-
observer = pvi.FWLink.globalDaqMessagesObservers.add((m, data) => {
|
|
200
|
-
console.log(m, data)
|
|
201
|
-
logGravacao.push(data)
|
|
202
187
|
if (data == "Script processing completed.") {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
controleGravacao = true
|
|
209
|
-
} else if (e == "Cannot connect to target.") {
|
|
210
|
-
error = e
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
if (controleGravacao) {
|
|
214
|
-
clearTimeout(timeOutGravacao)
|
|
215
|
-
callback(true, `Gravado com sucesso, caminho: ${dirProject}`)
|
|
216
|
-
} else if (error) {
|
|
188
|
+
|
|
189
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
190
|
+
|
|
191
|
+
if (logGravacao.includes(`O.K.`)) {
|
|
192
|
+
|
|
217
193
|
clearTimeout(timeOutGravacao)
|
|
218
|
-
|
|
219
|
-
|
|
194
|
+
resolve({ sucess: true, msg: `Gravado com sucesso, caminho: ${dirProject}` })
|
|
195
|
+
|
|
196
|
+
} else if (logGravacao.includes(`Cannot connect to target.`)) {
|
|
197
|
+
|
|
220
198
|
clearTimeout(timeOutGravacao)
|
|
221
|
-
|
|
199
|
+
resolve({ sucess: false, msg: `Cannot connect to target.` })
|
|
200
|
+
|
|
222
201
|
}
|
|
202
|
+
|
|
223
203
|
}
|
|
224
204
|
}, "sniffer.exec")
|
|
225
|
-
|
|
205
|
+
|
|
206
|
+
pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
|
|
207
|
+
|
|
226
208
|
let timeOutGravacao = setTimeout(() => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
209
|
+
|
|
210
|
+
PVI.FWLink.globalDaqMessagesObservers.remove(id)
|
|
211
|
+
resolve({ sucess: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
|
|
212
|
+
|
|
230
213
|
}, timeOut)
|
|
214
|
+
|
|
231
215
|
}
|
|
232
216
|
}
|