Counter
Dependencies: EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem
Uplink/uplink.h@0:ecaf3e593122, 2016-02-29 (annotated)
- Committer:
- Tuxitheone
- Date:
- Mon Feb 29 18:59:15 2016 +0000
- Revision:
- 0:ecaf3e593122
TankCounter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tuxitheone | 0:ecaf3e593122 | 1 | |
Tuxitheone | 0:ecaf3e593122 | 2 | #ifndef _TapTraqUplink_H |
Tuxitheone | 0:ecaf3e593122 | 3 | #define _TapTraqUplink_H |
Tuxitheone | 0:ecaf3e593122 | 4 | |
Tuxitheone | 0:ecaf3e593122 | 5 | #include "Websocket.h" |
Tuxitheone | 0:ecaf3e593122 | 6 | #include "mbed.h" |
Tuxitheone | 0:ecaf3e593122 | 7 | #include <string> |
Tuxitheone | 0:ecaf3e593122 | 8 | |
Tuxitheone | 0:ecaf3e593122 | 9 | #define MAX_NUMBER 10 |
Tuxitheone | 0:ecaf3e593122 | 10 | #define SetupStrSize 100 |
Tuxitheone | 0:ecaf3e593122 | 11 | #define MaxCtrl 10 //max antal ctrl der hænger på en gateway |
Tuxitheone | 0:ecaf3e593122 | 12 | |
Tuxitheone | 0:ecaf3e593122 | 13 | |
Tuxitheone | 0:ecaf3e593122 | 14 | class TapTraqUplink |
Tuxitheone | 0:ecaf3e593122 | 15 | { |
Tuxitheone | 0:ecaf3e593122 | 16 | public: |
Tuxitheone | 0:ecaf3e593122 | 17 | typedef struct {//Der er en setuprec for hver hane |
Tuxitheone | 0:ecaf3e593122 | 18 | uint16_t ID, //Hane ID |
Tuxitheone | 0:ecaf3e593122 | 19 | TabType, //Hane type om det er sodavand eller øl hanne |
Tuxitheone | 0:ecaf3e593122 | 20 | EscTryk, //mulighed for at hvis man tryker en ekstra gang, vil den stoppe med det samme |
Tuxitheone | 0:ecaf3e593122 | 21 | FlowEnable, //Hvis der er flowmåler |
Tuxitheone | 0:ecaf3e593122 | 22 | FlowMode, //0: stop ved flow, 1 fritløb sender ved timeout 2: festival mode sender hvert 10 s |
Tuxitheone | 0:ecaf3e593122 | 23 | IntervalUpload, //sekunder mellem hver upload |
Tuxitheone | 0:ecaf3e593122 | 24 | //SmartTab |
Tuxitheone | 0:ecaf3e593122 | 25 | XLOn, XLPause, XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 26 | LOn, LPause, LTopup, |
Tuxitheone | 0:ecaf3e593122 | 27 | MOn, MPause, MTopup, |
Tuxitheone | 0:ecaf3e593122 | 28 | SOn, SPause, STopup; |
Tuxitheone | 0:ecaf3e593122 | 29 | } SetupRec; //længde = 43byte |
Tuxitheone | 0:ecaf3e593122 | 30 | |
Tuxitheone | 0:ecaf3e593122 | 31 | typedef struct {//Der er en |
Tuxitheone | 0:ecaf3e593122 | 32 | char EUID[17];//uniq 64 identify |
Tuxitheone | 0:ecaf3e593122 | 33 | char ID; //id internt |
Tuxitheone | 0:ecaf3e593122 | 34 | } PanIdRec; |
Tuxitheone | 0:ecaf3e593122 | 35 | |
Tuxitheone | 0:ecaf3e593122 | 36 | //er hvor meget der er kommet igennem hver enkelt hane |
Tuxitheone | 0:ecaf3e593122 | 37 | /** |
Tuxitheone | 0:ecaf3e593122 | 38 | * Constructor |
Tuxitheone | 0:ecaf3e593122 | 39 | * |
Tuxitheone | 0:ecaf3e593122 | 40 | * @param id Name of the client on the network |
Tuxitheone | 0:ecaf3e593122 | 41 | * @param ws All communication between clients will be established over this websocket |
Tuxitheone | 0:ecaf3e593122 | 42 | */ |
Tuxitheone | 0:ecaf3e593122 | 43 | |
Tuxitheone | 0:ecaf3e593122 | 44 | |
Tuxitheone | 0:ecaf3e593122 | 45 | TapTraqUplink(Websocket *webs) : webs(webs), index(0), index_proc(0) { |
Tuxitheone | 0:ecaf3e593122 | 46 | std::string path = webs->getPath(); |
Tuxitheone | 0:ecaf3e593122 | 47 | std::string token = "/"; |
Tuxitheone | 0:ecaf3e593122 | 48 | size_t found; |
Tuxitheone | 0:ecaf3e593122 | 49 | found = path.find(token); |
Tuxitheone | 0:ecaf3e593122 | 50 | if (found != std::string::npos) |
Tuxitheone | 0:ecaf3e593122 | 51 | found = path.find(token, found + 1); |
Tuxitheone | 0:ecaf3e593122 | 52 | if (found != std::string::npos) |
Tuxitheone | 0:ecaf3e593122 | 53 | path = path.substr(found + 1, std::string::npos); |
Tuxitheone | 0:ecaf3e593122 | 54 | for (char ID=0; ID<MAX_NUMBER; ID++) { |
Tuxitheone | 0:ecaf3e593122 | 55 | strcpy(PanId[ID].EUID,"0000000000000000"); |
Tuxitheone | 0:ecaf3e593122 | 56 | PanId[ID].ID=0; |
Tuxitheone | 0:ecaf3e593122 | 57 | } |
Tuxitheone | 0:ecaf3e593122 | 58 | // strcpy(my_id, path.c_str()); |
Tuxitheone | 0:ecaf3e593122 | 59 | }; |
Tuxitheone | 0:ecaf3e593122 | 60 | //socket del |
Tuxitheone | 0:ecaf3e593122 | 61 | //sender en flowfram fra en counter til database |
Tuxitheone | 0:ecaf3e593122 | 62 | void FlowFrame (char *ID,uint8_t TapID, uint32_t Flow, uint32_t Spild, uint16_t Temp, uint16_t Key1,uint16_t Key2,uint16_t Key3,uint16_t Key4); |
Tuxitheone | 0:ecaf3e593122 | 63 | //Sender et givet setup record til database |
Tuxitheone | 0:ecaf3e593122 | 64 | void setuprec (char ID, char *node); |
Tuxitheone | 0:ecaf3e593122 | 65 | //Frame til tank måler |
Tuxitheone | 0:ecaf3e593122 | 66 | void TankFlowFrame (char *ID, float latitude, float longitude, uint32_t Flow, float Temp); |
Tuxitheone | 0:ecaf3e593122 | 67 | //Sender gateways ID |
Tuxitheone | 0:ecaf3e593122 | 68 | void alive(char *p); |
Tuxitheone | 0:ecaf3e593122 | 69 | |
Tuxitheone | 0:ecaf3e593122 | 70 | //sender ID for en counter tilkoblet gateway |
Tuxitheone | 0:ecaf3e593122 | 71 | void panlist(char *gateway, char id); |
Tuxitheone | 0:ecaf3e593122 | 72 | |
Tuxitheone | 0:ecaf3e593122 | 73 | //chekcer for indgående beskeder fra WS |
Tuxitheone | 0:ecaf3e593122 | 74 | int work(); |
Tuxitheone | 0:ecaf3e593122 | 75 | char RxStr; |
Tuxitheone | 0:ecaf3e593122 | 76 | //Modtager setuprecord om gemmer dem på SDkort |
Tuxitheone | 0:ecaf3e593122 | 77 | void Rxsetuprec(); |
Tuxitheone | 0:ecaf3e593122 | 78 | //dekode setup record modtaget fra ctrl. Denne sendes i to dele derfor denne opdeling |
Tuxitheone | 0:ecaf3e593122 | 79 | void RxSetuprec1(char *p,char CtrlNr); |
Tuxitheone | 0:ecaf3e593122 | 80 | void RxSetuprec2(char *p,char CtrlNr); |
Tuxitheone | 0:ecaf3e593122 | 81 | |
Tuxitheone | 0:ecaf3e593122 | 82 | //Logger/gemme del |
Tuxitheone | 0:ecaf3e593122 | 83 | //læser alle setup record ind i hukommelse |
Tuxitheone | 0:ecaf3e593122 | 84 | void ReadConfig(); |
Tuxitheone | 0:ecaf3e593122 | 85 | //skriver en default setup for alle |
Tuxitheone | 0:ecaf3e593122 | 86 | void WriteDefault(void); |
Tuxitheone | 0:ecaf3e593122 | 87 | //gemmer setuprecords fra hukommelse til SD kort |
Tuxitheone | 0:ecaf3e593122 | 88 | void SaveConfig(); |
Tuxitheone | 0:ecaf3e593122 | 89 | //åbner på, hvis ikke den kan finde en opsætning skriver den en default |
Tuxitheone | 0:ecaf3e593122 | 90 | void iniopen(void); |
Tuxitheone | 0:ecaf3e593122 | 91 | |
Tuxitheone | 0:ecaf3e593122 | 92 | void SavePanID(); |
Tuxitheone | 0:ecaf3e593122 | 93 | void ReadPanID(); |
Tuxitheone | 0:ecaf3e593122 | 94 | |
Tuxitheone | 0:ecaf3e593122 | 95 | SetupRec SetupArr[MAX_NUMBER*MaxCtrl]; |
Tuxitheone | 0:ecaf3e593122 | 96 | PanIdRec PanId[MaxCtrl]; //10 stik 64 bit Paid |
Tuxitheone | 0:ecaf3e593122 | 97 | int CheckPan(char *p); |
Tuxitheone | 0:ecaf3e593122 | 98 | bool AddPan(char *p); |
Tuxitheone | 0:ecaf3e593122 | 99 | |
Tuxitheone | 0:ecaf3e593122 | 100 | char json_recv[100]; //modtaget data |
Tuxitheone | 0:ecaf3e593122 | 101 | private: |
Tuxitheone | 0:ecaf3e593122 | 102 | Websocket * webs; |
Tuxitheone | 0:ecaf3e593122 | 103 | int index; |
Tuxitheone | 0:ecaf3e593122 | 104 | int index_proc; |
Tuxitheone | 0:ecaf3e593122 | 105 | char my_id[20]; |
Tuxitheone | 0:ecaf3e593122 | 106 | |
Tuxitheone | 0:ecaf3e593122 | 107 | char Confrec[MAX_NUMBER][SetupStrSize]; |
Tuxitheone | 0:ecaf3e593122 | 108 | }; |
Tuxitheone | 0:ecaf3e593122 | 109 | |
Tuxitheone | 0:ecaf3e593122 | 110 | |
Tuxitheone | 0:ecaf3e593122 | 111 | |
Tuxitheone | 0:ecaf3e593122 | 112 | |
Tuxitheone | 0:ecaf3e593122 | 113 | #endif |