Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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