The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
Battery/Battery.h@17:dc19b3b39790, 2016-06-13 (annotated)
- Committer:
- defrost
- Date:
- Mon Jun 13 09:04:53 2016 +0000
- Revision:
- 17:dc19b3b39790
- Parent:
- 13:de43f28c0365
- Child:
- 18:be77ad141fac
- Added a ChargeStart flag; - Added functions to check the status of the Battery state, they do not really work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
defrost | 5:57b06b4b47c6 | 1 | /** |
defrost | 5:57b06b4b47c6 | 2 | *@section DESCRIPTION |
defrost | 5:57b06b4b47c6 | 3 | * mbed SolarNanogrid Battery. |
defrost | 5:57b06b4b47c6 | 4 | *@section LICENSE |
defrost | 5:57b06b4b47c6 | 5 | * Copyright (c) 2016, Malcolm McCulloch |
defrost | 5:57b06b4b47c6 | 6 | * |
defrost | 5:57b06b4b47c6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
defrost | 5:57b06b4b47c6 | 8 | * of this software and associated documentation files (the "Software"), to deal |
defrost | 5:57b06b4b47c6 | 9 | * in the Software without restriction, including without limitation the rights |
defrost | 5:57b06b4b47c6 | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
defrost | 5:57b06b4b47c6 | 11 | * copies of the Software, and to permit persons to whom the Software is |
defrost | 5:57b06b4b47c6 | 12 | * furnished to do so, subject to the following conditions: |
defrost | 5:57b06b4b47c6 | 13 | * |
defrost | 5:57b06b4b47c6 | 14 | * The above copyright notice and this permission notice shall be included in |
defrost | 5:57b06b4b47c6 | 15 | * all copies or substantial portions of the Software. |
defrost | 5:57b06b4b47c6 | 16 | * |
defrost | 5:57b06b4b47c6 | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
defrost | 5:57b06b4b47c6 | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
defrost | 5:57b06b4b47c6 | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
defrost | 5:57b06b4b47c6 | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
defrost | 5:57b06b4b47c6 | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
defrost | 5:57b06b4b47c6 | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
defrost | 5:57b06b4b47c6 | 23 | * THE SOFTWARE. |
defrost | 5:57b06b4b47c6 | 24 | * @file "Battery.h" |
defrost | 5:57b06b4b47c6 | 25 | */ |
defrost | 5:57b06b4b47c6 | 26 | |
defrost | 5:57b06b4b47c6 | 27 | #ifndef BATTERY_H |
defrost | 5:57b06b4b47c6 | 28 | #define BATTERY_H |
defrost | 5:57b06b4b47c6 | 29 | #include <mbed.h> |
defrost | 5:57b06b4b47c6 | 30 | #include "NRF2401P.h" |
defrost | 5:57b06b4b47c6 | 31 | #include "nRF24l01.h" |
defrost | 5:57b06b4b47c6 | 32 | #include "SDFileSystem.h" |
defrost | 5:57b06b4b47c6 | 33 | #include "SolarNanoGrid.h" |
defrost | 10:30c9e8df0032 | 34 | |
defrost | 5:57b06b4b47c6 | 35 | /** \brief The battery logs data and interacts with the locker. |
defrost | 5:57b06b4b47c6 | 36 | * |
defrost | 5:57b06b4b47c6 | 37 | * The config.ini must start with B |
defrost | 5:57b06b4b47c6 | 38 | * |
defrost | 5:57b06b4b47c6 | 39 | */ |
defrost | 5:57b06b4b47c6 | 40 | class Battery : public SolarNanoGrid |
defrost | 5:57b06b4b47c6 | 41 | { |
defrost | 5:57b06b4b47c6 | 42 | public: |
defrost | 5:57b06b4b47c6 | 43 | // ********************* |
defrost | 5:57b06b4b47c6 | 44 | // * Public variables: * |
defrost | 5:57b06b4b47c6 | 45 | // ********************* |
adrienBiz | 8:0acda4f2e0a8 | 46 | char* logDir; |
adrienBiz | 8:0acda4f2e0a8 | 47 | float maxChargeRate; // Charge rate in amps |
defrost | 5:57b06b4b47c6 | 48 | |
defrost | 5:57b06b4b47c6 | 49 | // ********************* |
defrost | 5:57b06b4b47c6 | 50 | // * Public functions: * |
defrost | 5:57b06b4b47c6 | 51 | // ********************* |
defrost | 5:57b06b4b47c6 | 52 | |
defrost | 5:57b06b4b47c6 | 53 | // Constructor: |
epgmdm | 11:87ab310924f0 | 54 | Battery(FILE* fp, Serial *pc); |
defrost | 5:57b06b4b47c6 | 55 | |
defrost | 5:57b06b4b47c6 | 56 | // Main loop function: |
defrost | 13:de43f28c0365 | 57 | virtual void loop(void); |
defrost | 5:57b06b4b47c6 | 58 | /** |
defrost | 5:57b06b4b47c6 | 59 | * Checks in the battery to the locker |
defrost | 5:57b06b4b47c6 | 60 | * Transmits "C ID" |
defrost | 5:57b06b4b47c6 | 61 | */ |
defrost | 5:57b06b4b47c6 | 62 | void checkIn(); |
defrost | 5:57b06b4b47c6 | 63 | |
epgmdm | 12:d9b13f31206d | 64 | /** |
defrost | 17:dc19b3b39790 | 65 | * Returns the max current that can be drawn from the system, in amps |
defrost | 17:dc19b3b39790 | 66 | */ |
epgmdm | 12:d9b13f31206d | 67 | |
defrost | 17:dc19b3b39790 | 68 | float getMaxCurrent(); |
epgmdm | 12:d9b13f31206d | 69 | |
defrost | 17:dc19b3b39790 | 70 | /** |
defrost | 17:dc19b3b39790 | 71 | * returns a string of the log directory |
defrost | 17:dc19b3b39790 | 72 | */ |
defrost | 17:dc19b3b39790 | 73 | char *getLogDirectory(); |
defrost | 17:dc19b3b39790 | 74 | |
defrost | 17:dc19b3b39790 | 75 | /** |
defrost | 17:dc19b3b39790 | 76 | * Returns true if we are authorized to start charging. |
defrost | 17:dc19b3b39790 | 77 | */ |
defrost | 17:dc19b3b39790 | 78 | bool startCharging(void); |
defrost | 17:dc19b3b39790 | 79 | |
defrost | 17:dc19b3b39790 | 80 | /** |
defrost | 17:dc19b3b39790 | 81 | * Returns true if we are checked in. |
defrost | 17:dc19b3b39790 | 82 | */ |
defrost | 17:dc19b3b39790 | 83 | bool Battery::isCheckedIn(void); |
defrost | 5:57b06b4b47c6 | 84 | |
defrost | 5:57b06b4b47c6 | 85 | protected: |
defrost | 5:57b06b4b47c6 | 86 | // ********************** |
defrost | 5:57b06b4b47c6 | 87 | // * Protected variables: * |
defrost | 5:57b06b4b47c6 | 88 | // ********************** |
defrost | 5:57b06b4b47c6 | 89 | /** |
defrost | 5:57b06b4b47c6 | 90 | * Name of log directory, include last / |
defrost | 5:57b06b4b47c6 | 91 | */ |
defrost | 5:57b06b4b47c6 | 92 | |
adrienBiz | 8:0acda4f2e0a8 | 93 | char count; |
adrienBiz | 8:0acda4f2e0a8 | 94 | char* txFileName; |
defrost | 5:57b06b4b47c6 | 95 | |
adrienBiz | 8:0acda4f2e0a8 | 96 | char* fullTxFilePath; |
defrost | 5:57b06b4b47c6 | 97 | |
adrienBiz | 8:0acda4f2e0a8 | 98 | int sizeRead; |
adrienBiz | 8:0acda4f2e0a8 | 99 | unsigned int fileLength; |
adrienBiz | 8:0acda4f2e0a8 | 100 | unsigned int filePointer; |
adrienBiz | 8:0acda4f2e0a8 | 101 | unsigned int fileLeft; |
adrienBiz | 8:0acda4f2e0a8 | 102 | char *sdBuffer; |
adrienBiz | 8:0acda4f2e0a8 | 103 | unsigned int sdBuffPnt; |
defrost | 5:57b06b4b47c6 | 104 | /** |
defrost | 5:57b06b4b47c6 | 105 | * Open channel address of the locker |
defrost | 5:57b06b4b47c6 | 106 | */ |
adrienBiz | 8:0acda4f2e0a8 | 107 | long long openAddr; |
defrost | 5:57b06b4b47c6 | 108 | |
defrost | 5:57b06b4b47c6 | 109 | /** |
defrost | 5:57b06b4b47c6 | 110 | * Private channel address of the locker |
defrost | 5:57b06b4b47c6 | 111 | */ |
adrienBiz | 8:0acda4f2e0a8 | 112 | long long privateAddr; |
defrost | 5:57b06b4b47c6 | 113 | |
adrienBiz | 8:0acda4f2e0a8 | 114 | unsigned int countSD; |
defrost | 5:57b06b4b47c6 | 115 | |
defrost | 5:57b06b4b47c6 | 116 | // ********************** |
defrost | 5:57b06b4b47c6 | 117 | // * Protected flags: * |
defrost | 5:57b06b4b47c6 | 118 | // ********************** |
adrienBiz | 8:0acda4f2e0a8 | 119 | volatile char * flag; |
adrienBiz | 8:0acda4f2e0a8 | 120 | volatile char checkedIn; |
adrienBiz | 8:0acda4f2e0a8 | 121 | volatile char flagGetTime; |
adrienBiz | 8:0acda4f2e0a8 | 122 | volatile char flagNextFile; |
adrienBiz | 8:0acda4f2e0a8 | 123 | volatile char flagSendFileName; |
adrienBiz | 8:0acda4f2e0a8 | 124 | volatile char flagSendFileSize; |
adrienBiz | 8:0acda4f2e0a8 | 125 | volatile char flagSendFile; |
adrienBiz | 8:0acda4f2e0a8 | 126 | volatile char flagSendFileDone; |
epgmdm | 12:d9b13f31206d | 127 | volatile char flagGetMaxCharge; |
epgmdm | 12:d9b13f31206d | 128 | volatile char sendingFile; |
defrost | 17:dc19b3b39790 | 129 | volatile bool startCharge; |
defrost | 5:57b06b4b47c6 | 130 | |
defrost | 5:57b06b4b47c6 | 131 | |
defrost | 5:57b06b4b47c6 | 132 | // ********************** |
defrost | 5:57b06b4b47c6 | 133 | // * Protected interrupts: * |
defrost | 5:57b06b4b47c6 | 134 | // ********************** |
adrienBiz | 8:0acda4f2e0a8 | 135 | InterruptIn* button; |
adrienBiz | 8:0acda4f2e0a8 | 136 | Ticker* txWatch; |
adrienBiz | 8:0acda4f2e0a8 | 137 | Timeout* delay; |
defrost | 5:57b06b4b47c6 | 138 | |
defrost | 5:57b06b4b47c6 | 139 | // ********************** |
defrost | 5:57b06b4b47c6 | 140 | // * Protected functions: * |
defrost | 5:57b06b4b47c6 | 141 | // ********************** |
defrost | 5:57b06b4b47c6 | 142 | /** |
defrost | 5:57b06b4b47c6 | 143 | * Checks in the battery to the locker |
defrost | 5:57b06b4b47c6 | 144 | * Acknowledge received. |
defrost | 5:57b06b4b47c6 | 145 | * Changes the TX pipe address to private |
defrost | 5:57b06b4b47c6 | 146 | * |
defrost | 5:57b06b4b47c6 | 147 | */ |
defrost | 5:57b06b4b47c6 | 148 | void doCheckIn(); |
defrost | 5:57b06b4b47c6 | 149 | /** |
defrost | 5:57b06b4b47c6 | 150 | * Checks out the battery from the locker |
defrost | 5:57b06b4b47c6 | 151 | * Acknowledge received. |
defrost | 5:57b06b4b47c6 | 152 | * Changes the TX pipe address to open |
defrost | 5:57b06b4b47c6 | 153 | * |
defrost | 5:57b06b4b47c6 | 154 | */ |
defrost | 5:57b06b4b47c6 | 155 | void doCheckOut(); |
defrost | 5:57b06b4b47c6 | 156 | /** |
defrost | 5:57b06b4b47c6 | 157 | * sends a request for time update. |
defrost | 5:57b06b4b47c6 | 158 | */ |
epgmdm | 12:d9b13f31206d | 159 | void requestTime(); |
defrost | 5:57b06b4b47c6 | 160 | /** |
defrost | 5:57b06b4b47c6 | 161 | * Sets the value pointed to by flag to 1. |
defrost | 5:57b06b4b47c6 | 162 | */ |
defrost | 5:57b06b4b47c6 | 163 | |
defrost | 5:57b06b4b47c6 | 164 | void nextFileToTx(); |
defrost | 5:57b06b4b47c6 | 165 | void sendDirName(); |
defrost | 5:57b06b4b47c6 | 166 | void sendFileName(); |
defrost | 5:57b06b4b47c6 | 167 | void sendFileSize(); |
defrost | 5:57b06b4b47c6 | 168 | void sendFile(); |
defrost | 5:57b06b4b47c6 | 169 | void sendFileDone(); |
defrost | 5:57b06b4b47c6 | 170 | void setFlag(); |
defrost | 5:57b06b4b47c6 | 171 | /** |
defrost | 5:57b06b4b47c6 | 172 | * Retransmits the last data. |
defrost | 5:57b06b4b47c6 | 173 | * |
defrost | 5:57b06b4b47c6 | 174 | */ |
defrost | 5:57b06b4b47c6 | 175 | void retransmit(); |
defrost | 5:57b06b4b47c6 | 176 | |
defrost | 5:57b06b4b47c6 | 177 | |
defrost | 5:57b06b4b47c6 | 178 | /** |
defrost | 5:57b06b4b47c6 | 179 | * called when the nrf the button is pressed |
defrost | 5:57b06b4b47c6 | 180 | * |
defrost | 5:57b06b4b47c6 | 181 | */ |
defrost | 5:57b06b4b47c6 | 182 | void intButton(); |
defrost | 5:57b06b4b47c6 | 183 | /** |
defrost | 5:57b06b4b47c6 | 184 | * called when the nrf creates an interrupt. |
defrost | 5:57b06b4b47c6 | 185 | * |
defrost | 5:57b06b4b47c6 | 186 | */ |
defrost | 5:57b06b4b47c6 | 187 | void intNrf(); |
defrost | 5:57b06b4b47c6 | 188 | |
epgmdm | 12:d9b13f31206d | 189 | /** |
epgmdm | 12:d9b13f31206d | 190 | * sends a request for time update. |
epgmdm | 12:d9b13f31206d | 191 | */ |
epgmdm | 12:d9b13f31206d | 192 | void requestMaxCharge(); |
epgmdm | 12:d9b13f31206d | 193 | |
defrost | 5:57b06b4b47c6 | 194 | private: |
defrost | 5:57b06b4b47c6 | 195 | // ********************** |
defrost | 5:57b06b4b47c6 | 196 | // * Private variables: * |
defrost | 5:57b06b4b47c6 | 197 | // ********************** |
defrost | 5:57b06b4b47c6 | 198 | |
adrienBiz | 8:0acda4f2e0a8 | 199 | volatile bool maxRT; |
defrost | 5:57b06b4b47c6 | 200 | |
epgmdm | 12:d9b13f31206d | 201 | |
defrost | 5:57b06b4b47c6 | 202 | }; |
defrost | 5:57b06b4b47c6 | 203 | #endif |