Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / test / bq27500_bq241xx / module_test_bq27500_bq241xx.c @ 4c72a54c

History | View | Annotate | Download (4.337 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
#include <amiroos.h>
20

    
21
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
22

    
23
#include <module_test_bq27500_bq241xx.h>
24
#include <aos_test_bq27500_bq241xx.h>
25
#include <string.h>
26

    
27
/******************************************************************************/
28
/* LOCAL DEFINITIONS                                                          */
29
/******************************************************************************/
30

    
31
/******************************************************************************/
32
/* EXPORTED VARIABLES                                                         */
33
/******************************************************************************/
34

    
35
/******************************************************************************/
36
/* LOCAL TYPES                                                                */
37
/******************************************************************************/
38

    
39
/******************************************************************************/
40
/* LOCAL VARIABLES                                                            */
41
/******************************************************************************/
42

    
43
static aos_test_bq27500bq241xxdata_t _data = {
44
  /* bq27500 driver   */ NULL,
45
  /* bq24103a driver  */ NULL,
46
  /* timeout          */ MICROSECONDS_PER_SECOND,
47
};
48

    
49
static AOS_TEST(_test, "bq27500 & bq24103a", "fuel gauge & battery charger", moduleTestBq27500Bq241xxShellCb, aosTestBq27500Bq241xxFunc, &_data);
50

    
51
/******************************************************************************/
52
/* LOCAL FUNCTIONS                                                            */
53
/******************************************************************************/
54

    
55
/******************************************************************************/
56
/* EXPORTED FUNCTIONS                                                         */
57
/******************************************************************************/
58

    
59
int moduleTestBq27500Bq241xxShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
60
{
61
  enum {
62
    UNKNOWN,
63
    FRONT, REAR,
64
  } charger = UNKNOWN;
65

    
66
  // evaluate argument
67
  if (argc == 2) {
68
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
69
      charger = FRONT;
70
    } else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
71
      charger = REAR;
72
    }
73
  }
74

    
75
  // handle valid charger
76
  if (charger != UNKNOWN) {
77
    aos_testresult_t res = {0, 0};
78

    
79
    switch (charger) {
80
      case FRONT:
81
        _data.bq27500 = &moduleLldFuelGaugeFront;
82
        _data.bq241xx = &moduleLldBatteryChargerFront;
83
        res = aosTestRun(stream, &_test, "front battery");
84
        _data.bq27500 = NULL;
85
        _data.bq241xx = NULL;
86
        break;
87
      case REAR:
88
        _data.bq27500 = &moduleLldFuelGaugeRear;
89
        _data.bq241xx = &moduleLldBatteryChargerRear;
90
        res = aosTestRun(stream, &_test, "rear battery");
91
        _data.bq27500 = NULL;
92
        _data.bq241xx = NULL;
93
        break;
94
      default:
95
        break;
96
    }
97
    if (result != NULL) {
98
      *result = res;
99
    }
100
    return AOS_OK;
101
  }
102
  // handle invalid arguments
103
  else {
104
    // print help
105
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
106
    chprintf(stream, "Options:\n");
107
    chprintf(stream, "  --front, -f\n");
108
    chprintf(stream, "    Test the front battery fuel gauge and charger.\n");
109
    chprintf(stream, "  --rear, -r\n");
110
    chprintf(stream, "    Test the rear battery fuel gauge and charger.\n");
111
    if (result != NULL) {
112
      result->passed = 0;
113
      result->failed = 0;
114
    }
115
    return AOS_INVALIDARGUMENTS;
116
   }
117
}
118

    
119
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */