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
;
20 int32_t seconds
, secs
, fullmins
, mins
, hours
, days
, fullhours
;
22 static void refresh_lcd_file(void)
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");
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");
53 now
= time((time_t *)0);
54 int16_t cnt
= 0, idx
= 0, count_r
= 0, count_p
= 0, count_u
= 0;
57 if((fpsave
= fopen(temp_file
, "w")))
74 seconds
= now
- first_client
->login
;
78 fullmins
= seconds
/ 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
);
91 { fprintf(fpsave
, "up: %02d:%02d:%02d\n", hours
, mins
, secs
); }
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
);
99 fprintf(fpsave
, "Typ| Label | Idle | w | s | b | e | St\n");
100 fprintf(fpsave
, "---+------------+--------------+---+---+---+---+----\n");
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
))
120 seconds
= now
- cl
->last
;
126 label
= cl
->reader
->label
;
127 if(cl
->reader
->card_status
== CARD_INSERTED
)
132 else if(cl
->typ
== 'p')
135 iscccam
= strncmp(client_get_proto(cl
), "cccam", 5) == 0;
137 label
= cl
->reader
->label
;
139 if(cl
->reader
->card_status
== CARD_INSERTED
)
149 fullmins
= seconds
/ 60;
150 mins
= 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 "); }
185 fprintf(fpsave
, "%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
186 type
, idx
, label
, hours
, mins
,
187 secs
, emmtext
, status
);
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
203 fprintf(fpsave
, "Typ| Label | Channel | Time\n");
204 fprintf(fpsave
, "---+------------+-----------------------------+-----\n");
208 fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
218 for(i
= 0, cl
= first_client
; cl
; cl
= cl
->next
, i
++)
221 seconds
= now
- cl
->lastecm
;
223 if(cl
->typ
== 'c' && seconds
< 15)
227 label
= cl
->account
->usr
;
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",
235 get_cl_lastprovidername(cl
),
236 cl
->last_srvidptr
&& cl
->last_srvidptr
->name
? cl
->last_srvidptr
->name
: "",
241 fprintf(fpsave
, "---+------------+-----------------------------+-----\n");
246 cs_sleepms(cfg
.lcd_write_intervall
* 1000);
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)
261 start_thread("LCD", (void *) &refresh_lcd_file
, NULL
, NULL
, 1, 1);
265 void lcd_thread_stop(void)