The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
Battery/Battery.h@5:57b06b4b47c6, 2016-06-02 (annotated)
- Committer:
- defrost
- Date:
- Thu Jun 02 16:41:40 2016 +0000
- Revision:
- 5:57b06b4b47c6
- Child:
- 8:0acda4f2e0a8
- updated to v3.0 from Malcolm's email
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 | 5:57b06b4b47c6 | 34 | #define FUNCNAME "BATTERY" |
defrost | 5:57b06b4b47c6 | 35 | #include "defs.h" |
defrost | 5:57b06b4b47c6 | 36 | /** \brief The battery logs data and interacts with the locker. |
defrost | 5:57b06b4b47c6 | 37 | * |
defrost | 5:57b06b4b47c6 | 38 | * The config.ini must start with B |
defrost | 5:57b06b4b47c6 | 39 | * |
defrost | 5:57b06b4b47c6 | 40 | */ |
defrost | 5:57b06b4b47c6 | 41 | class Battery : public SolarNanoGrid |
defrost | 5:57b06b4b47c6 | 42 | { |
defrost | 5:57b06b4b47c6 | 43 | public: |
defrost | 5:57b06b4b47c6 | 44 | // ********************* |
defrost | 5:57b06b4b47c6 | 45 | // * Public variables: * |
defrost | 5:57b06b4b47c6 | 46 | // ********************* |
defrost | 5:57b06b4b47c6 | 47 | char* logDir=NULL; |
defrost | 5:57b06b4b47c6 | 48 | float maxChargeRate=0.0; // Charge rate in amps |
defrost | 5:57b06b4b47c6 | 49 | |
defrost | 5:57b06b4b47c6 | 50 | // ********************* |
defrost | 5:57b06b4b47c6 | 51 | // * Public functions: * |
defrost | 5:57b06b4b47c6 | 52 | // ********************* |
defrost | 5:57b06b4b47c6 | 53 | |
defrost | 5:57b06b4b47c6 | 54 | // Constructor: |
defrost | 5:57b06b4b47c6 | 55 | Battery(FILE* fp); |
defrost | 5:57b06b4b47c6 | 56 | |
defrost | 5:57b06b4b47c6 | 57 | // Main loop function: |
defrost | 5:57b06b4b47c6 | 58 | void loop(void); |
defrost | 5:57b06b4b47c6 | 59 | /** |
defrost | 5:57b06b4b47c6 | 60 | * Checks in the battery to the locker |
defrost | 5:57b06b4b47c6 | 61 | * Transmits "C ID" |
defrost | 5:57b06b4b47c6 | 62 | */ |
defrost | 5:57b06b4b47c6 | 63 | void checkIn(); |
defrost | 5:57b06b4b47c6 | 64 | |
defrost | 5:57b06b4b47c6 | 65 | |
defrost | 5:57b06b4b47c6 | 66 | protected: |
defrost | 5:57b06b4b47c6 | 67 | // ********************** |
defrost | 5:57b06b4b47c6 | 68 | // * Protected variables: * |
defrost | 5:57b06b4b47c6 | 69 | // ********************** |
defrost | 5:57b06b4b47c6 | 70 | /** |
defrost | 5:57b06b4b47c6 | 71 | * Name of log directory, include last / |
defrost | 5:57b06b4b47c6 | 72 | */ |
defrost | 5:57b06b4b47c6 | 73 | |
defrost | 5:57b06b4b47c6 | 74 | char count=0; |
defrost | 5:57b06b4b47c6 | 75 | char* txFileName=NULL; |
defrost | 5:57b06b4b47c6 | 76 | |
defrost | 5:57b06b4b47c6 | 77 | char* fullTxFilePath=NULL; |
defrost | 5:57b06b4b47c6 | 78 | |
defrost | 5:57b06b4b47c6 | 79 | int sizeRead=0; |
defrost | 5:57b06b4b47c6 | 80 | unsigned int fileLength=0; |
defrost | 5:57b06b4b47c6 | 81 | unsigned int filePointer=0; |
defrost | 5:57b06b4b47c6 | 82 | unsigned int fileLeft=0; |
defrost | 5:57b06b4b47c6 | 83 | char *sdBuffer=NULL; |
defrost | 5:57b06b4b47c6 | 84 | unsigned int sdBuffPnt=0; |
defrost | 5:57b06b4b47c6 | 85 | /** |
defrost | 5:57b06b4b47c6 | 86 | * Open channel address of the locker |
defrost | 5:57b06b4b47c6 | 87 | */ |
defrost | 5:57b06b4b47c6 | 88 | long long openAddr=0; |
defrost | 5:57b06b4b47c6 | 89 | |
defrost | 5:57b06b4b47c6 | 90 | /** |
defrost | 5:57b06b4b47c6 | 91 | * Private channel address of the locker |
defrost | 5:57b06b4b47c6 | 92 | */ |
defrost | 5:57b06b4b47c6 | 93 | long long privateAddr=0; |
defrost | 5:57b06b4b47c6 | 94 | |
defrost | 5:57b06b4b47c6 | 95 | unsigned int countSD=0; |
defrost | 5:57b06b4b47c6 | 96 | |
defrost | 5:57b06b4b47c6 | 97 | // ********************** |
defrost | 5:57b06b4b47c6 | 98 | // * Protected flags: * |
defrost | 5:57b06b4b47c6 | 99 | // ********************** |
defrost | 5:57b06b4b47c6 | 100 | volatile char * flag=NULL; |
defrost | 5:57b06b4b47c6 | 101 | volatile char checkedIn=0; |
defrost | 5:57b06b4b47c6 | 102 | volatile char flagGetTime=0; |
defrost | 5:57b06b4b47c6 | 103 | volatile char flagNextFile=0; |
defrost | 5:57b06b4b47c6 | 104 | volatile char flagSendFileName=0; |
defrost | 5:57b06b4b47c6 | 105 | volatile char flagSendFileSize=0; |
defrost | 5:57b06b4b47c6 | 106 | volatile char flagSendFile=0; |
defrost | 5:57b06b4b47c6 | 107 | volatile char flagSendFileDone=0; |
defrost | 5:57b06b4b47c6 | 108 | |
defrost | 5:57b06b4b47c6 | 109 | |
defrost | 5:57b06b4b47c6 | 110 | // ********************** |
defrost | 5:57b06b4b47c6 | 111 | // * Protected interrupts: * |
defrost | 5:57b06b4b47c6 | 112 | // ********************** |
defrost | 5:57b06b4b47c6 | 113 | InterruptIn* button=NULL; |
defrost | 5:57b06b4b47c6 | 114 | Ticker* txWatch=NULL; |
defrost | 5:57b06b4b47c6 | 115 | Timeout* delay=NULL; |
defrost | 5:57b06b4b47c6 | 116 | |
defrost | 5:57b06b4b47c6 | 117 | // ********************** |
defrost | 5:57b06b4b47c6 | 118 | // * Protected functions: * |
defrost | 5:57b06b4b47c6 | 119 | // ********************** |
defrost | 5:57b06b4b47c6 | 120 | /** |
defrost | 5:57b06b4b47c6 | 121 | * Checks in the battery to the locker |
defrost | 5:57b06b4b47c6 | 122 | * Acknowledge received. |
defrost | 5:57b06b4b47c6 | 123 | * Changes the TX pipe address to private |
defrost | 5:57b06b4b47c6 | 124 | * |
defrost | 5:57b06b4b47c6 | 125 | */ |
defrost | 5:57b06b4b47c6 | 126 | void doCheckIn(); |
defrost | 5:57b06b4b47c6 | 127 | /** |
defrost | 5:57b06b4b47c6 | 128 | * Checks out the battery from the locker |
defrost | 5:57b06b4b47c6 | 129 | * Acknowledge received. |
defrost | 5:57b06b4b47c6 | 130 | * Changes the TX pipe address to open |
defrost | 5:57b06b4b47c6 | 131 | * |
defrost | 5:57b06b4b47c6 | 132 | */ |
defrost | 5:57b06b4b47c6 | 133 | void doCheckOut(); |
defrost | 5:57b06b4b47c6 | 134 | /** |
defrost | 5:57b06b4b47c6 | 135 | * sends a request for time update. |
defrost | 5:57b06b4b47c6 | 136 | */ |
defrost | 5:57b06b4b47c6 | 137 | void getTime(); |
defrost | 5:57b06b4b47c6 | 138 | /** |
defrost | 5:57b06b4b47c6 | 139 | * Sets the value pointed to by flag to 1. |
defrost | 5:57b06b4b47c6 | 140 | */ |
defrost | 5:57b06b4b47c6 | 141 | |
defrost | 5:57b06b4b47c6 | 142 | void nextFileToTx(); |
defrost | 5:57b06b4b47c6 | 143 | void sendDirName(); |
defrost | 5:57b06b4b47c6 | 144 | void sendFileName(); |
defrost | 5:57b06b4b47c6 | 145 | void sendFileSize(); |
defrost | 5:57b06b4b47c6 | 146 | void sendFile(); |
defrost | 5:57b06b4b47c6 | 147 | void sendFileDone(); |
defrost | 5:57b06b4b47c6 | 148 | void setFlag(); |
defrost | 5:57b06b4b47c6 | 149 | /** |
defrost | 5:57b06b4b47c6 | 150 | * Retransmits the last data. |
defrost | 5:57b06b4b47c6 | 151 | * |
defrost | 5:57b06b4b47c6 | 152 | */ |
defrost | 5:57b06b4b47c6 | 153 | void retransmit(); |
defrost | 5:57b06b4b47c6 | 154 | |
defrost | 5:57b06b4b47c6 | 155 | |
defrost | 5:57b06b4b47c6 | 156 | /** |
defrost | 5:57b06b4b47c6 | 157 | * called when the nrf the button is pressed |
defrost | 5:57b06b4b47c6 | 158 | * |
defrost | 5:57b06b4b47c6 | 159 | */ |
defrost | 5:57b06b4b47c6 | 160 | void intButton(); |
defrost | 5:57b06b4b47c6 | 161 | /** |
defrost | 5:57b06b4b47c6 | 162 | * called when the nrf creates an interrupt. |
defrost | 5:57b06b4b47c6 | 163 | * |
defrost | 5:57b06b4b47c6 | 164 | */ |
defrost | 5:57b06b4b47c6 | 165 | void intNrf(); |
defrost | 5:57b06b4b47c6 | 166 | |
defrost | 5:57b06b4b47c6 | 167 | private: |
defrost | 5:57b06b4b47c6 | 168 | // ********************** |
defrost | 5:57b06b4b47c6 | 169 | // * Private variables: * |
defrost | 5:57b06b4b47c6 | 170 | // ********************** |
defrost | 5:57b06b4b47c6 | 171 | |
defrost | 5:57b06b4b47c6 | 172 | volatile bool maxRT=false; |
defrost | 5:57b06b4b47c6 | 173 | |
defrost | 5:57b06b4b47c6 | 174 | }; |
defrost | 5:57b06b4b47c6 | 175 | #endif |