Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

reminders.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "pi-source.h"
#include "pi-socket.h"
#include "pi-datebook.h"
#include "pi-dlp.h"
#include "pi-header.h"
#include "procrwil.h"

Go to the source code of this file.

Functions

void SuccessCallback (rwil_device dev)
int main (int argc, char *argv[])

Variables

volatile int value = 0
char * Weekday [7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
char * Month [12] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}


Function Documentation

int main int    argc,
char *    argv[]
 

Definition at line 62 of file reminders.c.

References rwil_create(), rwil_destroy(), rwil_handle, rwil_init(), rwil_interpolatebright(), rwil_off(), rwil_shutdown(), rwil_success_callback(), SuccessCallback(), and value.

00063 {
00064         rwil_handle rwi_handle; //a handle is necessary
00065         rwil_device rwi_device; //create the device to be used by rwil 
00066         struct tm start_time;
00067         struct pi_sockaddr addr;
00068         int db;
00069         int sd;
00070         int i;
00071         struct PilotUser U;
00072         int ret;
00073         unsigned char buffer[0xffff];
00074         char *progname = argv[0];
00075         char *device = argv[1];
00076 
00077         PalmHeader(progname);
00078         
00079         rwi_handle=rwil_init(); //we must initialize the handle
00080         rwi_device=rwil_create(rwi_handle,'A',1);
00081         //the device must be created and have the handle passed in
00082         //the A and 1 in this case is the location of the device we
00083         //are operating upon.  This is hardcoded for demo purposes
00084         rwil_success_callback(SuccessCallback); 
00085         //attach the callback function we created to rwil's built
00086         //in callback
00087 
00088         if (argc != 2) {
00089                 fprintf(stderr, "   Usage: %s %s\n\n", argv[0], TTYPrompt);
00090                 exit(2);
00091         }
00092         if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
00093                 perror("pi_socket");
00094                 exit(1);
00095         }
00096 
00097         addr.pi_family = PI_AF_SLP;
00098         strncpy(addr.pi_device, device, sizeof(addr.pi_device));
00099 
00100         ret = pi_bind(sd, (struct sockaddr *) &addr, sizeof(addr));
00101         if (ret == -1) {
00102                 fprintf(stderr, "\n   Unable to bind to port %s\n",
00103                         device);
00104                 perror("   pi_bind");
00105                 fprintf(stderr, "\n");
00106                 exit(1);
00107         }
00108 
00109         printf
00110             ("   Port: %s\n\n  Please press the HotSync button now...\n",
00111              device);
00112 
00113         ret = pi_listen(sd, 1);
00114         if (ret == -1) {
00115                 fprintf(stderr, "\n   Error listening on %s\n", device);
00116                 perror("   pi_listen");
00117                 fprintf(stderr, "\n");
00118                 exit(1);
00119         }
00120 
00121         sd = pi_accept(sd, 0, 0);
00122         if (sd == -1) {
00123                 fprintf(stderr, "\n   Error accepting data on %s\n",
00124                         device);
00125                 perror("   pi_accept");
00126                 fprintf(stderr, "\n");
00127                 exit(1);
00128         }
00129 
00130         fprintf(stderr, "Connected...\n");
00131 
00132         dlp_ReadUserInfo(sd, &U);
00133 
00134         dlp_OpenConduit(sd);
00135 
00136         if (dlp_OpenDB(sd, 0, 0x80 | 0x40, "DatebookDB", &db) < 0) {
00137                 puts("Unable to open DatebookDB");
00138                 dlp_AddSyncLogEntry(sd, "Unable to open DatebookDB.\n");
00139                 pi_close(sd);
00140                 exit(1);
00141         }
00142 
00143         for (i = 0;; i++) {
00144                 struct Appointment a;
00145                 int attr;
00146                 int j;
00147                 char delta[80];
00148                 char satisfy[256];
00149 
00150 
00151                 int len =
00152                     dlp_ReadRecordByIndex(sd, db, i, buffer, 0, 0, &attr,
00153                                           0);
00154               
00155                 if (len < 0)
00156                         break;
00157 
00158                 if ((attr & dlpRecAttrDeleted)
00159                     || (attr & dlpRecAttrArchived))
00160                         continue;
00161 
00162                 unpack_Appointment(&a, buffer, len);
00163                 strcpy(delta, "+7 ");
00164                 satisfy[0] = 0;
00165 
00166 
00167 
00168                 if(a.advance){
00169 
00170                 start_time=a.begin;
00171                
00172 
00173                 printf("Year    is: %d\n", start_time.tm_year);
00174                 printf("Month   is: %d\n", start_time.tm_mon);
00175                 printf("Day Mon is: %d\n", start_time.tm_mday);
00176                 printf("Hours   is: %d\n", start_time.tm_hour);
00177                 printf("Minutes is: %d\n", start_time.tm_min);
00178                 printf("Seconds is: %d\n", start_time.tm_sec);
00179                 printf("Alarm   is: %d\n", a.advance);
00180                 printf("Start Time: %d\n", mktime(&start_time)-a.advance*60);
00181                 printf("End Time  : %d\n", mktime(&start_time));
00182                 printf("Time      : %d\n", time(0));
00183                 value++;
00184                 rwil_interpolatebright(rwi_device, 0, 100, mktime(&start_time)-a.advance*60, mktime(&start_time), 5);
00185                 //the interpolatebright function queue's a group of actions that will cause the device's brightness (or power)
00186                 //to go from a designated start to end level over a period of time.  Here the device starts at 0 and will
00187                 //finish at 100% power.  The starting time is determined by the time of the appointment and alarm in the Palm device.
00188                 //The interpolate will begin when the alarm for the appointment goes off and will end when the appointment
00189                 //has arrived.  Here the alarm is in minutes, which is converted to seconds and subtracted from the actual appointment time
00190                 //Therefore an appointment at 3:30pm with an alarm 5 minutes before will cause the interpolate to start at 3:25 and finish
00191                 //at 3:30 with 100%. The number of steps used in the interpolation in this call is 5.
00192                 value++; //queue has increased
00193                 rwil_off(rwi_device, time(0)); 
00194                 }
00195                 
00196                 free_Appointment(&a);
00197 
00198         }
00199         dlp_CloseDB(sd, db);
00200 
00201         dlp_AddSyncLogEntry(sd, "Read datebook from Palm.\n");
00202 
00203         pi_close(sd);
00204         while(value) 
00205         //continue executing program while value is not zero (the queue is not empty)
00206         //if the program cannot end before rwil is finished and ready
00207           {}
00208        
00209         
00210         rwil_destroy(rwi_device);
00211         rwil_shutdown(rwi_handle);
00212         return 0;
00213 }

void SuccessCallback rwil_device    dev
 

Definition at line 55 of file reminders.c.

References value.

Referenced by main().

00056 {
00057         value--;
00058         printf("Callback\n");
00059 }


Variable Documentation

char* Month[12] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}
 

Definition at line 50 of file reminders.c.

volatile int value = 0
 

Definition at line 47 of file reminders.c.

Referenced by main(), rwil::MessageList::Query(), and SuccessCallback().

char* Weekday[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
 

Definition at line 49 of file reminders.c.


Generated on Tue Apr 9 13:53:08 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001