@libs-scripts-mep/grav-fw-pvi 1.2.0 → 1.4.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 +65 -143
- package/package.json +1 -1
package/grav-fw-pvi.js
CHANGED
|
@@ -5,131 +5,58 @@ 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
|
|
8
|
+
* @param {function(boolean, string)} callback
|
|
9
9
|
* @param {number} timeOut
|
|
10
|
-
|
|
11
|
-
static STM8(dirFirm = null, dirOpt = null,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
callback(true, result)
|
|
32
|
-
|
|
33
|
-
} else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
|
|
34
|
-
|
|
35
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
|
|
10
|
+
*/
|
|
11
|
+
static STM8(dirFirm = null, dirOpt = null, device = "STM8S003F3", callback = () => { }, timeOut = 5000) {
|
|
12
|
+
if (dirFirm != null || dirOpt != null) {
|
|
13
|
+
let validationMsg = ""
|
|
14
|
+
|
|
15
|
+
if (dirFirm != null && dirOpt != null) validationMsg = `Verify OPTION BYTE succeeds`
|
|
16
|
+
else if (dirFirm != null) validationMsg = `Verifying PROGRAM MEMORY succeeds`
|
|
17
|
+
else if (dirOpt != null) validationMsg = `Verify OPTION BYTE succeeds`
|
|
18
|
+
else validationMsg = "error"
|
|
19
|
+
|
|
20
|
+
const eventObserverId = pvi.FWLink.globalDaqMessagesObservers.add((msg, [stm8OutLog]) => {
|
|
21
|
+
console.log(`%cLog Program: ${stm8OutLog}`, ' color: #B0E0E6')
|
|
22
|
+
|
|
23
|
+
if (stm8OutLog != undefined) {
|
|
24
|
+
if (stm8OutLog.includes(validationMsg)) {
|
|
25
|
+
clearTimeout(timeoutGravacao)
|
|
26
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
27
|
+
callback(true, `Gravação bem-sucedida`)
|
|
28
|
+
} else if (stm8OutLog.includes(`ERROR : Cannot communicate with the tool`)) {
|
|
29
|
+
clearTimeout(timeoutGravacao)
|
|
30
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
36
31
|
callback(null, `Gravador não respondeu`)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
callback(false, `Falha na gravação do firmware final`)
|
|
42
|
-
|
|
32
|
+
} else if (stm8OutLog.includes(`(API) ERROR`)) {
|
|
33
|
+
clearTimeout(timeoutGravacao)
|
|
34
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
35
|
+
callback(null, `Não foi possível realizar a gravação`)
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
|
-
},
|
|
38
|
+
}, "sniffer.exec")
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
callback(false, `Tempo de gravação excedido`)
|
|
50
|
-
}, timeOut)
|
|
51
|
-
|
|
52
|
-
} else if (dirFirm != null) {
|
|
53
|
-
|
|
54
|
-
let result = pvi.runInstructionS(`ST.writeprogramstm8_stlink`, [
|
|
55
|
-
dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
|
|
56
|
-
modelo_uC
|
|
57
|
-
])
|
|
58
|
-
|
|
59
|
-
let monitor = setInterval(() => {
|
|
60
|
-
|
|
61
|
-
clearInterval(monitor)
|
|
62
|
-
clearTimeout(timeoutMonitor)
|
|
63
|
-
|
|
64
|
-
if (result != null) {
|
|
65
|
-
|
|
66
|
-
if (result.includes(`Verifying PROGRAM MEMORY succeeds`)) {
|
|
67
|
-
|
|
68
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
|
|
69
|
-
callback(true)
|
|
70
|
-
|
|
71
|
-
} else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
|
|
72
|
-
|
|
73
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
|
|
74
|
-
callback(null, `Gravador não respondeu`)
|
|
75
|
-
|
|
76
|
-
} else {
|
|
77
|
-
|
|
78
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
|
|
79
|
-
callback(false, `Falha na gravação do firmware`)
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, 100)
|
|
84
|
-
|
|
85
|
-
let timeoutMonitor = setTimeout(() => {
|
|
86
|
-
clearInterval(monitor)
|
|
87
|
-
callback(false, `Tempo de gravação excedido`)
|
|
88
|
-
}, timeOut)
|
|
89
|
-
|
|
90
|
-
} else if (dirOpt != null) {
|
|
91
|
-
|
|
92
|
-
let result = pvi.runInstructionS(`ST.writeoptionstm8_stlink`, [
|
|
93
|
-
dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`),
|
|
94
|
-
modelo_uC
|
|
95
|
-
])
|
|
96
|
-
|
|
97
|
-
let monitor = setInterval(() => {
|
|
98
|
-
|
|
99
|
-
clearInterval(monitor)
|
|
100
|
-
clearTimeout(timeoutMonitor)
|
|
101
|
-
|
|
102
|
-
if (result != null) {
|
|
103
|
-
|
|
104
|
-
if (result.includes(`Verify OPTION BYTE succeeds`)) {
|
|
105
|
-
|
|
106
|
-
console.log(`%cLog Desprotect:\n\n${result}`, ' color: #00EE66')
|
|
107
|
-
callback(true, result)
|
|
108
|
-
|
|
109
|
-
} else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
|
|
110
|
-
|
|
111
|
-
console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
|
|
112
|
-
callback(null, `Gravador não respondeu`)
|
|
113
|
-
|
|
114
|
-
} else {
|
|
115
|
-
|
|
116
|
-
console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
|
|
117
|
-
callback(false, `Falha na gravação do option byte`)
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}, 100)
|
|
122
|
-
|
|
123
|
-
let timeoutMonitor = setTimeout(() => {
|
|
124
|
-
clearInterval(monitor)
|
|
40
|
+
const timeoutGravacao = setTimeout(() => {
|
|
41
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
125
42
|
callback(false, `Tempo de gravação excedido`)
|
|
126
43
|
}, timeOut)
|
|
127
44
|
|
|
45
|
+
pvi.runInstructionS(
|
|
46
|
+
"EXEC",
|
|
47
|
+
[`${pvi.runInstructionS("GETRESOURCESPATH", [])}\\stvp\\STVP_CmdLine.exe`, this.stm8CommandLineArguments(dirFirm, dirOpt, device), "true", "true"]
|
|
48
|
+
)
|
|
128
49
|
} else {
|
|
129
50
|
callback(false, `Nenhum diretório de firmware ou option byte informado.`)
|
|
130
51
|
}
|
|
131
52
|
}
|
|
132
53
|
|
|
54
|
+
static stm8CommandLineArguments(dirFirm, dirOpt, device) {
|
|
55
|
+
const fileProg = dirFirm != null ? `-FileProg=${dirFirm.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)} ` : ""
|
|
56
|
+
const fileOption = dirOpt != null ? `-FileOption=${dirOpt.replace(/[\\]/g, `\/`).replace(/\.stp|\.STP/, `.HEX`)} ` : ""
|
|
57
|
+
return `-BoardName=ST-LINK -Tool_ID=0 -NbTools=1 -Port=USB -ProgMode=SWIM -no_loop -no_warn_protect ${fileProg}${fileOption}-Device=${device}`
|
|
58
|
+
}
|
|
59
|
+
|
|
133
60
|
/**
|
|
134
61
|
* Realiza gravacao nos microcontroladores renesas atraves do PVI, via renesas flash programmer command line
|
|
135
62
|
* @param {string} dirProject Formato esperado: "I:\\\Documentos\\\Softwares\\\RENESAS\\\R5F51303ADFL\\\INV-301\\\301v06\\\301v06.rpj"
|
|
@@ -139,45 +66,40 @@ class GravaFW {
|
|
|
139
66
|
static Renesas(dirProject = null, callback = () => { }, timeOut = 5000) {
|
|
140
67
|
|
|
141
68
|
if (dirProject != null) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
|
|
155
|
-
callback(true, result)
|
|
156
|
-
|
|
157
|
-
} else if (result.includes(`Cannot find the specified tool.`)) {
|
|
158
|
-
|
|
159
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
|
|
69
|
+
const eventObserverId = pvi.FWLink.globalDaqMessagesObservers.add((msg, [renesasOutLog]) => {
|
|
70
|
+
console.log(`%cLog Program: ${renesasOutLog}`, ' color: #B0E0E6')
|
|
71
|
+
|
|
72
|
+
if (renesasOutLog != undefined) {
|
|
73
|
+
if (renesasOutLog.includes(`Operation completed.`)) {
|
|
74
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
75
|
+
clearTimeout(timeoutGravacao)
|
|
76
|
+
callback(true, `Gravação bem-sucedida: ${dirProject}`)
|
|
77
|
+
} else if (renesasOutLog.includes(`Cannot find the specified tool.`)) {
|
|
78
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
79
|
+
clearTimeout(timeoutGravacao)
|
|
160
80
|
callback(null, `Gravador não respondeu`)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
|
|
81
|
+
} else if (renesasOutLog.includes(`Error: No project file specifed.`)) {
|
|
82
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
83
|
+
clearTimeout(timeoutGravacao)
|
|
165
84
|
callback(false, `Projeto informado é inválido`)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
85
|
+
} else if (renesasOutLog.includes(`The device is not responding.`)) {
|
|
86
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
87
|
+
clearTimeout(timeoutGravacao)
|
|
88
|
+
callback(false, `Sem resposta do microcontrolador`)
|
|
89
|
+
} else if (renesasOutLog.includes(`A framing error occurred while receiving data`)) {
|
|
90
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
91
|
+
clearTimeout(timeoutGravacao)
|
|
92
|
+
callback(false, `Falha ao receber dados do microcontrolador`)
|
|
172
93
|
}
|
|
173
94
|
}
|
|
174
|
-
},
|
|
95
|
+
}, "sniffer.exec")
|
|
175
96
|
|
|
176
|
-
let
|
|
177
|
-
|
|
97
|
+
let timeoutGravacao = setTimeout(() => {
|
|
98
|
+
pvi.FWLink.globalDaqMessagesObservers.remove(eventObserverId)
|
|
178
99
|
callback(false, `Tempo de gravação excedido`)
|
|
179
100
|
}, timeOut)
|
|
180
101
|
|
|
102
|
+
pvi.runInstructionS("EXEC", [`${pvi.runInstructionS("GETRESOURCESPATH", [])}/Renesas/RFPV3.Console.exe`, dirProject, "true", "true"])
|
|
181
103
|
} else {
|
|
182
104
|
callback(false, `Caminho do firmware não informado`)
|
|
183
105
|
}
|