-
Notifications
You must be signed in to change notification settings - Fork 0
/
eps_bat.c
1089 lines (1007 loc) · 28 KB
/
eps_bat.c
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* File: eps_bat.c
* Author: Peter Thornton
* Purpose: Functions to interface with the Clyde Space 3rd Generation EPS
* and 10 Wh battery
* Created on: 30 May 2020
*/
#include "xc.h"
#include "clock.h"
#include "i2c.h"
#include "eps_bat.h"
#define EPS_ADDR 0x2B // 7-bit address for EPS on I2C bus
#define EPS_READ_DELAY 0 // ms delay after EPS read command
#define BAT_ADDR 0x2A // 7-bit address for Batery on I2C bus
#define BAT_READ_DELAY 0 // ms delay after Battery read command
// common address values used by all commands
static int eps_add_w = EPS_ADDR << 1; // EPS address with write flag set (0)
static int eps_add_r = (EPS_ADDR << 1) | 0b1; // EPS address with read flag set (1)
static int bat_add_w = BAT_ADDR << 1; // Bat address with write flag set (0)
static int bat_add_r = (BAT_ADDR << 1) | 0b1; // Bat address with read flag set (1)
// common memory space used by all raw (byte-level) commands and responses
static unsigned char command[3]; // maximum size for any command
static unsigned char response[8]; // maximum size for any response
// low-level routine to write a command to EPS device
void eps_write_command(int nbytes, int delay)
{
int i;
// ensure i2c bus is in idle state
idle_i2c1();
// initiate an i2c bus start, and wait for it to complete
start_i2c1();
// transmit device address byte with write flag
transmit_i2c1(eps_add_w);
// transmit the requested number of command bytes
for (i=0 ; i<nbytes ; i++)
{
transmit_i2c1(command[i]);
}
// Initiate a stop and wait the specified time (ms)
// the wait gives device time to prepare response
// NB: the EPS User Manual does not show the stop condition on
// write command, but it doesn't work without it.
stop_i2c1(delay);
}
// low-level routine to read a response from EPS device
void eps_read_response(int nbytes)
{
int i;
int rcv;
// ensure i2c bus is in idle state
idle_i2c1();
// initiate an i2c bus start, and wait for it to complete
start_i2c1();
// transmit address byte with read flag
transmit_i2c1(eps_add_r);
// receive the requested number of response bytes
// receive with ack for first nbytes-1 bytes
for (i=0 ; i<nbytes-1 ; i++)
{
receive_i2c1(&rcv);
response[i] = rcv;
}
// receive with nack on last received byte
receive_i2c1_nack(&rcv);
response[i] = rcv;
// initiate a stop and wait for it to complete
stop_i2c1(EPS_READ_DELAY);
}
// low-level routine to write a command to Battery device
void bat_write_command(int nbytes, int delay)
{
int i;
// ensure i2c bus is in idle state
idle_i2c1();
// initiate an i2c bus start, and wait for it to complete
start_i2c1();
// transmit device address byte with write flag
transmit_i2c1(bat_add_w);
// transmit the requested number of command bytes
for (i=0 ; i<nbytes ; i++)
{
transmit_i2c1(command[i]);
}
// Initiate a stop and wait the specified time (ms)
// the wait gives device time to prepare response
// NB: the EPS User Manual does not show the stop condition on
// write command, but it doesn't work without it.
stop_i2c1(delay);
}
// low-level routine to read a response from Battery device
void bat_read_response(int nbytes)
{
int i;
int rcv;
// ensure i2c bus is in idle state
idle_i2c1();
// initiate an i2c bus start, and wait for it to complete
start_i2c1();
// transmit address byte with read flag
transmit_i2c1(bat_add_r);
// receive the requested number of response bytes
// receive with ack for first nbytes-1 bytes
for (i=0 ; i<nbytes-1 ; i++)
{
receive_i2c1(&rcv);
response[i] = rcv;
}
// receive with nack on last received byte
receive_i2c1_nack(&rcv);
response[i] = rcv;
// initiate a stop and wait for it to complete
stop_i2c1(BAT_READ_DELAY);
}
unsigned char eps_get_status()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x01;
command[1] = 0x00;
int delay = 1;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// the useful status byte is the second byte returned
return response[1];
}
void eps_reset_watchdog()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x22;
command[1] = 0x00;
int delay = 1;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
void eps_set_watchdog(unsigned char minutes)
{
// load command and parameters
int nbytes = 2;
command[0] = 0x21;
command[1] = minutes; // the number of minutes for watchdog timer (default is 4)
int delay = 1;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
float eps_get_bcr1v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x10;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// return -999.99 if response is 0xFFFF
if (response[0]==0xFF && response[1]==0xFF)
return -999.99;
// convert 2-byte (10-bit) ADC output to float
unsigned int adc = (response[0] << 8) | response[1];
return (float)adc * 0.032600898 - 0.163924275;
}
float eps_get_bcr2v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x20;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.032589813 - 0.149882281;
}
float eps_get_bcr3v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x30;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.009996558 + 0.001752591;
}
float eps_get_bcroutv()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x80;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.009009009 - 0.005405405;
}
float eps_get_batv()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x20;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.009237022 - 0.225405738;
}
float eps_get_bus12v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x30;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.013665944 - 0.22075922;
}
float eps_get_bus5v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x10;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.007616438 - 1.522821918;
}
float eps_get_bus33v()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x00;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.005818306 - 1.179393443;
}
float eps_get_bcr1ia()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x14;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.965003633 - 0.970816178;
}
float eps_get_bcr1ib()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x15;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.97409839 + 7.889228648;
}
float eps_get_bcr2ia()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x24;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.991807411 + 10.87345601;
}
float eps_get_bcr2ib()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x25;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.98125368 + 9.791931336;
}
float eps_get_bcr3ia()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x34;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 1.000522183 - 0.81609817;
}
float eps_get_bcr3ib()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x35;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.971043376 + 5.230754201;
}
float eps_get_bcrouti()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x84;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 14.45318313 - 11.89241354;
}
float eps_get_bati()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x24;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 6.843346065 - 10.61176728;
}
float eps_get_bus12i()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x34;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 2.056275285 + 0.641165577;
}
float eps_get_bus5i()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x14;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 6.848193861 - 11.51178137;
}
float eps_get_bus33i()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x04;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 6.834722211 - 12.64684042;
}
float eps_get_eps5i()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x15;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 1.327547;
}
float eps_get_eps33i()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x05;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 1.327547;
}
float eps_get_mbt()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE3;
command[2] = 0x08;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return ((float)adc * 0.379528154) - 288.923017;
}
// temperature sensor on solar array 1a (-X)
float eps_get_sa1at()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x18;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return ((float)adc * 0.4963) - 273.15;
}
// temperature sensor on solar array 1b (+X)
float eps_get_sa1bt()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x19;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return ((float)adc * 0.4963) - 273.15;
}
// temperature sensor on solar array 2a (-Y)
float eps_get_sa2at()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x28;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return ((float)adc * 0.4963) - 273.15;
}
// temperature sensor on solar array 2b (+Y)
float eps_get_sa2bt()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE1;
command[2] = 0x29;
int delay = 5;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return ((float)adc * 0.4963) - 273.15;
}
// turn off PDM initial state
void eps_set_pdm_all_off()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x41;
command[1] = 0x00;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// turn off all PDMs
void eps_set_pdm_initial_off(int pdm)
{
// load command and parameters
int nbytes = 2;
command[0] = 0x53;
command[1] = pdm;
int delay = 200;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Get initial state of all PDMs (4 byte response, see table 11-12 in EPS manual
int eps_get_pdm_initial()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x44;
command[1] = 0x00;
int delay = 40;
unsigned int output;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(4);
// last two bytes have the bit-wise data
output = (response[2] << 8) | response[3];
return output;
}
// Get expected state of all PDMs (4 byte response, see table 11-12 in EPS manual
int eps_get_pdm_expected()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x43;
command[1] = 0x00;
int delay = 1;
unsigned int output;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(4);
// last two bytes have the bit-wise data
output = (response[2] << 8) | response[3];
return output;
}
// Get actual state of all PDMs (4 byte response, see table 11-12 in EPS manual
int eps_get_pdm_actual()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x42;
command[1] = 0x00;
int delay = 40;
unsigned int output;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(4);
// last two bytes have the bit-wise data
output = (response[2] << 8) | response[3];
return output;
}
// Turn on PDM Switch #7, 5V power to Arducams
void eps_cameras_on()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x50;
command[1] = 0x07;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn off PDM Switch #7, 5V power to Arducams
void eps_cameras_off()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x51;
command[1] = 0x07;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn off each PDM switch, one at a time
void eps_allpdm_off()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x51;
//switch #1
command[1] = 0x01;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #2
command[1] = 0x02;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #3
command[1] = 0x03;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #4
command[1] = 0x04;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #5
command[1] = 0x05;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #6
command[1] = 0x06;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #7
command[1] = 0x07;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #8
command[1] = 0x08;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #9
command[1] = 0x09;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
//switch #10
command[1] = 0x0a;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn on PDM Switch #8, 3.3V power to Antenna
void eps_antenna_on()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x50;
command[1] = 0x08;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn off PDM Switch #8, 3.3V power to Antenna
void eps_antenna_off()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x51;
command[1] = 0x08;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn on PDM Switch #10, 3.3V backup power to Antenna
void eps_antenna_on2()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x50;
command[1] = 0x0a;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Turn off PDM Switch #10, 3.3V backup power to Antenna
void eps_antenna_off2()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x51;
command[1] = 0x0a;
int delay = 0;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// Check status of PDM Switch #8, 3.3V power to Antenna (1=on, 0=off))
unsigned char eps_antenna_status()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x54;
command[1] = 0x08;
int delay = 2;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// the useful status byte is the second byte returned
return response[1];
}
// Check status of PDM Switch #10, 3.3V backup power to Antenna (1=on, 0=off))
unsigned char eps_antenna_status2()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x54;
command[1] = 0x0a;
int delay = 2;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// the useful status byte is the second byte returned
return response[1];
}
// Get the last error code
unsigned char eps_get_last_error()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x03;
command[1] = 0x00;
int delay = 1;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
// the useful status byte is the second byte returned
return response[1];
}
// Reset the BatV bus (500 ms power-down)
void eps_batvbus_reset()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x70;
command[1] = 0x01;
int delay = 1;
// send command
eps_write_command(nbytes, delay);
// read response
eps_read_response(2);
}
// battery telemetry: status byte
unsigned char bat_get_status()
{
// load command and parameters
int nbytes = 2;
command[0] = 0x01;
command[1] = 0x00;
int delay = 1;
// send command
bat_write_command(nbytes, delay);
// read response
bat_read_response(2);
// the useful status byte is the second byte returned
return response[1];
}
// battery telemetry: voltage
float bat_get_batv()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x80;
int delay = 5;
// send command
bat_write_command(nbytes, delay);
// read response
bat_read_response(2);
// convert 2-byte (10-bit) ADC output to float (V)
int adc = (response[0] << 8) | response[1];
return (float)adc * 0.008967413;
}
// battery telemetry: current
float bat_get_bati()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x84;
int delay = 5;
// send command
bat_write_command(nbytes, delay);
// read response
bat_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
return (float)adc * 14.49751076 - 3.353549658;
}
// battery telemetry: charge/discharge status
int bat_get_batischarging()
{
// load command and parameters
int nbytes = 3;
command[0] = 0x10;
command[1] = 0xE2;
command[2] = 0x8E;
int delay = 5;
// send command
bat_write_command(nbytes, delay);
// read response
bat_read_response(2);
// convert 2-byte (10-bit) ADC output to float (mA)
int adc = (response[0] << 8) | response[1];
// if adc less than 512 battery is charging, otherwise battery is discharging
return (adc < 512);
}
// battery telemetry: motherboard temperature