Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 #ifndef _RADIO_CONFIG_H_
vpcola 0:f1d3878b8dd9 2 #define _RADIO_CONFIG_H_
vpcola 0:f1d3878b8dd9 3
vpcola 0:f1d3878b8dd9 4 #include <stdio.h>
vpcola 0:f1d3878b8dd9 5 #include <stdlib.h>
vpcola 0:f1d3878b8dd9 6 #include <string.h>
vpcola 0:f1d3878b8dd9 7 #include <vector>
vpcola 0:f1d3878b8dd9 8 #include "stdint.h"
vpcola 0:f1d3878b8dd9 9 #include "jsmn.h"
vpcola 0:f1d3878b8dd9 10
vpcola 0:f1d3878b8dd9 11 #define RADIO_NAME_LEN 100
vpcola 0:f1d3878b8dd9 12 struct RadioSlave
vpcola 0:f1d3878b8dd9 13 {
vpcola 0:f1d3878b8dd9 14 uint64_t radioID;
vpcola 0:f1d3878b8dd9 15 char name[RADIO_NAME_LEN];
vpcola 0:f1d3878b8dd9 16
vpcola 0:f1d3878b8dd9 17 uint16_t temp_pin;
vpcola 0:f1d3878b8dd9 18 uint16_t humid_pin;
vpcola 0:f1d3878b8dd9 19 uint16_t lumin_pin;
vpcola 0:f1d3878b8dd9 20 uint16_t sprinkler_pin;
vpcola 0:f1d3878b8dd9 21 uint16_t hthreshold;
vpcola 0:f1d3878b8dd9 22
vpcola 0:f1d3878b8dd9 23 RadioSlave()
vpcola 0:f1d3878b8dd9 24 :radioID(0),
vpcola 0:f1d3878b8dd9 25 temp_pin(0),
vpcola 0:f1d3878b8dd9 26 humid_pin(0),
vpcola 0:f1d3878b8dd9 27 lumin_pin(0),
vpcola 0:f1d3878b8dd9 28 sprinkler_pin(0),
vpcola 0:f1d3878b8dd9 29 hthreshold(0)
vpcola 0:f1d3878b8dd9 30 {
vpcola 0:f1d3878b8dd9 31 memset(&name[0], 0, RADIO_NAME_LEN);
vpcola 0:f1d3878b8dd9 32 }
vpcola 0:f1d3878b8dd9 33 void debug()
vpcola 0:f1d3878b8dd9 34 {
vpcola 0:f1d3878b8dd9 35 printf("Slave ID : %lld\r\n", radioID);
vpcola 0:f1d3878b8dd9 36 printf("Name : \"%s\"\r\n", &name[0]);
vpcola 0:f1d3878b8dd9 37 printf("Temperature Pin: %d\r\n", temp_pin);
vpcola 0:f1d3878b8dd9 38 printf("Humidity Pin: %d\r\n", humid_pin);
vpcola 0:f1d3878b8dd9 39 printf("Luminance Pin: %d\r\n", lumin_pin);
vpcola 0:f1d3878b8dd9 40 printf("Sprinkler Pin: %d\r\n", sprinkler_pin);
vpcola 0:f1d3878b8dd9 41 printf("Humidity Threshold: %d\r\n", hthreshold);
vpcola 0:f1d3878b8dd9 42 }
vpcola 0:f1d3878b8dd9 43 };
vpcola 0:f1d3878b8dd9 44
vpcola 0:f1d3878b8dd9 45 struct RadioCfg
vpcola 0:f1d3878b8dd9 46 {
vpcola 0:f1d3878b8dd9 47 uint64_t radioID;
vpcola 0:f1d3878b8dd9 48 char name[RADIO_NAME_LEN];
vpcola 0:f1d3878b8dd9 49 char country[RADIO_NAME_LEN];
vpcola 0:f1d3878b8dd9 50 uint32_t utc_offset;
vpcola 0:f1d3878b8dd9 51 std::vector<RadioSlave> radios;
vpcola 0:f1d3878b8dd9 52
vpcola 0:f1d3878b8dd9 53 RadioCfg()
vpcola 0:f1d3878b8dd9 54 :radioID(0),
vpcola 0:f1d3878b8dd9 55 utc_offset(0)
vpcola 0:f1d3878b8dd9 56 {
vpcola 0:f1d3878b8dd9 57 memset(&name[0], 0, RADIO_NAME_LEN);
vpcola 0:f1d3878b8dd9 58 memset(&country[0], 0, RADIO_NAME_LEN);
vpcola 0:f1d3878b8dd9 59 radios.clear();
vpcola 0:f1d3878b8dd9 60 }
vpcola 0:f1d3878b8dd9 61
vpcola 0:f1d3878b8dd9 62 inline void debug()
vpcola 0:f1d3878b8dd9 63 {
vpcola 0:f1d3878b8dd9 64 printf("Radio ID: %lld\r\n", radioID);
vpcola 0:f1d3878b8dd9 65 printf("Name : \"%s\"\r\n", &name[0]);
vpcola 0:f1d3878b8dd9 66 printf("Country : \"%s\"\r\n", &country[0]);
vpcola 0:f1d3878b8dd9 67 printf("UTC Offset: %d\r\n", utc_offset);
vpcola 0:f1d3878b8dd9 68 std::vector<RadioSlave>::iterator it;
vpcola 0:f1d3878b8dd9 69 for(it = radios.begin(); it != radios.end(); it++)
vpcola 0:f1d3878b8dd9 70 {
vpcola 0:f1d3878b8dd9 71 (*it).debug();
vpcola 0:f1d3878b8dd9 72 }
vpcola 0:f1d3878b8dd9 73 }
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75 };
vpcola 0:f1d3878b8dd9 76
vpcola 0:f1d3878b8dd9 77 int parseradioconfig(const char * jsonstring, RadioCfg &);
vpcola 0:f1d3878b8dd9 78
vpcola 0:f1d3878b8dd9 79 #endif