[gbx] - fix ccc->gbox reshare
[oscam.git] / module-lcd.c
blobaf462cd2728bf090c1933331ea1e59eed0d08bd2
1 #define MODULE_LOG_PREFIX "lcd"
3 #include "globals.h"
5 #ifdef LCDSUPPORT
6 /*
7 * module-lcd.c
9 * Created on: 24.05.2011
10 * Author: alno
13 #include "module-cccam.h"
14 #include "oscam-client.h"
15 #include "oscam-files.h"
16 #include "oscam-string.h"
17 #include "oscam-time.h"
19 static int8_t running;
21 static void refresh_lcd_file(void)
23 char targetfile[256];
24 char temp_file[256];
25 char channame[CS_SERVICENAME_SIZE];
27 set_thread_name(__func__);
29 if(cfg.lcd_output_path == NULL)
31 get_tmp_dir_filename(targetfile, sizeof(targetfile), "oscam.lcd");
32 get_tmp_dir_filename(temp_file, sizeof(temp_file), "oscam.lcd.tmp");
34 else
36 snprintf(targetfile, sizeof(targetfile), "%s%s", cfg.lcd_output_path, "/oscam.lcd");
37 snprintf(temp_file, sizeof(temp_file), "%s%s.tmp", cfg.lcd_output_path, "/oscam.lcd");
40 int8_t iscccam = 0;
41 int32_t seconds = 0, secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
42 time_t now;
45 while(running)
47 now = time((time_t *)0);
48 int16_t cnt = 0, idx = 0, count_r = 0, count_p = 0, count_u = 0;
49 FILE *fpsave;
51 if((fpsave = fopen(temp_file, "w")))
54 idx = 0;
55 int16_t i;
56 char *type;
57 char *label;
58 char *status;
60 // Statuslines start
61 secs = 0;
62 fullmins = 0;
63 mins = 0;
64 fullhours = 0;
65 hours = 0;
66 days = 0;
68 seconds = now - first_client->login;
69 secs = seconds % 60;
70 if(seconds > 60)
72 fullmins = seconds / 60;
73 mins = fullmins % 60;
74 if(fullmins > 60)
76 fullhours = fullmins / 60;
77 hours = fullhours % 24;
78 days = fullhours / 24;
82 fprintf(fpsave, "Version: %s\n", CS_VERSION);
83 fprintf(fpsave, "Revision: %s\n", CS_SVN_VERSION);
84 if(days == 0)
85 { fprintf(fpsave, "up: %02d:%02d:%02d\n", hours, mins, secs); }
86 else
87 { fprintf(fpsave, "up: %02dd %02d:%02d:%02d\n", days, hours, mins, secs); }
88 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);
89 fprintf(fpsave, "uptime: %d\n", seconds);
90 // Statuslines end
92 // Readertable head
93 fprintf(fpsave, "Typ| Label | Idle | w | s | b | e | St\n");
94 fprintf(fpsave, "---+------------+--------------+---+---+---+---+----\n");
96 struct s_client *cl;
98 // Reader/Proxy table start
99 for(i = 0, cl = first_client; cl ; cl = cl->next, i++)
102 if((cl->typ == 'r' || cl->typ == 'p') && ((now - cl->last) < 20 || !cfg.lcd_hide_idle))
104 type = "";
105 label = "";
106 status = "OFF";
107 secs = 0;
108 fullmins = 0;
109 mins = 0;
110 fullhours = 0;
111 hours = 0;
112 days = 0;
114 seconds = now - cl->last;
116 if(cl->typ == 'r')
118 type = "R";
119 idx = count_r;
120 label = cl->reader->label;
121 if(cl->reader->card_status == CARD_INSERTED)
122 { status = "OK"; }
123 count_r++;
126 else if(cl->typ == 'p')
128 type = "P";
129 iscccam = strncmp(client_get_proto(cl), "cccam", 5) == 0;
130 idx = count_p;
131 label = cl->reader->label;
133 if(cl->reader->card_status == CARD_INSERTED)
134 { status = "CON"; }
136 count_p++;
140 secs = seconds % 60;
141 if(seconds > 60)
143 fullmins = seconds / 60;
144 mins = fullmins % 60;
145 if(fullmins > 60)
147 fullhours = fullmins / 60;
148 hours = fullhours % 24;
149 days = fullhours / 24;
153 uint16_t written = 0, skipped = 0, blocked = 0, error = 0;
155 char emmtext[16] = " ";
156 if(cl->typ == 'r' || !iscccam)
158 for(i = 0; i < 4; i++)
160 error += cl->reader->emmerror[i];
161 blocked += cl->reader->emmblocked[i];
162 skipped += cl->reader->emmskipped[i];
163 written += cl->reader->emmwritten[i];
165 snprintf(emmtext, 16, "%3d|%3d|%3d|%3d",
166 written > 999 ? 999 : written,
167 skipped > 999 ? 999 : skipped,
168 blocked > 999 ? 999 : blocked,
169 error > 999 ? 999 : error);
171 else if(cl->typ == 'p' && iscccam)
173 if(!cccam_snprintf_cards_stat(cl, emmtext, 16))
174 { snprintf(emmtext, 16, " No cards "); }
177 if(days == 0)
179 fprintf(fpsave, "%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
180 type, idx, label, hours, mins,
181 secs, emmtext, status);
183 else
185 fprintf(fpsave, "%s%d | %-10.10s |% 3dd %02d:%02d:%02d |%s| %s\n",
186 type, idx, label, days, hours, mins,
187 secs, emmtext, status);
192 fprintf(fpsave, "---+------------+--------------+---+---+---+--++----\n");
193 // Reader/Proxy table end
196 // Usertable start
197 fprintf(fpsave, "Typ| Label | Channel | Time\n");
198 fprintf(fpsave, "---+------------+-----------------------------+-----\n");
201 //Testclient
202 fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
203 "U",
205 "test",
206 "Sky De",
207 "Discovery Channel",
208 568);
212 for(i = 0, cl = first_client; cl ; cl = cl->next, i++)
215 seconds = now - cl->lastecm;
217 if(cl->typ == 'c' && seconds < 15)
219 type = "U";
220 idx = count_u;
221 label = cl->account->usr;
222 count_u++;
224 get_servicename(cl, cl->last_srvid, cl->last_provid, cl->last_caid, channame, sizeof(channame));
225 fprintf(fpsave, "%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
226 type,
227 idx,
228 label,
229 get_cl_lastprovidername(cl),
230 cl->last_srvidptr && cl->last_srvidptr->name ? cl->last_srvidptr->name : "",
231 cl->cwlastresptime);
235 fprintf(fpsave, "---+------------+-----------------------------+-----\n");
236 // Usertable end
237 fclose(fpsave);
240 cs_sleepms(cfg.lcd_write_intervall * 1000);
241 cnt++;
243 if(rename(temp_file, targetfile) < 0)
244 { cs_log("An error occured while writing oscam.lcd file %s.", targetfile); }
250 void lcd_thread_start(void)
252 if(cfg.enablelcd)
254 running = 1;
255 start_thread("LCD", (void *) &refresh_lcd_file, NULL, NULL, 1, 1);
259 void lcd_thread_stop(void)
261 running = 0;
264 #endif