Junichi Katsu / Milkcocoa-os

Dependents:   mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn

Committer:
jksoft
Date:
Thu Jun 01 05:33:50 2017 +0000
Revision:
7:f1e123331cad
Parent:
6:1b5ec3a15d67
Child:
8:e2f15b1b4f70
??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:0a2f634d3324 1 #include "Milkcocoa.h"
jksoft 0:0a2f634d3324 2
jksoft 6:1b5ec3a15d67 3 #if 0
jksoft 0:0a2f634d3324 4 extern RawSerial pc;
jksoft 0:0a2f634d3324 5
jksoft 0:0a2f634d3324 6 #define DBG(x) x
jksoft 0:0a2f634d3324 7 #else
jksoft 0:0a2f634d3324 8 #define DBG(x)
jksoft 0:0a2f634d3324 9 #endif
jksoft 0:0a2f634d3324 10
jksoft 0:0a2f634d3324 11 DataElement::DataElement() {
jksoft 0:0a2f634d3324 12 json_msg[0] = '\0';
jksoft 0:0a2f634d3324 13 strcpy(json_msg,"{\"params\":{");
jksoft 0:0a2f634d3324 14 }
jksoft 0:0a2f634d3324 15
jksoft 0:0a2f634d3324 16 DataElement::DataElement(char *json_string) {
jksoft 0:0a2f634d3324 17 json_msg[0] = '\0';
jksoft 0:0a2f634d3324 18 strcpy(json_msg,json_string);
jksoft 0:0a2f634d3324 19 }
jksoft 0:0a2f634d3324 20
jksoft 0:0a2f634d3324 21 void DataElement::setValue(const char *key, const char *v) {
jksoft 0:0a2f634d3324 22 char json_string[64];
jksoft 0:0a2f634d3324 23 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 24 {
jksoft 0:0a2f634d3324 25 strcat(json_msg,",");
jksoft 0:0a2f634d3324 26 }
jksoft 0:0a2f634d3324 27 sprintf(json_string,"\"%s\":\"%s\"",key,v);
jksoft 0:0a2f634d3324 28 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 29 }
jksoft 0:0a2f634d3324 30
jksoft 0:0a2f634d3324 31 void DataElement::setValue(const char *key, int v) {
jksoft 0:0a2f634d3324 32 char json_string[64];
jksoft 0:0a2f634d3324 33 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 34 {
jksoft 0:0a2f634d3324 35 strcat(json_msg,",");
jksoft 0:0a2f634d3324 36 }
jksoft 0:0a2f634d3324 37 sprintf(json_string,"\"%s\":\"%d\"",key,v);
jksoft 0:0a2f634d3324 38 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 39 }
jksoft 0:0a2f634d3324 40
jksoft 0:0a2f634d3324 41 void DataElement::setValue(const char *key, double v) {
jksoft 0:0a2f634d3324 42 char json_string[64];
jksoft 0:0a2f634d3324 43 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 44 {
jksoft 0:0a2f634d3324 45 strcat(json_msg,",");
jksoft 0:0a2f634d3324 46 }
jksoft 0:0a2f634d3324 47 sprintf(json_string,"\"%s\":\"%f\"",key,v);
jksoft 0:0a2f634d3324 48 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 49 }
jksoft 0:0a2f634d3324 50
jksoft 0:0a2f634d3324 51 char *DataElement::getString(const char *key) {
jksoft 0:0a2f634d3324 52 static char _word[64];
jksoft 0:0a2f634d3324 53 char *p;
jksoft 0:0a2f634d3324 54 int i=0;
jksoft 0:0a2f634d3324 55
jksoft 0:0a2f634d3324 56 strcpy(_word , "\"\0");
jksoft 0:0a2f634d3324 57 strcat(_word , key );
jksoft 0:0a2f634d3324 58 strcat(_word , "\"" );
jksoft 0:0a2f634d3324 59
jksoft 0:0a2f634d3324 60 p = strstr( (char*)json_msg , _word ) + 2 + strlen(_word);
jksoft 0:0a2f634d3324 61
jksoft 0:0a2f634d3324 62 while( (p[i] != ',')&&(p[i] != '\n')&&(p[i] != '\"') )
jksoft 0:0a2f634d3324 63 {
jksoft 0:0a2f634d3324 64 _word[i] = p[i];
jksoft 0:0a2f634d3324 65 i++;
jksoft 0:0a2f634d3324 66 }
jksoft 0:0a2f634d3324 67 _word[i] = '\0';
jksoft 0:0a2f634d3324 68
jksoft 0:0a2f634d3324 69 return _word;
jksoft 0:0a2f634d3324 70 }
jksoft 0:0a2f634d3324 71
jksoft 0:0a2f634d3324 72 int DataElement::getInt(const char *key) {
jksoft 0:0a2f634d3324 73 return atoi(getString(key));
jksoft 0:0a2f634d3324 74 }
jksoft 0:0a2f634d3324 75
jksoft 0:0a2f634d3324 76 float DataElement::getFloat(const char *key) {
jksoft 0:0a2f634d3324 77 return atof(getString(key));
jksoft 0:0a2f634d3324 78 }
jksoft 0:0a2f634d3324 79
jksoft 0:0a2f634d3324 80 char *DataElement::toCharArray() {
jksoft 0:0a2f634d3324 81 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 82 {
jksoft 0:0a2f634d3324 83 strcat(json_msg,"}");
jksoft 0:0a2f634d3324 84 }
jksoft 0:0a2f634d3324 85 strcat(json_msg,"}");
jksoft 0:0a2f634d3324 86
jksoft 0:0a2f634d3324 87 return(json_msg);
jksoft 0:0a2f634d3324 88 }
jksoft 0:0a2f634d3324 89
jksoft 0:0a2f634d3324 90 Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id){
jksoft 0:0a2f634d3324 91 ipstack = new MQTTInterface(nif);
jksoft 0:0a2f634d3324 92 client = new MClient(ipstack);
jksoft 0:0a2f634d3324 93 strcpy(servername,host);
jksoft 0:0a2f634d3324 94 portnum = port;
jksoft 5:dd68fa651637 95 strcpy(app_id,_app_id);
jksoft 0:0a2f634d3324 96 strcpy(_clientid,client_id);
jksoft 0:0a2f634d3324 97 strcpy(username,"sdammy");
jksoft 0:0a2f634d3324 98 strcpy(password,app_id);
jksoft 6:1b5ec3a15d67 99
jksoft 7:f1e123331cad 100 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 7:f1e123331cad 101 milkcocoaSubscribers[i] = NULL;
jksoft 7:f1e123331cad 102 }
jksoft 7:f1e123331cad 103
jksoft 6:1b5ec3a15d67 104 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 105 setLoopCycle(5000);
jksoft 0:0a2f634d3324 106
jksoft 1:8e4149b53a8a 107 cycleThread1.start(Milkcocoa::threadStarter1,this);
jksoft 1:8e4149b53a8a 108 cycleThread2.start(Milkcocoa::threadStarter2,this);
jksoft 6:1b5ec3a15d67 109 #endif
jksoft 0:0a2f634d3324 110 }
jksoft 0:0a2f634d3324 111
jksoft 0:0a2f634d3324 112 Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session){
jksoft 0:0a2f634d3324 113 ipstack = new MQTTInterface(nif);
jksoft 0:0a2f634d3324 114 client = new MClient(ipstack);
jksoft 0:0a2f634d3324 115 strcpy(servername,host);
jksoft 0:0a2f634d3324 116 portnum = port;
jksoft 5:dd68fa651637 117 strcpy(app_id,_app_id);
jksoft 0:0a2f634d3324 118 strcpy(_clientid,client_id);
jksoft 0:0a2f634d3324 119 strcpy(username,_session);
jksoft 0:0a2f634d3324 120 strcpy(password,app_id);
jksoft 6:1b5ec3a15d67 121
jksoft 7:f1e123331cad 122 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 7:f1e123331cad 123 milkcocoaSubscribers[i] = NULL;
jksoft 7:f1e123331cad 124 }
jksoft 7:f1e123331cad 125
jksoft 6:1b5ec3a15d67 126 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 127 setLoopCycle(5000);
jksoft 0:0a2f634d3324 128
jksoft 1:8e4149b53a8a 129 cycleThread1.start(Milkcocoa::threadStarter1,this);
jksoft 1:8e4149b53a8a 130 cycleThread2.start(Milkcocoa::threadStarter2,this);
jksoft 6:1b5ec3a15d67 131 #endif
jksoft 0:0a2f634d3324 132 }
jksoft 0:0a2f634d3324 133
jksoft 0:0a2f634d3324 134 Milkcocoa* Milkcocoa::createWithApiKey(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret) {
jksoft 0:0a2f634d3324 135 char session[60];
jksoft 0:0a2f634d3324 136 sprintf(session, "k%s:%s", key, secret);
jksoft 0:0a2f634d3324 137 return new Milkcocoa(nif, host, port, _app_id, client_id, session);
jksoft 0:0a2f634d3324 138 }
jksoft 0:0a2f634d3324 139
jksoft 0:0a2f634d3324 140 void Milkcocoa::connect() {
jksoft 0:0a2f634d3324 141
jksoft 0:0a2f634d3324 142 if(client->isConnected())
jksoft 0:0a2f634d3324 143 return;
jksoft 0:0a2f634d3324 144
jksoft 0:0a2f634d3324 145 if(client->connect(servername, portnum)!=0) {
jksoft 0:0a2f634d3324 146 DBG(pc.printf("Network connect err\r\n");)
jksoft 0:0a2f634d3324 147 return;
jksoft 0:0a2f634d3324 148 }
jksoft 0:0a2f634d3324 149
jksoft 0:0a2f634d3324 150 MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
jksoft 0:0a2f634d3324 151 data.keepAliveInterval = 20;
jksoft 0:0a2f634d3324 152 data.cleansession = 1;
jksoft 0:0a2f634d3324 153 data.MQTTVersion = 4;
jksoft 0:0a2f634d3324 154 data.clientID.cstring = _clientid;
jksoft 0:0a2f634d3324 155 data.username.cstring = username;
jksoft 0:0a2f634d3324 156 data.password.cstring = password;
jksoft 0:0a2f634d3324 157
jksoft 0:0a2f634d3324 158 if (client->connect(data) != 0) {
jksoft 0:0a2f634d3324 159 DBG(pc.printf("Milkcocoa connect err\r\n");)
jksoft 0:0a2f634d3324 160 return;
jksoft 0:0a2f634d3324 161 }
jksoft 0:0a2f634d3324 162
jksoft 0:0a2f634d3324 163 }
jksoft 0:0a2f634d3324 164
jksoft 0:0a2f634d3324 165 bool Milkcocoa::push(const char *path, DataElement dataelement) {
jksoft 0:0a2f634d3324 166 milkcocoa_message_t *message = message_box.alloc();
jksoft 0:0a2f634d3324 167 char *buf;
jksoft 0:0a2f634d3324 168
jksoft 0:0a2f634d3324 169 if(message == NULL) return false;
jksoft 0:0a2f634d3324 170
jksoft 0:0a2f634d3324 171 sprintf(message->topic, "%s/%s/push", app_id, path);
jksoft 0:0a2f634d3324 172 buf = dataelement.toCharArray();
jksoft 0:0a2f634d3324 173 strcpy(message->message , buf);
jksoft 0:0a2f634d3324 174
jksoft 0:0a2f634d3324 175 osStatus stat = message_box.put(message);
jksoft 0:0a2f634d3324 176
jksoft 0:0a2f634d3324 177 if( stat != osOK ) return false;
jksoft 0:0a2f634d3324 178
jksoft 0:0a2f634d3324 179 return true;
jksoft 0:0a2f634d3324 180 }
jksoft 0:0a2f634d3324 181
jksoft 3:cddf81a87de3 182 bool Milkcocoa::push(const char *path, char *data) {
jksoft 6:1b5ec3a15d67 183
jksoft 3:cddf81a87de3 184 milkcocoa_message_t *message = message_box.alloc();
jksoft 3:cddf81a87de3 185 char *buf;
jksoft 3:cddf81a87de3 186
jksoft 3:cddf81a87de3 187 if(message == NULL) return false;
jksoft 3:cddf81a87de3 188
jksoft 3:cddf81a87de3 189 sprintf(message->topic, "%s/%s/push", app_id, path);
jksoft 3:cddf81a87de3 190
jksoft 4:9cfd43d8de16 191 strcpy(message->message , "{\"params\":");
jksoft 3:cddf81a87de3 192 strcat(message->message , data);
jksoft 3:cddf81a87de3 193 strcat(message->message , "}");
jksoft 3:cddf81a87de3 194
jksoft 3:cddf81a87de3 195 osStatus stat = message_box.put(message);
jksoft 3:cddf81a87de3 196
jksoft 3:cddf81a87de3 197 if( stat != osOK ) return false;
jksoft 3:cddf81a87de3 198
jksoft 3:cddf81a87de3 199 return true;
jksoft 3:cddf81a87de3 200 }
jksoft 3:cddf81a87de3 201
jksoft 0:0a2f634d3324 202 bool Milkcocoa::send(const char *path, DataElement dataelement) {
jksoft 0:0a2f634d3324 203 milkcocoa_message_t *message = message_box.alloc();
jksoft 0:0a2f634d3324 204 char *buf;
jksoft 0:0a2f634d3324 205
jksoft 0:0a2f634d3324 206 if(message == NULL) return false;
jksoft 0:0a2f634d3324 207
jksoft 0:0a2f634d3324 208 sprintf(message->topic, "%s/%s/send", app_id, path);
jksoft 0:0a2f634d3324 209 buf = dataelement.toCharArray();
jksoft 0:0a2f634d3324 210 strcpy(message->message , buf);
jksoft 0:0a2f634d3324 211
jksoft 0:0a2f634d3324 212 osStatus stat = message_box.put(message);
jksoft 0:0a2f634d3324 213
jksoft 0:0a2f634d3324 214 if( stat != osOK ) return false;
jksoft 6:1b5ec3a15d67 215
jksoft 0:0a2f634d3324 216 return true;
jksoft 0:0a2f634d3324 217 }
jksoft 0:0a2f634d3324 218
jksoft 3:cddf81a87de3 219 bool Milkcocoa::send(const char *path, char *data) {
jksoft 3:cddf81a87de3 220 milkcocoa_message_t *message = message_box.alloc();
jksoft 3:cddf81a87de3 221 char *buf;
jksoft 3:cddf81a87de3 222
jksoft 3:cddf81a87de3 223 if(message == NULL) return false;
jksoft 3:cddf81a87de3 224
jksoft 3:cddf81a87de3 225 sprintf(message->topic, "%s/%s/send", app_id, path);
jksoft 3:cddf81a87de3 226
jksoft 4:9cfd43d8de16 227 strcpy(message->message , "{\"params\":");
jksoft 3:cddf81a87de3 228 strcat(message->message , data);
jksoft 3:cddf81a87de3 229 strcat(message->message , "}");
jksoft 3:cddf81a87de3 230
jksoft 3:cddf81a87de3 231 osStatus stat = message_box.put(message);
jksoft 3:cddf81a87de3 232
jksoft 3:cddf81a87de3 233 if( stat != osOK ) return false;
jksoft 6:1b5ec3a15d67 234
jksoft 3:cddf81a87de3 235 return true;
jksoft 3:cddf81a87de3 236 }
jksoft 3:cddf81a87de3 237
jksoft 0:0a2f634d3324 238 void Milkcocoa::loop() {
jksoft 0:0a2f634d3324 239 connect();
jksoft 6:1b5ec3a15d67 240 client->yield(1);
jksoft 6:1b5ec3a15d67 241
jksoft 6:1b5ec3a15d67 242 #ifndef __MILKCOCOA_THREAD
jksoft 6:1b5ec3a15d67 243 osEvent evt = message_box.get(0);
jksoft 6:1b5ec3a15d67 244 if (evt.status == osEventMail) {
jksoft 6:1b5ec3a15d67 245 milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p;
jksoft 6:1b5ec3a15d67 246 MQTT::Message mq_message;
jksoft 6:1b5ec3a15d67 247 if(message != NULL) {
jksoft 6:1b5ec3a15d67 248 mq_message.qos = MQTT::QOS0;
jksoft 6:1b5ec3a15d67 249 mq_message.retained = 0;
jksoft 6:1b5ec3a15d67 250 mq_message.dup = false;
jksoft 6:1b5ec3a15d67 251 mq_message.payload = (void*)message->message;
jksoft 6:1b5ec3a15d67 252 mq_message.payloadlen = strlen(message->message);
jksoft 6:1b5ec3a15d67 253
jksoft 6:1b5ec3a15d67 254 client->publish(message->topic, mq_message);
jksoft 6:1b5ec3a15d67 255
jksoft 6:1b5ec3a15d67 256 message_box.free(message);
jksoft 6:1b5ec3a15d67 257 }
jksoft 6:1b5ec3a15d67 258 }
jksoft 6:1b5ec3a15d67 259 #endif
jksoft 0:0a2f634d3324 260 }
jksoft 0:0a2f634d3324 261
jksoft 0:0a2f634d3324 262 bool Milkcocoa::on(const char *path, const char *event, GeneralFunction cb) {
jksoft 0:0a2f634d3324 263 MilkcocoaSubscriber *sub = new MilkcocoaSubscriber(cb);
jksoft 0:0a2f634d3324 264 sprintf(sub->topic, "%s/%s/%s", app_id, path, event);
jksoft 0:0a2f634d3324 265
jksoft 0:0a2f634d3324 266 if (client->subscribe(sub->topic, MQTT::QOS0, cb) != 0) {
jksoft 0:0a2f634d3324 267 DBG(pc.printf("Milkcocoa subscribe err\r\n");)
jksoft 0:0a2f634d3324 268 return false;
jksoft 0:0a2f634d3324 269 }
jksoft 0:0a2f634d3324 270 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 0:0a2f634d3324 271 if (milkcocoaSubscribers[i] == sub) {
jksoft 0:0a2f634d3324 272 return false;
jksoft 0:0a2f634d3324 273 }
jksoft 0:0a2f634d3324 274 }
jksoft 0:0a2f634d3324 275 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 0:0a2f634d3324 276 if (milkcocoaSubscribers[i] == 0) {
jksoft 0:0a2f634d3324 277 milkcocoaSubscribers[i] = sub;
jksoft 0:0a2f634d3324 278 return true;
jksoft 0:0a2f634d3324 279 }
jksoft 0:0a2f634d3324 280 }
jksoft 0:0a2f634d3324 281 return true;
jksoft 0:0a2f634d3324 282 }
jksoft 0:0a2f634d3324 283
jksoft 6:1b5ec3a15d67 284 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 285 void Milkcocoa::setLoopCycle(int cycle) {
jksoft 0:0a2f634d3324 286 loop_cycle = cycle;
jksoft 0:0a2f634d3324 287 }
jksoft 0:0a2f634d3324 288 void Milkcocoa::start() {
jksoft 1:8e4149b53a8a 289 cycleThread1.signal_set(START_THREAD);
jksoft 1:8e4149b53a8a 290 cycleThread2.signal_set(START_THREAD);
jksoft 0:0a2f634d3324 291 }
jksoft 0:0a2f634d3324 292
jksoft 1:8e4149b53a8a 293 void Milkcocoa::cycle_Thread1(void) {
jksoft 1:8e4149b53a8a 294 cycleThread1.signal_wait(START_THREAD);
jksoft 0:0a2f634d3324 295 while(1) {
jksoft 0:0a2f634d3324 296 Timer timer;
jksoft 0:0a2f634d3324 297 timer.start();
jksoft 0:0a2f634d3324 298 connect();
jksoft 1:8e4149b53a8a 299
jksoft 1:8e4149b53a8a 300 client->yield(RECV_TIMEOUT);
jksoft 0:0a2f634d3324 301
jksoft 1:8e4149b53a8a 302 int sub_time = loop_cycle - timer.read();
jksoft 1:8e4149b53a8a 303 if( sub_time > 0 ){
jksoft 1:8e4149b53a8a 304 Thread::wait(sub_time);
jksoft 1:8e4149b53a8a 305 }
jksoft 1:8e4149b53a8a 306 timer.stop();
jksoft 1:8e4149b53a8a 307 }
jksoft 1:8e4149b53a8a 308 }
jksoft 1:8e4149b53a8a 309 void Milkcocoa::cycle_Thread2(void) {
jksoft 1:8e4149b53a8a 310 cycleThread2.signal_wait(START_THREAD);
jksoft 1:8e4149b53a8a 311 while(1) {
jksoft 1:8e4149b53a8a 312
jksoft 0:0a2f634d3324 313 osEvent evt = message_box.get();
jksoft 0:0a2f634d3324 314 if (evt.status == osEventMail) {
jksoft 0:0a2f634d3324 315 milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p;
jksoft 0:0a2f634d3324 316 MQTT::Message mq_message;
jksoft 0:0a2f634d3324 317
jksoft 0:0a2f634d3324 318 if(message == NULL) break;
jksoft 0:0a2f634d3324 319
jksoft 0:0a2f634d3324 320 mq_message.qos = MQTT::QOS0;
jksoft 0:0a2f634d3324 321 mq_message.retained = 0;
jksoft 0:0a2f634d3324 322 mq_message.dup = false;
jksoft 0:0a2f634d3324 323 mq_message.payload = (void*)message->message;
jksoft 0:0a2f634d3324 324 mq_message.payloadlen = strlen(message->message);
jksoft 0:0a2f634d3324 325
jksoft 0:0a2f634d3324 326 client->publish(message->topic, mq_message);
jksoft 0:0a2f634d3324 327
jksoft 0:0a2f634d3324 328 message_box.free(message);
jksoft 1:8e4149b53a8a 329 }
jksoft 1:8e4149b53a8a 330 Thread::wait(1000);
jksoft 0:0a2f634d3324 331 }
jksoft 0:0a2f634d3324 332 }
jksoft 0:0a2f634d3324 333
jksoft 1:8e4149b53a8a 334 void Milkcocoa::threadStarter1(void const *p) {
jksoft 0:0a2f634d3324 335 Milkcocoa *instance = (Milkcocoa*)p;
jksoft 1:8e4149b53a8a 336 instance->cycle_Thread1();
jksoft 1:8e4149b53a8a 337 }
jksoft 1:8e4149b53a8a 338 void Milkcocoa::threadStarter2(void const *p) {
jksoft 1:8e4149b53a8a 339 Milkcocoa *instance = (Milkcocoa*)p;
jksoft 1:8e4149b53a8a 340 instance->cycle_Thread2();
jksoft 0:0a2f634d3324 341 }
jksoft 6:1b5ec3a15d67 342 #endif
jksoft 0:0a2f634d3324 343
jksoft 0:0a2f634d3324 344 MilkcocoaSubscriber::MilkcocoaSubscriber(GeneralFunction _cb) {
jksoft 0:0a2f634d3324 345 cb = _cb;
jksoft 0:0a2f634d3324 346 }
jksoft 0:0a2f634d3324 347