- fix Building without Nagra not possible at Nagra_Merlin https://trac.streamboard...
[oscam.git] / module-lcd.c
blobe821de52380c6bcedc115907c190c1193de0737c
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;
20 int32_t seconds, secs, fullmins, mins, hours, days, fullhours;
22 static void refresh_lcd_file(void)
24 char targetfile[256];
25 char temp_file[256];
26 char channame[CS_SERVICENAME_SIZE];
28 set_thread_name(__func__);
30 if(cfg.lcd_output_path == NULL)
32 get_tmp_dir_filename(targetfile, sizeof(targetfile), "oscam.lcd");
33 get_tmp_dir_filename(temp_file, sizeof(temp_file), "oscam.lcd.tmp");
35 else
37 snprintf(targetfile, sizeof(targetfile), "%s%s", cfg.lcd_output_path, "/oscam.lcd");
38 snprintf(temp_file, sizeof(temp_file), "%s%s.tmp", cfg.lcd_output_path, "/oscam.lcd");
41 int8_t iscccam = 0;
42 fullhours = 0;
43 fullmins = 0;
44 seconds = 0;
45 hours = 0;
46 mins = 0;
47 secs = 0;
48 days = 0;
49 time_t now;
51 while(running)
53 now = time((time_t *)0);
54 int16_t cnt = 0, idx = 0, count_r = 0, count_p = 0, count_u = 0;
55 FILE *fpsave;
57 if((fpsave = fopen(temp_file, "w")))
60 idx = 0;
61 int16_t i;
62 char *type;
63 char *label;
64 char *status;
66 // Statuslines start
67 secs = 0;
68 fullmins = 0;
69 mins = 0;
70 fullhours = 0;
71 hours = 0;
72 days = 0;
74 seconds = now - first_client->login;
75 secs = seconds % 60;
76 if(seconds > 60)
78 fullmins = seconds / 60;
79 mins = fullmins % 60;
80 if(fullmins > 60)
82 fullhours = fullmins / 60;
83 hours = fullhours % 24;
84 days = fullhours / 24;
88 fprintf(fpsave, "Version: %s\n", CS_VERSION);
89 fprintf(fpsave, "Revision: %s\n", CS_SVN_VERSION);
90 if(days == 0)
91 { fprintf(fpsave, "up: %02d:%02d:%02d\n", hours, mins, secs); }
92 else
93 { fprintf(fpsave, "up: %02dd %02d:%02d:%02d\n", days, hours, mins, secs); }
94 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);
95 fprintf(fpsave, "uptime: %d\n", seconds);
96 // Statuslines end
98 // Readertable head
99 fprintf(fpsave, "Typ| Label | Idle | w | s | b | e | St\n");
100 fprintf(fpsave, "---+------------+--------------+---+---+---+---+----\n");
102 struct s_client *cl;
104 // Reader/Proxy table start
105 for(i = 0, cl = first_client; cl ; cl = cl->next, i++)
108 if((cl->typ == 'r' || cl->typ == 'p') && ((now - cl->last) < 20 || !cfg.lcd_hide_idle))
110 type = "";
111 label = "";
112 status = "OFF";
113 secs = 0;
114 fullmins = 0;
115 mins = 0;
116 fullhours = 0;
117 hours = 0;
118 days = 0;
120 seconds = now - cl->last;
122 if(cl->typ == 'r')
124 type = "R";
125 idx = count_r;
126 label = cl->reader->label;
127 if(cl->reader->card_status == CARD_INSERTED)
128 { status = "OK"; }
129 count_r++;
132 else if(cl->typ == 'p')
134 type = "P";
135 iscccam = strncmp(client_get_proto(cl), "cccam", 5) == 0;
136 idx = count_p;
137 label = cl->reader->label;
139 if(cl->reader->card_status == CARD_INSERTED)
140 { status = "CON"; }
142 count_p++;
146 secs = seconds % 60;
147 if(seconds > 60)
149 fullmins = seconds / 60;
150 mins = fullmins % 60;
151 if(fullmins > 60)
153 fullhours = fullmins / 60;
154 hours = fullhours % 24;
155 days = fullhours / 24;
159 uint16_t written = 0, skipped = 0, blocked = 0, error = 0;
161 char emmtext[16] = " ";
162 if(cl->typ == 'r' || !iscccam)
164 for(i = 0; i < 4; i++)
166 error += cl->reader->emmerror[i];
167 blocked += cl->reader->emmblocked[i];
168 skipped += cl->reader->emmskipped[i];
169 written += cl->reader->emmwritten[i];
171 snprintf(emmtext, 16, "%3d|%3d|%3d|%3d",
172 written > 999 ? 999 : written,
173 skipped > 999 ? 999 : skipped,
174 blocked > 999 ? 999 : blocked,
175 error > 999 ? 999 : error);
177 else if(cl->typ == 'p' && iscccam)
179 if(!cccam_snprintf_cards_stat(cl, emmtext, 16))
180 { snprintf(emmtext, 16, " No cards "); }
183 if(days == 0)
185 fprintf(fpsave, "%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
186 type, idx, label, hours, mins,
187 secs, emmtext, status);
189 else
191 fprintf(fpsave, "%s%d | %-10.10s |% 3dd %02d:%02d:%02d |%s| %s\n",
192 type, idx, label, days, hours, mins,
193 secs, emmtext, status);
198 fprintf(fpsave, "---+------------+--------------+---+---+---+--++----\n");
199 // Reader/Proxy table end
202 // Usertable start
203 fprintf(fpsave, "Typ| Label | Channel | Time\n");
204 fprintf(fpsave, "---+------------+-----------------------------+-----\n");
207 //Testclient
208 fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
209 "U",
211 "test",
212 "Sky De",
213 "Discovery Channel",
214 568);
218 for(i = 0, cl = first_client; cl ; cl = cl->next, i++)
221 seconds = now - cl->lastecm;
223 if(cl->typ == 'c' && seconds < 15)
225 type = "U";
226 idx = count_u;
227 label = cl->account->usr;
228 count_u++;
230 get_servicename(cl, cl->last_srvid, cl->last_provid, cl->last_caid, channame, sizeof(channame));
231 fprintf(fpsave, "%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
232 type,
233 idx,
234 label,
235 get_cl_lastprovidername(cl),
236 cl->last_srvidptr && cl->last_srvidptr->name ? cl->last_srvidptr->name : "",
237 cl->cwlastresptime);
241 fprintf(fpsave, "---+------------+-----------------------------+-----\n");
242 // Usertable end
243 fclose(fpsave);
246 cs_sleepms(cfg.lcd_write_intervall * 1000);
247 cnt++;
249 if(rename(temp_file, targetfile) < 0)
250 { cs_log("An error occured while writing oscam.lcd file %s.", targetfile); }
256 void lcd_thread_start(void)
258 if(cfg.enablelcd)
260 running = 1;
261 start_thread("LCD", (void *) &refresh_lcd_file, NULL, NULL, 1, 1);
265 void lcd_thread_stop(void)
267 running = 0;
270 #endif