@@ -45,18 +45,19 @@ class OWI {
45
45
/* *
46
46
* @override{OWI}
47
47
* Read the given number of bits from the one wire bus. Default
48
- * number of bits is CHARBITS (8). Calculates partial check-sum.
48
+ * number of bits is CHARBITS (8).
49
49
* @param[in] bits to be read (default CHARBITS).
50
50
* @return value read.
51
51
*/
52
52
virtual uint8_t read (uint8_t bits = CHARBITS) = 0;
53
53
54
54
/* *
55
55
* Read given number of bytes from one wire bus (device) to given
56
- * buffer.
56
+ * buffer. Calculates 8-bit Cyclic Redundancy Check sum and return
57
+ * result of check.
57
58
* @param[in] buf buffer pointer.
58
59
* @param[in] count number of bytes to read.
59
- * @return true(1) if correctly read otherwise false(0).
60
+ * @return true(1) if check sum is correct otherwise false(0).
60
61
*/
61
62
bool read (void * buf, size_t count)
62
63
{
@@ -80,15 +81,15 @@ class OWI {
80
81
virtual void write (uint8_t value, uint8_t bits = CHARBITS) = 0;
81
82
82
83
/* *
83
- * Write the given value and given number of bytes from buffer to
84
+ * Write the given command and given number of bytes from buffer to
84
85
* the one wire bus (device).
85
- * @param[in] value to write.
86
+ * @param[in] cmd command to write.
86
87
* @param[in] buf buffer pointer.
87
88
* @param[in] count number of bytes to write.
88
89
*/
89
- void write (uint8_t value , const void * buf, size_t count)
90
+ void write (uint8_t cmd , const void * buf, size_t count)
90
91
{
91
- write (value );
92
+ write (cmd );
92
93
const uint8_t * bp = (const uint8_t *) buf;
93
94
while (count--) write (*bp++);
94
95
}
@@ -121,6 +122,34 @@ class OWI {
121
122
}
122
123
}
123
124
125
+ /* *
126
+ * Standard 1-Wire ROM Commands.
127
+ */
128
+ enum {
129
+ SEARCH_ROM = 0xF0 ,// !< Initiate device search.
130
+ READ_ROM = 0x33 ,// !< Read device family code and serial number.
131
+ MATCH_ROM = 0x55 ,// !< Select device with 64-bit rom code.
132
+ SKIP_ROM = 0xCC ,// !< Broadcast or single device.
133
+ ALARM_SEARCH = 0xEC // !< Initiate device alarm search.
134
+ } __attribute__((packed));
135
+
136
+ /* *
137
+ * Optimized Dallas/Maxim iButton 8-bit Cyclic Redundancy Check
138
+ * calculation. Polynomial: x^8 + x^5 + x^4 + 1 (0x8C).
139
+ * See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27
140
+ */
141
+ static uint8_t crc_update (uint8_t crc, uint8_t data)
142
+ {
143
+ crc = crc ^ data;
144
+ for (uint8_t i = 0 ; i < 8 ; i++) {
145
+ if (crc & 0x01 )
146
+ crc = (crc >> 1 ) ^ 0x8C ;
147
+ else
148
+ crc >>= 1 ;
149
+ }
150
+ return (crc);
151
+ }
152
+
124
153
/* * Search position and return values. */
125
154
enum {
126
155
FIRST = -1 ,// !< Start position of search.
@@ -250,34 +279,6 @@ class OWI {
250
279
uint8_t m_rom[ROM_MAX];
251
280
};
252
281
253
- /* *
254
- * Standard ROM Commands.
255
- */
256
- enum {
257
- SEARCH_ROM = 0xF0 ,// !< Initiate device search.
258
- READ_ROM = 0x33 ,// !< Read device family code and serial number.
259
- MATCH_ROM = 0x55 ,// !< Select device with 64-bit rom code.
260
- SKIP_ROM = 0xCC ,// !< Broadcast or single device.
261
- ALARM_SEARCH = 0xEC // !< Initiate device alarm search.
262
- } __attribute__((packed));
263
-
264
- /* *
265
- * Optimized Dallas (now Maxim) iButton 8-bit CRC calculation.
266
- * Polynomial: x^8 + x^5 + x^4 + 1 (0x8C) Initial value: 0x0
267
- * See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27
268
- */
269
- static uint8_t crc_update (uint8_t crc, uint8_t data)
270
- {
271
- crc = crc ^ data;
272
- for (uint8_t i = 0 ; i < 8 ; i++) {
273
- if (crc & 0x01 )
274
- crc = (crc >> 1 ) ^ 0x8C ;
275
- else
276
- crc >>= 1 ;
277
- }
278
- return (crc);
279
- }
280
-
281
282
protected:
282
283
/* * Maximum number of reset retries. */
283
284
static const uint8_t RESET_RETRY_MAX = 4 ;
@@ -299,8 +300,10 @@ class OWI {
299
300
uint8_t dir = (pos == last) || ((pos < last) && (code[i] & (1 << j)));
300
301
switch (triplet (dir)) {
301
302
case 0b00 :
302
- if (pos == last) last = FIRST;
303
- else if (pos > last || (code[i] & (1 << j)) == 0 ) next = pos;
303
+ if (pos == last)
304
+ last = FIRST;
305
+ else if (pos > last || (code[i] & (1 << j)) == 0 )
306
+ next = pos;
304
307
break ;
305
308
case 0b11 :
306
309
return (ERROR);
0 commit comments