The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Committer:
adrienBiz
Date:
Fri Jun 03 13:43:11 2016 +0000
Revision:
9:541c2ae1cfec
Parent:
5:57b06b4b47c6
Child:
10:30c9e8df0032
Fixed the variable initialisation in locker.h and locker.cpp

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 * Locker extends SolarNanoGrid.
defrost 5:57b06b4b47c6 5 * Locker interacts with the batteries.
defrost 5:57b06b4b47c6 6 * The ID must 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 "Locker.h"
defrost 5:57b06b4b47c6 28 */
defrost 5:57b06b4b47c6 29
defrost 5:57b06b4b47c6 30 #ifndef LOCKER_H
defrost 5:57b06b4b47c6 31 #define LOCKER_H
defrost 5:57b06b4b47c6 32 #include <mbed.h>
defrost 5:57b06b4b47c6 33 #include "NRF2401P.h"
defrost 5:57b06b4b47c6 34 #include "nRF24l01.h"
defrost 5:57b06b4b47c6 35 #include "SDFileSystem.h"
defrost 5:57b06b4b47c6 36 #include "SolarNanoGrid.h"
defrost 5:57b06b4b47c6 37 #define FUNCNAME "LOCKER"
defrost 5:57b06b4b47c6 38 #include "defs.h"
defrost 5:57b06b4b47c6 39
defrost 5:57b06b4b47c6 40 // Battery states
defrost 5:57b06b4b47c6 41 #define CHECKED_OUT 0
defrost 5:57b06b4b47c6 42 #define CHECKED_IN 1
defrost 5:57b06b4b47c6 43 #define ON_AIR 2
defrost 5:57b06b4b47c6 44 #define SENDING 3
defrost 5:57b06b4b47c6 45
defrost 5:57b06b4b47c6 46
defrost 5:57b06b4b47c6 47 /** \brief Locker interacts with the batteries.
defrost 5:57b06b4b47c6 48 *
defrost 5:57b06b4b47c6 49 * The config.ini must start with L
defrost 5:57b06b4b47c6 50 * This library contains the code to drive batteries, hub etc.
defrost 5:57b06b4b47c6 51 */
defrost 5:57b06b4b47c6 52 class Locker : public SolarNanoGrid
defrost 5:57b06b4b47c6 53 {
defrost 5:57b06b4b47c6 54 public:
defrost 5:57b06b4b47c6 55
defrost 5:57b06b4b47c6 56 // *********************
defrost 5:57b06b4b47c6 57 // * Public variables: *
defrost 5:57b06b4b47c6 58 // *********************
defrost 5:57b06b4b47c6 59
defrost 5:57b06b4b47c6 60
defrost 5:57b06b4b47c6 61 // *********************
defrost 5:57b06b4b47c6 62 // * Public functions: *
defrost 5:57b06b4b47c6 63 // *********************
defrost 5:57b06b4b47c6 64
defrost 5:57b06b4b47c6 65 // Constructor:
defrost 5:57b06b4b47c6 66 Locker(FILE* fp);
defrost 5:57b06b4b47c6 67
defrost 5:57b06b4b47c6 68 // Main loop function:
defrost 5:57b06b4b47c6 69 void loop(void);
defrost 5:57b06b4b47c6 70
defrost 5:57b06b4b47c6 71
defrost 5:57b06b4b47c6 72
defrost 5:57b06b4b47c6 73 protected:
defrost 5:57b06b4b47c6 74 // *********************
defrost 5:57b06b4b47c6 75 // * Protected hardware: *
defrost 5:57b06b4b47c6 76 // *********************
defrost 5:57b06b4b47c6 77
defrost 5:57b06b4b47c6 78
defrost 5:57b06b4b47c6 79 // *********************
defrost 5:57b06b4b47c6 80 // * Protected interrupts: *
defrost 5:57b06b4b47c6 81 // *********************
defrost 5:57b06b4b47c6 82
adrienBiz 9:541c2ae1cfec 83 InterruptIn* button;
adrienBiz 9:541c2ae1cfec 84 Ticker* rxWatch;
adrienBiz 9:541c2ae1cfec 85 Ticker* oneSecond;
defrost 5:57b06b4b47c6 86 // **********************
defrost 5:57b06b4b47c6 87 // * Protected variables: *
defrost 5:57b06b4b47c6 88 // **********************
defrost 5:57b06b4b47c6 89
defrost 5:57b06b4b47c6 90 /**
defrost 5:57b06b4b47c6 91 * Open channel address of the locker
defrost 5:57b06b4b47c6 92 */
adrienBiz 9:541c2ae1cfec 93 long long openAddr;
defrost 5:57b06b4b47c6 94
defrost 5:57b06b4b47c6 95 /**
defrost 5:57b06b4b47c6 96 * Channel address for Utility
defrost 5:57b06b4b47c6 97 */
adrienBiz 9:541c2ae1cfec 98 long long addrUtil;
defrost 5:57b06b4b47c6 99 /**
defrost 5:57b06b4b47c6 100 * Array of battery states
defrost 5:57b06b4b47c6 101 */
adrienBiz 9:541c2ae1cfec 102 char* battIn; // array of all battery states
adrienBiz 9:541c2ae1cfec 103 char* battPipes; // array of RX pipes
defrost 5:57b06b4b47c6 104 char* dirNames[4];
defrost 5:57b06b4b47c6 105 char* fileNames[4];
defrost 5:57b06b4b47c6 106 unsigned int lengthFile[4];
adrienBiz 9:541c2ae1cfec 107 char* temp;
adrienBiz 9:541c2ae1cfec 108 char* sdBuffer;
adrienBiz 9:541c2ae1cfec 109 unsigned int sdBuffPnt;
adrienBiz 9:541c2ae1cfec 110 int battQP; // Battery queue pointer
adrienBiz 9:541c2ae1cfec 111 int pipeQP; // pipe q pointer (Add 2)
adrienBiz 9:541c2ae1cfec 112 int pipe;
adrienBiz 9:541c2ae1cfec 113 int width;
defrost 5:57b06b4b47c6 114
adrienBiz 9:541c2ae1cfec 115 char *timeValue;
defrost 5:57b06b4b47c6 116
adrienBiz 9:541c2ae1cfec 117 volatile time_t now;
adrienBiz 9:541c2ae1cfec 118 volatile time_t lastRxTme;
defrost 5:57b06b4b47c6 119
defrost 5:57b06b4b47c6 120 // flags
adrienBiz 9:541c2ae1cfec 121 volatile bool flagRotate;
adrienBiz 9:541c2ae1cfec 122 volatile char flagNrf;
adrienBiz 9:541c2ae1cfec 123 volatile char flagOneSecond;
defrost 5:57b06b4b47c6 124
defrost 5:57b06b4b47c6 125 // **********************
defrost 5:57b06b4b47c6 126 // * Protected functions: *
defrost 5:57b06b4b47c6 127 // **********************
defrost 5:57b06b4b47c6 128 /**
defrost 5:57b06b4b47c6 129 * set flag for 1 second interrupts
defrost 5:57b06b4b47c6 130 */
defrost 5:57b06b4b47c6 131 void intOneSecond();
defrost 5:57b06b4b47c6 132 /**
defrost 5:57b06b4b47c6 133 * Updates time string
defrost 5:57b06b4b47c6 134 */
defrost 5:57b06b4b47c6 135 void doOneSecond();
defrost 5:57b06b4b47c6 136 /**
defrost 5:57b06b4b47c6 137 * Called when the nrf creates an interrupt.
defrost 5:57b06b4b47c6 138 */
defrost 5:57b06b4b47c6 139 void intNrf();
defrost 5:57b06b4b47c6 140 /**
defrost 5:57b06b4b47c6 141 * Responds to the received signals from Master and Batteries
defrost 5:57b06b4b47c6 142 */
defrost 5:57b06b4b47c6 143 void doNrf();
defrost 5:57b06b4b47c6 144
defrost 5:57b06b4b47c6 145 /**
defrost 5:57b06b4b47c6 146 * When the button is pressed print status
defrost 5:57b06b4b47c6 147 */
defrost 5:57b06b4b47c6 148 void intButton();
defrost 5:57b06b4b47c6 149 /**
defrost 5:57b06b4b47c6 150 * Cleans the receiver
defrost 5:57b06b4b47c6 151 */
defrost 5:57b06b4b47c6 152 void intRxClean();
defrost 5:57b06b4b47c6 153 /**
defrost 5:57b06b4b47c6 154 * Rotates one battery the ON_AIR batteries.
defrost 5:57b06b4b47c6 155 */
defrost 5:57b06b4b47c6 156 void doRotate();
defrost 5:57b06b4b47c6 157
defrost 5:57b06b4b47c6 158 /**
defrost 5:57b06b4b47c6 159 * Take the info and saves to a file via a buffer.
defrost 5:57b06b4b47c6 160 **/
defrost 5:57b06b4b47c6 161 void saveFile (int p,char *data, int width);
defrost 5:57b06b4b47c6 162 /**
defrost 5:57b06b4b47c6 163 * writes the sdbuffer to file
defrost 5:57b06b4b47c6 164 */
defrost 5:57b06b4b47c6 165 void flushSDBuffer(int p);
defrost 5:57b06b4b47c6 166
defrost 5:57b06b4b47c6 167 /**
defrost 5:57b06b4b47c6 168 * Set NRF as RX
defrost 5:57b06b4b47c6 169 */
defrost 5:57b06b4b47c6 170 void setAsRX();
defrost 5:57b06b4b47c6 171
defrost 5:57b06b4b47c6 172 /**
defrost 5:57b06b4b47c6 173 * Set NRF as TX
defrost 5:57b06b4b47c6 174 */
defrost 5:57b06b4b47c6 175 void setAsTX();
defrost 5:57b06b4b47c6 176
defrost 5:57b06b4b47c6 177
defrost 5:57b06b4b47c6 178 private:
defrost 5:57b06b4b47c6 179 // **********************
defrost 5:57b06b4b47c6 180 // * Private variables: *
defrost 5:57b06b4b47c6 181 // **********************
defrost 5:57b06b4b47c6 182
defrost 5:57b06b4b47c6 183
defrost 5:57b06b4b47c6 184
defrost 5:57b06b4b47c6 185 };
defrost 5:57b06b4b47c6 186 #endif