-
Notifications
You must be signed in to change notification settings - Fork 4
/
otaReader.js
144 lines (129 loc) · 4.29 KB
/
otaReader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var OTAUtil = require('./otaUtil.js')
var debug = require('debug')('cypressDFU:otaReader')
var OTAResponseReceiver = function () {
// Substring Constants
var RESPONSE_START = 2
var RESPONSE_END = 4
var STATUS_START = 4
var STATUS_END = 6
var CHECKSUM_START = 4
var CHECKSUM_END = 6
var SILICON_ID_START = 8
var SILICON_ID_END = 16
var SILICON_REV_START = 16
var SILICON_REV_END = 18
var START_ROW_START = 8
var START_ROW_END = 12
var END_ROW_START = 12
var END_ROW_END = 16
var DATA_START = 8
var DATA_END = 10
var RADIX = 16
var CASE_SUCCESS = 0
this.parseParseSendDataAcknowledgement = function (hexValue, callback) {
var result = hexValue.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
var status = result.substring(STATUS_START, STATUS_END)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
callback(null, status)
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseEnterBootLoaderAcknowledgement = function (parse, callback) {
var result = parse.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
debug('Response>>>>>' + result)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
var siliconID = result.substring(SILICON_ID_START, SILICON_ID_END).toUpperCase()
var siliconRev = result.substring(SILICON_REV_START, SILICON_REV_END).toUpperCase()
callback(null, siliconID, siliconRev)
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseGetFlashSizeAcknowledgement = function (parse, callback) {
var result = parse.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
debug('Get flash size Response>>>>>' + result)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
var startRow = OTAUtil.swap(parseInt(result.substring(START_ROW_START, START_ROW_END), RADIX))
var endRow = OTAUtil.swap(parseInt(result.substring(END_ROW_START, END_ROW_END), RADIX))
callback(null, startRow, endRow)
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseParseRowAcknowledgement = function (parse, callback) {
var result = parse.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
var status = result.substring(STATUS_START, STATUS_END)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
callback(null, status)
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseVerifyRowAcknowledgement = function (parse, callback) {
var result = parse.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
var data = result.substring(DATA_START, DATA_END)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
callback(null, response, data)// VERIFY_ROW_STATUS, VERIFY_ROW_CHECKSUM
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseVerifyCheckSum = function (parse, callback) {
var result = parse.trim().replace(' ', '')
var response = result.substring(RESPONSE_START, RESPONSE_END)
var checkSumStatus = result.substring(CHECKSUM_START, CHECKSUM_END)
var responseBytes = parseInt(response, RADIX)
switch (responseBytes) {
case CASE_SUCCESS:
debug('CYRET_SUCCESS')
callback(null, checkSumStatus)
break
default:
debug('CYRET ERROR')
callback(responseBytes)
break
}
}
this.parseExitBootloader = function (parse, callback) {
var response = parse.trim().replace(' ', '')
debug('Reponse Byte Exit>>' + response)
callback(null, response)
}
}
module.exports = OTAResponseReceiver