The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Committer:
defrost
Date:
Tue Sep 06 06:08:56 2016 +0000
Revision:
36:a5620262f296
Parent:
18:be77ad141fac
Turned off the charge rate update from hub

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:
epgmdm 11:87ab310924f0 65 Locker(FILE* fp, Serial *pc);
defrost 5:57b06b4b47c6 66
defrost 5:57b06b4b47c6 67 // Main loop function:
defrost 13:de43f28c0365 68 virtual 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 */
epgmdm 11:87ab310924f0 101 char* battIn; /**< array of all battery states */
epgmdm 11:87ab310924f0 102 char* battPipes; /**< array of RX pipes */
epgmdm 11:87ab310924f0 103 char* dirNames[4]; /**< The directory for each pipe */
epgmdm 11:87ab310924f0 104 char* fileNames[4]; /**< The filename of each pipe */
epgmdm 11:87ab310924f0 105 unsigned int lengthFile[4]; /**< The file length of each pipe */
adrienBiz 9:541c2ae1cfec 106 char* temp;
epgmdm 11:87ab310924f0 107 char* sdBuffer; /**< The ram buffer for the SD card- large! */
epgmdm 11:87ab310924f0 108 unsigned int sdBuffPnt; /**< SD buffer pointer */
epgmdm 11:87ab310924f0 109 int battQP; /**< Battery queue pointer */
epgmdm 11:87ab310924f0 110 int pipeQP; /**< pipe queue pointer; add 2 to get pipe */
epgmdm 11:87ab310924f0 111 int pipe; /**< The pipe that has last received data */
epgmdm 11:87ab310924f0 112 int width; /**< The number of bytes of received data */
epgmdm 11:87ab310924f0 113 int userIDDrop; /**< User ID of drop off from HMI*/
epgmdm 11:87ab310924f0 114 int numBatDrop; /**< Num bat dropped off*/
defrost 5:57b06b4b47c6 115
epgmdm 18:be77ad141fac 116 char *maxChargeValue;
adrienBiz 9:541c2ae1cfec 117 char *timeValue;
epgmdm 18:be77ad141fac 118
epgmdm 11:87ab310924f0 119 DigitalOut *pods[16]; /**< Array of gpio to control the pod relays */
defrost 5:57b06b4b47c6 120
adrienBiz 9:541c2ae1cfec 121 volatile time_t now;
adrienBiz 9:541c2ae1cfec 122 volatile time_t lastRxTme;
epgmdm 18:be77ad141fac 123
epgmdm 18:be77ad141fac 124 volatile float maxCharge;
defrost 5:57b06b4b47c6 125
epgmdm 11:87ab310924f0 126 // *********************
epgmdm 11:87ab310924f0 127 // * Protected flags: *
epgmdm 11:87ab310924f0 128 // *********************
adrienBiz 9:541c2ae1cfec 129 volatile bool flagRotate;
adrienBiz 9:541c2ae1cfec 130 volatile char flagNrf;
adrienBiz 9:541c2ae1cfec 131 volatile char flagOneSecond;
defrost 5:57b06b4b47c6 132
defrost 5:57b06b4b47c6 133 // **********************
defrost 5:57b06b4b47c6 134 // * Protected functions: *
defrost 5:57b06b4b47c6 135 // **********************
defrost 5:57b06b4b47c6 136 /**
defrost 5:57b06b4b47c6 137 * set flag for 1 second interrupts
defrost 5:57b06b4b47c6 138 */
defrost 5:57b06b4b47c6 139 void intOneSecond();
defrost 5:57b06b4b47c6 140 /**
defrost 5:57b06b4b47c6 141 * Updates time string
defrost 5:57b06b4b47c6 142 */
defrost 5:57b06b4b47c6 143 void doOneSecond();
defrost 5:57b06b4b47c6 144 /**
defrost 5:57b06b4b47c6 145 * Called when the nrf creates an interrupt.
defrost 5:57b06b4b47c6 146 */
defrost 5:57b06b4b47c6 147 void intNrf();
defrost 5:57b06b4b47c6 148 /**
defrost 5:57b06b4b47c6 149 * Responds to the received signals from Master and Batteries
defrost 5:57b06b4b47c6 150 */
defrost 5:57b06b4b47c6 151 void doNrf();
defrost 5:57b06b4b47c6 152
defrost 5:57b06b4b47c6 153 /**
defrost 5:57b06b4b47c6 154 * When the button is pressed print status
defrost 5:57b06b4b47c6 155 */
defrost 5:57b06b4b47c6 156 void intButton();
defrost 5:57b06b4b47c6 157 /**
defrost 5:57b06b4b47c6 158 * Cleans the receiver
defrost 5:57b06b4b47c6 159 */
defrost 5:57b06b4b47c6 160 void intRxClean();
defrost 5:57b06b4b47c6 161 /**
defrost 5:57b06b4b47c6 162 * Rotates one battery the ON_AIR batteries.
defrost 5:57b06b4b47c6 163 */
defrost 5:57b06b4b47c6 164 void doRotate();
defrost 5:57b06b4b47c6 165
defrost 5:57b06b4b47c6 166 /**
defrost 5:57b06b4b47c6 167 * Take the info and saves to a file via a buffer.
defrost 5:57b06b4b47c6 168 **/
defrost 5:57b06b4b47c6 169 void saveFile (int p,char *data, int width);
defrost 5:57b06b4b47c6 170 /**
defrost 5:57b06b4b47c6 171 * writes the sdbuffer to file
defrost 5:57b06b4b47c6 172 */
defrost 5:57b06b4b47c6 173 void flushSDBuffer(int p);
defrost 5:57b06b4b47c6 174
epgmdm 11:87ab310924f0 175 // /**
epgmdm 11:87ab310924f0 176 // * Set NRF as RX
epgmdm 11:87ab310924f0 177 // */
epgmdm 11:87ab310924f0 178 // void setAsRX();
epgmdm 11:87ab310924f0 179 //
epgmdm 11:87ab310924f0 180 // /**
epgmdm 11:87ab310924f0 181 // * Set NRF as TX
epgmdm 11:87ab310924f0 182 // */
epgmdm 11:87ab310924f0 183 // void setAsTX();
defrost 5:57b06b4b47c6 184
defrost 5:57b06b4b47c6 185 /**
epgmdm 11:87ab310924f0 186 * Turns a pod power on
defrost 5:57b06b4b47c6 187 */
epgmdm 11:87ab310924f0 188 void turnPodOn(int pod, int on);
defrost 5:57b06b4b47c6 189
defrost 5:57b06b4b47c6 190 private:
defrost 5:57b06b4b47c6 191 // **********************
defrost 5:57b06b4b47c6 192 // * Private variables: *
defrost 5:57b06b4b47c6 193 // **********************
defrost 5:57b06b4b47c6 194
defrost 5:57b06b4b47c6 195
defrost 5:57b06b4b47c6 196
defrost 5:57b06b4b47c6 197 };
defrost 5:57b06b4b47c6 198 #endif