1 #define MODULE_LOG_PREFIX "lcd"
9 * Created on: 24.05.2011
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)
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");
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");
41 int32_t seconds
= 0, secs
= 0, fullmins
= 0, mins
= 0, fullhours
= 0, hours
= 0, days
= 0;
47 now
= time((time_t *)0);
48 int16_t cnt
= 0, idx
= 0, count_r
= 0, count_p
= 0, count_u
= 0;
51 if((fpsave
= fopen(temp_file
, "w")))
68 seconds
= now
- first_client
->login
;
72 fullmins
= seconds
/ 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
);
85 { fprintf(fpsave
, "up: %02d:%02d:%02d\n", hours
, mins
, secs
); }
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
);
93 fprintf(fpsave
, "Typ| Label | Idle | w | s | b | e | St\n");
94 fprintf(fpsave
, "---+------------+--------------+---+---+---+---+----\n");
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
))
114 seconds
= now
- cl
->last
;
120 label
= cl
->reader
->label
;
121 if(cl
->reader
->card_status
== CARD_INSERTED
)
126 else if(cl
->typ
== 'p')
129 iscccam
= strncmp(client_get_proto(cl
), "cccam", 5) == 0;
131 label
= cl
->reader
->label
;
133 if(cl
->reader
->card_status
== CARD_INSERTED
)
143 fullmins
= seconds
/ 60;
144 mins
= 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 "); }
179 fprintf(fpsave
, "%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
180 type
, idx
, label
, hours
, mins
,
181 secs
, emmtext
, status
);
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
197 fprintf(fpsave
, "Typ| Label | Channel | Time\n");
198 fprintf(fpsave
, "---+------------+-----------------------------+-----\n");
202 fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
212 for(i
= 0, cl
= first_client
; cl
; cl
= cl
->next
, i
++)
215 seconds
= now
- cl
->lastecm
;
217 if(cl
->typ
== 'c' && seconds
< 15)
221 label
= cl
->account
->usr
;
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",
229 get_cl_lastprovidername(cl
),
230 cl
->last_srvidptr
&& cl
->last_srvidptr
->name
? cl
->last_srvidptr
->name
: "",
235 fprintf(fpsave
, "---+------------+-----------------------------+-----\n");
240 cs_sleepms(cfg
.lcd_write_intervall
* 1000);
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)
255 start_thread("LCD", (void *) &refresh_lcd_file
, NULL
, NULL
, 1, 1);
259 void lcd_thread_stop(void)