The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Locker/Locker.h

Committer:
defrost
Date:
2016-06-03
Revision:
10:30c9e8df0032
Parent:
9:541c2ae1cfec
Child:
11:87ab310924f0

File content as of revision 10:30c9e8df0032:

/**
 *@section DESCRIPTION
 * mbed SolarNanogrid  Library
 * Locker extends SolarNanoGrid.
 * Locker interacts with the batteries.
 * The ID must end in 00.
 *@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 "Locker.h"
 */

#ifndef LOCKER_H
#define LOCKER_H
#include <mbed.h>
#include "NRF2401P.h"
#include "nRF24l01.h"
#include "SDFileSystem.h"
#include "SolarNanoGrid.h"


// Battery states
#define CHECKED_OUT 0
#define CHECKED_IN 1
#define ON_AIR 2
#define SENDING 3


/** \brief Locker interacts with the batteries.
 *
 *  The config.ini must start with L
 *   This library contains the code to drive batteries, hub etc.
 */
class Locker : public SolarNanoGrid
{
public:

    // *********************
    // * Public variables: *
    // *********************


    // *********************
    // * Public functions: *
    // *********************

    // Constructor:
    Locker(FILE* fp);

    // Main loop function:
    void loop(void);



protected:
    // *********************
    // * Protected hardware: *
    // *********************


    // *********************
    // * Protected interrupts: *
    // *********************

    InterruptIn* button;
    Ticker* rxWatch;
    Ticker* oneSecond;
    // **********************
    // * Protected variables: *
    // **********************

    /**
     * Open channel address of the locker
     */
    long long openAddr;

    /**
     * Channel address for Utility
     */
    long long addrUtil;
    /**
     * Array of battery states
     */
    char* battIn; // array of all battery states
    char* battPipes; // array of RX pipes
    char* dirNames[4];
    char* fileNames[4];
    unsigned int lengthFile[4];
    char* temp;
    char* sdBuffer;
    unsigned int sdBuffPnt;
    int battQP; // Battery queue pointer
    int pipeQP; // pipe q pointer (Add 2)
    int pipe;
    int width;

    char *timeValue;

    volatile time_t now;
    volatile time_t lastRxTme;

    // flags
    volatile bool flagRotate;
    volatile char flagNrf;
    volatile char flagOneSecond;

    // **********************
    // * Protected functions: *
    // **********************
    /**
     * set flag for 1 second interrupts
     */
    void intOneSecond();
    /**
     * Updates time string
     */
    void doOneSecond();
    /**
     * Called when the nrf creates an interrupt.
     */
    void intNrf();
    /**
    * Responds to the received signals from Master and Batteries
    */
    void doNrf();

    /**
     * When the button is pressed print status
     */
    void intButton();
    /**
     * Cleans the receiver
     */
    void intRxClean();
    /**
     * Rotates one battery the ON_AIR batteries.
     */
    void doRotate();

    /**
     * Take the info and saves to a file via a buffer.
     **/
    void saveFile (int p,char *data, int width);
    /**
    * writes the sdbuffer to file
    */
    void flushSDBuffer(int p);

    /**
     * Set NRF as RX
     */
    void setAsRX();

    /**
     * Set NRF as TX
     */
    void setAsTX();


private:
    // **********************
    // * Private variables: *
    // **********************



};
#endif