The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
Diff: Battery/Battery.h
- Revision:
- 5:57b06b4b47c6
- Child:
- 8:0acda4f2e0a8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Battery/Battery.h Thu Jun 02 16:41:40 2016 +0000 @@ -0,0 +1,175 @@ +/** + *@section DESCRIPTION + * mbed SolarNanogrid Battery. + *@section LICENSE + * Copyright (c) 2016, Malcolm McCulloch + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * @file "Battery.h" + */ + +#ifndef BATTERY_H +#define BATTERY_H +#include <mbed.h> +#include "NRF2401P.h" +#include "nRF24l01.h" +#include "SDFileSystem.h" +#include "SolarNanoGrid.h" +#define FUNCNAME "BATTERY" +#include "defs.h" +/** \brief The battery logs data and interacts with the locker. + * + * The config.ini must start with B + * + */ +class Battery : public SolarNanoGrid +{ +public: + // ********************* + // * Public variables: * + // ********************* + char* logDir=NULL; + float maxChargeRate=0.0; // Charge rate in amps + + // ********************* + // * Public functions: * + // ********************* + + // Constructor: + Battery(FILE* fp); + + // Main loop function: + void loop(void); + /** + * Checks in the battery to the locker + * Transmits "C ID" + */ + void checkIn(); + + +protected: + // ********************** + // * Protected variables: * + // ********************** + /** + * Name of log directory, include last / + */ + + char count=0; + char* txFileName=NULL; + + char* fullTxFilePath=NULL; + + int sizeRead=0; + unsigned int fileLength=0; + unsigned int filePointer=0; + unsigned int fileLeft=0; + char *sdBuffer=NULL; + unsigned int sdBuffPnt=0; + /** + * Open channel address of the locker + */ + long long openAddr=0; + + /** + * Private channel address of the locker + */ + long long privateAddr=0; + + unsigned int countSD=0; + + // ********************** + // * Protected flags: * + // ********************** + volatile char * flag=NULL; + volatile char checkedIn=0; + volatile char flagGetTime=0; + volatile char flagNextFile=0; + volatile char flagSendFileName=0; + volatile char flagSendFileSize=0; + volatile char flagSendFile=0; + volatile char flagSendFileDone=0; + + + // ********************** + // * Protected interrupts: * + // ********************** + InterruptIn* button=NULL; + Ticker* txWatch=NULL; + Timeout* delay=NULL; + + // ********************** + // * Protected functions: * + // ********************** + /** + * Checks in the battery to the locker + * Acknowledge received. + * Changes the TX pipe address to private + * + */ + void doCheckIn(); + /** + * Checks out the battery from the locker + * Acknowledge received. + * Changes the TX pipe address to open + * + */ + void doCheckOut(); + /** + * sends a request for time update. + */ + void getTime(); + /** + * Sets the value pointed to by flag to 1. + */ + + void nextFileToTx(); + void sendDirName(); + void sendFileName(); + void sendFileSize(); + void sendFile(); + void sendFileDone(); + void setFlag(); + /** + * Retransmits the last data. + * + */ + void retransmit(); + + + /** + * called when the nrf the button is pressed + * + */ + void intButton(); + /** + * called when the nrf creates an interrupt. + * + */ + void intNrf(); + +private: + // ********************** + // * Private variables: * + // ********************** + + volatile bool maxRT=false; + +}; +#endif