emma controller code in production board v1

Dependencies:   ADE7758_v1 Crypto DHT11 MQTT MbedJSONValueEmma SDFileSystem TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src SoftSerial

Fork of emma_controller_energy by Emma

Committer:
arsenalist
Date:
Tue Jul 14 16:48:24 2015 +0000
Revision:
14:8287f0f5d987
Parent:
12:96f637ed37f9
Child:
21:33bd8b82560f
Working RTC with backup.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arsenalist 0:f4e449fa34d7 1 #ifndef MBED_EMMACODE_H
arsenalist 0:f4e449fa34d7 2 #define MBED_EMMACODE_H
arsenalist 0:f4e449fa34d7 3
arsenalist 0:f4e449fa34d7 4 #include "mbed.h"
arsenalist 12:96f637ed37f9 5 #include "espduino.h" //wifi mqtt
arsenalist 12:96f637ed37f9 6 #include "mqtt.h" //wifi mqtt
arsenalist 12:96f637ed37f9 7 #include "rest.h" //wifi rest
arsenalist 12:96f637ed37f9 8 #include "MQTTClient.h" //eth mqtt
arsenalist 12:96f637ed37f9 9 #include "MQTTEthernet.h" //eth mqtt
arsenalist 12:96f637ed37f9 10 #include "MbedJSONValue.h" //json
arsenalist 12:96f637ed37f9 11 #include "SDFileSystem.h" //sd card
arsenalist 12:96f637ed37f9 12 #include "Crypto.h" //hash calculation
arsenalist 12:96f637ed37f9 13 #include "cmsis_os.h" //threads
arsenalist 12:96f637ed37f9 14 #include "ade7758.h" //ade7758
arsenalist 12:96f637ed37f9 15 #include "SPI_TFT_ILI9341.h" //lcd
arsenalist 12:96f637ed37f9 16 #include "Touch.h" //touch
arsenalist 12:96f637ed37f9 17 #include "Arial12x12.h" //font
arsenalist 14:8287f0f5d987 18 #include "SetRTC.h" //rtc
arsenalist 0:f4e449fa34d7 19 #include <string>
arsenalist 0:f4e449fa34d7 20
arsenalist 0:f4e449fa34d7 21 //platform
arsenalist 0:f4e449fa34d7 22 #if defined TARGET_NUCLEO_F103RB
arsenalist 0:f4e449fa34d7 23 #define BASE_ADDR 0x1FFFF7E8
arsenalist 0:f4e449fa34d7 24 #elif defined TARGET_NUCLEO_F401RE
arsenalist 0:f4e449fa34d7 25 #define BASE_ADDR 0x1FFF7A10
arsenalist 0:f4e449fa34d7 26 #endif
arsenalist 0:f4e449fa34d7 27
arsenalist 0:f4e449fa34d7 28 //mode
arsenalist 0:f4e449fa34d7 29 #define MODE_WIFI_CONFIG 0x00 //wifi config
arsenalist 0:f4e449fa34d7 30 #define MODE_SETTINGS 0x01 //settings
arsenalist 0:f4e449fa34d7 31 #define MODE_REGISTER 0x02 //registration
arsenalist 0:f4e449fa34d7 32 #define MODE_OPERATION 0x03 //operational
arsenalist 0:f4e449fa34d7 33 #define MODE_FIRMWARE_DOWNLOAD 0x04 //firmware download
arsenalist 0:f4e449fa34d7 34
arsenalist 0:f4e449fa34d7 35 //interface
arsenalist 0:f4e449fa34d7 36 #define IF_WIFI 0x00
arsenalist 0:f4e449fa34d7 37 #define IF_ETH 0x01
arsenalist 0:f4e449fa34d7 38 #define IF_GPRS 0x02
arsenalist 0:f4e449fa34d7 39
arsenalist 0:f4e449fa34d7 40 //wifi
arsenalist 0:f4e449fa34d7 41 #define ESP_BAUD 19200
arsenalist 0:f4e449fa34d7 42
arsenalist 0:f4e449fa34d7 43 //mqtt
arsenalist 0:f4e449fa34d7 44 #define MQTT_MAX_PACKET_SIZE 250 //for eth
arsenalist 0:f4e449fa34d7 45 #define MQTT_HOST "192.168.131.200"
arsenalist 0:f4e449fa34d7 46 #define MQTT_PORT 1883
arsenalist 0:f4e449fa34d7 47
arsenalist 0:f4e449fa34d7 48 //eth rest
arsenalist 0:f4e449fa34d7 49 #define SERVER_PORT 80
arsenalist 0:f4e449fa34d7 50
arsenalist 4:76ab12e2f8a3 51 //nodes and remote
arsenalist 0:f4e449fa34d7 52 #define REMOTE_TCP_PORT 16038
arsenalist 4:76ab12e2f8a3 53 #define NODES_MAX 5
arsenalist 4:76ab12e2f8a3 54 #define NODES_INVALID 99
arsenalist 0:f4e449fa34d7 55
arsenalist 0:f4e449fa34d7 56 //emma server
arsenalist 0:f4e449fa34d7 57 #define EMMA_SERVER_HOST "192.168.131.200"
arsenalist 0:f4e449fa34d7 58 #define EMMA_SERVER_PORT 8080
arsenalist 0:f4e449fa34d7 59
arsenalist 0:f4e449fa34d7 60 //ade7758 offset
arsenalist 0:f4e449fa34d7 61 #define AIRMSOFFSET 0xFB1
arsenalist 0:f4e449fa34d7 62 #define BIRMSOFFSET 0xFB0
arsenalist 0:f4e449fa34d7 63 #define CIRMSOFFSET 0xFB1
arsenalist 0:f4e449fa34d7 64 #define AVRMSOFFSET 0xFFB
arsenalist 0:f4e449fa34d7 65 #define BVRMSOFFSET 0x2
arsenalist 0:f4e449fa34d7 66 #define CVRMSOFFSET 0xFFF
arsenalist 0:f4e449fa34d7 67
arsenalist 4:76ab12e2f8a3 68 //threshold
arsenalist 4:76ab12e2f8a3 69 #define VRMSTHRESHOLD 250
arsenalist 4:76ab12e2f8a3 70 #define WATTTHRESHOLD 200
arsenalist 4:76ab12e2f8a3 71
arsenalist 12:96f637ed37f9 72 /*start lcd and touch*/
arsenalist 12:96f637ed37f9 73 int emmaModeSelection(void);
arsenalist 12:96f637ed37f9 74 /*end lcd and touch*/
arsenalist 12:96f637ed37f9 75
arsenalist 0:f4e449fa34d7 76 /*start emma mode*/
arsenalist 12:96f637ed37f9 77 void emmaInit(int mode);
arsenalist 0:f4e449fa34d7 78 void emmaModeWiFiConfig(void);
arsenalist 0:f4e449fa34d7 79 void emmaModeSettings(void);
arsenalist 0:f4e449fa34d7 80 void emmaModeRegister(void);
arsenalist 0:f4e449fa34d7 81 void emmaModeOperation(void);
arsenalist 0:f4e449fa34d7 82 void emmaModeFirmwareDownload(void);
arsenalist 0:f4e449fa34d7 83 /*end emma mode*/
arsenalist 0:f4e449fa34d7 84
arsenalist 4:76ab12e2f8a3 85 /*start energy related*/
arsenalist 0:f4e449fa34d7 86 void energyThread(void const*);
arsenalist 4:76ab12e2f8a3 87 void checkVoltagePower();
arsenalist 4:76ab12e2f8a3 88 /*end energy related*/
arsenalist 0:f4e449fa34d7 89
arsenalist 0:f4e449fa34d7 90 /*start wifi mqtt*/
arsenalist 0:f4e449fa34d7 91 void mqttConnected(void* response);
arsenalist 0:f4e449fa34d7 92 void mqttDisconnected(void* response);
arsenalist 0:f4e449fa34d7 93 /*end wifi mqtt*/
arsenalist 0:f4e449fa34d7 94
arsenalist 0:f4e449fa34d7 95 /*start wifi rest*/
arsenalist 4:76ab12e2f8a3 96 void rxInterrupt(void);
arsenalist 4:76ab12e2f8a3 97 void checkRxBuffer(void);
arsenalist 0:f4e449fa34d7 98 /*end wifi rest*/
arsenalist 0:f4e449fa34d7 99
arsenalist 0:f4e449fa34d7 100 /*start eth mqtt*/
arsenalist 0:f4e449fa34d7 101 void ethMQTTMessageArrived(MQTT::MessageData& md);
arsenalist 0:f4e449fa34d7 102 int ethMQTTConnect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack);
arsenalist 0:f4e449fa34d7 103 void ethMQTTAttemptConnect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack);
arsenalist 0:f4e449fa34d7 104 /*end eth mqtt*/
arsenalist 0:f4e449fa34d7 105
arsenalist 0:f4e449fa34d7 106 /*start emma settings*/
arsenalist 0:f4e449fa34d7 107 string getUID(void);
arsenalist 0:f4e449fa34d7 108 string readSetting(string parameter);
arsenalist 0:f4e449fa34d7 109 bool writeSetting(string parameter, string value);
arsenalist 0:f4e449fa34d7 110 /*end emma settings*/
arsenalist 0:f4e449fa34d7 111
arsenalist 0:f4e449fa34d7 112 /*start nodes*/
arsenalist 0:f4e449fa34d7 113 string readNodeIP(string macAddr);
arsenalist 0:f4e449fa34d7 114 string readNodeCmd(string dType, string cmd);
arsenalist 0:f4e449fa34d7 115 string *readNodeList(void);
arsenalist 0:f4e449fa34d7 116 string wifiGetNodeTemp(string macAddr);
arsenalist 0:f4e449fa34d7 117 /*end nodes*/
arsenalist 0:f4e449fa34d7 118
arsenalist 0:f4e449fa34d7 119 /*start emma connection function*/
arsenalist 0:f4e449fa34d7 120 string ethGET(string host, int port, string data);
arsenalist 0:f4e449fa34d7 121 /*end emma connection function*/
arsenalist 0:f4e449fa34d7 122
arsenalist 0:f4e449fa34d7 123 /*start emma private function*/
arsenalist 8:51a0ca9079ca 124 //void connectedIface(void);
arsenalist 8:51a0ca9079ca 125 void isEthAvailable(void);
arsenalist 8:51a0ca9079ca 126 void isEthConnected(void);
arsenalist 8:51a0ca9079ca 127 void isWiFiConnected(void);
arsenalist 8:51a0ca9079ca 128 void isGprsConnected(void);
arsenalist 0:f4e449fa34d7 129 void addChar(char *s, char c);
arsenalist 0:f4e449fa34d7 130 void rcvReply(char *r, int to);
arsenalist 0:f4e449fa34d7 131 string calculateMD5(string text);
arsenalist 0:f4e449fa34d7 132 bool writeFirmwareHexToChar(string value);
arsenalist 0:f4e449fa34d7 133 bool clearFirmware(void);
arsenalist 0:f4e449fa34d7 134 /*end emma private function*/
arsenalist 0:f4e449fa34d7 135
arsenalist 0:f4e449fa34d7 136 #endif