@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.
Files changed (2) hide show
  1. package/grav-fw-pvi.js +65 -143
  2. 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, 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
- ])
20
-
21
- let monitor = setInterval(() => {
22
-
23
- if (result != null) {
24
-
25
- clearInterval(monitor)
26
- clearTimeout(timeoutMonitor)
27
-
28
- if (result.includes(`Verify OPTION BYTE succeeds`)) {
29
-
30
- console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
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
- } else {
39
-
40
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
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
- }, 100)
38
+ }, "sniffer.exec")
46
39
 
47
- let timeoutMonitor = setTimeout(() => {
48
- clearInterval(monitor)
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
- let result = pvi.runInstructionS(`RENESAS.gravafw`, [dirProject])
144
-
145
- let monitor = setInterval(() => {
146
-
147
- if (result != null) {
148
-
149
- clearInterval(monitor)
150
- clearTimeout(timeoutMonitor)
151
-
152
- if (result.includes(`Operation completed.`)) {
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
- } else if (result.includes(`Error: No project file specifed.`)) {
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
- } else {
168
-
169
- console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
170
- callback(false, `Falha na gravação do firmware final`)
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
- }, 100)
95
+ }, "sniffer.exec")
175
96
 
176
- let timeoutMonitor = setTimeout(() => {
177
- clearInterval(monitor)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "1.2.0",
3
+ "version": "1.4.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": {