1 | #include "globals.h"
|
---|
2 | #ifdef LCDSUPPORT
|
---|
3 | /*
|
---|
4 | * module-lcd.c
|
---|
5 | *
|
---|
6 | * Created on: 24.05.2011
|
---|
7 | * Author: alno
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <string.h>
|
---|
12 | #include <time.h>
|
---|
13 | #include <sys/stat.h>
|
---|
14 | #include <dirent.h>
|
---|
15 |
|
---|
16 | #ifdef MODULE_CCCAM
|
---|
17 | #include "module-cccam.h"
|
---|
18 | #include "module-cccshare.h"
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | int8_t running;
|
---|
22 |
|
---|
23 | void refresh_lcd_file() {
|
---|
24 |
|
---|
25 | char targetfile[256];
|
---|
26 | char tmpfile[256];
|
---|
27 | char channame[32];
|
---|
28 |
|
---|
29 | if(cfg.lcd_output_path == NULL){
|
---|
30 | snprintf(targetfile, sizeof(targetfile),"%s%s", get_tmp_dir(), "/oscam.lcd");
|
---|
31 | snprintf(tmpfile, sizeof(tmpfile), "%s%s.tmp", get_tmp_dir(), "/oscam.lcd");
|
---|
32 | } else {
|
---|
33 | snprintf(targetfile, sizeof(targetfile),"%s%s", cfg.lcd_output_path, "/oscam.lcd");
|
---|
34 | snprintf(tmpfile, sizeof(tmpfile), "%s%s.tmp", cfg.lcd_output_path, "/oscam.lcd");
|
---|
35 | }
|
---|
36 |
|
---|
37 | int8_t iscccam = 0;
|
---|
38 | int32_t seconds = 0, secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
|
---|
39 | time_t now = time((time_t)0);
|
---|
40 |
|
---|
41 |
|
---|
42 | while(running) {
|
---|
43 | now = time((time_t)0);
|
---|
44 | int16_t cnt = 0, idx = 0, count_r = 0, count_p = 0, count_u = 0;
|
---|
45 | FILE *fpsave;
|
---|
46 |
|
---|
47 | if((fpsave = fopen(tmpfile, "w"))){
|
---|
48 |
|
---|
49 | idx = 0;
|
---|
50 | int16_t i;
|
---|
51 | char *type;
|
---|
52 | char *label;
|
---|
53 | char *status;
|
---|
54 |
|
---|
55 | // Statuslines start
|
---|
56 | secs = 0; fullmins = 0; mins = 0; fullhours = 0; hours = 0; days = 0;
|
---|
57 |
|
---|
58 | seconds = now - first_client->login;
|
---|
59 | secs = seconds % 60;
|
---|
60 | if (seconds > 60) {
|
---|
61 | fullmins = seconds / 60;
|
---|
62 | mins = fullmins % 60;
|
---|
63 | if(fullmins > 60) {
|
---|
64 | fullhours = fullmins / 60;
|
---|
65 | hours = fullhours % 24;
|
---|
66 | days = fullhours / 24;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | fprintf(fpsave,"Version: %s\n", CS_VERSION);
|
---|
71 | fprintf(fpsave,"Revision: %s\n", CS_SVN_VERSION);
|
---|
72 | if(days == 0)
|
---|
73 | fprintf(fpsave, "up: %02d:%02d:%02d\n", hours, mins, secs);
|
---|
74 | else
|
---|
75 | fprintf(fpsave, "up: %02dd %02d:%02d:%02d\n", days, hours, mins, secs);
|
---|
76 | fprintf(fpsave,"totals: %d/%d/%d/%d/%d/%d\n", first_client->cwfound, first_client->cwnot, first_client->cwignored, first_client->cwtout, first_client->cwcache, first_client->cwtun);
|
---|
77 | fprintf(fpsave,"uptime: %d\n", seconds);
|
---|
78 | // Statuslines end
|
---|
79 |
|
---|
80 | // Readertable head
|
---|
81 | fprintf(fpsave,"Typ| Label | Idle | w | s | b | e | St\n");
|
---|
82 | fprintf(fpsave,"---+------------+--------------+---+---+---+---+----\n");
|
---|
83 |
|
---|
84 | struct s_client *cl;
|
---|
85 |
|
---|
86 | // Reader/Proxy table start
|
---|
87 | for ( i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
88 |
|
---|
89 | if ((cl->typ=='r' || cl->typ=='p') && ((now - cl->last) < 20 || !cfg.lcd_hide_idle)){
|
---|
90 | type = "";
|
---|
91 | label = "";
|
---|
92 | status = "OFF";
|
---|
93 | secs = 0; fullmins = 0; mins = 0; fullhours = 0; hours = 0; days = 0;
|
---|
94 |
|
---|
95 | seconds = now - cl->last;
|
---|
96 |
|
---|
97 | if (cl->typ == 'r'){
|
---|
98 | type = "R";
|
---|
99 | idx = count_r;
|
---|
100 | label = cl->reader->label;
|
---|
101 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
102 | status = "OK";
|
---|
103 | count_r++;
|
---|
104 | }
|
---|
105 |
|
---|
106 | else if (cl->typ == 'p'){
|
---|
107 | type = "P";
|
---|
108 | iscccam = 0;
|
---|
109 | idx = count_p;
|
---|
110 | label = cl->reader->label;
|
---|
111 | if ((strncmp(monitor_get_proto(cl), "cccam", 5) == 0))
|
---|
112 | iscccam = 1;
|
---|
113 |
|
---|
114 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
115 | status = "CON";
|
---|
116 |
|
---|
117 | count_p++;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | secs = seconds % 60;
|
---|
122 | if (seconds > 60) {
|
---|
123 | fullmins = seconds / 60;
|
---|
124 | mins = fullmins % 60;
|
---|
125 | if(fullmins > 60) {
|
---|
126 | fullhours = fullmins / 60;
|
---|
127 | hours = fullhours % 24;
|
---|
128 | days = fullhours / 24;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | int16_t written = 0, skipped = 0, blocked = 0, error = 0;
|
---|
133 |
|
---|
134 | char *emmtext;
|
---|
135 | if(cs_malloc(&emmtext, 16 * sizeof(char), -1)){
|
---|
136 | if(cl->typ == 'r' || !iscccam ){
|
---|
137 | for (i=0; i<4; i++) {
|
---|
138 | error += cl->reader->emmerror[i];
|
---|
139 | blocked += cl->reader->emmblocked[i];
|
---|
140 | skipped += cl->reader->emmskipped[i];
|
---|
141 | written += cl->reader->emmwritten[i];
|
---|
142 | }
|
---|
143 | snprintf(emmtext, 16, "%3d|%3d|%3d|%3d",
|
---|
144 | written > 999? 999 : written,
|
---|
145 | skipped > 999? 999 : skipped,
|
---|
146 | blocked > 999? 999 : blocked,
|
---|
147 | error > 999? 999 : error);
|
---|
148 |
|
---|
149 | }
|
---|
150 | #ifdef MODULE_CCCAM
|
---|
151 | else if(cl->typ == 'p' && iscccam ){
|
---|
152 | struct cc_data *rcc = cl->cc;
|
---|
153 | if(rcc){
|
---|
154 | LLIST *cards = rcc->cards;
|
---|
155 | if (cards) {
|
---|
156 | int32_t cnt = ll_count(cards);
|
---|
157 | int32_t locals = rcc->num_hop1;
|
---|
158 | snprintf(emmtext, 16, " %3d/%3d card%s", locals, cnt, (cnt > 1)? "s ": " ");
|
---|
159 | }
|
---|
160 | } else {
|
---|
161 | snprintf(emmtext, 16, " No cards ");
|
---|
162 | }
|
---|
163 | }
|
---|
164 | #endif
|
---|
165 | else {
|
---|
166 | snprintf(emmtext, 16, " ");
|
---|
167 | }
|
---|
168 |
|
---|
169 | }
|
---|
170 |
|
---|
171 | if(days == 0) {
|
---|
172 | fprintf(fpsave,"%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
|
---|
173 | type, idx, label, hours, mins,
|
---|
174 | secs, emmtext, status);
|
---|
175 | } else {
|
---|
176 | fprintf(fpsave,"%s%d | %-10.10s |% 2dd %02d:%02d:%02d |%s| %s\n",
|
---|
177 | type, idx, label, days, hours, mins,
|
---|
178 | secs, emmtext, status);
|
---|
179 | }
|
---|
180 | free(emmtext);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | fprintf(fpsave,"---+------------+--------------+---+---+---+--++----\n");
|
---|
185 | // Reader/Proxy table end
|
---|
186 |
|
---|
187 |
|
---|
188 | // Usertable start
|
---|
189 | fprintf(fpsave,"Typ| Label | Channel | Time\n");
|
---|
190 | fprintf(fpsave,"---+------------+-----------------------------+-----\n");
|
---|
191 |
|
---|
192 | /*
|
---|
193 | //Testclient
|
---|
194 | fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
|
---|
195 | "U",
|
---|
196 | 1,
|
---|
197 | "test",
|
---|
198 | "Sky De",
|
---|
199 | "Discovery Channel",
|
---|
200 | 568);
|
---|
201 |
|
---|
202 | */
|
---|
203 |
|
---|
204 | for ( i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
205 |
|
---|
206 | seconds = now - cl->lastecm;
|
---|
207 |
|
---|
208 | if (cl->typ == 'c' && seconds < 15){
|
---|
209 | type = "U";
|
---|
210 | idx = count_u;
|
---|
211 | label = cl->account->usr;
|
---|
212 | count_u++;
|
---|
213 |
|
---|
214 | get_servicename(cl, cl->last_srvid, cl->last_caid, channame);
|
---|
215 | fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
|
---|
216 | type,
|
---|
217 | idx,
|
---|
218 | label,
|
---|
219 | cl->last_srvidptr && cl->last_srvidptr->prov ? cl->last_srvidptr->prov : "",
|
---|
220 | cl->last_srvidptr && cl->last_srvidptr->name ? cl->last_srvidptr->name : "",
|
---|
221 | cl->cwlastresptime);
|
---|
222 |
|
---|
223 | }
|
---|
224 | }
|
---|
225 | fprintf(fpsave,"---+------------+-----------------------------+-----\n");
|
---|
226 | // Usertable end
|
---|
227 | fclose(fpsave);
|
---|
228 | }
|
---|
229 |
|
---|
230 | idx = 0;
|
---|
231 | cs_sleepms(cfg.lcd_write_intervall * 1000);
|
---|
232 | cnt++;
|
---|
233 |
|
---|
234 | if(rename(tmpfile, targetfile) < 0)
|
---|
235 | cs_log("An error occured while writing oscam.lcd file %s.", targetfile);
|
---|
236 |
|
---|
237 | }
|
---|
238 |
|
---|
239 | }
|
---|
240 |
|
---|
241 | void start_lcd_thread() {
|
---|
242 | running = 1;
|
---|
243 | start_thread((void *) &refresh_lcd_file, "LCD");
|
---|
244 | }
|
---|
245 |
|
---|
246 | void end_lcd_thread() {
|
---|
247 | running = 0;
|
---|
248 | }
|
---|
249 |
|
---|
250 | #endif
|
---|