@libs-scripts-mep/grav-fw-pvi 1.3.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 +36 -109
  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`)) {
10
+ */
11
+ static STM8(dirFirm = null, dirOpt = null, device = "STM8S003F3", callback = () => { }, timeOut = 5000) {
12
+ if (dirFirm != null || dirOpt != null) {
13
+ let validationMsg = ""
29
14
 
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')
36
- 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
-
43
- }
44
- }
45
- }, 100)
46
-
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`)
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"
75
19
 
76
- } else {
20
+ const eventObserverId = pvi.FWLink.globalDaqMessagesObservers.add((msg, [stm8OutLog]) => {
21
+ console.log(`%cLog Program: ${stm8OutLog}`, ' color: #B0E0E6')
77
22
 
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')
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)
112
31
  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
-
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`)
119
36
  }
120
37
  }
121
- }, 100)
38
+ }, "sniffer.exec")
122
39
 
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "1.3.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": {