30 skn_logger(
SD_ERR,
"DeviceManager failed to acquire needed resources. %d:%s", errno, strerror(errno));
46 skn_logger(
SD_ERR,
"DeviceManager failed to acquire needed resources: SerialPort=%s %d:%s",
52 char display_on[] = { 0xfe, 0x42 };
53 char cls[] = { 0xfe, 0x58 };
54 char home[] = { 0xfe, 0x48 };
56 char set_contrast[] = {0xfe, 0x50, 0xdc};
57 char cursor_off[] = {0xfe, 0x4B };
59 write(pdm->
lcd_handle, set_contrast,
sizeof(set_contrast));
63 write(pdm->
lcd_handle, cursor_off,
sizeof(cursor_off));
67 write(pdm->
lcd_handle, display_on,
sizeof(display_on));
77 skn_logger(
SD_ERR,
"DeviceManager failed to acquire needed resources. %d:%s", errno, strerror(errno));
97 plcd->
af_e = base + 13;
98 plcd->
af_rs = base + 15;
99 plcd->
af_rw = base + 14;
106 plcd->
setup = &mcp23017Setup;
115 skn_logger(
SD_ERR,
"DeviceManager failed to acquire needed resources. %d:%s", errno, strerror(errno));
131 plcd->
af_e = base + 2;
132 plcd->
af_rs = base + 1;
133 plcd->
af_rw = base + 0;
140 plcd->
setup = &mcp23008Setup;
150 skn_logger(
SD_ERR,
"DeviceManager failed to acquire needed resources. %d:%s", errno, strerror(errno));
167 plcd->
af_e = base + 2;
168 plcd->
af_rs = base + 0;
169 plcd->
af_rw = base + 1;
177 plcd->
setup = &pcf8574Setup;
185 digitalWrite(af_backlight, state);
195 pinMode(plcd->
af_rw, OUTPUT);
196 digitalWrite(plcd->
af_rw, LOW);
200 pinMode(plcd->
af_red, OUTPUT);
204 pinMode(plcd->
af_blue, OUTPUT);
220 skn_logger(
SD_ERR,
"I2C Services failed to initialize. lcdInit(%d)", pdm->
lcd_handle);
241 if (strcmp(device_name,
"mcp") == 0) {
243 }
else if (strcmp(device_name,
"mc7") == 0) {
245 }
else if (strcmp(device_name,
"ser") == 0) {
259 char display_off[] = { 0xfe, 0x46 };
260 char cls[] = { 0xfe, 0x58 };
262 write(pdm->
lcd_handle, display_off,
sizeof(display_off));
297 FILE *sysFs = fopen(
"/sys/class/thermal/thermal_zone0/temp",
"r");
299 skn_logger(
SD_WARNING,
"Warning: Failed to open Debian CPU temperature: %d:%s\n", errno, strerror(errno));
300 sysFs = fopen(
"/sys/class/hwmon/hwmon0/device/temp1_input",
"r");
302 skn_logger(
SD_WARNING,
"Warning: Failed to open Centos CPU temperature: %d:%s\n", errno, strerror(errno));
307 rc = fscanf(sysFs,
"%ld", &lRaw);
310 if (rc != 1 || lRaw < 0) {
311 skn_logger(
SD_WARNING,
"Warning: Failed to READ CPU temperature: %d:%s\n", strerror(errno));
316 snprintf(temps->
c,
sizeof(temps->
c),
"%3.1fC", (
double )(lRaw / 1000.0));
317 snprintf(temps->
f,
sizeof(temps->
f),
"%3.1fF", (
double )(lRaw / 1000.0 * 9 / 5 + 32));
319 strncpy(temps->
cbName,
"CpuTemps",
sizeof(temps->
cbName) - 1);
329 int model = 0, rev = 0, mem = 0, maker = 0, overVolted = 0, mLen = 0;
330 char * message =
"Device has an unknown model type.\n";
332 piBoardId(&model, &rev, &mem, &maker, &overVolted);
333 if (model == PI_MODEL_UNKNOWN) {
336 mLen = snprintf(msg,
SZ_INFO_BUFF -1,
"Device: %s, Cpus: %ld, Rev: %s, Mem: %dMB, Maker: %s %s, %s:%s", piModelNames[model],
352 memset(&cpuTemp, 0,
sizeof(
CpuTemps));
354 mLen = snprintf(msg,
SZ_INFO_BUFF-1,
"CPU: %s %s", cpuTemp.
c, cpuTemp.
f);
370 for (hIndex = strlen(buffer); hIndex <
gd_i_cols; hIndex++) {
371 buffer[hIndex] =
' ';
384 char col_width_padding[16];
391 snprintf(worker, (
SZ_INFO_BUFF - 1), col_width_padding,
" ", buffer,
" ");
405 signed int hAdjust = 0, mLen = 0, mfLen = 0;
406 char set_col_row_position[] = {0xfe, 0x47, 0x01, 0x01};
418 set_col_row_position[3] = (
unsigned int)line + 1;
419 write(lcd_handle, set_col_row_position,
sizeof(set_col_row_position));
423 lcdPosition(lcd_handle, 0, line);
424 lcdPuts(lcd_handle, buf);
440 int index = 0, next = 0, prev = 0;
446 skn_logger(
SD_ERR,
"Display Manager cannot acquire needed resources. %d:%s", errno, strerror(errno));
451 strcpy(pdm->
cbName,
"PDisplayManager");
453 pdm->
msg_len = strlen(welcome);
463 strcpy(pdl->
cbName,
"PDisplayLine");
476 next = (((index + 1) == ARY_MAX_DM_LINES) ? 0 : (index + 1));
477 prev = (((index - 1) == -1) ? (ARY_MAX_DM_LINES - 1) : (index - 1));
488 if (pdm == NULL || client_request_message == NULL) {
532 int index = 0, dsp_line_number = 0;
536 long host_update_cycle = 0;
541 skn_logger(
SD_ERR,
"Display Manager cannot acquire needed resources. DMCreate()");
556 skn_logger(
SD_ERR,
"Display Manager cannot acquire needed resources: lcdSetup().");
563 skn_logger(
SD_ERR,
"Display Manager cannot acquire needed resources: Consumer().");
568 skn_logger(
SD_NOTICE,
"Application Active... ");
577 for (index = 0; index < pdm->
dsp_rows; index++) {
585 if ((host_update_cycle++ % 900) == 0) {
593 host_update_cycle = 1;
599 skn_logger(
SD_NOTICE,
"Application InActive...");
607 gp_structure_pdm = pdm = NULL;
633 if (pdm->
i_socket == EXIT_FAILURE) {
634 skn_logger(
SD_EMERG,
"DisplayManager: Host Init Failed!");
641 if (i_thread_rc == -1) {
642 skn_logger(
SD_WARNING,
"DisplayManager: Create thread failed: %s", strerror(errno));
648 skn_logger(
SD_NOTICE,
"DisplayManager: Thread startup successful... ");
658 skn_logger(
SD_WARNING,
"DisplayManager: Canceling thread.");
662 skn_logger(
SD_WARNING,
"DisplayManager: Thread was already stopped.");
666 skn_logger(
SD_NOTICE,
"DisplayManager: Thread ended:(%ld)", (
long int) trc);
675 struct sockaddr_in remaddr;
676 socklen_t addrlen =
sizeof(remaddr);
682 signed int rLen = 0, rc = 0;
683 long int exit_code = EXIT_SUCCESS;
685 bzero(request,
sizeof(request));
686 memset(recvHostName, 0,
sizeof(recvHostName));
691 pthread_exit((
void *) exit_code);
697 memset(&remaddr, 0,
sizeof(remaddr));
698 remaddr.sin_family = AF_INET;
700 remaddr.sin_addr.s_addr = htonl(INADDR_ANY);
701 addrlen =
sizeof(remaddr);
703 if ((rLen = recvfrom(pdm->
i_socket, request,
sizeof(request) - 1, 0, (
struct sockaddr *) &remaddr, &addrlen)) < 0) {
704 if (errno == EAGAIN || errno == EWOULDBLOCK) {
707 skn_logger(
SD_ERR,
"DisplayManager: RcvFrom() Failure code=%d, etext=%s", errno, strerror(errno));
713 rc = getnameinfo(((
struct sockaddr *) &remaddr),
sizeof(
struct sockaddr_in), recvHostName,
sizeof(recvHostName) - 1, NULL, 0, NI_DGRAM);
715 skn_logger(
SD_ERR,
"GetNameInfo() Failure code=%d, etext=%s", errno, strerror(errno));
719 skn_logger(
SD_NOTICE,
"Received request from %s @ %s:%d", recvHostName, inet_ntoa(remaddr.sin_addr), ntohs(remaddr.sin_port));
723 pch = strtok(recvHostName,
".");
724 snprintf(strPrefix,
sizeof(strPrefix) -1 ,
"%s|%s", pch, request);
727 if (sendto(pdm->
i_socket,
"200 Accepted", strlen(
"200 Accepted"), 0, (
struct sockaddr *) &remaddr, addrlen) < 0) {
728 skn_logger(
SD_ERR,
"SendTo() Failure code=%d, etext=%s", errno, strerror(errno));
735 if (strcmp(
"QUIT!", request) == 0) {
738 skn_logger(
SD_NOTICE,
"COMMAND: Shutdown Requested! exit code=%d", exit_code);
747 skn_logger(
SD_NOTICE,
"Display Manager Thread: shutdown complete: (%ld)", exit_code);
751 pthread_exit((
void *) exit_code);
766 skn_logger(
" ",
"\tSkoona Development <skoona@gmail.com>");
767 skn_logger(
" ",
"Usage:\n %s [-v] [-m 'Welcome Message'] [-r 4|2] [-c 20|16] [-i 39|32] [-t pcf|mcp|mc7|ser] [-p string] [-h|--help]",
gd_ch_program_name);
768 skn_logger(
" ",
"\nOptions:");
769 skn_logger(
" ",
" -r, --rows=dd\t\tNumber of rows in physical display.");
770 skn_logger(
" ",
" -c, --cols=dd\t\tNumber of columns in physical display.");
771 skn_logger(
" ",
" -m, --message\tWelcome Message for line 1.");
772 skn_logger(
" ",
" -p, --serial-port=string\tSerial port. | ['/dev/ttyACM0']");
773 skn_logger(
" ",
" -i, --i2c-address=ddd\tI2C decimal address. | [0x27=39, 0x20=32]");
774 skn_logger(
" ",
" -t, --i2c-chipset=pcf\tI2C Chipset. | [pcf|mc7|mcp|ser]");
775 skn_logger(
" ",
" -v, --version\tVersion printout.");
776 skn_logger(
" ",
" -h, --help\t\tShow this help screen.");
788 struct option longopts[] = {
789 {
"debug", 1, NULL,
'd' },
790 {
"rows", 1, NULL,
'r' },
791 {
"cols", 1, NULL,
'c' },
792 {
"message", 1, NULL,
'm' },
793 {
"i2c-address", 1, NULL,
'i' },
794 {
"12c-chipset", 1, NULL,
't' },
795 {
"serial-port", 1, NULL,
'p' },
796 {
"version", 0, NULL,
'v' },
797 {
"help", 0, NULL,
'h' },
807 while ((opt = getopt_long(argc, argv,
"d:m:r:c:i:t:p:vh", longopts, &longindex)) != -1) {
813 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
815 return (EXIT_FAILURE);
828 (
char) opt, longindex, optind, opterr);
832 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
834 return (EXIT_FAILURE);
847 (
char) opt, longindex, optind, opterr);
851 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
853 return (EXIT_FAILURE);
860 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
862 return (EXIT_FAILURE);
869 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
871 return (EXIT_FAILURE);
885 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind,
887 return (EXIT_FAILURE);
894 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind, opterr);
898 skn_logger(
SD_ERR,
"%s: input param was invalid! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind, opterr);
899 return (EXIT_FAILURE);
903 skn_logger(
SD_ERR,
"\n\tProgram => %s\n\tVersion => %s\n\tSkoona Development\n\t<skoona@gmail.com>\n",
gd_ch_program_name,
905 return (EXIT_FAILURE);
908 skn_logger(
SD_ERR,
"%s: unknown input param! %c[%d:%d:%d]\n",
gd_ch_program_name, (
char) opt, longindex, optind, opterr);
910 return (EXIT_FAILURE);
914 return (EXIT_FAILURE);
long skn_get_number_of_cpu_cores()
int skn_udp_host_create_regular_socket(int port, double rcvTimeout)
char gd_ch_program_desc[SZ_INFO_BUFF]
static void skn_display_manager_destroy(PDisplayManager pdm)
int generate_cpu_temps_info(char *msg)
void skn_device_manager_backlight(int af_backlight, int state)
int(* setup)(const int, const int)
int skn_handle_display_command_line(int argc, char **argv)
char ch_serial_port_name[SZ_CHAR_BUFF]
char gd_ch_intfName[SZ_CHAR_BUFF]
int skn_time_delay(double delay_time)
PLCDDevice skn_device_manager_SerialPort(PDisplayManager pdm)
char * skn_scroller_wrap_blanks(char *buffer)
PLCDDevice skn_device_manager_MCP23017(PDisplayManager pdm)
PDisplayLine pdsp_collection[ARY_MAX_DM_LINES]
PLCDDevice skn_device_manager_PCF8574(PDisplayManager pdm)
int skn_display_manager_message_consumer_startup(PDisplayManager pdm)
long getCpuTemps(PCpuTemps temps)
PLCDDevice skn_device_manager_MCP23008(PDisplayManager pdm)
static PDisplayManager skn_display_manager_create(char *welcome)
void skn_display_manager_message_consumer_shutdown(PDisplayManager pdm)
char * gd_pch_device_name
int skn_device_manager_LCD_setup(PDisplayManager pdm, char *device_name)
static void * skn_display_manager_message_consumer_thread(void *ptr)
int skn_scroller_scroll_lines(PDisplayLine pdl, int lcd_handle, int line)
char cbName[SZ_CHAR_BUFF]
char gd_ch_program_name[SZ_INFO_BUFF]
int generate_uname_info(char *msg)
char * skn_scroller_pad_right(char *buffer)
char ch_display_msg[SZ_INFO_BUFF]
int skn_device_manager_LCD_shutdown(PDisplayManager pdm)
sig_atomic_t gi_exit_flag
char cbName[SZ_CHAR_BUFF]
int get_broadcast_ip_array(PIPBroadcastArray paB)
PDisplayManager gp_structure_pdm
char cbName[SZ_CHAR_LABEL]
int skn_display_manager_do_work(char *client_request_message)
int generate_rpi_model_info(char *msg)
char ch_welcome_msg[SZ_INFO_BUFF]
char * gd_pch_serial_port
int generate_datetime_info(char *msg)
char gd_ch_ipAddress[SZ_CHAR_BUFF]
int generate_loadavg_info(char *msg)
PDisplayManager skn_get_display_manager_ref()
static void skn_display_print_usage()
PDisplayLine skn_display_manager_add_line(PDisplayManager pdmx, char *client_request_message)
static PLCDDevice skn_device_manager_init_i2c(PDisplayManager pdm)
char cbName[SZ_CHAR_BUFF]