The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Committer:
defrost
Date:
Fri Jun 03 14:55:12 2016 +0000
Revision:
10:30c9e8df0032
Parent:
9:541c2ae1cfec
Child:
11:87ab310924f0
- Warnings all cleared up

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