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