-
Notifications
You must be signed in to change notification settings - Fork 77
/
EBYTE.cpp
777 lines (561 loc) · 19.7 KB
/
EBYTE.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
/*
The MIT License (MIT)
Copyright (c) 2019 Kris Kasrpzak
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
On a personal note, if you develop an application or product using this library
and make millions of dollars, I'm happy for you!
*/
/*
Code by Kris Kasprzak [email protected]
This library is intended to be used with EBYTE transcievers, small wireless units for MCU's such as
Teensy and Arduino. This library let's users program the operating parameters and both send and recieve data.
This company makes several modules with different capabilities, but most #defines here should be compatible with them
All constants were extracted from several data sheets and listed in binary as that's how the data sheet represented each setting
Hopefully, any changes or additions to constants can be a matter of copying the data sheet constants directly into these #defines
Usage of this library consumes around 970 bytes
Revision Data Author Description
1.0 3/6/2019 Kasprzak Initial creation
2.0 3/2/2020 Kasprzak Added all functions to build the options bit (FEC, Pullup, and TransmissionMode
3.0 3/27/2020 Kasprzak Added more Get functions
4.0 6/23/2020 Kasprzak Added private method to clear the buffer to ensure read methods would not be filled with buffered data
5.0 12/4/2020 Kasprzak moved Reset to public, added Clear to SetMode to avoid buffer corruption during programming
5.5 1/26/2022 Kasprzak implemented attempt parameter and adjusted the pinmode delays--in an attempt to make NANO's connect more successful
5.7 8/10/2024 Kasprzak fixed attempt iterator if connection is not made
*/
#include <EBYTE.h>
#include <Stream.h>
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/*
create the transciever object
*/
EBYTE::EBYTE(Stream *s, uint8_t PIN_M0, uint8_t PIN_M1, uint8_t PIN_AUX)
{
_s = s;
_M0 = PIN_M0;
_M1 = PIN_M1;
_AUX = PIN_AUX;
}
/*
Initialize the unit--basicall this reads the modules parameters and stores the parameters
for potential future module programming
*/
bool EBYTE::init(uint8_t Attempts) {
bool ok = true;
pinMode(_AUX, INPUT);
pinMode(_M0, OUTPUT);
pinMode(_M1, OUTPUT);
_Attempts = Attempts;
delay(PIN_RECOVER);
if (_Attempts < 1){
_Attempts = 1;
}
if (_Attempts > 10){
_Attempts = 10;
}
SetMode(EBYTE_MODE_NORMAL);
// first get the module data (must be called first for some odd reason
ok = ReadModelData();
if (!ok) {
return false;
}
// now get parameters to put unit defaults into the class variables
ok = ReadParameters();
if (!ok) {
return false;
}
return true;
}
/*
Method to indicate availability
*/
bool EBYTE::available() {
return _s->available();
}
/*
Method to indicate availability
*/
void EBYTE::flush() {
_s->flush();
}
/*
Method to write a single byte...not sure how useful this really is. If you need to send
more that one byte, put the data into a data structure and send it in a big chunk
*/
void EBYTE::SendByte( uint8_t TheByte) {
_s->write(TheByte);
}
/*
Method to get a single byte...not sure how useful this really is. If you need to get
more that one byte, put the data into a data structure and send/receive it in a big chunk
*/
uint8_t EBYTE::GetByte() {
return _s->read();
}
/*
Method to send a chunk of data provided data is in a struct--my personal favorite as you
need not parse or worry about sprintf() inability to handle floats
TTP: put your structure definition into a .h file and include in both the sender and reciever
sketches
NOTE: of your sender and receiver MCU's are different (Teensy and Arduino) caution on the data
types each handle ints floats differently
*/
bool EBYTE::SendStruct(const void *TheStructure, uint16_t size_) {
_buf = _s->write((uint8_t *) TheStructure, size_);
CompleteTask(1000);
return (_buf == size_);
}
/*
Method to get a chunk of data provided data is in a struct--my personal favorite as you
need not parse or worry about sprintf() inability to handle floats
TTP: put your structure definition into a .h file and include in both the sender and reciever
sketches
NOTE: of your sender and receiver MCU's are different (Teensy and Arduino) caution on the data
types each handle ints floats differently
*/
bool EBYTE::GetStruct(const void *TheStructure, uint16_t size_) {
_buf = _s->readBytes((uint8_t *) TheStructure, size_);
CompleteTask(1000);
return (_buf == size_);
}
/*
Utility method to wait until module is doen tranmitting
a timeout is provided to avoid an infinite loop
*/
void EBYTE::CompleteTask(unsigned long timeout) {
unsigned long t = millis();
// make darn sure millis() is not about to reach max data type limit and start over
if (((unsigned long) (t + timeout)) == 0){
t = 0;
}
// if AUX pin was supplied and look for HIGH state
// note you can omit using AUX if no pins are available, but you will have to use delay() to let module finish
// per data sheet control after aux goes high is 2ms so delay for at least that long
// some MCU are slow so give 50 ms
if (_AUX != -1) {
while (digitalRead(_AUX) == LOW) {
//Serial.println("waiting for aux");
delay(2);
if ((millis() - t) > timeout){
//Serial.println("aux timeout");
break;
}
}
}
else {
// if you can't use aux pin, use 4K7 pullup with Arduino
// you may need to adjust this value if transmissions fail
delay(1000);
}
// delay(PIN_RECOVER);
}
/*
method to set the mode (program, normal, etc.)
*/
void EBYTE::SetMode(uint8_t mode) {
// data sheet claims module needs some extra time after mode setting (2ms)
// most of my projects uses 10 ms, but 40ms is safer
delay(PIN_RECOVER);
if (mode == EBYTE_MODE_NORMAL) {
digitalWrite(_M0, LOW);
digitalWrite(_M1, LOW);
}
else if (mode == MODE_WAKEUP) {
digitalWrite(_M0, HIGH);
digitalWrite(_M1, LOW);
}
else if (mode == MODE_POWERDOWN) {
digitalWrite(_M0, LOW);
digitalWrite(_M1, HIGH);
}
else if (mode == MODE_PROGRAM) {
digitalWrite(_M0, HIGH);
digitalWrite(_M1, HIGH);
}
// data sheet says 2ms later control is returned, let's give just a bit more time
// these modules can take time to activate pins
delay(PIN_RECOVER);
// clear out any junk
// added rev 5
// i've had some issues where after programming, the returned model is 0, and all settings appear to be corrupt
// i imagine the issue is due to the internal buffer full of junk, hence clearing
// Reset() *MAY* work but this seems better.
ClearBuffer();
// wait until aux pin goes back low
CompleteTask(4000);
}
// i've asked EBYTE what's supposed to happen--got an unclear answer
// but my testing indicates it clears buffer
// I use this when needing to restart the EBYTE after programming while data is still streaming in
// to let the unit start reading from a cleared internal buffer
// it does NOT return the ebyte back to factory defaults
// if your unit gets corrupt or you need to restore values, you will have to do brute force
// example for and E44-915
// look at the data sheet for default values
// Trans.SetAddressH(0);
// Trans.SetAddressL(0);
// Trans.SetSpeed(0b00011100);
// Trans.SetChannel(1);
// Trans.SetOptions(0b01000100);
// Trans.SaveParameters(PERMANENT);
void EBYTE::Reset() {
SetMode(MODE_PROGRAM);
_s->write(0xC4);
_s->write(0xC4);
_s->write(0xC4);
CompleteTask(4000);
SetMode(EBYTE_MODE_NORMAL);
}
void EBYTE::SetSpeed(uint8_t val) {
_Speed = val;
}
void EBYTE::SetOptions(uint8_t val) {
_Options = val;
}
uint8_t EBYTE::GetSpeed() {
return _Speed ;
}
uint8_t EBYTE::GetOptions() {
return _Options;
}
/*
method to set the high bit of the address
*/
void EBYTE::SetAddressH(uint8_t val) {
_AddressHigh = val;
}
uint8_t EBYTE::GetAddressH() {
return _AddressHigh;
}
/*
method to set the lo bit of the address
*/
void EBYTE::SetAddressL(uint8_t val) {
_AddressLow = val;
}
uint8_t EBYTE::GetAddressL() {
return _AddressLow;
}
/*
method to set the channel
*/
void EBYTE::SetChannel(uint8_t val) {
_Channel = val;
}
uint8_t EBYTE::GetChannel() {
return _Channel;
}
/*
method to set the air data rate
*/
void EBYTE::SetAirDataRate(uint8_t val) {
_AirDataRate = val;
BuildSpeedByte();
}
uint8_t EBYTE::GetAirDataRate() {
return _AirDataRate;
}
/*
method to set the parity bit
*/
void EBYTE::SetParityBit(uint8_t val) {
_ParityBit = val;
BuildSpeedByte();
}
uint8_t EBYTE::GetParityBit( ) {
return _ParityBit;
}
/*
method to set the options bits
*/
void EBYTE::SetTransmissionMode(uint8_t val) {
_OptionTrans = val;
BuildOptionByte();
}
uint8_t EBYTE::GetTransmissionMode( ) {
return _OptionTrans;
}
void EBYTE::SetPullupMode(uint8_t val) {
_OptionPullup = val;
BuildOptionByte();
}
uint8_t EBYTE::GetPullupMode( ) {
return _OptionPullup;
}
void EBYTE::SetWORTIming(uint8_t val) {
_OptionWakeup = val;
BuildOptionByte();
}
uint8_t EBYTE::GetWORTIming() {
return _OptionWakeup;
}
void EBYTE::SetFECMode(uint8_t val) {
_OptionFEC = val;
BuildOptionByte();
}
uint8_t EBYTE::GetFECMode( ) {
return _OptionFEC;
}
void EBYTE::SetTransmitPower(uint8_t val) {
_OptionPower = val;
BuildOptionByte();
}
uint8_t EBYTE::GetTransmitPower() {
return _OptionPower;
}
/*
method to compute the address based on high and low bits
*/
void EBYTE::SetAddress(uint16_t Val) {
_AddressHigh = ((Val & 0xFFFF) >> 8);
_AddressLow = (Val & 0xFF);
}
/*
method to get the address which is a collection of hi and lo bytes
*/
uint16_t EBYTE::GetAddress() {
return (_AddressHigh << 8) | (_AddressLow );
}
/*
set the UART baud rate
*/
void EBYTE::SetUARTBaudRate(uint8_t val) {
_UARTDataRate = val;
BuildSpeedByte();
}
uint8_t EBYTE::GetUARTBaudRate() {
return _UARTDataRate;
}
/*
method to build the byte for programming (notice it's a collection of a few variables)
*/
void EBYTE::BuildSpeedByte() {
_Speed = 0;
_Speed = ((_ParityBit & 0xFF) << 6) | ((_UARTDataRate & 0xFF) << 3) | (_AirDataRate & 0xFF);
}
/*
method to build the option byte for programming (notice it's a collection of a few variables)
*/
void EBYTE::BuildOptionByte() {
_Options = 0;
_Options = ((_OptionTrans & 0xFF) << 7) | ((_OptionPullup & 0xFF) << 6) | ((_OptionWakeup & 0xFF) << 3) | ((_OptionFEC & 0xFF) << 2) | (_OptionPower&0b11);
}
bool EBYTE::GetAux() {
return digitalRead(_AUX);
}
/*
method to save parameters to the module
*/
void EBYTE::SaveParameters(uint8_t val) {
SetMode(MODE_PROGRAM);
/*
ClearBuffer();
Serial.print("val: ");
Serial.println(val);
Serial.print("_AddressHigh: ");
Serial.println(_AddressHigh);
Serial.print("_AddressLow: ");
Serial.println(_AddressLow);
Serial.print("_Speed: ");
Serial.println(_Speed);
Serial.print("_Channel: ");
Serial.println(_Channel);
Serial.print("_Options: ");
Serial.println(_Options);
*/
_s->write(val);
_s->write(_AddressHigh);
_s->write(_AddressLow);
_s->write(_Speed);
_s->write(_Channel);
_s->write(_Options);
delay(PIN_RECOVER);
CompleteTask(4000);
SetMode(EBYTE_MODE_NORMAL);
}
/*
method to print parameters, this can be called anytime after init(), because init gets parameters
and any method updates the variables
*/
void EBYTE::PrintParameters() {
_ParityBit = (_Speed & 0XC0) >> 6;
_UARTDataRate = (_Speed & 0X38) >> 3;
_AirDataRate = _Speed & 0X07;
_OptionTrans = (_Options & 0X80) >> 7;
_OptionPullup = (_Options & 0X40) >> 6;
_OptionWakeup = (_Options & 0X38) >> 3;
_OptionFEC = (_Options & 0X07) >> 2;
_OptionPower = (_Options & 0X03);
Serial.println("----------------------------------------");
Serial.print(F("Model no.: ")); Serial.println(_Model, HEX);
Serial.print(F("Version : ")); Serial.println(_Version, HEX);
Serial.print(F("Features : ")); Serial.println(_Features, HEX);
Serial.println(F(" "));
Serial.print(F("Mode (HEX/DEC/BIN): ")); Serial.print(_Save, HEX); Serial.print(F("/")); Serial.print(_Save, DEC); Serial.print(F("/")); Serial.println(_Save, BIN);
Serial.print(F("AddH (HEX/DEC/BIN): ")); Serial.print(_AddressHigh, HEX); Serial.print(F("/")); Serial.print(_AddressHigh, DEC); Serial.print(F("/")); Serial.println(_AddressHigh, BIN);
Serial.print(F("AddL (HEX/DEC/BIN): ")); Serial.print(_AddressLow, HEX); Serial.print(F("/")); Serial.print(_AddressLow, DEC); Serial.print(F("/")); Serial.println(_AddressLow, BIN);
Serial.print(F("Sped (HEX/DEC/BIN): ")); Serial.print(_Speed, HEX); Serial.print(F("/")); Serial.print(_Speed, DEC); Serial.print(F("/")); Serial.println(_Speed, BIN);
Serial.print(F("Chan (HEX/DEC/BIN): ")); Serial.print(_Channel, HEX); Serial.print(F("/")); Serial.print(_Channel, DEC); Serial.print(F("/")); Serial.println(_Channel, BIN);
Serial.print(F("Optn (HEX/DEC/BIN): ")); Serial.print(_Options, HEX); Serial.print(F("/")); Serial.print(_Options, DEC); Serial.print(F("/")); Serial.println(_Options, BIN);
Serial.print(F("Addr (HEX/DEC/BIN): ")); Serial.print(GetAddress(), HEX); Serial.print(F("/")); Serial.print(GetAddress(), DEC); Serial.print(F("/")); Serial.println(GetAddress(), BIN);
Serial.println(F(" "));
Serial.print(F("SpeedParityBit (HEX/DEC/BIN) : ")); Serial.print(_ParityBit, HEX); Serial.print(F("/")); Serial.print(_ParityBit, DEC); Serial.print(F("/")); Serial.println(_ParityBit, BIN);
Serial.print(F("SpeedUARTDataRate (HEX/DEC/BIN) : ")); Serial.print(_UARTDataRate, HEX); Serial.print(F("/")); Serial.print(_UARTDataRate, DEC); Serial.print(F("/")); Serial.println(_UARTDataRate, BIN);
Serial.print(F("SpeedAirDataRate (HEX/DEC/BIN) : ")); Serial.print(_AirDataRate, HEX); Serial.print(F("/")); Serial.print(_AirDataRate, DEC); Serial.print(F("/")); Serial.println(_AirDataRate, BIN);
Serial.print(F("OptionTrans (HEX/DEC/BIN) : ")); Serial.print(_OptionTrans, HEX); Serial.print(F("/")); Serial.print(_OptionTrans, DEC); Serial.print(F("/")); Serial.println(_OptionTrans, BIN);
Serial.print(F("OptionPullup (HEX/DEC/BIN) : ")); Serial.print(_OptionPullup, HEX); Serial.print(F("/")); Serial.print(_OptionPullup, DEC); Serial.print(F("/")); Serial.println(_OptionPullup, BIN);
Serial.print(F("OptionWakeup (HEX/DEC/BIN) : ")); Serial.print(_OptionWakeup, HEX); Serial.print(F("/")); Serial.print(_OptionWakeup, DEC); Serial.print(F("/")); Serial.println(_OptionWakeup, BIN);
Serial.print(F("OptionFEC (HEX/DEC/BIN) : ")); Serial.print(_OptionFEC, HEX); Serial.print(F("/")); Serial.print(_OptionFEC, DEC); Serial.print(F("/")); Serial.println(_OptionFEC, BIN);
Serial.print(F("OptionPower (HEX/DEC/BIN) : ")); Serial.print(_OptionPower, HEX); Serial.print(F("/")); Serial.print(_OptionPower, DEC); Serial.print(F("/")); Serial.println(_OptionPower, BIN);
Serial.println("----------------------------------------");
}
/*
method to read parameters,
*/
bool EBYTE::ReadParameters() {
_Params[0] = 0;
_Params[1] = 0;
_Params[2] = 0;
_Params[3] = 0;
_Params[4] = 0;
_Params[5] = 0;
SetMode(MODE_PROGRAM);
_s->write(0xC1);
_s->write(0xC1);
_s->write(0xC1);
_s->readBytes((uint8_t*)&_Params, (uint8_t) sizeof(_Params));
_Save = _Params[0];
_AddressHigh = _Params[1];
_AddressLow = _Params[2];
_Speed = _Params[3];
_Channel = _Params[4];
_Options = _Params[5];
_Address = (_AddressHigh << 8) | (_AddressLow);
_ParityBit = (_Speed & 0XC0) >> 6;
_UARTDataRate = (_Speed & 0X38) >> 3;
_AirDataRate = _Speed & 0X07;
_OptionTrans = (_Options & 0X80) >> 7;
_OptionPullup = (_Options & 0X40) >> 6;
_OptionWakeup = (_Options & 0X38) >> 3;
_OptionFEC = (_Options & 0X07) >> 2;
_OptionPower = (_Options & 0X03);
SetMode(EBYTE_MODE_NORMAL);
if (0xC0 != _Params[0]){
return false;
}
return true;
}
bool EBYTE::ReadModelData() {
_Params[0] = 0;
_Params[1] = 0;
_Params[2] = 0;
_Params[3] = 0;
_Params[4] = 0;
_Params[5] = 0;
bool found = false;
int i = 0;
SetMode(MODE_PROGRAM);
_s->write(0xC3);
_s->write(0xC3);
_s->write(0xC3);
_s->readBytes((uint8_t*)& _Params, (uint8_t) sizeof(_Params));
_Save = _Params[0];
_Model = _Params[1];
_Version = _Params[2];
_Features = _Params[3];
SetMode(EBYTE_MODE_NORMAL);
//Serial.print("_Params[0] ");Serial.println(_Save);
//Serial.print("_Params[1] ");Serial.println(_Model);
//Serial.print("_Params[2] ");Serial.println(_Version);
//Serial.print("_Params[3] ");Serial.println(_Features);
if (0xC3 != _Save) {
// i'm not terribly sure this is the best way to retry
// may need to set the mode back to normal first....
for (i = 0; i < _Attempts; i++){
SetMode(MODE_PROGRAM);
_Params[0] = 0;
_Params[1] = 0;
_Params[2] = 0;
_Params[3] = 0;
_Params[4] = 0;
_Params[5] = 0;
_s->write(0xC3);
_s->write(0xC3);
_s->write(0xC3);
_s->readBytes((uint8_t*)& _Params, (uint8_t) sizeof(_Params));
_Save = _Params[0];
_Model = _Params[1];
_Version = _Params[2];
_Features = _Params[3];
SetMode(EBYTE_MODE_NORMAL);
//Serial.print("_Attempts ");Serial.println(_Attempts);
//Serial.print("_Params[0] ");Serial.println(_Params[0]);
//Serial.print("_Params[1] ");Serial.println(_Params[1]);
//Serial.print("_Params[2] ");Serial.println(_Params[2]);
//Serial.print("_Params[3] ");Serial.println(_Params[3]);
//Serial.print("_Params[4] ");Serial.println(_Params[4]);
//Serial.print("_Params[5] ");Serial.println(_Params[5]);
if (0xC3 == _Params[0]){
found = true;
break;
}
delay(100);
}
}
else {
found = true;
}
SetMode(EBYTE_MODE_NORMAL);
return found;
}
/*
method to get module model and E50-TTL-100 will return 50
*/
uint8_t EBYTE::GetModel() {
return _Model;
}
/*
method to get module version (undocumented as to the value)
*/
uint8_t EBYTE::GetVersion() {
return _Version;
}
/*
method to get module version (undocumented as to the value)
*/
uint8_t EBYTE::GetFeatures() {
return _Features;
}
/*
method to clear the serial buffer
without clearing the buffer, i find getting the parameters very unreliable after programming.
i suspect stuff in the buffer affects rogramming
hence, let's clean it out
this is called as part of the setmode
*/
void EBYTE::ClearBuffer(){
unsigned long amt = millis();
while(_s->available()) {
_s->read();
if ((millis() - amt) > 5000) {
Serial.println("runaway");
break;
}
}
}