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:
26:10e8b9908631
Turned off the charge rate update from hub

Who changed what in which revision?

UserRevisionLine numberNew contents of line
defrost 0:dc8a45ec969a 1 /**
defrost 5:57b06b4b47c6 2 *@section DESCRIPTION
defrost 5:57b06b4b47c6 3 * mbed SolarNanogrid Library
defrost 5:57b06b4b47c6 4 *@section LICENSE
defrost 5:57b06b4b47c6 5 * Copyright (c) 2016, Malcolm McCulloch
defrost 5:57b06b4b47c6 6 *
defrost 5:57b06b4b47c6 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
defrost 5:57b06b4b47c6 8 * of this software and associated documentation files (the "Software"), to deal
defrost 5:57b06b4b47c6 9 * in the Software without restriction, including without limitation the rights
defrost 5:57b06b4b47c6 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
defrost 5:57b06b4b47c6 11 * copies of the Software, and to permit persons to whom the Software is
defrost 5:57b06b4b47c6 12 * furnished to do so, subject to the following conditions:
defrost 5:57b06b4b47c6 13 *
defrost 5:57b06b4b47c6 14 * The above copyright notice and this permission notice shall be included in
defrost 5:57b06b4b47c6 15 * all copies or substantial portions of the Software.
defrost 5:57b06b4b47c6 16 *
defrost 5:57b06b4b47c6 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
defrost 5:57b06b4b47c6 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
defrost 5:57b06b4b47c6 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
defrost 5:57b06b4b47c6 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
defrost 5:57b06b4b47c6 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
defrost 5:57b06b4b47c6 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
defrost 5:57b06b4b47c6 23 * THE SOFTWARE.
defrost 5:57b06b4b47c6 24 * @file "SolarNanoGrid.h"
defrost 5:57b06b4b47c6 25 */
defrost 0:dc8a45ec969a 26
defrost 0:dc8a45ec969a 27 #ifndef SOLARNANOGRID_H
defrost 0:dc8a45ec969a 28 #define SOLARNANOGRID_H
defrost 5:57b06b4b47c6 29 #include <mbed.h>
defrost 5:57b06b4b47c6 30 #include <pinmap.h>
epgmdm 11:87ab310924f0 31 #include <RawSerial.h>
defrost 1:df924e0126d1 32 #include "NRF2401P.h"
defrost 1:df924e0126d1 33 #include "SDFileSystem.h"
defrost 5:57b06b4b47c6 34
defrost 5:57b06b4b47c6 35
defrost 10:30c9e8df0032 36
defrost 13:de43f28c0365 37
defrost 13:de43f28c0365 38
defrost 5:57b06b4b47c6 39
defrost 15:e719c1cb0ea2 40
defrost 5:57b06b4b47c6 41 /** \brief A library for the base of the solar nano grid controllers.
defrost 5:57b06b4b47c6 42 *
defrost 5:57b06b4b47c6 43 * This library contains the code to drive batteries, hub etc.
defrost 5:57b06b4b47c6 44 */
defrost 5:57b06b4b47c6 45 class SolarNanoGrid {
defrost 5:57b06b4b47c6 46 public:
defrost 5:57b06b4b47c6 47 // *********************
defrost 5:57b06b4b47c6 48 // * Public variables: *
defrost 5:57b06b4b47c6 49 // *********************
defrost 7:5db9aeec9c2e 50 int sdVersion;
defrost 7:5db9aeec9c2e 51 unsigned int id;
defrost 7:5db9aeec9c2e 52 unsigned int communityID;
defrost 7:5db9aeec9c2e 53 int chan;
defrost 5:57b06b4b47c6 54 char dataRx[33];
defrost 5:57b06b4b47c6 55 char dataTx[33];
epgmdm 11:87ab310924f0 56 Serial *pc;
defrost 5:57b06b4b47c6 57
epgmdm 11:87ab310924f0 58 DigitalOut *ledRed, *ledGreen, *ledBlue;
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
defrost 5:57b06b4b47c6 66 /**
defrost 5:57b06b4b47c6 67 * Reads in config.ini and sets up the CommunityId, UserId, and the channel.
defrost 5:57b06b4b47c6 68 */
defrost 5:57b06b4b47c6 69
epgmdm 11:87ab310924f0 70 SolarNanoGrid(FILE* fp, Serial *pc);
defrost 5:57b06b4b47c6 71 /**
defrost 5:57b06b4b47c6 72 * Asks the user for the time and sets the real time clock
defrost 5:57b06b4b47c6 73 */
defrost 5:57b06b4b47c6 74 void userSetRTCpc();
defrost 0:dc8a45ec969a 75
defrost 5:57b06b4b47c6 76 // Main loop function:
defrost 13:de43f28c0365 77 virtual void loop(void) = 0;
defrost 5:57b06b4b47c6 78
defrost 22:93fde34d9a94 79
defrost 5:57b06b4b47c6 80
defrost 5:57b06b4b47c6 81 protected:
defrost 5:57b06b4b47c6 82 // *********************
defrost 5:57b06b4b47c6 83 // * Protected interrupts: *
defrost 5:57b06b4b47c6 84 // *********************
defrost 5:57b06b4b47c6 85 InterruptIn* nrfInt;
defrost 1:df924e0126d1 86
defrost 5:57b06b4b47c6 87 // **********************
defrost 5:57b06b4b47c6 88 // * Protected variables: *
defrost 5:57b06b4b47c6 89 // **********************
defrost 5:57b06b4b47c6 90 DigitalOut* ce;
defrost 7:5db9aeec9c2e 91 FILE* _fp;
defrost 7:5db9aeec9c2e 92 NRF2401P* nrf;
defrost 5:57b06b4b47c6 93
defrost 1:df924e0126d1 94
defrost 5:57b06b4b47c6 95 // *********************
defrost 5:57b06b4b47c6 96 // * Protected functions: *
defrost 5:57b06b4b47c6 97 // *********************
defrost 5:57b06b4b47c6 98 /**
defrost 5:57b06b4b47c6 99 * Flushes the rx and tx buffers and resets the status.
defrost 5:57b06b4b47c6 100 */
defrost 5:57b06b4b47c6 101 void nrfFlush();
defrost 5:57b06b4b47c6 102
epgmdm 11:87ab310924f0 103 /**
epgmdm 11:87ab310924f0 104 * Set NRF as RX and flush
epgmdm 11:87ab310924f0 105 */
epgmdm 11:87ab310924f0 106 void setAsRX(long long addr);
epgmdm 11:87ab310924f0 107
epgmdm 11:87ab310924f0 108 /**
epgmdm 11:87ab310924f0 109 * Sets NRF as TX and flushes the NRF
epgmdm 11:87ab310924f0 110 */
epgmdm 11:87ab310924f0 111 void setAsTX(long long addr);
epgmdm 11:87ab310924f0 112
defrost 5:57b06b4b47c6 113 private:
defrost 5:57b06b4b47c6 114 // **********************
defrost 5:57b06b4b47c6 115 // * Private variables: *
defrost 5:57b06b4b47c6 116 // **********************
defrost 5:57b06b4b47c6 117
defrost 1:df924e0126d1 118 };
defrost 0:dc8a45ec969a 119
defrost 16:919e37e5a895 120 // Other functions:
defrost 16:919e37e5a895 121
defrost 22:93fde34d9a94 122 // spi pin assignments:
defrost 16:919e37e5a895 123 /**
defrost 22:93fde34d9a94 124 * Turns SPI on for SD card
defrost 16:919e37e5a895 125 */
defrost 22:93fde34d9a94 126 void spiSD(void);
defrost 22:93fde34d9a94 127
defrost 22:93fde34d9a94 128 /**
defrost 22:93fde34d9a94 129 * Turns SPI on for nrf
defrost 22:93fde34d9a94 130 */
defrost 22:93fde34d9a94 131 void spiNRF(void);
defrost 22:93fde34d9a94 132
defrost 16:919e37e5a895 133
defrost 16:919e37e5a895 134 /**
defrost 16:919e37e5a895 135 * Class to hold of the Song Settings
defrost 16:919e37e5a895 136 */
defrost 16:919e37e5a895 137
defrost 16:919e37e5a895 138 class SongSettings{
defrost 16:919e37e5a895 139 public:
defrost 16:919e37e5a895 140 // Constructor:
defrost 16:919e37e5a895 141 SongSettings();
defrost 16:919e37e5a895 142
defrost 16:919e37e5a895 143 // Variables:
defrost 16:919e37e5a895 144 char role;
defrost 16:919e37e5a895 145 int sdVersion;
defrost 16:919e37e5a895 146 unsigned int communityID;
defrost 16:919e37e5a895 147 unsigned int id;
defrost 16:919e37e5a895 148 int chan;
defrost 22:93fde34d9a94 149 char LogDir[128];
defrost 16:919e37e5a895 150 bool LoadSongSettings(void);
defrost 16:919e37e5a895 151
defrost 16:919e37e5a895 152 };
defrost 16:919e37e5a895 153
defrost 26:10e8b9908631 154 // Creates a new config file, BLOCKING function:
defrost 26:10e8b9908631 155 void doNewConfig(Serial *pc);
defrost 26:10e8b9908631 156
defrost 5:57b06b4b47c6 157 #endif /* SOLARNANOGRID_H */