The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Locker/Locker.h

Committer:
defrost
Date:
2016-06-02
Revision:
5:57b06b4b47c6
Child:
9:541c2ae1cfec

File content as of revision 5:57b06b4b47c6:

/**
 *@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"
#define FUNCNAME "LOCKER"
#include "defs.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=NULL;
    Ticker* rxWatch=NULL;
    Ticker* oneSecond=NULL;
    // **********************
    // * Protected variables: *
    // **********************

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

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

    char *timeValue=NULL;

    volatile time_t now=0;
    volatile time_t lastRxTme=0;

    // flags
    volatile bool flagRotate=false;
    volatile char flagNrf=0;
    volatile char flagOneSecond=0;

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