Counter
Dependencies: EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem
Uplink/uplink.cpp@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 | #include "uplink.h" |
Tuxitheone | 0:ecaf3e593122 | 2 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Tuxitheone | 0:ecaf3e593122 | 3 | //Frames til T2 |
Tuxitheone | 0:ecaf3e593122 | 4 | void TapTraqUplink::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 | 5 | { |
Tuxitheone | 0:ecaf3e593122 | 6 | time_t sec = time(NULL); |
Tuxitheone | 0:ecaf3e593122 | 7 | char tidstr[32]; |
Tuxitheone | 0:ecaf3e593122 | 8 | sec = time(NULL); |
Tuxitheone | 0:ecaf3e593122 | 9 | strftime(tidstr, 32, "%Y/%m/%d-%H:%M:%S", localtime(&sec)); |
Tuxitheone | 0:ecaf3e593122 | 10 | sprintf(json_recv, "{1,%s,%s,%x,%x,%x,%x,%x,%x,%x,%x}" ,ID,tidstr,TapID,Flow,Spild,Temp,Key1,Key2,Key3,Key4); |
Tuxitheone | 0:ecaf3e593122 | 11 | webs->send(json_recv); |
Tuxitheone | 0:ecaf3e593122 | 12 | } |
Tuxitheone | 0:ecaf3e593122 | 13 | |
Tuxitheone | 0:ecaf3e593122 | 14 | void TapTraqUplink::setuprec (char ID, char *node) |
Tuxitheone | 0:ecaf3e593122 | 15 | { |
Tuxitheone | 0:ecaf3e593122 | 16 | sprintf(json_recv, "{2,%s,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}",node, |
Tuxitheone | 0:ecaf3e593122 | 17 | SetupArr[ID].ID, SetupArr[ID].TabType, SetupArr[ID].EscTryk, SetupArr[ID].FlowEnable, |
Tuxitheone | 0:ecaf3e593122 | 18 | SetupArr[ID].FlowMode, SetupArr[ID].IntervalUpload, |
Tuxitheone | 0:ecaf3e593122 | 19 | SetupArr[ID].XLOn, SetupArr[ID].XLPause, SetupArr[ID].XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 20 | SetupArr[ID].LOn, SetupArr[ID].LPause, SetupArr[ID].LTopup, |
Tuxitheone | 0:ecaf3e593122 | 21 | SetupArr[ID].MOn, SetupArr[ID].MPause, SetupArr[ID].MTopup, |
Tuxitheone | 0:ecaf3e593122 | 22 | SetupArr[ID].SOn, SetupArr[ID].SPause, SetupArr[ID].STopup); |
Tuxitheone | 0:ecaf3e593122 | 23 | webs->send(json_recv); |
Tuxitheone | 0:ecaf3e593122 | 24 | } |
Tuxitheone | 0:ecaf3e593122 | 25 | |
Tuxitheone | 0:ecaf3e593122 | 26 | void TapTraqUplink::TankFlowFrame (char *ID, float latitude, float longitude, uint32_t Flow, float Temp) |
Tuxitheone | 0:ecaf3e593122 | 27 | { |
Tuxitheone | 0:ecaf3e593122 | 28 | time_t sec = time(NULL); |
Tuxitheone | 0:ecaf3e593122 | 29 | char tidstr[32]; |
Tuxitheone | 0:ecaf3e593122 | 30 | sec = time(NULL); |
Tuxitheone | 0:ecaf3e593122 | 31 | strftime(tidstr, 32, "%Y/%m/%d-%H:%M:%S", localtime(&sec)); |
Tuxitheone | 0:ecaf3e593122 | 32 | sprintf(json_recv,"{%s,%s,%.4f,%.4f,%d,%.1f}", |
Tuxitheone | 0:ecaf3e593122 | 33 | ID,tidstr,latitude,longitude,Flow,Temp); |
Tuxitheone | 0:ecaf3e593122 | 34 | webs->send(json_recv); |
Tuxitheone | 0:ecaf3e593122 | 35 | } |
Tuxitheone | 0:ecaf3e593122 | 36 | |
Tuxitheone | 0:ecaf3e593122 | 37 | |
Tuxitheone | 0:ecaf3e593122 | 38 | void TapTraqUplink::alive(char *p) |
Tuxitheone | 0:ecaf3e593122 | 39 | { |
Tuxitheone | 0:ecaf3e593122 | 40 | sprintf(json_recv, "{100,%s}",p); //sender gateway ID |
Tuxitheone | 0:ecaf3e593122 | 41 | webs->send(json_recv); |
Tuxitheone | 0:ecaf3e593122 | 42 | } |
Tuxitheone | 0:ecaf3e593122 | 43 | |
Tuxitheone | 0:ecaf3e593122 | 44 | void TapTraqUplink::panlist(char *gateway, char id) |
Tuxitheone | 0:ecaf3e593122 | 45 | { |
Tuxitheone | 0:ecaf3e593122 | 46 | sprintf(json_recv, "{101,%s,%d,%s}",gateway,id,PanId[id].EUID); //sender gateway ID |
Tuxitheone | 0:ecaf3e593122 | 47 | webs->send(json_recv); |
Tuxitheone | 0:ecaf3e593122 | 48 | } |
Tuxitheone | 0:ecaf3e593122 | 49 | |
Tuxitheone | 0:ecaf3e593122 | 50 | |
Tuxitheone | 0:ecaf3e593122 | 51 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Tuxitheone | 0:ecaf3e593122 | 52 | //Frames fra T2 |
Tuxitheone | 0:ecaf3e593122 | 53 | //dekodning af beskeder |
Tuxitheone | 0:ecaf3e593122 | 54 | //Setup frames |
Tuxitheone | 0:ecaf3e593122 | 55 | void TapTraqUplink::Rxsetuprec() |
Tuxitheone | 0:ecaf3e593122 | 56 | { |
Tuxitheone | 0:ecaf3e593122 | 57 | SetupRec Setup; //vi er nødt til at ligge det over i et setup inde vi ved hvilke setup der kommet |
Tuxitheone | 0:ecaf3e593122 | 58 | sscanf(json_recv,"{2,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}", |
Tuxitheone | 0:ecaf3e593122 | 59 | &Setup.ID, &Setup.TabType,&Setup.EscTryk,&Setup.FlowEnable, |
Tuxitheone | 0:ecaf3e593122 | 60 | &Setup.FlowMode, &Setup.IntervalUpload, |
Tuxitheone | 0:ecaf3e593122 | 61 | &Setup.XLOn, &Setup.XLPause, &Setup.XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 62 | &Setup.LOn, &Setup.LPause, &Setup.LTopup, |
Tuxitheone | 0:ecaf3e593122 | 63 | &Setup.MOn, &Setup.MPause, &Setup.MTopup, |
Tuxitheone | 0:ecaf3e593122 | 64 | &Setup.SOn, &Setup.SPause, &Setup.STopup); |
Tuxitheone | 0:ecaf3e593122 | 65 | memcpy(&SetupArr[Setup.ID].ID,&Setup.ID,sizeof(Setup)); //kopiere den over |
Tuxitheone | 0:ecaf3e593122 | 66 | SaveConfig(); //Skriv den til disk |
Tuxitheone | 0:ecaf3e593122 | 67 | } |
Tuxitheone | 0:ecaf3e593122 | 68 | //setup frames fra ZB, der skal dekodes og gemmes her |
Tuxitheone | 0:ecaf3e593122 | 69 | void TapTraqUplink::RxSetuprec1(char *p,char CtrlNr) |
Tuxitheone | 0:ecaf3e593122 | 70 | { |
Tuxitheone | 0:ecaf3e593122 | 71 | SetupRec SetupData; //vi er nødt til at ligge det over i et setup inde vi ved hvilke setup der kommet |
Tuxitheone | 0:ecaf3e593122 | 72 | sscanf(p,"02,%X,%X,%X,%X,%X,%X", |
Tuxitheone | 0:ecaf3e593122 | 73 | &SetupData.ID, &SetupData.TabType, &SetupData.EscTryk, &SetupData.FlowEnable, |
Tuxitheone | 0:ecaf3e593122 | 74 | &SetupData.FlowMode, &SetupData.IntervalUpload); |
Tuxitheone | 0:ecaf3e593122 | 75 | memcpy(&SetupArr[SetupData.ID+(CtrlNr*MaxCtrl)].ID,&SetupData.ID,sizeof(SetupData)); //kopiere den over |
Tuxitheone | 0:ecaf3e593122 | 76 | } |
Tuxitheone | 0:ecaf3e593122 | 77 | |
Tuxitheone | 0:ecaf3e593122 | 78 | void TapTraqUplink::RxSetuprec2(char *p,char CtrlNr ) |
Tuxitheone | 0:ecaf3e593122 | 79 | { |
Tuxitheone | 0:ecaf3e593122 | 80 | char id; |
Tuxitheone | 0:ecaf3e593122 | 81 | SetupRec SetupData; //vi er nødt til at ligge det over i et setup inde vi ved hvilke setup der kommet |
Tuxitheone | 0:ecaf3e593122 | 82 | sscanf(p,"03,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X", &SetupData.ID, |
Tuxitheone | 0:ecaf3e593122 | 83 | &SetupData.XLOn, &SetupData.XLPause, &SetupData.XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 84 | &SetupData.LOn, &SetupData.LPause, &SetupData.LTopup, |
Tuxitheone | 0:ecaf3e593122 | 85 | &SetupData.MOn, &SetupData.MPause, &SetupData.MTopup, |
Tuxitheone | 0:ecaf3e593122 | 86 | &SetupData.SOn, &SetupData.SPause, &SetupData.STopup); |
Tuxitheone | 0:ecaf3e593122 | 87 | //SetupData.ID er setup rec numeret for den enkelte ctrl (0..9) |
Tuxitheone | 0:ecaf3e593122 | 88 | //Derudover skal vi vide hvilke ctrl det er (1..MaxCtrl) |
Tuxitheone | 0:ecaf3e593122 | 89 | id=SetupData.ID+(CtrlNr*MaxCtrl); |
Tuxitheone | 0:ecaf3e593122 | 90 | SetupArr[id].XLOn=SetupData.XLOn; |
Tuxitheone | 0:ecaf3e593122 | 91 | SetupArr[id].XLPause=SetupData.XLPause; |
Tuxitheone | 0:ecaf3e593122 | 92 | SetupArr[id].XLTopup=SetupData.XLTopup; |
Tuxitheone | 0:ecaf3e593122 | 93 | SetupArr[id].LOn=SetupData.LOn; |
Tuxitheone | 0:ecaf3e593122 | 94 | SetupArr[id].LPause=SetupData.LPause; |
Tuxitheone | 0:ecaf3e593122 | 95 | SetupArr[id].LTopup=SetupData.LTopup; |
Tuxitheone | 0:ecaf3e593122 | 96 | SetupArr[id].MOn=SetupData.MOn; |
Tuxitheone | 0:ecaf3e593122 | 97 | SetupArr[id].MPause=SetupData.MPause; |
Tuxitheone | 0:ecaf3e593122 | 98 | SetupArr[id].MTopup=SetupData.MTopup; |
Tuxitheone | 0:ecaf3e593122 | 99 | SetupArr[id].SOn=SetupData.SOn; |
Tuxitheone | 0:ecaf3e593122 | 100 | SetupArr[id].SPause=SetupData.SPause; |
Tuxitheone | 0:ecaf3e593122 | 101 | SetupArr[id].STopup=SetupData.STopup; |
Tuxitheone | 0:ecaf3e593122 | 102 | SaveConfig(); //Skriv den til disk |
Tuxitheone | 0:ecaf3e593122 | 103 | } |
Tuxitheone | 0:ecaf3e593122 | 104 | //Det var nok om setup records, tilbage til T2 |
Tuxitheone | 0:ecaf3e593122 | 105 | |
Tuxitheone | 0:ecaf3e593122 | 106 | //T vil gerne se hvordan setup er for en given counter |
Tuxitheone | 0:ecaf3e593122 | 107 | |
Tuxitheone | 0:ecaf3e593122 | 108 | //T vil gerne se en liste over hvilke counter der er online |
Tuxitheone | 0:ecaf3e593122 | 109 | |
Tuxitheone | 0:ecaf3e593122 | 110 | |
Tuxitheone | 0:ecaf3e593122 | 111 | |
Tuxitheone | 0:ecaf3e593122 | 112 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Tuxitheone | 0:ecaf3e593122 | 113 | int TapTraqUplink::work() |
Tuxitheone | 0:ecaf3e593122 | 114 | { |
Tuxitheone | 0:ecaf3e593122 | 115 | if (webs->read(json_recv)) return 1; |
Tuxitheone | 0:ecaf3e593122 | 116 | else return 0; |
Tuxitheone | 0:ecaf3e593122 | 117 | } |
Tuxitheone | 0:ecaf3e593122 | 118 | //--------------------------Pan liste------------------------------------------------------- |
Tuxitheone | 0:ecaf3e593122 | 119 | //gem liste over PANID, som vi kan se |
Tuxitheone | 0:ecaf3e593122 | 120 | void TapTraqUplink::SavePanID() |
Tuxitheone | 0:ecaf3e593122 | 121 | { |
Tuxitheone | 0:ecaf3e593122 | 122 | char str[200]; |
Tuxitheone | 0:ecaf3e593122 | 123 | FILE *fp = fopen("/sd/taptraq/PanId.sys", "w"); // |
Tuxitheone | 0:ecaf3e593122 | 124 | sprintf(str, "{%s,%s,%s,%s,%s,%s,%s,%s,%s,%s}\r\n", |
Tuxitheone | 0:ecaf3e593122 | 125 | PanId[0].EUID,PanId[1].EUID,PanId[2].EUID,PanId[3].EUID,PanId[4].EUID,PanId[5].EUID,PanId[6].EUID,PanId[7].EUID,PanId[8].EUID,PanId[9].EUID); |
Tuxitheone | 0:ecaf3e593122 | 126 | fputs(str, fp); |
Tuxitheone | 0:ecaf3e593122 | 127 | sprintf(str, "{%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}\r\n", |
Tuxitheone | 0:ecaf3e593122 | 128 | PanId[0].ID,PanId[1].ID,PanId[2].ID,PanId[3].ID,PanId[4].ID,PanId[5].ID,PanId[6].ID,PanId[7].ID,PanId[8].ID,PanId[9].ID); |
Tuxitheone | 0:ecaf3e593122 | 129 | fputs(str, fp); |
Tuxitheone | 0:ecaf3e593122 | 130 | fclose(fp); |
Tuxitheone | 0:ecaf3e593122 | 131 | } |
Tuxitheone | 0:ecaf3e593122 | 132 | |
Tuxitheone | 0:ecaf3e593122 | 133 | void TapTraqUplink::ReadPanID() |
Tuxitheone | 0:ecaf3e593122 | 134 | { |
Tuxitheone | 0:ecaf3e593122 | 135 | char str[200]; |
Tuxitheone | 0:ecaf3e593122 | 136 | char *p_items; |
Tuxitheone | 0:ecaf3e593122 | 137 | FILE *fp = fopen("/sd/taptraq/PanId.sys", "r"); // |
Tuxitheone | 0:ecaf3e593122 | 138 | p_items = fgets(str, SetupStrSize, fp); // |
Tuxitheone | 0:ecaf3e593122 | 139 | strtok(str, "\n\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 140 | strtok(str, "\r\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 141 | sscanf(str, "{%s,%s,%s,%s,%s,%s,%s,%s,%s,%s}", |
Tuxitheone | 0:ecaf3e593122 | 142 | PanId[0].EUID,PanId[1].EUID,PanId[2].EUID,PanId[3].EUID,PanId[4].EUID,PanId[5].EUID,PanId[6].EUID,PanId[7].EUID,PanId[8].EUID,PanId[9].EUID); |
Tuxitheone | 0:ecaf3e593122 | 143 | p_items = fgets(str, SetupStrSize, fp); // |
Tuxitheone | 0:ecaf3e593122 | 144 | strtok(str, "\n\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 145 | strtok(str, "\r\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 146 | sscanf(str, "{%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}", |
Tuxitheone | 0:ecaf3e593122 | 147 | PanId[0].ID,PanId[1].ID,PanId[2].ID,PanId[3].ID,PanId[4].ID,PanId[5].ID,PanId[6].ID,PanId[7].ID,PanId[8].ID,PanId[9].ID); |
Tuxitheone | 0:ecaf3e593122 | 148 | fclose(fp); |
Tuxitheone | 0:ecaf3e593122 | 149 | } |
Tuxitheone | 0:ecaf3e593122 | 150 | |
Tuxitheone | 0:ecaf3e593122 | 151 | bool TapTraqUplink::AddPan(char *p) |
Tuxitheone | 0:ecaf3e593122 | 152 | { |
Tuxitheone | 0:ecaf3e593122 | 153 | char i=0; |
Tuxitheone | 0:ecaf3e593122 | 154 | while ((PanId[i].ID!=0) & (i<MaxCtrl)) i++; |
Tuxitheone | 0:ecaf3e593122 | 155 | if (i<MaxCtrl) { |
Tuxitheone | 0:ecaf3e593122 | 156 | strncpy(PanId[i].EUID,p,16); |
Tuxitheone | 0:ecaf3e593122 | 157 | PanId[i].ID=i+1; |
Tuxitheone | 0:ecaf3e593122 | 158 | SavePanID(); //Skriver den til SD-kortet |
Tuxitheone | 0:ecaf3e593122 | 159 | return true; |
Tuxitheone | 0:ecaf3e593122 | 160 | } else { |
Tuxitheone | 0:ecaf3e593122 | 161 | return false; |
Tuxitheone | 0:ecaf3e593122 | 162 | } |
Tuxitheone | 0:ecaf3e593122 | 163 | } |
Tuxitheone | 0:ecaf3e593122 | 164 | |
Tuxitheone | 0:ecaf3e593122 | 165 | int TapTraqUplink::CheckPan(char *p) |
Tuxitheone | 0:ecaf3e593122 | 166 | //finder hvad ctrl nummeret er ud fra pan id. |
Tuxitheone | 0:ecaf3e593122 | 167 | //ctrl nummeret er mellem 0..MaxCtrl |
Tuxitheone | 0:ecaf3e593122 | 168 | { |
Tuxitheone | 0:ecaf3e593122 | 169 | char i=0; |
Tuxitheone | 0:ecaf3e593122 | 170 | int fundet=-1; |
Tuxitheone | 0:ecaf3e593122 | 171 | char TmpEUID[17]; |
Tuxitheone | 0:ecaf3e593122 | 172 | strcpy(TmpEUID,p); |
Tuxitheone | 0:ecaf3e593122 | 173 | while ((PanId[i].ID!=0) & (i<MaxCtrl)) { |
Tuxitheone | 0:ecaf3e593122 | 174 | if (strcmp(PanId[i].EUID, TmpEUID) == 0) fundet=i; |
Tuxitheone | 0:ecaf3e593122 | 175 | i++; |
Tuxitheone | 0:ecaf3e593122 | 176 | } |
Tuxitheone | 0:ecaf3e593122 | 177 | return fundet; |
Tuxitheone | 0:ecaf3e593122 | 178 | } |
Tuxitheone | 0:ecaf3e593122 | 179 | |
Tuxitheone | 0:ecaf3e593122 | 180 | //------------------Ini file---------------------------------------------------------------- |
Tuxitheone | 0:ecaf3e593122 | 181 | //Vi gemmer setup records på SDkort i Ascii format, således at vi senere kan rette i dem |
Tuxitheone | 0:ecaf3e593122 | 182 | //Read læser dem alle ind i hukommelsen |
Tuxitheone | 0:ecaf3e593122 | 183 | //Save skriver dem tilbage på SD kortet |
Tuxitheone | 0:ecaf3e593122 | 184 | |
Tuxitheone | 0:ecaf3e593122 | 185 | void TapTraqUplink::ReadConfig() |
Tuxitheone | 0:ecaf3e593122 | 186 | { |
Tuxitheone | 0:ecaf3e593122 | 187 | //læser det hele igennem for at finde setup record for den pågældende ctrl |
Tuxitheone | 0:ecaf3e593122 | 188 | char str[SetupStrSize]; |
Tuxitheone | 0:ecaf3e593122 | 189 | char *p_items; |
Tuxitheone | 0:ecaf3e593122 | 190 | char dummy; |
Tuxitheone | 0:ecaf3e593122 | 191 | FILE *fp = fopen("/sd/taptraq/config.sys", "r"); |
Tuxitheone | 0:ecaf3e593122 | 192 | if (fp != NULL) { |
Tuxitheone | 0:ecaf3e593122 | 193 | for (int ID=0; ID<MAX_NUMBER*MaxCtrl; ID++) { |
Tuxitheone | 0:ecaf3e593122 | 194 | p_items = fgets(str, SetupStrSize, fp); // |
Tuxitheone | 0:ecaf3e593122 | 195 | strtok(str, "\n\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 196 | strtok(str, "\r\0"); // change \n to \0 method |
Tuxitheone | 0:ecaf3e593122 | 197 | if (p_items == NULL) break; |
Tuxitheone | 0:ecaf3e593122 | 198 | sscanf(str,"{%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}",dummy, //dummy fordi vi ved det er den ctrl |
Tuxitheone | 0:ecaf3e593122 | 199 | &SetupArr[ID].ID, &SetupArr[ID].TabType, &SetupArr[ID].EscTryk, &SetupArr[ID].FlowEnable, |
Tuxitheone | 0:ecaf3e593122 | 200 | &SetupArr[ID].FlowMode, &SetupArr[ID].IntervalUpload, |
Tuxitheone | 0:ecaf3e593122 | 201 | &SetupArr[ID].XLOn, &SetupArr[ID].XLPause, &SetupArr[ID].XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 202 | &SetupArr[ID].LOn, &SetupArr[ID].LPause, &SetupArr[ID].LTopup, |
Tuxitheone | 0:ecaf3e593122 | 203 | &SetupArr[ID].MOn, &SetupArr[ID].MPause, &SetupArr[ID].MTopup, |
Tuxitheone | 0:ecaf3e593122 | 204 | &SetupArr[ID].SOn, &SetupArr[ID].SPause, &SetupArr[ID].STopup); |
Tuxitheone | 0:ecaf3e593122 | 205 | } |
Tuxitheone | 0:ecaf3e593122 | 206 | } |
Tuxitheone | 0:ecaf3e593122 | 207 | } |
Tuxitheone | 0:ecaf3e593122 | 208 | |
Tuxitheone | 0:ecaf3e593122 | 209 | void TapTraqUplink::WriteDefault(void) |
Tuxitheone | 0:ecaf3e593122 | 210 | { |
Tuxitheone | 0:ecaf3e593122 | 211 | for (char i=0; i<MAX_NUMBER*MaxCtrl; i++) { |
Tuxitheone | 0:ecaf3e593122 | 212 | SetupArr[i].ID=i%MaxCtrl; |
Tuxitheone | 0:ecaf3e593122 | 213 | SetupArr[i].TabType=0; |
Tuxitheone | 0:ecaf3e593122 | 214 | SetupArr[i].EscTryk=1; |
Tuxitheone | 0:ecaf3e593122 | 215 | SetupArr[i].FlowEnable=0; |
Tuxitheone | 0:ecaf3e593122 | 216 | SetupArr[i].FlowMode=0; |
Tuxitheone | 0:ecaf3e593122 | 217 | SetupArr[i].IntervalUpload=600; |
Tuxitheone | 0:ecaf3e593122 | 218 | SetupArr[i].XLOn=0; |
Tuxitheone | 0:ecaf3e593122 | 219 | SetupArr[i].XLPause=0; |
Tuxitheone | 0:ecaf3e593122 | 220 | SetupArr[i].XLTopup=0; |
Tuxitheone | 0:ecaf3e593122 | 221 | SetupArr[i].LOn=0; |
Tuxitheone | 0:ecaf3e593122 | 222 | SetupArr[i].LPause=0; |
Tuxitheone | 0:ecaf3e593122 | 223 | SetupArr[i].LTopup=0; |
Tuxitheone | 0:ecaf3e593122 | 224 | SetupArr[i].MOn=0; |
Tuxitheone | 0:ecaf3e593122 | 225 | SetupArr[i].MPause=0; |
Tuxitheone | 0:ecaf3e593122 | 226 | SetupArr[i].MTopup=0; |
Tuxitheone | 0:ecaf3e593122 | 227 | SetupArr[i].SOn=0; |
Tuxitheone | 0:ecaf3e593122 | 228 | SetupArr[i].SPause=0; |
Tuxitheone | 0:ecaf3e593122 | 229 | SetupArr[i].STopup=0; |
Tuxitheone | 0:ecaf3e593122 | 230 | } |
Tuxitheone | 0:ecaf3e593122 | 231 | SaveConfig(); |
Tuxitheone | 0:ecaf3e593122 | 232 | } |
Tuxitheone | 0:ecaf3e593122 | 233 | |
Tuxitheone | 0:ecaf3e593122 | 234 | |
Tuxitheone | 0:ecaf3e593122 | 235 | void TapTraqUplink::SaveConfig() //writes config to sdcard |
Tuxitheone | 0:ecaf3e593122 | 236 | { |
Tuxitheone | 0:ecaf3e593122 | 237 | char str[SetupStrSize]; |
Tuxitheone | 0:ecaf3e593122 | 238 | FILE *fp = fopen("/sd/taptraq/config.sys", "w"); // |
Tuxitheone | 0:ecaf3e593122 | 239 | for (int ID=0; ID<MAX_NUMBER*MaxCtrl; ID++) { |
Tuxitheone | 0:ecaf3e593122 | 240 | sprintf(str, "{%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x}\r\n", ID+1, |
Tuxitheone | 0:ecaf3e593122 | 241 | SetupArr[ID].ID, SetupArr[ID].TabType, SetupArr[ID].EscTryk, SetupArr[ID].FlowEnable, |
Tuxitheone | 0:ecaf3e593122 | 242 | SetupArr[ID].FlowMode, SetupArr[ID].IntervalUpload, |
Tuxitheone | 0:ecaf3e593122 | 243 | SetupArr[ID].XLOn, SetupArr[ID].XLPause, SetupArr[ID].XLTopup, |
Tuxitheone | 0:ecaf3e593122 | 244 | SetupArr[ID].LOn, SetupArr[ID].LPause, SetupArr[ID].LTopup, |
Tuxitheone | 0:ecaf3e593122 | 245 | SetupArr[ID].MOn, SetupArr[ID].MPause, SetupArr[ID].MTopup, |
Tuxitheone | 0:ecaf3e593122 | 246 | SetupArr[ID].SOn, SetupArr[ID].SPause, SetupArr[ID].STopup); |
Tuxitheone | 0:ecaf3e593122 | 247 | |
Tuxitheone | 0:ecaf3e593122 | 248 | fputs(str, fp); |
Tuxitheone | 0:ecaf3e593122 | 249 | // printf(str); |
Tuxitheone | 0:ecaf3e593122 | 250 | } |
Tuxitheone | 0:ecaf3e593122 | 251 | fclose(fp); |
Tuxitheone | 0:ecaf3e593122 | 252 | } |
Tuxitheone | 0:ecaf3e593122 | 253 | |
Tuxitheone | 0:ecaf3e593122 | 254 | void TapTraqUplink::iniopen(void) |
Tuxitheone | 0:ecaf3e593122 | 255 | { |
Tuxitheone | 0:ecaf3e593122 | 256 | FILE *fp = fopen("/sd/taptraq/config.sys", "r"); |
Tuxitheone | 0:ecaf3e593122 | 257 | if (fp == NULL) { //For at være sikker på at der er nogle data |
Tuxitheone | 0:ecaf3e593122 | 258 | fclose(fp); |
Tuxitheone | 0:ecaf3e593122 | 259 | printf("Failure to read a configuration file.\n"); |
Tuxitheone | 0:ecaf3e593122 | 260 | WriteDefault(); |
Tuxitheone | 0:ecaf3e593122 | 261 | } else fclose(fp); |
Tuxitheone | 0:ecaf3e593122 | 262 | ReadConfig(); |
Tuxitheone | 0:ecaf3e593122 | 263 | } |