forked from on7lds/NextionDriver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasicFunctions.c
274 lines (248 loc) · 10.6 KB
/
basicFunctions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* Copyright (C) 2017,2018 by Lieven De Samblanx ON7LDS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <syslog.h>
#include "NextionDriver.h"
#include "helpers.h"
void basicFunctions() {
char text[100];
//---------------------------------------------------
// the 'page' variable holds the last selected page
//---------------------------------------------------
if (strcmp(TXbuffer,"page MMDVM")==0) {
page=0;
}
if (strcmp(TXbuffer,"page Info")==0) {
page=1;
}
if (strcmp(TXbuffer,"page DStar")==0) {
page=2;
}
if (strcmp(TXbuffer,"page DMR1")==0) {
page=3;
}
if (strcmp(TXbuffer,"page DMR2")==0) {
page=4;
}
if (strcmp(TXbuffer,"page YSF")==0) {
page=5;
}
if (strcmp(TXbuffer,"page P25")==0) {
page=6;
}
if (strcmp(TXbuffer,"page NXDN")==0) {
page=7;
}
if (strcmp(TXbuffer,"page SYSTEM1")==0) {
page=8;
}
if (strcmp(TXbuffer,"page SYSTEM2")==0) {
page=9;
}
if ((strncmp(TXbuffer,"page ",10)==0)&&(changepages==1)) {
strcat(TXbuffer,"0");
}
//--------------------------------------------------------------
// Rest page
//--------------------------------------------------------------
// * remove Freq and time when stopping
// * regularly check IP interface and send to display
// * get CPU temperature & frequency & load average
// and send to display
// * send RX frequency and location (info from MMDVM.ini)
//--------------------------------------------------------------
if ((page==0)&&(strstr(TXbuffer,"MMDVM STOPPED")>0)){
sprintf(TXbuffer, "t30.txt=\"\"");
sendCommand(text);
sprintf(TXbuffer, "t52.txt=\"\"");
}
// if date/time is sent, check IP interface from time to time:
// and disk free in %
if ((page==0)&&(strstr(TXbuffer,"t52.txt=")>0)&&(check++>100)) {
getNetworkInterface(ipaddr);
netIsActive[0]=getInternetStatus(check);
sprintf(TXbuffer, "t53.txt=\"%s\"", ipaddr);
check=0;
}
// check temp & CPU freq (also not too often)
if ((page==0)&&(strstr(TXbuffer,"t52.txt=")>0)&&(check%8==0)) {
FILE *deviceInfoFile;
double val;
//CPU temperature
deviceInfoFile = fopen ("/sys/class/thermal/thermal_zone0/temp", "r");
if (deviceInfoFile == NULL) {
sprintf(text, "t20.txt=\"?\"");
} else {
fscanf (deviceInfoFile, "%lf", &val);
val /= 1000;
sprintf(text, "t20.txt=\"%2.2f %cC\"", val, 176);
fclose(deviceInfoFile);
}
sendCommand(text);
//CPU frequency
deviceInfoFile = fopen ("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq", "r");
if (deviceInfoFile == NULL) {
sprintf(text, "t21.txt=\"?\"");
} else {
fscanf (deviceInfoFile, "%lf", &val);
val /= 1000;
sprintf(text, "t21.txt=\"%0.0f MHz\"", val);
fclose(deviceInfoFile);
}
sendCommand(text);
//CPU loadavg 1 min
deviceInfoFile = fopen ("/proc/loadavg", "r");
if (deviceInfoFile == NULL) {
sprintf(text, "t22.txt=\"?\"");
sendCommand(text);
sprintf(text, "cpuload.val=0");
} else {
fscanf (deviceInfoFile, "%lf", &val);
sprintf(text, "t22.txt=\"%0.2f\"", val);
sendCommand(text);
sprintf(text, "cpuload.val=%d", (int)(val*100));
fclose(deviceInfoFile);
}
sendCommand(text);
//Disk free %
sprintf(text, "t23.txt=\"%d\"",getDiskFree());
sendCommand(text);
//RXFrequency
float fx;
fx=RXfrequency;
fx/=1000000;
sprintf(text, "t30.txt=\"%3.4fMHz\"",fx);
sendCommand(text);
//TXFrequency
fx=TXfrequency;
fx/=1000000;
sprintf(text, "t32.txt=\"%3.4fMHz\"",fx);
sendCommand(text);
//Location
sprintf(text, "t31.txt=\"%s\"",location);
sendCommand(text);
//disable 25356 text 46486
//enable 1472 text 0
//error 55879
#define bcoEN 1472
#define bcoDIS 25356
#define pcoEN 0
#define pcoDIS 46486
//Modes enabled/disabled
sprintf(text, "A1.bco=%d",modeIsEnabled[DSTAR] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "A1.pco=%d",modeIsEnabled[DSTAR] ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "A2.bco=%d",modeIsEnabled[DMR] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "A2.pco=%d",modeIsEnabled[DMR] ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "A3.bco=%d",modeIsEnabled[FUSION] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "A3.pco=%d",modeIsEnabled[FUSION] ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "A4.bco=%d",modeIsEnabled[P25] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "A4.pco=%d",modeIsEnabled[P25] ? pcoEN : pcoDIS); sendCommand(text);
// sprintf(text, "A5.bco=%d",modeIsEnabled[YSFDMR] ? bcoEN : bcoDIS); sendCommand(text);
// sprintf(text, "A5.pco=%d",modeIsEnabled[YSFDMR] ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "A6.bco=%d",modeIsEnabled[NXDN] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "A6.pco=%d",modeIsEnabled[NXDN] ? pcoEN : pcoDIS); sendCommand(text);
//Internet
sprintf(text, "N0.bco=%d",netIsActive[0] ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N0.pco=%d",netIsActive[0] ? pcoEN : pcoDIS); sendCommand(text);
//Network connections
sprintf(text, "N1.bco=%d",(modeIsEnabled[DSTAR_NET]&&(proc_find("ircddbgatewayd")>0)) ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N1.pco=%d",(modeIsEnabled[DSTAR_NET]&&(proc_find("ircddbgatewayd")>0)) ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "N2.bco=%d",(modeIsEnabled[DMR_NET]&&(proc_find("MMDVMHost")>0)) ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N2.pco=%d",(modeIsEnabled[DMR_NET]&&(proc_find("MMDVMHost")>0)) ? pcoEN : pcoDIS); sendCommand(text);
// sprintf(text, "N2.bco=%d",(modeIsEnabled[]&&(proc_find("DMRGateway")>0)) ? bcoEN : bcoDIS); sendCommand(text);
// sprintf(text, "N2.pco=%d",(modeIsEnabled[]&&(proc_find("DMRGateway")>0)) ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "N3.bco=%d",(modeIsEnabled[FUSION_NET]&&(proc_find("YSFGateway")>0)) ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N3.pco=%d",(modeIsEnabled[FUSION_NET]&&(proc_find("YSFGateway")>0)) ? pcoEN : pcoDIS); sendCommand(text);
sprintf(text, "N4.bco=%d",(modeIsEnabled[P25_NET]&&(proc_find("P25Gateway")>0)) ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N4.pco=%d",(modeIsEnabled[P25_NET]&&(proc_find("P25Gateway")>0)) ? pcoEN : pcoDIS); sendCommand(text);
// sprintf(text, "N5.bco=%d",(modeIsEnabled[YSFDMR_NET]&&(proc_find("")>0) ? bcoEN : bcoDIS)); sendCommand(text);
// sprintf(text, "N5.pco=%d",(modeIsEnabled[YSFDMR_NET]&&(proc_find("")>0) ? pcoEN : pcoDIS)); sendCommand(text);
sprintf(text, "N6.bco=%d",(modeIsEnabled[NXDN_NET]&&(proc_find("MMDVMHost")>0)) ? bcoEN : bcoDIS); sendCommand(text);
sprintf(text, "N6.pco=%d",(modeIsEnabled[NXDN_NET]&&(proc_find("MMDVMHost")>0)) ? pcoEN : pcoDIS); sendCommand(text);
//Done
sprintf(text, "MMDVM.status.val=20");
sendCommand(text);
sendCommand("click S0,1");
}
//send TG name if found
if ((page==2)&&(strstr(TXbuffer,"t53.txt")!=NULL)) {
char *TGname;
int nr,TGindex;
sendCommand(TXbuffer);
if ((TXbuffer[8]>='0')&&(TXbuffer[8]<='9'))
nr=atoi(&TXbuffer[8]);
else
nr=atoi(&TXbuffer[10]);
TGindex=search_group(nr,groups,0,nmbr_groups-1);
if (TGindex>=0) {
TGname=groups[TGindex].name;
sprintf(TXbuffer,"t8.txt=\"%s\"",TGname);
} else if (TGindex<0) {
//is it maybe a user private call ?
TGindex=search_userID(nr,users,0,nmbr_users-1);
if (TGindex>0) sprintf(TXbuffer,"t8.txt=\"Private %s\"",users[TGindex].data1);
} else {
sprintf(TXbuffer,"t8.txt=\"TG%d name not found\"",nr);
}
sendCommand(TXbuffer);
}
//send user data if found
if ((page==2)&&(strstr(TXbuffer,"t52.txt")!=NULL)) {
int nr,user;
sendCommand(TXbuffer);
nr=atoi(&TXbuffer[12]);
if (nr>0) {
user=search_userID(nr,users,0,nmbr_users-1);
} else {
TXbuffer[strlen(TXbuffer)-1]=' ';
char* l=strchr(&TXbuffer[12], ' ');
if (l!=NULL) l[0]=0;
printf("Zoeken naar [%s] \n",&TXbuffer[12]);
user=search_userCALL(&TXbuffer[12],users,0,nmbr_users-1);
}
if (user>=0) {
sprintf(TXbuffer,"t13.txt=\"%s\"",users[user].data1);
sendCommand(TXbuffer);
sprintf(TXbuffer,"t14.txt=\"%s\"",users[user].data2);
sendCommand(TXbuffer);
sprintf(TXbuffer,"t15.txt=\"%s\"",users[user].data3);
sendCommand(TXbuffer);
sprintf(TXbuffer,"t16.txt=\"%s\"",users[user].data4);
sendCommand(TXbuffer);
sprintf(TXbuffer,"t17.txt=\"%s\"",users[user].data5);
sendCommand(TXbuffer);
} else if (nr>0) {
sprintf(TXbuffer,"t13.txt=\"DMRID %d\"",nr);
sendCommand(TXbuffer);
sprintf(TXbuffer,"t14.txt=\"Not found in\"");
sendCommand(TXbuffer);
sprintf(TXbuffer,"t15.txt=\"%s\"",usersFile);
sendCommand(TXbuffer);
}
sprintf(text, "MMDVM.status.val=78");
sendCommand(text);
sendCommand("click S0,1");
}