|
From: <mla...@us...> - 2006-11-04 12:54:55
|
Revision: 90
http://svn.sourceforge.net/g15daemon/?rev=90&view=rev
Author: mlampard
Date: 2006-11-04 04:54:43 -0800 (Sat, 04 Nov 2006)
Log Message:
-----------
add g15_send_cmd() to client library.
Modified Paths:
--------------
trunk/g15daemon/ChangeLog
trunk/g15daemon/Documentation/g15daemon_client_devel.3
trunk/g15daemon/g15daemon/lcdclient_test.c
trunk/g15daemon/g15daemon/main.c
trunk/g15daemon/libg15daemon_client/g15daemon_client.h
trunk/g15daemon/libg15daemon_client/g15daemon_net.c
Modified: trunk/g15daemon/ChangeLog
===================================================================
--- trunk/g15daemon/ChangeLog 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/ChangeLog 2006-11-04 12:54:43 UTC (rev 90)
@@ -77,3 +77,5 @@
- If compiled with libg15 1.1.0 or greater (or svn versions later than 3/11/06), the daemon
will now reset the keyboard to defaults on exit.
- make distcheck && make dist now work as expected.
+- libg15daemon_client is now slightly more useful
+- debian packaging now installs manpages
Modified: trunk/g15daemon/Documentation/g15daemon_client_devel.3
===================================================================
--- trunk/g15daemon/Documentation/g15daemon_client_devel.3 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/Documentation/g15daemon_client_devel.3 2006-11-04 12:54:43 UTC (rev 90)
@@ -1,8 +1,7 @@
.TH "G15daemon Client Development" "" "1.0" "G15Daemon" ""
.SH "SYNOPSIS"
-
#include <libg15.h>
-.br
+.br
#include <g15daemon_client.h>
link with
@@ -10,15 +9,16 @@
\-lg15daemon_client
int new_g15_screen(int screentype);
-.br
+.br
int g15_close_screen(int sock);
-.br
+.br
int g15_send(int sock, char *buf, unsigned int len);
-.br
+.br
int g15_recv(int sock, char *buf, unsigned int len);
+.br
+int g15_send_cmd (int sock, unsigned char command, unsigned char value);
.br
.SH "G15Daemon Server / Client communication"
-
G15Daemon uses INET sockets to talk to its clients, listening on localhost port 15550 for connection requests. Once connected, the server sends the text string "G15 daemon HELLO" to confirm to the client that it is a valid g15daemon process, creates a new screen, and waits for LCD buffers or commands to be sent from the client. Clients are able to create multiple screens simply by opening more socket connections to the server process. If the socket is closed or the client exits, all LCD buffers and the screen associated with that socket are automatically destroyed.
Clients wishing to display on the LCD must send entire screens in the format of their choice. Currently partial screen updates (icons etc) are not supported.
@@ -66,11 +66,16 @@
.SH "int g15_recv (int sock, char *buf, unsigned int len)"
-
A simple wrapper around recv() to ensure that all 'len' bytes of data are received from the daemon. It simply uses poll() to block until the entire message is received.
Returns 0 on success, \-1 if the recv failed due to timeout or socket error.
+.SH "int g15_send_cmd ( int sock, unsigned char command, unsigned char value)"
+Sends a command to the daemon (possible commands are listed below). Returns 0 or the return value of the command on success, \-1 on failure.
+
+See examples for usage.
+
+
.SH "G15Daemon Command Types"
.P
Commands and requests to the daemon are sent via OOB data packets. Changes to the backlight and mkey state will only affect the calling client. The following commands are supported as defined in g15daemon_client.h:
@@ -100,97 +105,111 @@
On reciept of this command, G15daemon will return a byte indicating if the user selected the client be foreground or background.
.SH "EXAMPLES"
-Below is a completely nonsensical client which demonstrates most of the commands.
+Below is a completely nonsensical client which (poorly) demonstrates the usage of most of the commands.
\-\-\- Cut here \-\-\-
.P
#include <stdio.h>
-.br
+.br
#include <stdlib.h>
-.br
+.br
#include <string.h>
-.br
+.br
#include <sys/types.h>
-.br
+.br
#include <sys/socket.h>
-.br
+.br
#include <errno.h>
-.br
+.br
#include <poll.h>
-.br
+.br
#include <g15daemon_client.h>
-.br
+.br
#include <libg15.h>
-.br
+.br
.P
+/* #define TEST_KEYHANDLER */
+
int main(int argc, char *argv[])
{
int g15screen_fd, retval;
char lcdbuffer[6880];
unsigned int keystate;
char msgbuf[256];
+ int foo = 0;
if((g15screen_fd = new_g15_screen(G15_PIXELBUF))<0){
printf("Sorry, cant connect to the G15daemon\n");
- return \-1;
+ return 5;
}else
- printf("Connected to g15daemon. sending image\\n");
- /* create a half black image */
- memset(lcdbuffer,0,6880);
- memset(lcdbuffer,1,6880/2);
+ printf("Connected to g15daemon. sending image\n");
- /* send the image to the daemon */
- retval = g15_send(g15screen_fd,(char*)lcdbuffer,6880);
+ if(argc<2)
+ retval = g15_send(g15screen_fd,(char*)logo_data,6880);
+ else {
+ memset(lcdbuffer,0,6880);
+ memset(lcdbuffer,1,6880/2);
+ retval = g15_send(g15screen_fd,(char*)lcdbuffer,6880);
+ }
printf("checking key status \- press G1 to exit\n",retval);
while(1){
keystate = 0;
- memset(msgbuf,0,256);
-
- /* request key status */
- if(send(g15screen_fd, G15DAEMON_GET_KEYSTATE, 1, MSG_OOB)<1)
- printf("Error in send\n");
- retval = recv(g15screen_fd, &keystate , sizeof(keystate),0);
+ int foo;
+
+ keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
if(keystate)
printf("keystate = %i\n",keystate);
- /* quit if G1 is pressed */
- if(keystate & G15_KEY_G1 ) /* See libg15.h for details on key values. */
+ if(keystate & G15_KEY_G1) //G1 key. See libg15.h for details on key values.
break;
- memset(msgbuf,0,5);
/* G2,G3 & G4 change LCD backlight */
- if(keystate & G15_KEY_G2 ){
- msgbuf[0]=G15_BRIGHTNESS_DARK|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G2){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK);
}
- if(keystate & G15_KEY_G3 ){
- msgbuf[0]=G15_BRIGHTNESS_MEDIUM|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G3){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM);
}
- if(keystate & G15_KEY_G4 ){
- msgbuf[0]=G15_BRIGHTNESS_BRIGHT|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G4){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT);
}
- msgbuf[0]=G15DAEMON_IS_FOREGROUND; /* are we viewable? */
- send(g15screen_fd,msgbuf,1,MSG_OOB);
- recv(g15screen_fd,msgbuf,1,0);
- if(msgbuf[0])
+ /* is this client in the foreground?? */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
+
+ if(retval)
printf("Hey, we are in the foreground, Doc\n");
else
printf("What dastardly wabbit put me in the background?\n");
+
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_USER_SELECTED, foo);
+ if(retval)
+ printf("You wanted me in the foreground, right Doc?\n");
+ else
+ printf("You dastardly wabbit !\n");
- if(msgbuf[0]){ /* we've been backgrounded! */
+ if(retval){ /* we've been backgrounded! */
sleep(2); /* remain in the background for a bit */
- msgbuf[0] = G15DAEMON_SWITCH_PRIORITIES; /* switch priorities */
- send(g15screen_fd,msgbuf,1,MSG_OOB);
- sleep(2);
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
+ sleep(2); /* switch to foreground */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
}
-
- usleep(5000);
+
+ usleep(500);
+#ifdef TEST_KEYHANDLER
+ /* ok.. request that all G&M keys are passed to us.. */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo);
+
+ while(1){
+ printf("waiting on keystate\n");
+ keystate=0;
+ retval = recv(g15screen_fd, &keystate , sizeof(keystate),0);
+ if(keystate)
+ printf("Recieved %i as keystate",keystate);
+ }
+#endif
}
g15_close_screen(g15screen_fd);
return 0;
Modified: trunk/g15daemon/g15daemon/lcdclient_test.c
===================================================================
--- trunk/g15daemon/g15daemon/lcdclient_test.c 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/g15daemon/lcdclient_test.c 2006-11-04 12:54:43 UTC (rev 90)
@@ -38,6 +38,7 @@
#include <libg15.h>
+/* #define TEST_KEYHANDLER */
int main(int argc, char *argv[])
{
@@ -45,6 +46,7 @@
char lcdbuffer[6880];
unsigned int keystate;
char msgbuf[256];
+ int foo = 0;
if((g15screen_fd = new_g15_screen(G15_PIXELBUF))<0){
printf("Sorry, cant connect to the G15daemon\n");
@@ -64,53 +66,53 @@
while(1){
keystate = 0;
- memset(msgbuf,0,256);
+ int foo;
- if(send(g15screen_fd, "k", 1, MSG_OOB)<1) /* request key status */
- printf("Error in send\n");
- retval = recv(g15screen_fd, &keystate , sizeof(keystate),0);
+ keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
if(keystate)
printf("keystate = %i\n",keystate);
- if(keystate & 1) //G1 key. See libg15.h for details on key values.
+ if(keystate & G15_KEY_G1) //G1 key. See libg15.h for details on key values.
break;
- memset(msgbuf,0,5);
/* G2,G3 & G4 change LCD backlight */
- if(keystate & 2){
- msgbuf[0]=G15_BRIGHTNESS_DARK|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G2){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK);
}
- if(keystate & 4){
- msgbuf[0]=G15_BRIGHTNESS_MEDIUM|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G3){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM);
}
- if(keystate & 8){
- msgbuf[0]=G15_BRIGHTNESS_BRIGHT|G15DAEMON_BACKLIGHT;
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ if(keystate & G15_KEY_G4){
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT);
}
- msgbuf[0]='v'; /* are we viewable? */
- send(g15screen_fd,msgbuf,1,MSG_OOB);
- recv(g15screen_fd,msgbuf,1,0);
- if(msgbuf[0])
+ /* is this client in the foreground?? */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
+
+ if(retval)
printf("Hey, we are in the foreground, Doc\n");
else
printf("What dastardly wabbit put me in the background?\n");
+
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_USER_SELECTED, foo);
+ if(retval)
+ printf("You wanted me in the foreground, right Doc?\n");
+ else
+ printf("You dastardly wabbit !\n");
- if(msgbuf[0]){ /* we've been backgrounded! */
+ if(retval){ /* we've been backgrounded! */
sleep(2); /* remain in the background for a bit */
- msgbuf[0]='p'; /* switch priorities */
- send(g15screen_fd,msgbuf,1,MSG_OOB);
- sleep(2);
- send(g15screen_fd,msgbuf,1,MSG_OOB);
-
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
+ sleep(2); /* switch to foreground */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
}
-// usleep(5000);
- msgbuf[0]=0x10; /* we demand all M&G Keys */
- send(g15screen_fd,msgbuf,1,MSG_OOB);
+ usleep(500);
+#ifdef TEST_KEYHANDLER
+ /* ok.. request that all G&M keys are passed to us.. */
+ retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo);
+
while(1){
printf("waiting on keystate\n");
keystate=0;
@@ -118,6 +120,8 @@
if(keystate)
printf("Recieved %i as keystate",keystate);
}
+#endif
+
}
g15_close_screen(g15screen_fd);
return 0;
Modified: trunk/g15daemon/g15daemon/main.c
===================================================================
--- trunk/g15daemon/g15daemon/main.c 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/g15daemon/main.c 2006-11-04 12:54:43 UTC (rev 90)
@@ -39,6 +39,10 @@
#include "g15daemon.h"
#include "logo.h"
+#ifndef LIBG15_VERSION
+#define LIBG15_VERSION 1000
+#endif
+
/* all threads will exit if leaving >0 */
int leaving = 0;
@@ -176,7 +180,9 @@
return retval < 0 ? 1 : 0;
}
if (!strncmp(daemonargs, "-v",2) || !strncmp(daemonargs, "--version",9)) {
+ float lg15ver = LIBG15_VERSION;
printf("G15Daemon version %s - %s\n",VERSION,daemon_pid_file_is_running() >= 0 ?"Loaded & Running":"Not Running");
+ printf("compiled with libg15 version %.3f\n\n",lg15ver/1000);
exit(0);
}
Modified: trunk/g15daemon/libg15daemon_client/g15daemon_client.h
===================================================================
--- trunk/g15daemon/libg15daemon_client/g15daemon_client.h 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/libg15daemon_client/g15daemon_client.h 2006-11-04 12:54:43 UTC (rev 90)
@@ -62,6 +62,9 @@
int g15_send(int sock, char *buf, unsigned int len);
int g15_recv(int sock, char *buf, unsigned int len);
+/* send a command (defined above) to the daemon. any replies from the daemon are returned */
+int g15_send_cmd (int sock, unsigned char command, unsigned char value);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/g15daemon/libg15daemon_client/g15daemon_net.c
===================================================================
--- trunk/g15daemon/libg15daemon_client/g15daemon_net.c 2006-11-04 10:54:11 UTC (rev 89)
+++ trunk/g15daemon/libg15daemon_client/g15daemon_net.c 2006-11-04 12:54:43 UTC (rev 90)
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <config.h>
+#include <libg15.h>
#include "g15daemon_client.h"
#define G15SERVER_PORT 15550
@@ -133,3 +134,69 @@
}
return total;
}
+
+int g15_send_cmd (int sock, unsigned char command, unsigned char value)
+{
+ int retval;
+ unsigned char packet[2];
+
+ switch (command) {
+ case G15DAEMON_KEY_HANDLER:
+ if (value > G15_LED_MR)
+ value = G15_LED_MR;
+ packet[0] = command | value;
+ retval = send( sock, packet, 1, MSG_OOB );
+ break;
+ case G15DAEMON_CONTRAST:
+ if (value > G15_CONTRAST_HIGH)
+ value = G15_CONTRAST_HIGH;
+ packet[0] = command | value;
+ retval = send( sock, packet, 1, MSG_OOB );
+ break;
+ case G15DAEMON_BACKLIGHT:
+ if (value > G15_BRIGHTNESS_BRIGHT)
+ value = G15_BRIGHTNESS_BRIGHT;
+ packet[0] = command | value;
+ retval = send( sock, packet, 1, MSG_OOB );
+ break;
+ case G15DAEMON_MKEYLEDS:
+ if (value > G15_LED_MR)
+ value = G15_LED_MR;
+ packet[0] = command | value;
+ retval = send( sock, packet, 1, MSG_OOB );
+ break;
+ case G15DAEMON_SWITCH_PRIORITIES:
+ packet[0] = command;
+ retval = send( sock, packet, 1, MSG_OOB );
+ break;
+ case G15DAEMON_GET_KEYSTATE:{
+ retval = 0;
+ packet[0] = command;
+ send( sock, packet, 1, MSG_OOB );
+ recv(sock, &retval, sizeof(retval),0);
+ break;
+ }
+ case G15DAEMON_IS_FOREGROUND:{
+ unsigned int foreground = 0;
+ packet[0] = command;
+ send( sock, packet, 1, MSG_OOB );
+ memset(packet,0,sizeof(packet));
+ recv( sock, packet, 1, 0);
+ retval = packet[0] - 48;
+ break;
+ }
+ case G15DAEMON_IS_USER_SELECTED:{
+ unsigned int chosen = 0;
+ packet[0] = command;
+ send( sock, packet, 1, MSG_OOB );
+ memset(packet,0,sizeof(packet));
+ retval = recv(sock, packet , 1,0);
+ retval = packet[0] - 48;
+ break;
+ }
+ default:
+ return -1;
+ }
+
+ return retval;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|