36 |
36 |
37 |
37 |
38 void socket_recv(SGOBJ *dlg) |
38 void socket_recv(SGOBJ *dlg) |
39 { |
39 { |
40 uint16_t data; |
40 uint16_t data; |
|
41 unsigned char cgdata[8]; |
41 struct sockaddr_in clntaddr; |
42 struct sockaddr_in clntaddr; |
42 socklen_t clntlen = sizeof(clntaddr); |
43 socklen_t clntlen = sizeof(clntaddr); |
43 ssize_t recv_len; |
44 ssize_t recv_len; |
44 int fd = 0, my_error; |
45 int i, index, fd = 0, my_error; |
45 |
46 |
46 recv_len = recvfrom(sock, &data, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *)&clntaddr, &clntlen); |
47 recv_len = recvfrom(sock, &data, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *)&clntaddr, &clntlen); |
47 if (recv_len == sizeof(uint16_t)) { |
48 if (recv_len == sizeof(uint16_t)) { |
48 /* |
49 /* |
49 * Get device from data |
50 * Get device from data |
53 fprintf(stdout, "Device %d ", fd); |
54 fprintf(stdout, "Device %d ", fd); |
54 if ((data & SLCD_MCLEAR) == SLCD_CLEAR) { |
55 if ((data & SLCD_MCLEAR) == SLCD_CLEAR) { |
55 slcdClear(dlg, fd); |
56 slcdClear(dlg, fd); |
56 } else if ((data & SLCD_MHOME) == SLCD_HOME) { |
57 } else if ((data & SLCD_MHOME) == SLCD_HOME) { |
57 slcdHome(dlg, fd); |
58 slcdHome(dlg, fd); |
|
59 } else if ((data & SLCD_MCGRAM) == SLCD_CGRAM) { |
|
60 index = (data & 0x038) >> 3; |
|
61 for (i = 0; i < 8; i++) { |
|
62 /* |
|
63 * Reply with the current keyboard state. Looks too early but the very last reply |
|
64 * will be sent at the end of this function and we need to take 8 data words. |
|
65 */ |
|
66 if (sendto(sock, &keys, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *) &clntaddr, clntlen) == -1) { |
|
67 syslog(LOG_NOTICE, "socket_recv() sendto error: %s", strerror(errno)); |
|
68 } |
|
69 recv_len = recvfrom(sock, &data, sizeof(uint16_t), 0, (struct sockaddr *)&clntaddr, &clntlen); |
|
70 cgdata[i] = data & 0x00ff; |
|
71 } |
|
72 fprintf(stdout, "Got new CGRAM index=%d, %02x %02x %02x %02x %02x %02x %02x %02x\n", index, |
|
73 cgdata[0], cgdata[1], cgdata[2], cgdata[3], cgdata[4], cgdata[5], cgdata[6], cgdata[7]); |
|
74 slcdCharDef(dlg, fd, index, cgdata); |
58 } else if ((data & SLCD_MDGRAM) == SLCD_DGRAM) { |
75 } else if ((data & SLCD_MDGRAM) == SLCD_DGRAM) { |
59 slcdPosition(dlg, fd, data & 0x001f, (data & 0x0060) >> 5); |
76 slcdPosition(dlg, fd, data & 0x001f, (data & 0x0060) >> 5); |
60 } else if ((data & 0xfe00) == SLCD_DATA) { |
77 } else if ((data & 0xfe00) == SLCD_DATA) { |
61 slcdPutchar(dlg, fd, data & 0x00ff); |
78 slcdPutchar(dlg, fd, data & 0x00ff); |
62 } else if ((data & SLCD_MLEDS) == SLCD_LEDS) { |
79 } else if ((data & SLCD_MLEDS) == SLCD_LEDS) { |