The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Battery/Battery.h

Committer:
adrienBiz
Date:
2016-06-03
Revision:
8:0acda4f2e0a8
Parent:
5:57b06b4b47c6
Child:
10:30c9e8df0032

File content as of revision 8:0acda4f2e0a8:

/**
 *@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;
    float maxChargeRate; // 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;
    char* txFileName;

    char* fullTxFilePath;

    int sizeRead;
    unsigned int fileLength;
    unsigned int filePointer;
    unsigned int fileLeft;
    char *sdBuffer;
    unsigned int sdBuffPnt;
    /**
     * Open channel address of the locker
     */
    long long openAddr;

    /**
     * Private channel address of the locker
     */
    long long privateAddr;

    unsigned int countSD;

    // **********************
    // * Protected flags: *
    // **********************
    volatile char * flag;
    volatile char checkedIn;
    volatile char flagGetTime;
    volatile char flagNextFile;
    volatile char flagSendFileName;
    volatile char flagSendFileSize;
    volatile char flagSendFile;
    volatile char flagSendFileDone;


    // **********************
    // * Protected interrupts: *
    // **********************
    InterruptIn* button;
    Ticker* txWatch;
    Timeout* delay;

    // **********************
    // * 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;

};
#endif