condens

Dependencies:   mbed MbedJSONValue

Committer:
duchonic
Date:
Thu Aug 22 22:31:27 2019 +0000
Revision:
3:26d5a21bbc66
Parent:
2:d5f4f429f3db
docu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duchonic 2:d5f4f429f3db 1 #pragma once
duchonic 2:d5f4f429f3db 2
duchonic 2:d5f4f429f3db 3 #include "MbedJSONValue/MbedJSONValue.h"
duchonic 2:d5f4f429f3db 4
duchonic 2:d5f4f429f3db 5 enum Commands {TYPE, CONF, STATUS};
duchonic 2:d5f4f429f3db 6
duchonic 2:d5f4f429f3db 7 /** HeartBeat Class
duchonic 2:d5f4f429f3db 8 *
duchonic 2:d5f4f429f3db 9 *
duchonic 2:d5f4f429f3db 10 */
duchonic 2:d5f4f429f3db 11 class HeartBeat{
duchonic 2:d5f4f429f3db 12 public:
duchonic 2:d5f4f429f3db 13 HeartBeat(){
duchonic 2:d5f4f429f3db 14 currentKey = "A";
duchonic 2:d5f4f429f3db 15 flowKey = "DF";
duchonic 2:d5f4f429f3db 16 tempKey = "T";
duchonic 2:d5f4f429f3db 17 pumpStatusKey = "PS";
duchonic 2:d5f4f429f3db 18 }
duchonic 2:d5f4f429f3db 19 void sendFrame(){
duchonic 2:d5f4f429f3db 20 MbedJSONValue send;
duchonic 2:d5f4f429f3db 21 send[currentKey] = 11.2;
duchonic 2:d5f4f429f3db 22 send[flowKey] = 33;
duchonic 2:d5f4f429f3db 23 send[tempKey] = 12.2f;
duchonic 2:d5f4f429f3db 24 send[pumpStatusKey] = 0;
duchonic 2:d5f4f429f3db 25
duchonic 2:d5f4f429f3db 26 printf("%s\n", send.serialize().c_str() );
duchonic 2:d5f4f429f3db 27 }
duchonic 2:d5f4f429f3db 28 private:
duchonic 2:d5f4f429f3db 29 std::string currentKey;
duchonic 2:d5f4f429f3db 30 std::string flowKey;
duchonic 2:d5f4f429f3db 31 std::string tempKey;
duchonic 2:d5f4f429f3db 32 std::string pumpStatusKey;
duchonic 2:d5f4f429f3db 33 };
duchonic 2:d5f4f429f3db 34
duchonic 2:d5f4f429f3db 35 /** Type Class
duchonic 2:d5f4f429f3db 36 *
duchonic 2:d5f4f429f3db 37 *
duchonic 2:d5f4f429f3db 38 */
duchonic 2:d5f4f429f3db 39 class Type{
duchonic 2:d5f4f429f3db 40 public:
duchonic 2:d5f4f429f3db 41 Type(int actId=1) {
duchonic 2:d5f4f429f3db 42 idKey = "ID";
duchonic 2:d5f4f429f3db 43 id = actId;
duchonic 2:d5f4f429f3db 44 typeKey = "TYPE";
duchonic 2:d5f4f429f3db 45 type = "DC";
duchonic 2:d5f4f429f3db 46 }
duchonic 2:d5f4f429f3db 47
duchonic 2:d5f4f429f3db 48 /**
duchonic 2:d5f4f429f3db 49 * Set new id
duchonic 2:d5f4f429f3db 50 * @param newId new id of the device
duchonic 2:d5f4f429f3db 51 */
duchonic 2:d5f4f429f3db 52 void setId(int newId){
duchonic 2:d5f4f429f3db 53 id=newId;
duchonic 2:d5f4f429f3db 54 }
duchonic 2:d5f4f429f3db 55 void sendFrame(void){
duchonic 2:d5f4f429f3db 56 MbedJSONValue send;
duchonic 2:d5f4f429f3db 57 send[idKey] = id;
duchonic 2:d5f4f429f3db 58 send[typeKey] = type;
duchonic 2:d5f4f429f3db 59 printf("%s\n", send.serialize().c_str() );
duchonic 2:d5f4f429f3db 60 }
duchonic 2:d5f4f429f3db 61 private:
duchonic 2:d5f4f429f3db 62 std::string idKey;
duchonic 2:d5f4f429f3db 63 int id;
duchonic 2:d5f4f429f3db 64 std::string typeKey;
duchonic 2:d5f4f429f3db 65 std::string type;
duchonic 2:d5f4f429f3db 66 };
duchonic 2:d5f4f429f3db 67
duchonic 3:26d5a21bbc66 68 /** Conf Class
duchonic 3:26d5a21bbc66 69 *
duchonic 3:26d5a21bbc66 70 *
duchonic 3:26d5a21bbc66 71 */
duchonic 2:d5f4f429f3db 72 class Conf{
duchonic 2:d5f4f429f3db 73 public:
duchonic 2:d5f4f429f3db 74 Conf(int newTemperature=20){
duchonic 2:d5f4f429f3db 75 responseKey = "RSP";
duchonic 2:d5f4f429f3db 76 tempKey = "T";
duchonic 2:d5f4f429f3db 77 temperature = newTemperature;
duchonic 2:d5f4f429f3db 78 }
duchonic 2:d5f4f429f3db 79
duchonic 2:d5f4f429f3db 80 /**
duchonic 2:d5f4f429f3db 81 * Set the configs
duchonic 2:d5f4f429f3db 82 * @param receive received json data
duchonic 2:d5f4f429f3db 83 * @returns status of the setConfig
duchonic 2:d5f4f429f3db 84 */
duchonic 2:d5f4f429f3db 85 bool setConfig(MbedJSONValue receive){
duchonic 2:d5f4f429f3db 86 temperature = receive[tempKey].get<int>();
duchonic 2:d5f4f429f3db 87 if(temperature > 50){
duchonic 2:d5f4f429f3db 88 temperature=50;
duchonic 2:d5f4f429f3db 89 return false;
duchonic 2:d5f4f429f3db 90 }
duchonic 2:d5f4f429f3db 91 else if(temperature < -20){
duchonic 2:d5f4f429f3db 92 temperature = -20;
duchonic 2:d5f4f429f3db 93 return false;
duchonic 2:d5f4f429f3db 94 }
duchonic 2:d5f4f429f3db 95 else{
duchonic 2:d5f4f429f3db 96 return true;
duchonic 2:d5f4f429f3db 97 }
duchonic 2:d5f4f429f3db 98 }
duchonic 2:d5f4f429f3db 99
duchonic 2:d5f4f429f3db 100 int getTemparature(void){
duchonic 2:d5f4f429f3db 101 return temperature;
duchonic 2:d5f4f429f3db 102 }
duchonic 2:d5f4f429f3db 103 void sendAck(void){
duchonic 2:d5f4f429f3db 104 MbedJSONValue send;
duchonic 2:d5f4f429f3db 105 send[responseKey] = "OK";
duchonic 2:d5f4f429f3db 106 printf("%s\n", send.serialize().c_str() );
duchonic 2:d5f4f429f3db 107 }
duchonic 2:d5f4f429f3db 108 private:
duchonic 2:d5f4f429f3db 109 int temperature;
duchonic 2:d5f4f429f3db 110 std::string responseKey;
duchonic 2:d5f4f429f3db 111 std::string tempKey;
duchonic 2:d5f4f429f3db 112 };
duchonic 2:d5f4f429f3db 113
duchonic 3:26d5a21bbc66 114 /** Status Class
duchonic 3:26d5a21bbc66 115 *
duchonic 3:26d5a21bbc66 116 *
duchonic 3:26d5a21bbc66 117 */
duchonic 2:d5f4f429f3db 118 class Status{
duchonic 2:d5f4f429f3db 119 public:
duchonic 3:26d5a21bbc66 120 /** Constructor, set the keys
duchonic 3:26d5a21bbc66 121 * @code
duchonic 3:26d5a21bbc66 122 n1Key[0] = "N1.1";
duchonic 3:26d5a21bbc66 123 n1Key[1] = "N1.2";
duchonic 3:26d5a21bbc66 124 n1Key[2] = "N1.3";
duchonic 3:26d5a21bbc66 125 n1Key[3] = "N1.4";
duchonic 3:26d5a21bbc66 126 n2Key = "N2";
duchonic 3:26d5a21bbc66 127 n3Key = "N3";
duchonic 3:26d5a21bbc66 128 t1Key = "T1";
duchonic 3:26d5a21bbc66 129 hsKey = "HS";
duchonic 3:26d5a21bbc66 130 statusKey = "STATUS";
duchonic 3:26d5a21bbc66 131 * @endcode
duchonic 3:26d5a21bbc66 132 */
duchonic 2:d5f4f429f3db 133 Status(){
duchonic 2:d5f4f429f3db 134 n1Key[0] = "N1.1";
duchonic 2:d5f4f429f3db 135 n1Key[1] = "N1.2";
duchonic 2:d5f4f429f3db 136 n1Key[2] = "N1.3";
duchonic 2:d5f4f429f3db 137 n1Key[3] = "N1.4";
duchonic 2:d5f4f429f3db 138 n2Key = "N2";
duchonic 2:d5f4f429f3db 139 n3Key = "N3";
duchonic 2:d5f4f429f3db 140 t1Key = "T1";
duchonic 2:d5f4f429f3db 141 hsKey = "HS";
duchonic 2:d5f4f429f3db 142 statusKey = "STATUS";
duchonic 2:d5f4f429f3db 143 }
duchonic 2:d5f4f429f3db 144 void sendFrame(){
duchonic 2:d5f4f429f3db 145 MbedJSONValue send;
duchonic 2:d5f4f429f3db 146 send[n1Key[0]] = n1[0];
duchonic 2:d5f4f429f3db 147 send[n1Key[1]] = n1[1];
duchonic 2:d5f4f429f3db 148 send[n1Key[2]] = n1[2];
duchonic 2:d5f4f429f3db 149 send[n1Key[3]] = n1[3];
duchonic 2:d5f4f429f3db 150 send[t1Key] = t1;
duchonic 2:d5f4f429f3db 151 send[hsKey] = hs;
duchonic 2:d5f4f429f3db 152 send[statusKey] = status;
duchonic 2:d5f4f429f3db 153 printf("%s\n", send.serialize().c_str() );
duchonic 2:d5f4f429f3db 154
duchonic 2:d5f4f429f3db 155 }
duchonic 2:d5f4f429f3db 156 int n1[4];
duchonic 2:d5f4f429f3db 157 int t1;
duchonic 2:d5f4f429f3db 158 int hs;
duchonic 2:d5f4f429f3db 159 int status;
duchonic 2:d5f4f429f3db 160
duchonic 2:d5f4f429f3db 161 private:
duchonic 2:d5f4f429f3db 162 std::string n1Key[4];
duchonic 2:d5f4f429f3db 163 std::string n2Key;
duchonic 2:d5f4f429f3db 164 std::string n3Key;
duchonic 2:d5f4f429f3db 165 std::string t1Key;
duchonic 2:d5f4f429f3db 166 std::string hsKey;
duchonic 2:d5f4f429f3db 167 std::string statusKey;
duchonic 2:d5f4f429f3db 168 };
duchonic 2:d5f4f429f3db 169
duchonic 3:26d5a21bbc66 170 /** Command Class
duchonic 3:26d5a21bbc66 171 *
duchonic 3:26d5a21bbc66 172 *
duchonic 3:26d5a21bbc66 173 */
duchonic 2:d5f4f429f3db 174 class Command{
duchonic 2:d5f4f429f3db 175 public:
duchonic 2:d5f4f429f3db 176 Command(){
duchonic 2:d5f4f429f3db 177 cmdKey = "CMD";
duchonic 2:d5f4f429f3db 178 }
duchonic 2:d5f4f429f3db 179 Commands get(MbedJSONValue receive){
duchonic 2:d5f4f429f3db 180 std::string cmd = receive[cmdKey].get<std::string>();
duchonic 2:d5f4f429f3db 181
duchonic 2:d5f4f429f3db 182 if(cmd == std::string("TYPE") ){
duchonic 2:d5f4f429f3db 183 return TYPE;
duchonic 2:d5f4f429f3db 184 }
duchonic 2:d5f4f429f3db 185 else if(cmd == std::string("CONF") ){
duchonic 2:d5f4f429f3db 186 return CONF;
duchonic 2:d5f4f429f3db 187 }
duchonic 2:d5f4f429f3db 188 else if(cmd == std::string("STATUS")) {
duchonic 2:d5f4f429f3db 189 return STATUS;
duchonic 2:d5f4f429f3db 190 }
duchonic 2:d5f4f429f3db 191 else{
duchonic 2:d5f4f429f3db 192 assert(0);
duchonic 2:d5f4f429f3db 193 return TYPE;
duchonic 2:d5f4f429f3db 194 }
duchonic 2:d5f4f429f3db 195 }
duchonic 2:d5f4f429f3db 196 private:
duchonic 2:d5f4f429f3db 197 std::string cmdKey;
duchonic 2:d5f4f429f3db 198 };