00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <time.h>
00037
00038 #include "pi-source.h"
00039 #include "pi-socket.h"
00040 #include "pi-datebook.h"
00041 #include "pi-dlp.h"
00042 #include "pi-header.h"
00043
00044
00045 #include "procrwil.h"
00046
00047 volatile int value=0;
00048
00049 char *Weekday[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
00050 char *Month[12] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
00051
00052
00053
00054
00055 void SuccessCallback(rwil_device dev)
00056 {
00057 value--;
00058 printf("Callback\n");
00059 }
00060
00061
00062 int main(int argc, char *argv[])
00063 {
00064 rwil_handle rwi_handle;
00065 rwil_device rwi_device;
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();
00080 rwi_device=rwil_create(rwi_handle,'A',1);
00081
00082
00083
00084 rwil_success_callback(SuccessCallback);
00085
00086
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
00186
00187
00188
00189
00190
00191
00192 value++;
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
00206
00207 {}
00208
00209
00210 rwil_destroy(rwi_device);
00211 rwil_shutdown(rwi_handle);
00212 return 0;
00213 }