-
Notifications
You must be signed in to change notification settings - Fork 9
/
funcOther.h.8
312 lines (234 loc) · 9.75 KB
/
funcOther.h.8
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// Bahasa Anak Indonesia untuk Komputer - BAIK
// Copyright Haris Hasanudin - 2005 - 2015
//
// Kupersembahkan untuk istriku tercinta Masako, anakku tersayang Takumi
// dan Tomoki serta seluruh putra putri Indonesia
int power_stat(char *myport);
VAL_LABEL funcSaklarStatus() {
VAL_LABEL datx;
VAL_LABEL valdat, tmpdat;
char class_tmpvar[MAX_STRING_LEN];
int pwr = -1;
memset(&datx, '\0', sizeof(datx));
memset(&valdat, '\0', sizeof(valdat));
memset(&tmpdat, '\0', sizeof(tmpdat));
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
//printf("saklar inside...\n");
getlex();
if(lex.type == TYPE_STR) {
datx.val = power_stat(lex.detail.string);
datx.datatype = 0;
} else if(lex.type == TYPE_IDENT) {
/* read data */
// printf("get panjang array ident\n");
if(currentClass != NULL && strlen(currentClass) > 0) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#endif
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#endif
//printf("construct class var: %s\n", class_tmpvar);
tmpdat = ValLabel( class_tmpvar, sub_deep, valdat, VAL_FLAG_SEARCH_R );
} else {
tmpdat = ValLabel( lex.detail.ident, sub_deep, valdat, VAL_FLAG_SEARCH_R );
}
// printf("read panjang array ident, type : \n", tmpdat.datatype);
if(tmpdat.datatype == 3) {
datx.val = power_stat(tmpdat.str);
datx.datatype = 0;
}
}
return datx;
}
VAL_LABEL funcOther() {
VAL_LABEL datx;
VAL_LABEL valdat, tmpdat;
// var list for class params
char class_tmpvar[MAX_STRING_LEN];
memset(&datx, '\0', sizeof(datx));
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
memset(&valdat, '\0', sizeof(valdat));
memset(&tmpdat, '\0', sizeof(tmpdat));
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
/* ======================================================== */
/* OTHER ======================================= */
/* ======================================================== */
if( !strcmp(lex.detail.string, "xxxxxxxxxxxxxxxxxxxxxxxxxxx") ||
!strcmp(lex.detail.string, "xxxxxxxxxxxxxxxxxxxxxxxxx") ) {
/* ======================================================== */
/* PANJANG =================================== */
/* ======================================================== */
} else if( !strcmp(lex.detail.string, "PANJANG") ||
!strcmp(lex.detail.string, "panjang") ||
!strcmp(lex.detail.string, "Panjang") ) {
/* printf("PANJANG function\n"); */
memset(&tmpdat, '\0', sizeof(tmpdat));
memset(&valdat, '\0', sizeof(valdat));
getlex();
// printf("panjang get ident : %s\n", lex.detail.ident);
// printf("panjang get type : %d\n", lex.type);
if(lex.type == TYPE_ARRAY) {
if(strlen(lex.detail.array_str) > 0) {
strcpy(valdat.array_str, lex.detail.array_str);
getArrayName(lex.detail.array_str, (char *)&valdat.array_name);
getArrayIdx(lex.detail.array_str, (char *)&valdat.array_idx);
if(currentClass != NULL && strlen(currentClass) > 0) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_name);
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_name);
#endif
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_name);
#endif
//printf("construct class var: %s\n", class_tmpvar);
memset(&valdat.array_name[0], '\0', sizeof(valdat.array_name));
strcpy(valdat.array_name, class_tmpvar);
if(!isdigit(valdat.array_idx[0])) {
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_idx);
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_idx);
#endif
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, valdat.array_idx);
#endif
//printf("construct class var: %s\n", class_tmpvar);
memset(&valdat.array_idx[0], '\0', sizeof(valdat.array_idx));
strcpy(valdat.array_idx, class_tmpvar);
}
}
/* read data */
valdat = ValLabel( valdat.array_name, sub_deep, valdat, VAL_FLAG_SEARCH_R );
/* printf("panjang array %d", valdat.array_max); */
datx.val = tmpdat.array_max;
datx.datatype = 0;
}
} else if(lex.type == TYPE_STR) {
datx.val = (long)strlen(lex.detail.string);
datx.datatype = 0;
} else if(lex.type == TYPE_IDENT) {
/* read data */
// printf("get panjang array ident\n");
if(currentClass != NULL && strlen(currentClass) > 0) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#endif
#else
snprintf(class_tmpvar, sizeof(class_tmpvar),"%s->%s", currentClass, lex.detail.ident);
#endif
//printf("construct class var: %s\n", class_tmpvar);
tmpdat = ValLabel( class_tmpvar, sub_deep, valdat, VAL_FLAG_SEARCH_R );
} else {
tmpdat = ValLabel( lex.detail.ident, sub_deep, valdat, VAL_FLAG_SEARCH_R );
}
// printf("read panjang array ident, type : \n", tmpdat.datatype);
if(tmpdat.datatype == 3) {
datx.val = (long)strlen(tmpdat.str);
datx.datatype = 0;
}
else if(tmpdat.datatype >= 6 && tmpdat.datatype <=8) {
/*
printf("array type = %d\n", tmpdat.datatype);
printf("panjang array ident = %d\n", tmpdat.array_max);
*/
datx.val = tmpdat.array_max;
datx.datatype = 0;
/*
printf("ident type = %d\n", datx.datatype);
printf("ident val = %d\n", datx.val);
*/
}
else
if(tmpdat.datatype == 10) {
/*
printf("array type = %d\n", tmpdat.datatype);
printf("panjang array ident = %d\n", tmpdat.array_max);
*/
datx.val = tmpdat.array_max;
datx.datatype = 0;
/*
printf("ident type = %d\n", datx.datatype);
printf("ident val = %d\n", datx.val);
*/
}
else
{
// including not valued yet array
datx.val = tmpdat.array_max;
datx.datatype = 0;
}
} else {
/* not array, so there is no length */
datx.val = 0;
datx.datatype = 0;
}
}
if(valdat.left != NULL)
free(valdat.left);
if(valdat.right != NULL)
free(valdat.right);
if(valdat.pnext != NULL)
free(valdat.pnext);
if(tmpdat.left != NULL)
free(tmpdat.left);
if(tmpdat.right != NULL)
free(tmpdat.right);
if(tmpdat.pnext != NULL)
free(tmpdat.pnext);
return datx;
}
int power_stat(char *myport) {
FILE *fp=NULL;
// create a variable to store whether we are sending a '1' or a '0'
char set_value[4];
// Integer to keep track of whether we want on or off
int toggle = 0;
// path for GPIO file
char mypath[128];
int get_value = -1;
// Initialize memory
memset(&set_value, '\0', sizeof(set_value));
memset(&mypath, '\0', sizeof(mypath));
//printf("power stat ...\n");
// Check GPIO
if ((fp = fopen("/sys/class/gpio/export", "ab")) == NULL)
{
printf("Cannot open GPIO export file.\n");
exit(1);
}
//Set pointer to begining of the file
rewind(fp);
//Write our value of "myport" to the file
strcpy(set_value, myport);
fwrite(&set_value, sizeof(char), 3, fp);
fclose(fp);
// /////////////////////////////////////////////
//GET VALUE
// /////////////////////////////////////////////
memset(&mypath, '\0', sizeof(mypath));
strcpy(set_value, myport);
sprintf(mypath, "/sys/class/gpio/gpio%s/value", set_value);
//printf("get value , path : %s \n", mypath);
if ((fp = fopen(mypath, "r")) == NULL)
{
printf("Cannot open value file.\n");
exit(1);
}
memset(&set_value, '\0', sizeof(set_value));
fread(set_value, sizeof(int), 1, fp);
fclose(fp);
get_value = atoi (set_value);
//printf("get val : %s \n", set_value);
return get_value;
}