The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Committer:
epgmdm
Date:
Tue Jun 14 21:43:17 2016 +0000
Revision:
18:be77ad141fac
Parent:
17:dc19b3b39790
Child:
22:93fde34d9a94
Added following features:; 1) Send Dir will retry every 25s if can't access locker. ; 2) Battery checkout - revert to open address.; 3) Locker responds to maxCurrent (can be open or private address).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
defrost 5:57b06b4b47c6 1 /**
defrost 5:57b06b4b47c6 2 *@section DESCRIPTION
defrost 5:57b06b4b47c6 3 * mbed SolarNanogrid Library
defrost 5:57b06b4b47c6 4 * Battery extends SolarNanoGrid.
defrost 5:57b06b4b47c6 5 * Battery interacts with the lockers.
defrost 5:57b06b4b47c6 6 * The ID must NOT end in 00.
defrost 5:57b06b4b47c6 7 *@section LICENSE
defrost 5:57b06b4b47c6 8 * Copyright (c) 2016, Malcolm McCulloch
defrost 5:57b06b4b47c6 9 *
defrost 5:57b06b4b47c6 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
defrost 5:57b06b4b47c6 11 * of this software and associated documentation files (the "Software"), to deal
defrost 5:57b06b4b47c6 12 * in the Software without restriction, including without limitation the rights
defrost 5:57b06b4b47c6 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
defrost 5:57b06b4b47c6 14 * copies of the Software, and to permit persons to whom the Software is
defrost 5:57b06b4b47c6 15 * furnished to do so, subject to the following conditions:
defrost 5:57b06b4b47c6 16 *
defrost 5:57b06b4b47c6 17 * The above copyright notice and this permission notice shall be included in
defrost 5:57b06b4b47c6 18 * all copies or substantial portions of the Software.
defrost 5:57b06b4b47c6 19 *
defrost 5:57b06b4b47c6 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
defrost 5:57b06b4b47c6 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
defrost 5:57b06b4b47c6 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
defrost 5:57b06b4b47c6 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
defrost 5:57b06b4b47c6 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
defrost 5:57b06b4b47c6 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
defrost 5:57b06b4b47c6 26 * THE SOFTWARE.
defrost 5:57b06b4b47c6 27 * @file "Battery.c"
defrost 5:57b06b4b47c6 28 */
defrost 5:57b06b4b47c6 29 #include "Battery.h"
defrost 10:30c9e8df0032 30 #define FUNCNAME "BATTERY"
defrost 10:30c9e8df0032 31 #include "defs.h"
defrost 5:57b06b4b47c6 32
defrost 5:57b06b4b47c6 33 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 34 // Constructors
defrost 5:57b06b4b47c6 35 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 36
epgmdm 18:be77ad141fac 37 Battery::Battery(FILE* fp, Serial *pc) : SolarNanoGrid(fp,pc)
epgmdm 18:be77ad141fac 38 {
defrost 5:57b06b4b47c6 39 DBG("Initialize class");
adrienBiz 8:0acda4f2e0a8 40 // ***** Variable initialisation *****
adrienBiz 8:0acda4f2e0a8 41 // Public variable initialisation
epgmdm 11:87ab310924f0 42
epgmdm 12:d9b13f31206d 43 maxChargeRate=1.0; // Charge rate in amps
epgmdm 11:87ab310924f0 44
adrienBiz 8:0acda4f2e0a8 45 // Protected variables initialisation
adrienBiz 8:0acda4f2e0a8 46 count=0;
adrienBiz 8:0acda4f2e0a8 47 sizeRead=0;
adrienBiz 8:0acda4f2e0a8 48 fileLength=0;
adrienBiz 8:0acda4f2e0a8 49 filePointer=0;
adrienBiz 8:0acda4f2e0a8 50 fileLeft=0;
epgmdm 11:87ab310924f0 51
adrienBiz 8:0acda4f2e0a8 52 sdBuffPnt=0;
adrienBiz 8:0acda4f2e0a8 53 /**
adrienBiz 8:0acda4f2e0a8 54 * Open channel address of the locker
adrienBiz 8:0acda4f2e0a8 55 */
adrienBiz 8:0acda4f2e0a8 56 openAddr=0;
adrienBiz 8:0acda4f2e0a8 57
adrienBiz 8:0acda4f2e0a8 58 /**
adrienBiz 8:0acda4f2e0a8 59 * Private channel address of the locker
adrienBiz 8:0acda4f2e0a8 60 */
adrienBiz 8:0acda4f2e0a8 61 privateAddr=0;
adrienBiz 8:0acda4f2e0a8 62
adrienBiz 8:0acda4f2e0a8 63 countSD=0;
adrienBiz 8:0acda4f2e0a8 64
adrienBiz 8:0acda4f2e0a8 65 // Protected flags: *
adrienBiz 8:0acda4f2e0a8 66 checkedIn=0;
epgmdm 18:be77ad141fac 67 flagDirFileName=0;
adrienBiz 8:0acda4f2e0a8 68 flagGetTime=0;
adrienBiz 8:0acda4f2e0a8 69 flagNextFile=0;
adrienBiz 8:0acda4f2e0a8 70 flagSendFileName=0;
adrienBiz 8:0acda4f2e0a8 71 flagSendFileSize=0;
adrienBiz 8:0acda4f2e0a8 72 flagSendFile=0;
adrienBiz 8:0acda4f2e0a8 73 flagSendFileDone=0;
epgmdm 12:d9b13f31206d 74 flagGetMaxCharge=0;
epgmdm 12:d9b13f31206d 75 sendingFile=0;
epgmdm 18:be77ad141fac 76 flagStartFileTx=0;
defrost 17:dc19b3b39790 77 startCharge = false;
epgmdm 18:be77ad141fac 78 flagHubNotReady=0;
epgmdm 18:be77ad141fac 79 flagCheckOut=0;
epgmdm 11:87ab310924f0 80
adrienBiz 8:0acda4f2e0a8 81 // Protected interrupts
adrienBiz 8:0acda4f2e0a8 82 button=NULL;
adrienBiz 8:0acda4f2e0a8 83 txWatch=NULL;
adrienBiz 8:0acda4f2e0a8 84 delay=NULL;
epgmdm 11:87ab310924f0 85
adrienBiz 8:0acda4f2e0a8 86 //Private variables initialisation
adrienBiz 8:0acda4f2e0a8 87 maxRT=false;
epgmdm 11:87ab310924f0 88
adrienBiz 8:0acda4f2e0a8 89 // ***** End of variables initialisation *****
epgmdm 11:87ab310924f0 90
epgmdm 11:87ab310924f0 91 // No other information needed from the config file
epgmdm 11:87ab310924f0 92 fclose(fp);
epgmdm 11:87ab310924f0 93 //
epgmdm 11:87ab310924f0 94 // Setup variables
epgmdm 11:87ab310924f0 95 //
epgmdm 11:87ab310924f0 96 txFileName = (char*) calloc(80, 1);
epgmdm 11:87ab310924f0 97 fullTxFilePath = (char*) calloc(80, 1);
epgmdm 11:87ab310924f0 98 logDir = (char*) calloc(20, 1);
epgmdm 11:87ab310924f0 99 sdBuffer = (char*) calloc(SDBUFFERSIZE, 1);
epgmdm 11:87ab310924f0 100
epgmdm 11:87ab310924f0 101
epgmdm 11:87ab310924f0 102
epgmdm 11:87ab310924f0 103
defrost 5:57b06b4b47c6 104 //
defrost 5:57b06b4b47c6 105 // Setup NRF
defrost 5:57b06b4b47c6 106 //
defrost 5:57b06b4b47c6 107 privateAddr = ((long long)communityID <<16)+ (id &0XFFFF);
defrost 5:57b06b4b47c6 108 openAddr = privateAddr & 0xFFFFFFFF00;
defrost 5:57b06b4b47c6 109
defrost 5:57b06b4b47c6 110 DBG("Channel %x Address %llx Address Locker %llx", chan, privateAddr, openAddr);
defrost 5:57b06b4b47c6 111
epgmdm 11:87ab310924f0 112 spiNRF();
defrost 5:57b06b4b47c6 113 nrf->quickTxSetup(chan, openAddr);
defrost 5:57b06b4b47c6 114 nrf->setRadio(0x01, 0x03); // 2MB/S 0dB
defrost 5:57b06b4b47c6 115 nrf->setTxRetry(0x0F, 0x0F);
defrost 5:57b06b4b47c6 116 nrfFlush();
defrost 5:57b06b4b47c6 117 DBG("Nrf Details:");
defrost 5:57b06b4b47c6 118 #ifdef DEBUG
defrost 5:57b06b4b47c6 119 nrf->printDetails();
defrost 5:57b06b4b47c6 120 #endif
defrost 5:57b06b4b47c6 121 //
defrost 5:57b06b4b47c6 122 // Setup logging directories
defrost 5:57b06b4b47c6 123 //
defrost 5:57b06b4b47c6 124 sprintf(logDir, "/sd/data/%02X%04X", (communityID&0XFF),(id&0XFFFF));
defrost 5:57b06b4b47c6 125 DBG(" Log directory %s", logDir);
defrost 5:57b06b4b47c6 126 spiSD();
defrost 5:57b06b4b47c6 127 mkdir("/sd/data", 777);
defrost 5:57b06b4b47c6 128 mkdir(logDir, 777);
defrost 5:57b06b4b47c6 129 DBG(" made");
defrost 5:57b06b4b47c6 130 //
defrost 5:57b06b4b47c6 131 // Setup interrupts
defrost 5:57b06b4b47c6 132 //
defrost 5:57b06b4b47c6 133 button = new InterruptIn(SW2);
defrost 5:57b06b4b47c6 134 button->fall(this, &Battery::intButton);
defrost 5:57b06b4b47c6 135
defrost 5:57b06b4b47c6 136 nrfInt = new InterruptIn(PTC18);
defrost 5:57b06b4b47c6 137 nrfInt->fall(this, &Battery::intNrf); // attach nrf interrupt.
defrost 5:57b06b4b47c6 138
defrost 5:57b06b4b47c6 139 txWatch = new Ticker ();
defrost 5:57b06b4b47c6 140 txWatch->attach(this,&Battery::retransmit,10.01);
defrost 5:57b06b4b47c6 141
defrost 5:57b06b4b47c6 142 delay = new Timeout();
defrost 5:57b06b4b47c6 143
defrost 5:57b06b4b47c6 144 loop();
defrost 5:57b06b4b47c6 145 }
defrost 5:57b06b4b47c6 146
defrost 5:57b06b4b47c6 147 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 148 // Interrupt routines
defrost 5:57b06b4b47c6 149 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 150
defrost 5:57b06b4b47c6 151 /**
defrost 5:57b06b4b47c6 152 * When the button is pressed transmit something
defrost 5:57b06b4b47c6 153 */
epgmdm 18:be77ad141fac 154 void Battery::intButton()
epgmdm 18:be77ad141fac 155 {
epgmdm 18:be77ad141fac 156 if (!maxRT) {
defrost 5:57b06b4b47c6 157 *ce = 1;
epgmdm 18:be77ad141fac 158 if(checkedIn==0) {
defrost 5:57b06b4b47c6 159 checkIn();
epgmdm 18:be77ad141fac 160 } else {
defrost 5:57b06b4b47c6 161 flagNextFile = 1;
defrost 5:57b06b4b47c6 162 }
defrost 5:57b06b4b47c6 163
defrost 5:57b06b4b47c6 164 }
defrost 5:57b06b4b47c6 165 }
defrost 5:57b06b4b47c6 166
defrost 5:57b06b4b47c6 167 /**
defrost 5:57b06b4b47c6 168 * Called when the nrf creates an interrupt.
defrost 5:57b06b4b47c6 169 *
defrost 5:57b06b4b47c6 170 */
epgmdm 18:be77ad141fac 171 void Battery::intNrf()
epgmdm 18:be77ad141fac 172 {
defrost 5:57b06b4b47c6 173 // DBG("NRF Interrupt Started.");
defrost 5:57b06b4b47c6 174 int pipe=0;
defrost 5:57b06b4b47c6 175 int status=0;
defrost 5:57b06b4b47c6 176 int width=0;
defrost 5:57b06b4b47c6 177
defrost 5:57b06b4b47c6 178 //
defrost 5:57b06b4b47c6 179 //Get status and pipe
defrost 5:57b06b4b47c6 180 //
epgmdm 11:87ab310924f0 181 spiNRF();
defrost 5:57b06b4b47c6 182 status = nrf->checkStatus();
defrost 5:57b06b4b47c6 183 pipe = (status >> 1);
defrost 5:57b06b4b47c6 184 pipe = (pipe & 0x0007);
defrost 5:57b06b4b47c6 185
defrost 5:57b06b4b47c6 186 //
defrost 5:57b06b4b47c6 187 // Check if max RT is reached
defrost 5:57b06b4b47c6 188 //
defrost 5:57b06b4b47c6 189 if (((status >>MAX_RT)& 01) ==1) {
epgmdm 18:be77ad141fac 190 if (flagStartFileTx==1) { // Locker not ready to reacieve - wait 25s.
epgmdm 18:be77ad141fac 191 flagHubNotReady = 1;
epgmdm 18:be77ad141fac 192 nrf->clearStatus();
epgmdm 18:be77ad141fac 193 flag = &flagDirFileName;
epgmdm 18:be77ad141fac 194 delay->detach();
epgmdm 18:be77ad141fac 195 delay->attach(this, &Battery::setFlag, 25.0f);
epgmdm 18:be77ad141fac 196 } else {
epgmdm 18:be77ad141fac 197 maxRT=true;
epgmdm 18:be77ad141fac 198 DBG("MAX RT flag is set. PTB20= %d status=%x",(unsigned int) *ce,status);
epgmdm 18:be77ad141fac 199 *ce = 0;
epgmdm 18:be77ad141fac 200 DBG("PTB20= %d status=%x",(unsigned int) *ce,status);
epgmdm 18:be77ad141fac 201 nrf->clearStatus();
epgmdm 18:be77ad141fac 202 *ledRed=0;
epgmdm 18:be77ad141fac 203 }
defrost 5:57b06b4b47c6 204 }
defrost 5:57b06b4b47c6 205
defrost 5:57b06b4b47c6 206 //
defrost 5:57b06b4b47c6 207 // Check if data received
defrost 5:57b06b4b47c6 208 //
defrost 5:57b06b4b47c6 209 if (((status >>RX_DR)& 01) ==1) { // Received a packet
defrost 5:57b06b4b47c6 210 width= nrf->getRxData(dataRx);
defrost 5:57b06b4b47c6 211 dataRx[width]='\0';
epgmdm 18:be77ad141fac 212 if (dataRx[0]!='S') {
defrost 5:57b06b4b47c6 213 DBG("intNrf>D[p=%1d]=<%2s> ",pipe,dataRx);
defrost 5:57b06b4b47c6 214 }
defrost 5:57b06b4b47c6 215 maxRT=false;
epgmdm 18:be77ad141fac 216 flagHubNotReady = 0;
defrost 5:57b06b4b47c6 217 *ce = 1;
defrost 5:57b06b4b47c6 218 nrf->clearStatus();
defrost 5:57b06b4b47c6 219 switch (dataRx[0]) {
epgmdm 18:be77ad141fac 220 case ('C'): {
epgmdm 18:be77ad141fac 221 doCheckIn();
epgmdm 18:be77ad141fac 222 flagNextFile = 1;
epgmdm 18:be77ad141fac 223 DBG("Flag Set");
epgmdm 18:be77ad141fac 224 break;
epgmdm 18:be77ad141fac 225 }
epgmdm 18:be77ad141fac 226 case ('D'): {
epgmdm 18:be77ad141fac 227 flagStartFileTx=0; // Hub commmunicating.
epgmdm 18:be77ad141fac 228 flag = &flagSendFileName;
epgmdm 18:be77ad141fac 229 delay->detach();
epgmdm 18:be77ad141fac 230 delay->attach(this, &Battery::setFlag, 1.5);
epgmdm 18:be77ad141fac 231 break;
epgmdm 18:be77ad141fac 232 }
epgmdm 18:be77ad141fac 233 case ('F'): {
epgmdm 18:be77ad141fac 234 flag = &flagSendFileSize;
epgmdm 18:be77ad141fac 235 countSD = 0;
epgmdm 18:be77ad141fac 236 delay->detach();
epgmdm 18:be77ad141fac 237 delay->attach(this, &Battery::setFlag, 1.50);
epgmdm 18:be77ad141fac 238 break;
epgmdm 18:be77ad141fac 239 }
epgmdm 18:be77ad141fac 240 case ('O'): {
epgmdm 18:be77ad141fac 241 doCheckOut();
epgmdm 18:be77ad141fac 242 break;
epgmdm 18:be77ad141fac 243 }
epgmdm 18:be77ad141fac 244 case ('S'): {
epgmdm 18:be77ad141fac 245 flag = &flagSendFile;
epgmdm 18:be77ad141fac 246 delay->detach();
epgmdm 18:be77ad141fac 247 // printf("%d\n\r",countSD%16);
epgmdm 18:be77ad141fac 248 //delay->attach(this, &Battery::setFlag, 0.05);
defrost 5:57b06b4b47c6 249
epgmdm 18:be77ad141fac 250 if (countSD % (SDBUFFERSIZE/32) == 0) {
epgmdm 18:be77ad141fac 251 delay->attach(this, &Battery::setFlag, 1.5); // wait to write to SD card
epgmdm 18:be77ad141fac 252 } else {
epgmdm 18:be77ad141fac 253 delay->attach_us(this, &Battery::setFlag, 800);
epgmdm 18:be77ad141fac 254 }
epgmdm 18:be77ad141fac 255 countSD++;
epgmdm 18:be77ad141fac 256 break;
defrost 5:57b06b4b47c6 257 }
epgmdm 18:be77ad141fac 258 case ('T'): {
epgmdm 18:be77ad141fac 259 time_t now;
epgmdm 18:be77ad141fac 260 sscanf (&dataRx[2],"%x",&now );
epgmdm 18:be77ad141fac 261 set_time(now);
epgmdm 18:be77ad141fac 262 now= time(NULL);
epgmdm 18:be77ad141fac 263 struct tm * timeInf = localtime(&now);
epgmdm 18:be77ad141fac 264 DBG ("Time is now: %04d-%02d-%02d %02d:%02d:%02d \n\r",timeInf->tm_year+1900,timeInf->tm_mon+1,timeInf->tm_mday,timeInf->tm_hour, timeInf->tm_min,timeInf->tm_sec);
defrost 5:57b06b4b47c6 265
epgmdm 18:be77ad141fac 266 break;
epgmdm 18:be77ad141fac 267 }
defrost 5:57b06b4b47c6 268
epgmdm 12:d9b13f31206d 269
epgmdm 18:be77ad141fac 270 case ('M'): {
epgmdm 18:be77ad141fac 271 time_t now;
epgmdm 18:be77ad141fac 272 sscanf (&dataRx[2],"%f",&maxChargeRate );
epgmdm 18:be77ad141fac 273 if(maxChargeRate>2.0f) {
epgmdm 18:be77ad141fac 274 maxChargeRate=2.0f;
epgmdm 18:be77ad141fac 275 }
epgmdm 18:be77ad141fac 276 if (maxChargeRate<0.0f) {
epgmdm 18:be77ad141fac 277 maxChargeRate=0.0f;
epgmdm 18:be77ad141fac 278 }
epgmdm 18:be77ad141fac 279 DBG ("Max charge %f \n\r",maxChargeRate);
epgmdm 18:be77ad141fac 280
epgmdm 18:be77ad141fac 281 break;
epgmdm 12:d9b13f31206d 282 }
defrost 5:57b06b4b47c6 283 }
epgmdm 12:d9b13f31206d 284
defrost 5:57b06b4b47c6 285 }
epgmdm 12:d9b13f31206d 286
defrost 5:57b06b4b47c6 287 if (((status >>TX_DS)& 01) ==1) {
defrost 5:57b06b4b47c6 288 // maxRT=false;
defrost 5:57b06b4b47c6 289 nrf->flushTx();
defrost 5:57b06b4b47c6 290 nrf->flushRx();
defrost 5:57b06b4b47c6 291 //DBG(" TX_DS");
defrost 5:57b06b4b47c6 292 }
defrost 5:57b06b4b47c6 293
defrost 5:57b06b4b47c6 294 *ledBlue = !*ledBlue;
defrost 5:57b06b4b47c6 295 *ledRed = !maxRT;
defrost 5:57b06b4b47c6 296 }
defrost 5:57b06b4b47c6 297
defrost 5:57b06b4b47c6 298 /**
defrost 5:57b06b4b47c6 299 * Transmits the data and sets up a call back to check data sent 30s later.
defrost 5:57b06b4b47c6 300 */
defrost 5:57b06b4b47c6 301
defrost 5:57b06b4b47c6 302 /**
defrost 5:57b06b4b47c6 303 * Checks to see if transmit failed and then retransmit
defrost 5:57b06b4b47c6 304 *
defrost 5:57b06b4b47c6 305 */
epgmdm 18:be77ad141fac 306 void Battery::retransmit()
epgmdm 18:be77ad141fac 307 {
defrost 5:57b06b4b47c6 308
defrost 5:57b06b4b47c6 309 if (maxRT) {
defrost 5:57b06b4b47c6 310 DBG("Retransmit");
defrost 5:57b06b4b47c6 311 *ledRed=1;
defrost 5:57b06b4b47c6 312 *ce = 1;
defrost 5:57b06b4b47c6 313 maxRT=false;
defrost 5:57b06b4b47c6 314 nrf->clearStatus();
defrost 5:57b06b4b47c6 315 nrf->flushRx();
defrost 5:57b06b4b47c6 316 nrf->retransmitData();
defrost 5:57b06b4b47c6 317 }
epgmdm 18:be77ad141fac 318 if ((!sendingFile)&&(checkedIn == 1)) {
epgmdm 12:d9b13f31206d 319 flagGetTime=1;
epgmdm 12:d9b13f31206d 320 flagGetMaxCharge=1;
epgmdm 12:d9b13f31206d 321 }
defrost 5:57b06b4b47c6 322 }
defrost 5:57b06b4b47c6 323
defrost 5:57b06b4b47c6 324 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 325 // Main routines
defrost 5:57b06b4b47c6 326 // ------------------------------------------------------------------------
defrost 5:57b06b4b47c6 327
defrost 5:57b06b4b47c6 328 /**
defrost 5:57b06b4b47c6 329 * Checks in the Battery to the locker
defrost 5:57b06b4b47c6 330 * Transmits "C ID"
defrost 5:57b06b4b47c6 331 *
defrost 5:57b06b4b47c6 332 */
epgmdm 18:be77ad141fac 333 void Battery::checkIn()
epgmdm 18:be77ad141fac 334 {
defrost 5:57b06b4b47c6 335 sprintf(dataTx, "C %04X", (int) (id&0XFFFF));
defrost 5:57b06b4b47c6 336 DBG("Check into locker [%s]", dataTx);
epgmdm 11:87ab310924f0 337 spiNRF();
defrost 5:57b06b4b47c6 338 nrf->transmitData(dataTx, strlen(dataTx));
defrost 5:57b06b4b47c6 339 }
defrost 5:57b06b4b47c6 340
epgmdm 18:be77ad141fac 341
epgmdm 18:be77ad141fac 342 /**
epgmdm 18:be77ad141fac 343 * Checks out. Sends O %d, ID to locker
epgmdm 18:be77ad141fac 344 *
epgmdm 18:be77ad141fac 345 */
epgmdm 18:be77ad141fac 346 void Battery::checkOut()
epgmdm 18:be77ad141fac 347 {
epgmdm 18:be77ad141fac 348 sprintf(dataTx, "O %04X", (int) (id&0XFFFF));
epgmdm 18:be77ad141fac 349 DBG("Check out locker [%s]", dataTx);
epgmdm 18:be77ad141fac 350 spiNRF();
epgmdm 18:be77ad141fac 351 nrf->transmitData(dataTx, strlen(dataTx));
epgmdm 18:be77ad141fac 352 // Reset to locker public comms channel
epgmdm 18:be77ad141fac 353 }
epgmdm 18:be77ad141fac 354
epgmdm 18:be77ad141fac 355
defrost 5:57b06b4b47c6 356 /**
defrost 5:57b06b4b47c6 357 * Checks in the Battery to the locker
defrost 5:57b06b4b47c6 358 * Acknowledge received.
defrost 5:57b06b4b47c6 359 * Changes the TX pipe address.
defrost 5:57b06b4b47c6 360 *
defrost 5:57b06b4b47c6 361 */
epgmdm 18:be77ad141fac 362 void Battery::doCheckIn()
epgmdm 18:be77ad141fac 363 {
defrost 5:57b06b4b47c6 364 nrf->setTxAddress(privateAddr);
defrost 5:57b06b4b47c6 365 checkedIn = 1;
defrost 5:57b06b4b47c6 366 DBG("Checked into locker");
defrost 5:57b06b4b47c6 367 DBG("Nrf Details:");
defrost 5:57b06b4b47c6 368 #ifdef DEBUG
defrost 5:57b06b4b47c6 369 nrf->printDetails();
defrost 5:57b06b4b47c6 370 #endif
defrost 5:57b06b4b47c6 371 }
defrost 5:57b06b4b47c6 372 /**
defrost 5:57b06b4b47c6 373 * Checks in the Battery to the locker
defrost 5:57b06b4b47c6 374 * Acknowledge received.
defrost 5:57b06b4b47c6 375 * Changes the TX pipe address.
defrost 5:57b06b4b47c6 376 *
defrost 5:57b06b4b47c6 377 */
epgmdm 18:be77ad141fac 378 void Battery::doCheckOut()
epgmdm 18:be77ad141fac 379 {
defrost 5:57b06b4b47c6 380 nrf->setTxAddress(openAddr);
defrost 5:57b06b4b47c6 381 checkedIn = 0;
defrost 5:57b06b4b47c6 382 DBG("Checked out of locker");
defrost 5:57b06b4b47c6 383 DBG("Nrf Details:");
defrost 5:57b06b4b47c6 384 #ifdef DEBUG
defrost 5:57b06b4b47c6 385 nrf->printDetails();
defrost 5:57b06b4b47c6 386 #endif
defrost 5:57b06b4b47c6 387 }
defrost 5:57b06b4b47c6 388
defrost 5:57b06b4b47c6 389 /**
defrost 5:57b06b4b47c6 390 * Slow routines for Battery
defrost 5:57b06b4b47c6 391 */
epgmdm 18:be77ad141fac 392 void Battery::loop()
epgmdm 18:be77ad141fac 393 {
epgmdm 12:d9b13f31206d 394
epgmdm 12:d9b13f31206d 395 *ledGreen = !checkedIn;
epgmdm 18:be77ad141fac 396
defrost 5:57b06b4b47c6 397
epgmdm 12:d9b13f31206d 398 if (flagGetTime) {
epgmdm 12:d9b13f31206d 399 flagGetTime=0;
epgmdm 12:d9b13f31206d 400 requestTime();
epgmdm 12:d9b13f31206d 401
epgmdm 12:d9b13f31206d 402 }
epgmdm 12:d9b13f31206d 403 if (flagGetMaxCharge) {
epgmdm 12:d9b13f31206d 404 flagGetMaxCharge=0;
epgmdm 12:d9b13f31206d 405 requestMaxCharge();
defrost 5:57b06b4b47c6 406
epgmdm 12:d9b13f31206d 407 }
epgmdm 12:d9b13f31206d 408 if (flagNextFile) {
epgmdm 12:d9b13f31206d 409 flagNextFile = 0;
defrost 13:de43f28c0365 410 DBG("NextFile called");
epgmdm 12:d9b13f31206d 411 requestTime();
epgmdm 12:d9b13f31206d 412 nextFileToTx();
epgmdm 18:be77ad141fac 413 if (fileLength>0) {
epgmdm 12:d9b13f31206d 414 INFO("Sending file %s.",txFileName)
epgmdm 18:be77ad141fac 415 flagDirFileName=1;
epgmdm 12:d9b13f31206d 416 } else {
epgmdm 12:d9b13f31206d 417 sendingFile=0;
epgmdm 18:be77ad141fac 418 flagStartFileTx=0;
epgmdm 12:d9b13f31206d 419 INFO("No more files to send.")
epgmdm 18:be77ad141fac 420 checkOut();
defrost 5:57b06b4b47c6 421 }
epgmdm 12:d9b13f31206d 422 }
epgmdm 18:be77ad141fac 423 if (flagDirFileName) {
epgmdm 18:be77ad141fac 424 flagDirFileName=0;
epgmdm 18:be77ad141fac 425 sendDirName();
epgmdm 18:be77ad141fac 426 }
epgmdm 12:d9b13f31206d 427 if (flagSendFileName) {
epgmdm 12:d9b13f31206d 428 flagSendFileName = 0;
epgmdm 12:d9b13f31206d 429 sendFileName();
defrost 5:57b06b4b47c6 430
epgmdm 12:d9b13f31206d 431 }
epgmdm 12:d9b13f31206d 432 if (flagSendFileSize) {
epgmdm 12:d9b13f31206d 433 flagSendFileSize = 0;
epgmdm 12:d9b13f31206d 434 sendFileSize();
epgmdm 12:d9b13f31206d 435 }
epgmdm 12:d9b13f31206d 436 if (flagSendFile) {
epgmdm 12:d9b13f31206d 437 flagSendFile = 0;
epgmdm 12:d9b13f31206d 438 sendFile();
defrost 5:57b06b4b47c6 439 }
epgmdm 12:d9b13f31206d 440 if (flagSendFileDone) {
epgmdm 12:d9b13f31206d 441 flagSendFileDone = 0;
epgmdm 12:d9b13f31206d 442 sendFileDone();
epgmdm 12:d9b13f31206d 443 INFO("File sent <%s>",txFileName);
epgmdm 12:d9b13f31206d 444 flag = &flagNextFile;
epgmdm 12:d9b13f31206d 445 delay->detach();
epgmdm 12:d9b13f31206d 446 delay->attach(this, &Battery::setFlag, 2.5);
epgmdm 12:d9b13f31206d 447 }
epgmdm 18:be77ad141fac 448 if (flagCheckOut) {
epgmdm 18:be77ad141fac 449 flagCheckOut=0;
epgmdm 18:be77ad141fac 450 doCheckOut();
epgmdm 18:be77ad141fac 451 }
epgmdm 12:d9b13f31206d 452
defrost 5:57b06b4b47c6 453 }
defrost 5:57b06b4b47c6 454
defrost 5:57b06b4b47c6 455 /**
defrost 5:57b06b4b47c6 456 * sends a request for time update.
defrost 5:57b06b4b47c6 457 */
epgmdm 18:be77ad141fac 458 void Battery::requestTime()
epgmdm 18:be77ad141fac 459 {
defrost 5:57b06b4b47c6 460 DBG("getTime");
defrost 5:57b06b4b47c6 461 nrf->transmitData("T ",2);
defrost 5:57b06b4b47c6 462 }
epgmdm 12:d9b13f31206d 463
epgmdm 12:d9b13f31206d 464 /**
epgmdm 12:d9b13f31206d 465 * sends a request for time update.
epgmdm 12:d9b13f31206d 466 */
epgmdm 18:be77ad141fac 467 void Battery::requestMaxCharge()
epgmdm 18:be77ad141fac 468 {
epgmdm 12:d9b13f31206d 469 DBG("getTime");
epgmdm 12:d9b13f31206d 470 nrf->transmitData("M ",2);
epgmdm 12:d9b13f31206d 471 }
defrost 5:57b06b4b47c6 472 /**
defrost 5:57b06b4b47c6 473 * Selects the next file to transmit
defrost 5:57b06b4b47c6 474 * Uses /sd/lastFileTx.txt to store the lst file transmitted
defrost 5:57b06b4b47c6 475 */
epgmdm 18:be77ad141fac 476 void Battery::nextFileToTx()
epgmdm 18:be77ad141fac 477 {
defrost 5:57b06b4b47c6 478
defrost 5:57b06b4b47c6 479 DBG("> nextTxFile");
defrost 5:57b06b4b47c6 480
defrost 5:57b06b4b47c6 481 char lastFileName[64];
defrost 5:57b06b4b47c6 482 char fileName[64];
defrost 5:57b06b4b47c6 483 char fn[40];
defrost 5:57b06b4b47c6 484 unsigned int txLength;
defrost 5:57b06b4b47c6 485
defrost 5:57b06b4b47c6 486 sdBuffPnt=0;// Tells sendFile to read from SD the first time.
defrost 5:57b06b4b47c6 487 fileLength = 0;
defrost 5:57b06b4b47c6 488 strcpy(txFileName, "");
defrost 5:57b06b4b47c6 489 spiSD();
defrost 5:57b06b4b47c6 490 // Read in last file name
defrost 5:57b06b4b47c6 491 FILE *fp = fopen("/sd/lastFileTx.txt", "r");
defrost 5:57b06b4b47c6 492 if (fp != NULL) {
defrost 5:57b06b4b47c6 493 if (fscanf(fp, "%s %u", lastFileName, &txLength) != 2) {
defrost 5:57b06b4b47c6 494 sprintf(lastFileName, "a");
defrost 5:57b06b4b47c6 495 }
defrost 5:57b06b4b47c6 496 fclose(fp);
defrost 5:57b06b4b47c6 497 } else {
defrost 5:57b06b4b47c6 498 sprintf(lastFileName, "a");
defrost 5:57b06b4b47c6 499 }
defrost 5:57b06b4b47c6 500 DBG("nextFileToTx>Last Filename=%s len=%u",lastFileName,txLength);
defrost 5:57b06b4b47c6 501 // Open directory and read files
defrost 5:57b06b4b47c6 502 DIR *dp;
defrost 5:57b06b4b47c6 503 struct dirent *dirp;
defrost 5:57b06b4b47c6 504 spiSD();
defrost 5:57b06b4b47c6 505 dp = opendir(logDir);
defrost 5:57b06b4b47c6 506 if (dp == NULL) {
defrost 5:57b06b4b47c6 507 DBG("nextTxFile logdir %s is NULL", logDir);
defrost 5:57b06b4b47c6 508 } else
defrost 5:57b06b4b47c6 509 //read all directory and file names in current directory into filename vector
defrost 5:57b06b4b47c6 510 while ((dirp = readdir(dp)) != NULL) {
defrost 5:57b06b4b47c6 511 DBG("nextFileToTx> WHILE lst [%s] dir [%s] %d",lastFileName, dirp->d_name,strcmp(lastFileName, dirp->d_name));
defrost 5:57b06b4b47c6 512
defrost 5:57b06b4b47c6 513 if (strcmp(lastFileName, dirp->d_name) < 0) {
defrost 5:57b06b4b47c6 514 strcpy(fileName, dirp->d_name);
defrost 5:57b06b4b47c6 515 sprintf(txFileName, "%s/%s", logDir, dirp->d_name);
defrost 5:57b06b4b47c6 516 fp = fopen(txFileName, "r");
defrost 5:57b06b4b47c6 517 fseek(fp, 0L, SEEK_END);
defrost 5:57b06b4b47c6 518 fileLength = ftell(fp);
defrost 5:57b06b4b47c6 519 fclose(fp);
defrost 5:57b06b4b47c6 520 DBG("CHOSEN %s old %s ", fileName, lastFileName );
defrost 5:57b06b4b47c6 521 break;
defrost 5:57b06b4b47c6 522 }
defrost 5:57b06b4b47c6 523 if (strcmp(lastFileName, dirp->d_name) == 0) {
defrost 5:57b06b4b47c6 524
defrost 5:57b06b4b47c6 525 strcpy(fileName, dirp->d_name);
defrost 5:57b06b4b47c6 526 sprintf(fn, "%s/%s", logDir, dirp->d_name);
defrost 5:57b06b4b47c6 527 fp = fopen(fn, "r");
defrost 5:57b06b4b47c6 528 fseek(fp, 0L, SEEK_END);
defrost 5:57b06b4b47c6 529 fileLength = ftell(fp);
defrost 5:57b06b4b47c6 530 fclose(fp);
defrost 5:57b06b4b47c6 531 if (txLength < fileLength) {
defrost 5:57b06b4b47c6 532 sprintf(txFileName, "%s/%s", logDir, dirp->d_name);
defrost 5:57b06b4b47c6 533 DBG("More to send is %s old %u new %u ", fileName, txLength,fileLength );
defrost 5:57b06b4b47c6 534 break;
defrost 5:57b06b4b47c6 535 }
defrost 5:57b06b4b47c6 536 }
defrost 5:57b06b4b47c6 537 // test filename and if greater than last read then choose.
defrost 5:57b06b4b47c6 538 }
defrost 5:57b06b4b47c6 539 closedir(dp);
defrost 5:57b06b4b47c6 540 if (strlen(txFileName) > 0) {
defrost 5:57b06b4b47c6 541 strcpy(txFileName, fileName);
defrost 5:57b06b4b47c6 542 sprintf(fullTxFilePath, "%s/%s", logDir, txFileName);
defrost 5:57b06b4b47c6 543 fileLeft = fileLength;
defrost 5:57b06b4b47c6 544
defrost 5:57b06b4b47c6 545 } else {
defrost 5:57b06b4b47c6 546 fileLength =0;
defrost 5:57b06b4b47c6 547 }
defrost 5:57b06b4b47c6 548 DBG("nextTxFile> Next is [%s] length %d", txFileName, fileLength);
defrost 5:57b06b4b47c6 549
defrost 5:57b06b4b47c6 550 }
epgmdm 18:be77ad141fac 551
defrost 5:57b06b4b47c6 552 /**
defrost 5:57b06b4b47c6 553 * Sends the directory name, allows the otherside to create.
defrost 5:57b06b4b47c6 554 */
defrost 5:57b06b4b47c6 555
epgmdm 18:be77ad141fac 556 void Battery::sendDirName()
epgmdm 18:be77ad141fac 557 {
epgmdm 18:be77ad141fac 558 flagStartFileTx=1;
defrost 5:57b06b4b47c6 559 sprintf(dataTx, "D %s", logDir);
defrost 5:57b06b4b47c6 560
defrost 5:57b06b4b47c6 561 DBG("send Dir Name [%s].\n\r", dataTx);
defrost 5:57b06b4b47c6 562
epgmdm 11:87ab310924f0 563 spiNRF();
defrost 5:57b06b4b47c6 564 nrf->transmitData(dataTx, strlen(dataTx));
defrost 5:57b06b4b47c6 565
defrost 5:57b06b4b47c6 566 }
defrost 5:57b06b4b47c6 567 /**
defrost 5:57b06b4b47c6 568 * Sends the file name, if fileLength >0
defrost 5:57b06b4b47c6 569 */
defrost 5:57b06b4b47c6 570
epgmdm 18:be77ad141fac 571 void Battery::sendFileName()
epgmdm 18:be77ad141fac 572 {
defrost 5:57b06b4b47c6 573 // delay->detach();
defrost 5:57b06b4b47c6 574 if (fileLength < 1) {
defrost 5:57b06b4b47c6 575 return;
defrost 5:57b06b4b47c6 576 }
defrost 5:57b06b4b47c6 577 sprintf(dataTx, "F %20s", txFileName);
defrost 5:57b06b4b47c6 578
defrost 5:57b06b4b47c6 579 DBG("send File Name [%s] \n\r", dataTx);
defrost 5:57b06b4b47c6 580
epgmdm 11:87ab310924f0 581 spiNRF();
defrost 5:57b06b4b47c6 582 nrf->transmitData(dataTx, strlen(dataTx));
defrost 5:57b06b4b47c6 583 }
defrost 5:57b06b4b47c6 584
defrost 5:57b06b4b47c6 585 /**
defrost 5:57b06b4b47c6 586 * Sends the file length to the locker - this is also the cue that the following bytes are the file.
defrost 5:57b06b4b47c6 587 */
epgmdm 18:be77ad141fac 588 void Battery::sendFileSize()
epgmdm 18:be77ad141fac 589 {
defrost 5:57b06b4b47c6 590 if (fileLength < 1) {
defrost 5:57b06b4b47c6 591 return;
defrost 5:57b06b4b47c6 592 }
epgmdm 12:d9b13f31206d 593 sendingFile=1;
defrost 5:57b06b4b47c6 594 filePointer = 0;
defrost 5:57b06b4b47c6 595 sprintf(dataTx, "S %X", fileLength);
defrost 5:57b06b4b47c6 596
defrost 5:57b06b4b47c6 597
defrost 5:57b06b4b47c6 598 DBG("send File size [%s]", dataTx);
defrost 5:57b06b4b47c6 599
epgmdm 11:87ab310924f0 600 spiNRF();
defrost 5:57b06b4b47c6 601 nrf->transmitData(dataTx, strlen(dataTx));
defrost 5:57b06b4b47c6 602 }
defrost 5:57b06b4b47c6 603
defrost 5:57b06b4b47c6 604 /**
defrost 5:57b06b4b47c6 605 * Sends the file length to the locker - this is also the cue that the following bytes are the file.
defrost 5:57b06b4b47c6 606 */
epgmdm 18:be77ad141fac 607 void Battery::sendFile()
epgmdm 18:be77ad141fac 608 {
defrost 5:57b06b4b47c6 609
defrost 5:57b06b4b47c6 610 // printf("send File [%s] at %d %d\n\r",fullTxFilePath,fileLength, fileLeft );
defrost 5:57b06b4b47c6 611
epgmdm 11:87ab310924f0 612 // if (fileLength < 1) {
epgmdm 11:87ab310924f0 613 // INFO("File Sent");
epgmdm 11:87ab310924f0 614 // sdBuffPnt=0;
epgmdm 11:87ab310924f0 615 // return;
epgmdm 11:87ab310924f0 616 // }
epgmdm 18:be77ad141fac 617 if (sdBuffPnt>=SDBUFFERSIZE) {
defrost 5:57b06b4b47c6 618 sdBuffPnt=0;
defrost 5:57b06b4b47c6 619 }
defrost 5:57b06b4b47c6 620 if (sdBuffPnt == 0) {
defrost 5:57b06b4b47c6 621 spiSD();
defrost 5:57b06b4b47c6 622 FILE *fp = fopen(fullTxFilePath, "rb");
defrost 5:57b06b4b47c6 623 if (fp == NULL) {
epgmdm 11:87ab310924f0 624 spiNRF();
defrost 5:57b06b4b47c6 625 INFO("sendFile> File %s not found for reading",fullTxFilePath);
defrost 5:57b06b4b47c6 626 return;
defrost 5:57b06b4b47c6 627 }
defrost 5:57b06b4b47c6 628 spiSD();
defrost 5:57b06b4b47c6 629 fseek(fp, fileLength - fileLeft, SEEK_SET);
defrost 5:57b06b4b47c6 630 sizeRead = fread(sdBuffer, 1,SDBUFFERSIZE, fp);
defrost 5:57b06b4b47c6 631 fileLeft -= sizeRead;
defrost 5:57b06b4b47c6 632 fclose(fp);
defrost 5:57b06b4b47c6 633 // printf("File %s %d \n\r",fullTxFilePath,sizeRead);
epgmdm 11:87ab310924f0 634 spiNRF();
defrost 5:57b06b4b47c6 635
defrost 5:57b06b4b47c6 636 }
defrost 5:57b06b4b47c6 637
defrost 5:57b06b4b47c6 638 if ((count++) % 256 ==0) {
defrost 5:57b06b4b47c6 639 DBG("W %d %d", fileLeft, sizeRead);
defrost 5:57b06b4b47c6 640 }
defrost 5:57b06b4b47c6 641 int size=32;
epgmdm 18:be77ad141fac 642 if (sizeRead<32) {
defrost 5:57b06b4b47c6 643 size=sizeRead;
defrost 5:57b06b4b47c6 644 }
epgmdm 18:be77ad141fac 645 if ((fileLeft==0)&&(sizeRead==0)) {
defrost 5:57b06b4b47c6 646 sdBuffPnt=0;
defrost 5:57b06b4b47c6 647 flagSendFileDone=1;
defrost 5:57b06b4b47c6 648 DBG("Done sending");
defrost 17:dc19b3b39790 649 startCharge = true;
epgmdm 18:be77ad141fac 650 } else {
defrost 5:57b06b4b47c6 651 sizeRead -= size;
defrost 5:57b06b4b47c6 652 nrf->transmitData(&(sdBuffer[sdBuffPnt]), size);
defrost 5:57b06b4b47c6 653 sdBuffPnt+=size;
defrost 5:57b06b4b47c6 654 }
defrost 5:57b06b4b47c6 655
defrost 5:57b06b4b47c6 656
defrost 5:57b06b4b47c6 657 }
defrost 5:57b06b4b47c6 658
defrost 5:57b06b4b47c6 659 /**
defrost 5:57b06b4b47c6 660 * Update the last file sent file
defrost 5:57b06b4b47c6 661 */
epgmdm 18:be77ad141fac 662 void Battery::sendFileDone()
epgmdm 18:be77ad141fac 663 {
epgmdm 18:be77ad141fac 664 if (strlen(txFileName)>0) {
defrost 5:57b06b4b47c6 665 spiSD();
defrost 5:57b06b4b47c6 666 FILE *fp = fopen("/sd/lastFileTx.txt", "w");
defrost 5:57b06b4b47c6 667 if (fp != NULL) {
defrost 5:57b06b4b47c6 668 fprintf(fp, "%s %u \n", txFileName, fileLength);
defrost 5:57b06b4b47c6 669 fclose(fp);
defrost 5:57b06b4b47c6 670 DBG("sendFileDone> updated lastFileTx.txt %s %u ", txFileName, fileLength);
epgmdm 18:be77ad141fac 671 } else {
defrost 5:57b06b4b47c6 672 INFO("sendFileDone> Cannot update file lastFiletx.txt");
defrost 5:57b06b4b47c6 673 }
epgmdm 11:87ab310924f0 674 spiNRF();
defrost 5:57b06b4b47c6 675
defrost 5:57b06b4b47c6 676 }
defrost 5:57b06b4b47c6 677
defrost 5:57b06b4b47c6 678 }
defrost 5:57b06b4b47c6 679
defrost 5:57b06b4b47c6 680 /**
defrost 5:57b06b4b47c6 681 * Sets the value pointed to by flag to 1.
defrost 5:57b06b4b47c6 682 */
epgmdm 18:be77ad141fac 683 void Battery::setFlag()
epgmdm 18:be77ad141fac 684 {
defrost 5:57b06b4b47c6 685 if (flag != NULL) {
defrost 5:57b06b4b47c6 686 *flag = 1;
defrost 5:57b06b4b47c6 687 }
defrost 5:57b06b4b47c6 688 flag = NULL;
defrost 5:57b06b4b47c6 689 }
epgmdm 12:d9b13f31206d 690
epgmdm 12:d9b13f31206d 691
epgmdm 12:d9b13f31206d 692 /**
epgmdm 12:d9b13f31206d 693 * Returns the max current that can be drawn from the system, in amps
epgmdm 12:d9b13f31206d 694 */
epgmdm 12:d9b13f31206d 695
epgmdm 18:be77ad141fac 696 float Battery::getMaxCurrent()
epgmdm 18:be77ad141fac 697 {
epgmdm 12:d9b13f31206d 698 return maxChargeRate;
epgmdm 12:d9b13f31206d 699 }
epgmdm 12:d9b13f31206d 700
epgmdm 12:d9b13f31206d 701 /**
epgmdm 12:d9b13f31206d 702 * returns a string of the log directory
epgmdm 12:d9b13f31206d 703 */
epgmdm 18:be77ad141fac 704 char* Battery::getLogDirectory()
epgmdm 18:be77ad141fac 705 {
epgmdm 12:d9b13f31206d 706
epgmdm 12:d9b13f31206d 707 return logDir;
epgmdm 12:d9b13f31206d 708 }
defrost 17:dc19b3b39790 709
defrost 17:dc19b3b39790 710 /**
defrost 17:dc19b3b39790 711 * Returns true if we are authorized to start charging.
defrost 17:dc19b3b39790 712 */
epgmdm 18:be77ad141fac 713 bool Battery::startCharging(void)
epgmdm 18:be77ad141fac 714 {
defrost 17:dc19b3b39790 715 return startCharge;
defrost 17:dc19b3b39790 716 }
defrost 17:dc19b3b39790 717
epgmdm 18:be77ad141fac 718 bool Battery::isCheckedIn(void)
epgmdm 18:be77ad141fac 719 {
epgmdm 18:be77ad141fac 720 if(checkedIn == 1) {
defrost 17:dc19b3b39790 721 return true;
epgmdm 18:be77ad141fac 722 } else {
defrost 17:dc19b3b39790 723 return false;
defrost 17:dc19b3b39790 724 }
defrost 17:dc19b3b39790 725 }