| 1 |
G15daemon Client Development() G15daemon Client Development() |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
[1mSYNOPSIS[0m |
| 6 |
#include <libg15.h> |
| 7 |
#include <g15daemon_client.h> |
| 8 |
|
| 9 |
link with |
| 10 |
|
| 11 |
-lg15daemon_client |
| 12 |
|
| 13 |
int new_g15_screen(int screentype); |
| 14 |
int g15_close_screen(int sock); |
| 15 |
int g15_send(int sock, char *buf, unsigned int len); |
| 16 |
int g15_recv(int sock, char *buf, unsigned int len); |
| 17 |
|
| 18 |
[1mG15Daemon Server / Client communication[0m |
| 19 |
G15Daemon uses INET sockets to talk to its clients, listening on local- |
| 20 |
host port 15550 for connection requests. Once connected, the server |
| 21 |
sends the text string "G15 daemon HELLO" to confirm to the client that |
| 22 |
it is a valid g15daemon process, creates a new screen, and waits for |
| 23 |
LCD buffers or commands to be sent from the client. Clients are able |
| 24 |
to create multiple screens simply by opening more socket connections to |
| 25 |
the server process. If the socket is closed or the client exits, all |
| 26 |
LCD buffers and the screen associated with that socket are automati- |
| 27 |
cally destroyed. |
| 28 |
|
| 29 |
Clients wishing to display on the LCD must send entire screens in the |
| 30 |
format of their choice. Currently partial screen updates (icons etc) |
| 31 |
are not supported. |
| 32 |
|
| 33 |
G15Daemon commands are sent to the daemon via the OOB (out-of-band) |
| 34 |
messagetype, replies are sent inband back to the client. |
| 35 |
|
| 36 |
|
| 37 |
[1mint new_g15_screen(int screentype)[0m |
| 38 |
Opens a new connection and returns a network socket for use. Creates a |
| 39 |
screen with one of the following pixel formats defined in g15dae- |
| 40 |
mon_client.h: |
| 41 |
|
| 42 |
G15_PIXELBUF: this buffer must be exactly 6880 bytes, and uses 1 byte |
| 43 |
per pixel. |
| 44 |
|
| 45 |
G15_TEXTBUF: currently ignored by the daemon. |
| 46 |
|
| 47 |
G15_WBMPBUF: this is a packed pixel buffer in WBMP format with 8 pix- |
| 48 |
els per byte. Useful for perl programmers using the GD:: and G15Dae- |
| 49 |
mon.pm (see lang_bindings directory) perl modules. |
| 50 |
|
| 51 |
G15_G15RBUF: another packed pixel buffer type, also with 8 pix- |
| 52 |
els/byte, and is the native libg15render format. |
| 53 |
|
| 54 |
Example of use: |
| 55 |
|
| 56 |
int screen_fd = new_g15_screen( G15_WBMPBUF ); |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
[1mint g15_close_screen (int screen_fd)[0m |
| 64 |
Simply closes a socket previously opened with new_g15_screen(). The |
| 65 |
daemon will automatically clean up any buffers and remove the LCD |
| 66 |
screen from the display list. |
| 67 |
|
| 68 |
Returns 0 if successful, or errno if there was an error. |
| 69 |
|
| 70 |
Example: |
| 71 |
|
| 72 |
int retval = 0; int screen_fd = new_g15_screen( G15_WBMPBUF ); |
| 73 |
|
| 74 |
|
| 75 |
retval = g15_close_screen( screen_fd ); |
| 76 |
|
| 77 |
|
| 78 |
[1mint g15_send (int sock, char *buf, unsigned int len)[0m |
| 79 |
A simple wrapper around send() to ensure that all 'len' bytes of data |
| 80 |
is sent to the daemon. It simply uses poll() to block until the entire |
| 81 |
message is sent. |
| 82 |
|
| 83 |
Returns 0 on success, -1 if the send failed due to timeout or socket |
| 84 |
error. |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
[1mint g15_recv (int sock, char *buf, unsigned int len)[0m |
| 90 |
A simple wrapper around recv() to ensure that all 'len' bytes of data |
| 91 |
are received from the daemon. It simply uses poll() to block until the |
| 92 |
entire message is received. |
| 93 |
|
| 94 |
Returns 0 on success, -1 if the recv failed due to timeout or socket |
| 95 |
error. |
| 96 |
|
| 97 |
|
| 98 |
[1mG15Daemon Command Types[0m |
| 99 |
Commands and requests to the daemon are sent via OOB data packets. |
| 100 |
Changes to the backlight and mkey state will only affect the calling |
| 101 |
client. The following commands are supported as defined in g15dae- |
| 102 |
mon_client.h: |
| 103 |
|
| 104 |
|
| 105 |
G15DAEMON_KEY_HANDLER |
| 106 |
Requests that all M and G key presses are sent to this client. |
| 107 |
All keys are packed into an unsigned int, and sent to the client |
| 108 |
inband when a key is pressed. |
| 109 |
|
| 110 |
|
| 111 |
G15DAEMON_MKEYLEDS |
| 112 |
Sets the M key LED state. In order to change LED state, each |
| 113 |
LED that is to be turned on is OR'd with the command byte. See |
| 114 |
libg15.h for values. For examples see the end of this document. |
| 115 |
|
| 116 |
|
| 117 |
G15DAEMON_BACKLIGHT |
| 118 |
Sets the LCD Backlight brightness. Brightness level (0|1|2) is |
| 119 |
OR'd with the command byte. For examples see the end of this |
| 120 |
document. |
| 121 |
|
| 122 |
|
| 123 |
G15DAEMON_CONTRAST |
| 124 |
Sets the LCD contrast. Contrast level (0|1|2) is OR'd with the |
| 125 |
command byte. For examples see the end of this document. |
| 126 |
|
| 127 |
|
| 128 |
G15DAEMON_GET_KEYSTATE |
| 129 |
Requests a packet containing the current keystate. The daemon |
| 130 |
will return an unsigned int containing any keys pressed. See |
| 131 |
libg15.h for details on key values, and lcdclient_test.c in the |
| 132 |
source distribution for an example. |
| 133 |
|
| 134 |
|
| 135 |
G15DAEMON_SWITCH_PRIORITIES |
| 136 |
Toggles the client's LCD screen to/from the front. Clients can |
| 137 |
check their foreground/background state with the following: |
| 138 |
|
| 139 |
|
| 140 |
G15DAEMON_IS_FOREGROUND |
| 141 |
On reciept of this command, G15Daemon will send a 1 byte packet |
| 142 |
back with the value 1 if the client is foreground, or 0 if not. |
| 143 |
|
| 144 |
|
| 145 |
G15DAEMON_IS_USER_SELECTED |
| 146 |
On reciept of this command, G15daemon will return a byte indi- |
| 147 |
cating if the user selected the client be foreground or back- |
| 148 |
ground. |
| 149 |
|
| 150 |
|
| 151 |
[1mEXAMPLES[0m |
| 152 |
Below is a completely nonsensical client which demonstrates most of the |
| 153 |
commands. |
| 154 |
|
| 155 |
--- Cut here --- |
| 156 |
|
| 157 |
#include <stdio.h> |
| 158 |
#include <stdlib.h> |
| 159 |
#include <string.h> |
| 160 |
#include <sys/types.h> |
| 161 |
#include <sys/socket.h> |
| 162 |
#include <errno.h> |
| 163 |
#include <poll.h> |
| 164 |
#include <g15daemon_client.h> |
| 165 |
#include <libg15.h> |
| 166 |
|
| 167 |
int main(int argc, char *argv[]) { |
| 168 |
int g15screen_fd, retval; |
| 169 |
char lcdbuffer[6880]; |
| 170 |
unsigned int keystate; |
| 171 |
char msgbuf[256]; |
| 172 |
|
| 173 |
if((g15screen_fd = new_g15_screen(G15_PIXELBUF))<0){ |
| 174 |
printf("Sorry, cant connect to the G15daemon0); |
| 175 |
return -1; |
| 176 |
}else |
| 177 |
printf("Connected to g15daemon. sending image\n"); /* |
| 178 |
create a half black image */ |
| 179 |
memset(lcdbuffer,0,6880); |
| 180 |
memset(lcdbuffer,1,6880/2); |
| 181 |
|
| 182 |
/* send the image to the daemon */ |
| 183 |
retval = g15_send(g15screen_fd,(char*)lcdbuffer,6880); |
| 184 |
|
| 185 |
printf("checking key status - press G1 to exit0,retval); |
| 186 |
|
| 187 |
while(1){ |
| 188 |
keystate = 0; |
| 189 |
memset(msgbuf,0,256); /* request key status |
| 190 |
*/ |
| 191 |
if(send(g15screen_fd, G15DAEMON_GET_KEYSTATE, 1, |
| 192 |
MSG_OOB)<1) |
| 193 |
printf("Error in send0); |
| 194 |
retval = recv(g15screen_fd, &keystate , |
| 195 |
sizeof(keystate),0); |
| 196 |
if(keystate) |
| 197 |
printf("keystate = %i0,keystate); |
| 198 |
|
| 199 |
/* quit if G1 is pressed */ |
| 200 |
if(keystate & G15_KEY_G1 ) /* See libg15.h for details on |
| 201 |
key values. */ |
| 202 |
break; |
| 203 |
|
| 204 |
memset(msgbuf,0,5); |
| 205 |
/* G2,G3 & G4 change LCD backlight */ |
| 206 |
if(keystate & G15_KEY_G2 ){ |
| 207 |
msgbuf[0]=G15_BRIGHTNESS_DARK|G15DAEMON_BACKLIGHT; |
| 208 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 209 |
} |
| 210 |
if(keystate & G15_KEY_G3 ){ |
| 211 |
msgbuf[0]=G15_BRIGHTNESS_MEDIUM|G15DAEMON_BACKLIGHT; |
| 212 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 213 |
} |
| 214 |
if(keystate & G15_KEY_G4 ){ |
| 215 |
msgbuf[0]=G15_BRIGHTNESS_BRIGHT|G15DAEMON_BACKLIGHT; |
| 216 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 217 |
} |
| 218 |
|
| 219 |
msgbuf[0]=G15DAEMON_IS_FOREGROUND; /* are we viewable? */ |
| 220 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 221 |
recv(g15screen_fd,msgbuf,1,0); |
| 222 |
if(msgbuf[0]) |
| 223 |
printf("Hey, we are in the foreground, Doc0); |
| 224 |
else |
| 225 |
printf("What dastardly wabbit put me in the back- |
| 226 |
ground?0); |
| 227 |
|
| 228 |
if(msgbuf[0]){ /* we've been backgrounded! */ |
| 229 |
sleep(2); /* remain in the background for a bit */ |
| 230 |
msgbuf[0] = G15DAEMON_SWITCH_PRIORITIES; /* switch pri- |
| 231 |
orities */ |
| 232 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 233 |
sleep(2); |
| 234 |
send(g15screen_fd,msgbuf,1,MSG_OOB); |
| 235 |
} |
| 236 |
|
| 237 |
usleep(5000); |
| 238 |
} |
| 239 |
g15_close_screen(g15screen_fd); |
| 240 |
return 0; } |
| 241 |
|
| 242 |
-- end cutting -- |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
G15Daemon 1.0 G15daemon Client Development() |