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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00104 #include <stdio.h>
00105 #include <string.h>
00106 #include <math.h>
00107
00108 #include <sys/types.h>
00109 #include <linux/limits.h>
00110 #include <usb.h>
00111
00112 #include <ctype.h>
00113 #include <time.h>
00114
00115 #include <fcntl.h>
00116 #include <unistd.h>
00117 #include <sys/stat.h>
00118
00119 #include "../config.h"
00120
00121 #include <locale.h>
00122
00123 #include <libintl.h>
00124 #define _(String) gettext (String)
00125
00126 #include "hp215.h"
00127
00128
00129 char monNameLong [12][30];
00130 char monNameShort[12][30];
00131
00132
00133 int DEBUG = 0;
00134 int TIMEOUT;
00135 int DEBUG_HEXDUMP = 0;
00136
00137
00138
00139
00140
00152 void dprint (char *msg)
00153 {
00154 if (DEBUG)
00155 {
00156 printf ("%s",msg);
00157 }
00158 }
00159
00160
00161
00162
00163
00164
00177 void
00178 hex_dump (unsigned char *msg, int size, char *text)
00179 {
00180 int i, i1, k, m, cnt=0, mm;
00181
00182 if (DEBUG_HEXDUMP == 0) return;
00183
00184
00185 printf ("\n");
00186 printf (_("Hexdump of message:"));
00187 printf ( " <%s> %d Bytes\n", text, size);
00188 printf ("----------------------------------------------------------------------\n");
00189
00190 printf ("%3d -%3d: ", 0, 7);
00191
00192
00193 k=0;
00194 for (i=0; i<size; i++)
00195 {
00196 printf ("0x%02X ", msg[i]);
00197 cnt++;
00198
00199 if (cnt%4 == 0) printf (" ");
00200
00201
00202 if (cnt == 8)
00203 {
00204 printf ("| ");
00205 m=1;
00206 for (i1=i-7; i1<=i; i1++)
00207 {
00208
00209 if (isgraph (msg[i1])) printf ("%c ", msg[i1]);
00210 else printf (". ");
00211
00212 if (m%4 == 0) printf (" ");
00213 k++; m++;
00214 }
00215 printf ("\n");
00216 cnt=0;
00217 if (i+1+8 > size) printf ("%3d -%3d: ", i+1, size-1);
00218 else printf ("%3d -%3d: ", i+1,i+8);
00219 }
00220 }
00221
00222
00223 mm=0;
00224 for (i=size-k; i<8; i++)
00225 {
00226 if (i%4 == 0 && mm==1) printf (" ");
00227 mm=1;
00228 printf (" ");
00229 }
00230 printf (" | ");
00231
00232
00233 mm=0;
00234 for (i=k; i<size; i++)
00235 {
00236 if (i%4 == 0 && mm==1) printf ("+");
00237 mm=1;
00238 if (isgraph (msg[i])) printf ("%c ", msg[i]);
00239 else printf (". ");
00240 }
00241
00242
00243 printf ("\n\n");
00244 }
00245
00246
00247
00248
00249
00311 int
00312 hp_gen_cmd (int cmd, int num, unsigned char *buffer)
00313 {
00314 int x4, x5, x6;
00315 int myx7, myx8, myx9, myx10;
00316
00317 buffer[0] = 0x02;
00318 buffer[1] = cmd;
00319 buffer[2] = 0x84;
00320 buffer[3] = 0x80;
00321 buffer[4] = ((num&0xf00)>>8) | 0x80;
00322 buffer[5] = ((num&0xf0 )>>4) | 0x80;
00323 buffer[6] = ((num&0xf ) ) | 0x80;
00324
00325 x4 = buffer[4]&0xf;
00326 x5 = buffer[5]&0xf;
00327 x6 = buffer[6]&0xf;
00328
00329
00330 switch (cmd)
00331 {
00332 case 0xb3:
00333 myx7=0xf,myx8=0x2,myx9=0xe,myx10=0x8;
00334 break;
00335
00336 case 0xb4:
00337 myx7=0x3,myx8=0xa,myx9=0xa,myx10=0x9;
00338 break;
00339
00340 case 0xc5:
00341 myx7=0x3,myx8=0xa,myx9=0x9,myx10=0x5;
00342 break;
00343
00344 case 0xb1:
00345 myx7=0x7,myx8=0x9,myx9=0xa,myx10=0x8;
00346 break;
00347
00348 default:
00349 fprintf (stderr, _("ERROR: Unknown command "));
00350 fprintf (stderr, "%x !\n", cmd);
00351 return FAIL;
00352 break;
00353 }
00354
00355
00356 myx7 ^= x6^((x5<<1)&0xf)^x5^((x4<<1)&0xf)^x4^x4>>2;
00357 myx8 ^= (x6>>3)^((x5<<1)&0xf)^(x5>>3)^x5^((x4<<2)&0xf)^((x4<<1)&0xf)^x4;
00358 myx9 ^= ((x6<<1)&0xf)^((x5>>3<<1)&0xf)^((x5<<1)&0xf)^x5^((x4<<1)&0xf)^x4;
00359 myx10 ^= x6^x5^(x5>>3);
00360
00361 buffer[7] = myx7 | 0x80;
00362 buffer[8] = myx8 | 0x80;
00363 buffer[9] = myx9 | 0x80;
00364 buffer[10] = myx10 | 0x80;
00365
00366 buffer[11] = 0x03;
00367
00368 return SUCCESS;
00369 }
00370
00371
00372
00373
00374
00385 int
00386 hp_new_file (CamFile **file)
00387 {
00388
00389 *file = malloc (sizeof (CamFile));
00390 if (*file == NULL)
00391 {
00392 fprintf (stderr, _("ERROR: Out of memory!\n"));
00393 fprintf (stderr, _(" In function hp_new_file (*file) \n"));
00394 return FAIL;
00395 }
00396
00397
00398 (*file)->data = NULL;
00399 (*file)->size = 0;
00400
00401 return SUCCESS;
00402 }
00403
00404
00405
00406
00407
00420 int
00421 hp_append_file (CamFile *file,
00422 const unsigned char *data, unsigned long int size)
00423 {
00424 char *d;
00425
00426
00427 if (file->size == 0)
00428 {
00429 file->data = malloc (sizeof(char)*size);
00430 if (file->data == 0)
00431 {
00432 fprintf (stderr, _("ERROR: Out of memory!\n"));
00433 fprintf (stderr, _(" In function hp_append_file (file->data)\n"));
00434 myExit (-1, 1);
00435 }
00436 }
00437
00438 else
00439 {
00440 d = realloc (file->data, sizeof(char)*(file->size+size));
00441 if (d == 0)
00442 {
00443 fprintf (stderr, _("ERROR: Out of memory!\n"));
00444 fprintf (stderr, _(" In function hp_append_file (d)\n"));
00445 myExit (-1, 1);
00446 }
00447
00448 file->data = d;
00449 }
00450
00451
00452 memcpy (&file->data[file->size], data, size);
00453
00454
00455 file->size += size;
00456
00457 return SUCCESS;
00458 }
00459
00460
00461
00462
00463
00474 int
00475 hp_send_ack (t_camera *cam, int ep)
00476 {
00477 int i;
00478 unsigned char byte = ACK;
00479
00480 dprint (_("-D- Sending ACK ... "));
00481
00482
00483 i = usb_bulk_write (cam->dh, ep, &byte, 1, TIMEOUT);
00484 if (i == 1)
00485 {
00486 dprint (_("OK!\n"));
00487 return SUCCESS;
00488 }
00489 else
00490 {
00491 dprint (_("FAILED!\n"));
00492 return FAIL;
00493 }
00494 }
00495
00496
00497
00498
00499
00510 int
00511 hp_rcv_ack (t_camera *cam, int ep)
00512 {
00513 int i;
00514 unsigned char byte = '\0';
00515
00516 dprint (_("-D- Receiving ACK ... "));
00517
00518
00519 i = usb_bulk_read (cam->dh, ep, &byte, 1, TIMEOUT);
00520 if (byte == ACK)
00521 {
00522 dprint (_("OK!\n"));
00523 return SUCCESS;
00524 }
00525 else
00526 {
00527 dprint (_("FAILED!\n"));
00528 return FAIL;
00529 }
00530 }
00531
00532
00533
00534
00535
00548 struct usb_device *find_device(int vendorID, int productID)
00549 {
00550 struct usb_bus *bus;
00551 struct usb_device *dev;
00552
00553
00554 for (bus=usb_busses; bus; bus=bus->next)
00555 {
00556
00557 for (dev = bus->devices; dev; dev=dev->next)
00558 {
00559
00560 if ((dev->descriptor.idVendor == vendorID) &&
00561 (dev->descriptor.idProduct == productID) )
00562 {
00563
00564 return (dev);
00565 }
00566 }
00567 }
00568
00569
00570
00571 return (NULL);
00572 }
00573
00574
00575
00576
00577
00588 int
00589 hp_open (t_camera *cam, int tryInitCamTwice)
00590 {
00591
00592 if (DEBUG) usb_set_debug(3);
00593
00594
00595 usb_init();
00596
00597
00598 usb_find_busses();
00599 usb_find_devices();
00600
00601
00602 dprint (_("-D- Looking for camera ... "));
00603 cam->device = find_device (HP_VENDOR_ID, HP215_ID);
00604 if (cam->device)
00605 {
00606 dprint (_("OK!\n"));
00607 }
00608 else
00609 {
00610 dprint (_("FAILED!\n"));
00611 return FAIL;
00612 }
00613
00614
00615
00616 dprint(_("-D- Opening camera ... "));
00617
00618 cam->dh = NULL;
00619 cam->dh = usb_open(cam->device);
00620 if (cam->dh)
00621 {
00622 dprint (_("OK!\n"));
00623 }
00624 else
00625 {
00626 dprint (_("FAILED!\n"));
00627 return FAIL;
00628 }
00629
00630
00631
00632
00633
00634
00635
00636 if (tryInitCamTwice == 1)
00637 {
00638
00639 dprint(_("-D- Resetting camera ... \n"));
00640 usb_reset(cam->dh);
00641 sleep(4);
00642
00643
00644 usb_find_devices();
00645
00646
00647 dprint(_("-D- Looking for camera again ... "));
00648 cam->device = find_device (HP_VENDOR_ID, HP215_ID);
00649 if (cam->device)
00650 {
00651 dprint (_("OK!\n"));
00652 }
00653 else
00654 {
00655 dprint (_("FAILED!\n"));
00656 return FAIL;
00657 }
00658
00659
00660 dprint(_("-D- Opening camera ... "));
00661
00662 cam->dh = NULL;
00663 cam->dh = usb_open(cam->device);
00664 if(cam->dh)
00665 {
00666 dprint (_("OK!\n"));
00667 }
00668 else
00669 {
00670 dprint (_("FAILED!\n"));
00671 return FAIL;
00672 }
00673 }
00674
00675
00676 return SUCCESS;
00677 }
00678
00679
00680
00681
00682
00701 int
00702 hp_init_sequence (t_camera *cam)
00703 {
00704 int i, cnt;
00705 unsigned char msg[10];
00706 unsigned char buffer[] = HP_CMD_INIT;
00707
00708
00709 for (i=0; i<10; i++) msg[i] = '\0';
00710
00711
00712 dprint(_("-D- Sending init sequence ... "));
00713 i = usb_bulk_write (cam->dh, 0x4, buffer, 8, TIMEOUT);
00714 if (i == 8)
00715 {
00716 dprint (_("OK!\n"));
00717 }
00718 else
00719 {
00720 dprint (_("FAILED!\n"));
00721 fprintf (stderr, _("ERROR: INIT FAILED, sent: "));
00722 fprintf (stderr, "%d bytes !\n", i);
00723 if (strstr (usb_strerror (), "error writing to bulk endpoint") != 0)
00724 {
00725 if (strstr (usb_strerror (), "Operation not permitted") != 0)
00726 {
00727 fprintf (stderr, _("ERROR: Writing to usb bulk endpoint: Operation not permitted\n"));
00728 fprintf (stderr, _(" Please try it again as superuser.\n"));
00729 fprintf (stderr, _(" If that works and you want this to work for a \n"));
00730 fprintf (stderr, _(" normal user, you must do the following:\n"));
00731 fprintf (stderr, _(" Edit as superuser the hotplug configuration file\n"));
00732 fprintf (stderr, _(" /etc/hotplug/usb/usbcam.usermap\n"));
00733 fprintf (stderr, _(" Add at the end of that file the output of\n"));
00734 fprintf (stderr, _(" the command.\n"));
00735 fprintf (stderr, _(" ./hp215 -puu\n"));
00736 fprintf (stderr, _(" Save the file and it should work as normal user!\n"));
00737 myExit (-1, 1);
00738 }
00739 else if (strstr (usb_strerror (), "Connection timed out") != 0)
00740 {
00741 fprintf (stderr, _("ERROR: Writing to usb bulk endpoint: Connection timed out\n"));
00742 fprintf (stderr, _(" There are some problems with the usb connection!\n"));
00743 fprintf (stderr, _(" To solve this:\n"));
00744 fprintf (stderr, _(" 1. Don't turn off the camera for this!\n"));
00745 fprintf (stderr, _(" 2. Pull off the usb cable from the camera.\n"));
00746 fprintf (stderr, _(" 3. Wait 3 seconds.\n"));
00747 fprintf (stderr, _(" 4. Insert the the usb cable to the camera again.\n"));
00748 fprintf (stderr, _(" 5. Wait 3 seconds -> \n"));
00749 fprintf (stderr, _(" If the kernel detects the camera, there should be a beep!\n"));
00750 fprintf (stderr, _(" 6. Try your commandline command again!\n"));
00751 myExit (-1, 1);
00752 }
00753
00754 }
00755
00756 return FAIL;
00757 }
00758
00759
00760 if (hp_rcv_ack (cam, 0x83))
00761 {
00762 return FAIL;
00763 }
00764
00765
00766
00767 dprint(_("-D- Expecting init sequence ... "));
00768
00769 i = usb_bulk_read (cam->dh, 0x83, msg, 10, TIMEOUT);
00770 if (i != 10)
00771 {
00772 dprint ("FAILED!\n");
00773 fprintf (stderr, _("ERROR: Init failed. %d bytes received instead of 10 !\n"), i);
00774
00775
00776 for (cnt=0; cnt<i; cnt++)
00777 {
00778 printf ("%x ", msg[cnt]);
00779 }
00780 printf ("\n");
00781 return FAIL;
00782 }
00783
00784 dprint (_("OK!\n"));
00785
00786
00787 if (hp_send_ack (cam, 0x4))
00788 {
00789 return FAIL;
00790 }
00791
00792
00793 return SUCCESS;
00794
00795 }
00796
00797
00798
00799
00800
00810 int
00811 hp_get_timeDate_cam (t_camera *cam)
00812 {
00813 int i;
00814 unsigned char msg[0x6b];
00815 unsigned char buffer[] = HP_CMD_DATETIME;
00816 t_date date;
00817
00818
00819
00820 for (i=0; i<0x6b; i++) msg[i] = '\0';
00821
00822
00823 dprint (_("-D- Sending date/time command ... "));
00824 i = usb_bulk_write (cam->dh, 0x04, buffer, 8, TIMEOUT);
00825 if (i != 8)
00826 {
00827 dprint ("FAILED!\n");
00828 fprintf (stderr, _("Get Date/Time Failed: %d bytes send instead of 8\n"), i);
00829
00830 return FAIL;
00831 }
00832 dprint ("OK!\n");
00833
00834
00835 if (hp_rcv_ack (cam, 0x83))
00836 {
00837 return FAIL;
00838 }
00839
00840
00841 dprint (_("-D- Receiving date/time msg ... "));
00842
00843
00844
00845 i = usb_bulk_read (cam->dh, 0x83, msg, 0x6b, TIMEOUT);
00846 if (i != 0x6b)
00847 {
00848 dprint (_("FAILED: Could not receive 0x6b bytes!\n"));
00849 return FAIL;
00850 }
00851
00852 hex_dump (msg, 0x6b, _("Receiving date/time msg"));
00853
00854
00855 if (msg[0]!=2)
00856 {
00857 dprint (_("FAILED: Start code missing!\n"));
00858 return FAIL;
00859 }
00860
00861 if (msg[0x6a]!=3)
00862 {
00863 dprint (_("FAILED: Start code missing!\n"));
00864 return FAIL;
00865 }
00866 dprint(_("OK!\n"));
00867
00868 if (hp_send_ack(cam, 0x04))
00869 {
00870 return FAIL;
00871 }
00872
00873
00874 hex_dump (msg, 0x6b, _("Receiving date/time msg ...") );
00875
00876
00877
00878 date.day = (msg[8]-48)*10 + (msg[9]-48);
00879 date.month = (msg[5]-48)*10 + (msg[6]-48) - 1;
00880 date.year = 2000 + (msg[11]-48)*10 + (msg[12]-48);
00881
00882 date.hour = (msg[14]-48)*10 + (msg[15]-48);
00883 date.min = (msg[17]-48)*10 + (msg[18]-48);
00884
00885 printf (_("Actual date and time of the camera: "));
00886 printf ("%02d.%s.%04d %02d:%02d \n",
00887 date.day, monNameShort[date.month], date.year, date.hour, date.min);
00888
00889 return SUCCESS;
00890 }
00891
00892
00893
00894
00895
00930 int
00931 hp_get_photo_album (t_camera *cam)
00932 {
00933 int i;
00934 unsigned char msg[0x32];
00935 unsigned char buffer[] = HP_CMD_GET_PHOTO_ALBUM;
00936
00937
00938 for (i=0; i<0x32; i++) msg[i] = '\0';
00939
00940
00941
00942 dprint(_("-D- Sending photo album request ... "));
00943 i = usb_bulk_write (cam->dh, 0x04, buffer, 16, TIMEOUT);
00944
00945
00946 if(i != 16)
00947 {
00948 dprint (_("FAILED!\n"));
00949 printf (_("%d bytes send instead of 16\n"), i);
00950 return FAIL;
00951 }
00952 dprint(_("OK!\n"));
00953
00954
00955 if (hp_rcv_ack(cam, 0x83))
00956 {
00957 return FAIL;
00958 }
00959
00960
00961 dprint(_("-D- Receiving photo album ... "));
00962 i = usb_bulk_read (cam->dh, 0x83, msg, 0x32, TIMEOUT);
00963
00964 if(i != 0x32)
00965 {
00966 dprint (_("FAILED: Could not receive 0x32 bytes!\n"));
00967 return FAIL;
00968 }
00969
00970
00971 if (msg[0] != 2)
00972 {
00973 dprint(_("FAILED: Start code missing!\n"));
00974 return FAIL;
00975 }
00976
00977
00978 if (msg[0x31] != 3)
00979 {
00980 dprint(_("FAILED: Stop code missing!\n"));
00981 return FAIL;
00982 }
00983 dprint (_("OK!\n"));
00984
00985
00986 if (hp_send_ack (cam, 0x04))
00987 {
00988 return FAIL;
00989 }
00990
00991 hex_dump (msg, 0x32, _("Receiving photo album ..."));
00992
00993
00994 cam->num_pics = 256*(msg[42]&0x7f) +
00995 16*(msg[43]&0x7f) +
00996 (msg[44]&0x7f);
00997
00998 printf (_("Number of pictures found: %d\n\n"), cam->num_pics);
00999
01000
01001 return SUCCESS;
01002 }
01003
01004
01005
01006
01007
01008
01023 int
01024 hp_get_previews (t_camera *cam, int picNumbers, int picNumber[MAX_PICS],
01025 char *subDir)
01026 {
01027 int i, cnt;
01028 unsigned char msg[0x01000];
01029 unsigned char buffer[12];
01030
01031
01032 for (i=0; i<0x1000; i++) msg[i] = '\0';
01033
01034
01035 for (cnt=0; cnt<picNumbers; cnt++)
01036 {
01037 printf (_("Requesting preview number: %d\n"), cnt);
01038
01039
01040 hp_gen_cmd (0xb3, picNumber[cnt], buffer);
01041
01042
01043
01044 dprint(_("-D- Sending preview request ... "));
01045 i = usb_bulk_write(cam->dh, 0x04, buffer, 0x0c, TIMEOUT);
01046 if (i!=0x0c)
01047 {
01048 fprintf (stderr, _("ERROR: Attempted write of 0x0c bytes, only sent: %d !\n"),
01049 i);
01050 dprint (_("FAILED: Could not write 0x0c bytes!\n"));
01051 return FAIL;
01052 }
01053 dprint (_("OK\n"));
01054
01055
01056 if (hp_rcv_ack(cam, 0x83))
01057 {
01058 return FAIL;
01059 }
01060
01061
01062 dprint(_("-D- Receiving preview header ... "));
01063 i = usb_bulk_read(cam->dh, 0x83, msg, 0x87, TIMEOUT);
01064
01065
01066 if (i!=0x87)
01067 {
01068 fprintf (stderr, _("ERROR: Expected 135 bytes - read only %d bytes, possibly corrupted, skipping preview!\n"), i);
01069 dprint (_("FAILED: Could not read 0x87 bytes!\n"));
01070
01071 hex_dump(msg, i, _("Receiving preview header ..."));
01072
01073
01074
01075
01076
01077
01078
01079
01080 if (hp_send_ack (cam, 0x04))
01081 {
01082 return FAIL;
01083 }
01084
01085
01086 continue;
01087 }
01088
01089
01090 if (msg[0]!=2)
01091 {
01092 dprint (_("FAILED: Start code missing!\n"));
01093 return FAIL;
01094 }
01095
01096
01097 if (msg[i-1]!=3)
01098 {
01099 dprint (_("FAILED: Stop code missing!\n"));
01100 return FAIL;
01101 }
01102 dprint (_("OK!\n"));
01103
01104
01105 if (hp_send_ack(cam, 0x04))
01106 {
01107 return FAIL;
01108 }
01109
01110
01111 dprint(_("-D- Receiving preview ...\n"));
01112
01113
01114
01115 while(1)
01116 {
01117 i = usb_bulk_read(cam->dh, 0x83, msg, 0x1000, TIMEOUT);
01118
01119
01120 if ((i==1) && (msg[0]==0x04))
01121 {
01122 dprint (_("Preview complete!\n"));
01123 break;
01124 }
01125
01126
01127 if (i==-1)
01128 {
01129 fprintf (stderr, _("Warning: Preview may be corrupted...\n"));
01130 break;
01131 }
01132
01133
01134 hp_append_file (cam->pic[cnt+1], msg, i);
01135 }
01136
01137 if (DEBUG)
01138 {
01139
01140 printf (_("%lu bytes receive \n"), (cam->pic[cnt+1])->size);
01141 }
01142
01143 }
01144
01145 printf ("\n");
01146
01147 return SUCCESS;
01148
01149 }
01150
01151
01152
01153
01154
01166 int
01167 hp_write_previews (t_camera *cam, int picNumbers, int picNumber[MAX_PICS])
01168 {
01169 int cnt;
01170 FILE *fp;
01171
01172
01173 for (cnt=0; cnt<picNumbers; cnt++)
01174 {
01175 if (cam->pic[cnt+1]==NULL)
01176 {
01177 continue;
01178 }
01179
01180
01181 fp = fopen( (cam->pic[cnt+1])->preview_name, "wb");
01182 if (fp == NULL)
01183 {
01184 fprintf (stderr, _("ERROR: Opening for write: %s\n"),
01185 (cam->pic[cnt+1])->preview_name);
01186 return FAIL;
01187 }
01188
01189
01190 if (fwrite ((cam->pic[cnt+1])->data, (size_t)sizeof(char), (size_t)(cam->pic[cnt+1])->size, fp)
01191 != (size_t)(cam->pic[cnt+1])->size)
01192 {
01193 fprintf (stderr, _("WARNING: Writing preview number: %d!\n"), cnt+1);
01194
01195 }
01196
01197
01198 fclose (fp);
01199 }
01200
01201 return SUCCESS;
01202 }
01203
01204
01205
01206
01207
01224 int
01225 hp_get_write_pics (t_camera *cam, int picNumbers, int picNumber[MAX_PICS],
01226 char *subDir)
01227 {
01228 FILE *fp;
01229 int i, cnt;
01230 char *date;
01231 unsigned char msg[0x1000];
01232 unsigned char buffer[12];
01233
01234
01235 for (i=0; i<0x1000; i++) msg[i] = '\0';
01236
01237
01238 for (cnt=0; cnt<picNumbers; cnt++)
01239 {
01240 printf (_("Requesting picture: %d\n"), picNumber[cnt]);
01241
01242
01243 hp_gen_cmd (0xb4, picNumber[cnt], buffer);
01244
01245 dprint (_("-D- Sending picture request ... "));
01246
01247 i = usb_bulk_write (cam->dh, 0x04, buffer, 0x0c, TIMEOUT);
01248 if (i != 0x0c)
01249 {
01250 dprint (_("FAILED: Could not write 0x0c bytes!\n"));
01251 fprintf (stderr, _("ERROR: Attempted write of 0x0c bytes, only sent: %d !\n"),
01252 i);
01253 return FAIL;
01254 }
01255 dprint ("OK!\n");
01256
01257
01258 if (hp_rcv_ack(cam, 0x83))
01259 {
01260 return FAIL;
01261 }
01262
01263 dprint(_("-D- Receiving picture header ... "));
01264 i = usb_bulk_read(cam->dh, 0x83, msg, 0x87, TIMEOUT);
01265 if(i!=0x87)
01266 {
01267 dprint (_("FAILED: Could not read 0x87 bytes!\n"));
01268 fprintf (stderr, _("ERROR: %d bytes only read, possibly corrupted pic, skipping!\n"), i);
01269 if (hp_send_ack(cam, 0x04))
01270 {
01271 return FAIL;
01272 }
01273 continue;
01274 }
01275
01276 if (msg[0] != 2)
01277 {
01278 dprint (_("FAILED: Start code missing!\n"));
01279 return FAIL;
01280 }
01281
01282 if (msg[0x86] != 3)
01283 {
01284 dprint (_("FAILED: Stop code missing!\n"));
01285 return FAIL;
01286 }
01287
01288 dprint (_("OK!\n"));
01289
01290 if (hp_send_ack (cam, 0x04))
01291 {
01292 return FAIL;
01293 }
01294
01295 dprint (_("-D- Receiving picture...\n"));
01296
01297 date = cam->pic[cnt+1]->date_time;
01298
01299
01300 if (date == 0)
01301 {
01302 printf (_("ERROR: Unknown date name!\n"));
01303 myExit (-1, 1);
01304 }
01305
01306
01307 fp = fopen ( cam->pic[cnt+1]->name, "wb");
01308 if (fp == NULL)
01309 {
01310 fprintf (stderr, _("ERROR: Opening file for write: %s!\n"), cam->pic[cnt+1]->name);
01311 return FAIL;
01312 }
01313
01314
01315 while (1)
01316 {
01317 i = usb_bulk_read (cam->dh, 0x83, msg, 0x1000, TIMEOUT);
01318 if ( (i==1) && (msg[0]==0x04) )
01319 {
01320 dprint (_("Picture complete!\n"));
01321 break;
01322 }
01323 else if (i==-1)
01324 {
01325 fprintf (stderr, _("WARNING: Picture may be corrupted...\n"));
01326 break;
01327 }
01328
01329
01330 if (fwrite (msg, (size_t)sizeof(char), (size_t)i, fp)
01331 != (size_t)(i))
01332 {
01333 fprintf (stderr, _("ERROR: Writing picture number %d!\n"), cnt);
01334 }
01335
01336 }
01337
01338
01339 fclose (fp);
01340
01341 }
01342
01343 return SUCCESS;
01344 }
01345
01346
01347
01348
01349
01363 int
01364 hp_delete_pics (t_camera *cam, int picAll, int picNumbers, int picNumber[MAX_PICS])
01365 {
01366 int back = SUCCESS;
01367
01368 if (picAll == 1)
01369 {
01370 back = hp_delete_all_pics (cam);
01371 }
01372 else
01373 {
01374 back = hp_delete_some_pics (cam, picNumbers, picNumber);
01375 }
01376
01377 return back;
01378 }
01379
01380
01381
01382
01383
01395 int
01396 hp_delete_some_pics (t_camera *cam, int picNumbers, int picNumber[MAX_PICS])
01397 {
01398 int i, cnt;
01399 unsigned char msg[0x1000];
01400 unsigned char buffer[12];
01401 int cam_numPics;
01402
01403
01404 cam_numPics = cam->num_pics;
01405
01406
01407 for (i=0; i<0x1000; i++) msg[i] = '\0';
01408
01409
01410 for (cnt=picNumbers-1; cnt>=0; cnt--)
01411 {
01412 printf (_("Deleting picture: %d\n"), picNumber[cnt]);
01413
01414
01415 hp_gen_cmd (0xb1, picNumber[cnt], buffer);
01416
01417 dprint (_("-D- Sending picture request ... "));
01418
01419
01420 i = usb_bulk_write (cam->dh, 0x04, buffer, 0x0c, TIMEOUT);
01421 if (i != 0x0c)
01422 {
01423 dprint (_("FAILED: Coulnd not write 0x0c bytes!\n"));
01424 fprintf (stderr, _("ERROR: Attempted write of 0x0c bytes, only sent: %d !\n"),
01425 i);
01426 return FAIL;
01427 }
01428 dprint (_("OK\n"));
01429
01430
01431 if (hp_rcv_ack(cam, 0x83))
01432 {
01433 return FAIL;
01434 }
01435
01436
01437
01438 i = usb_bulk_read (cam->dh, 0x83, msg, 10, TIMEOUT);
01439 if (i!=10)
01440 {
01441 dprint (_("Failed: Could notread 10 bytes!\n"));
01442 return FAIL;
01443 }
01444
01445 hex_dump (msg, i, _("Answer after delete one pic"));
01446
01447 if (hp_send_ack(cam, 0x04))
01448 {
01449 return FAIL;
01450 }
01451 }
01452
01453
01454 hp_get_photo_album (cam);
01455
01456 if (cam_numPics - cam->num_pics != picNumbers)
01457 {
01458 printf (_("Warning: Deleting some pics was not fully successfull !\n"));
01459 printf (_(" No. pics bevore deleting: %3d\n"), cam_numPics);
01460 printf (_(" No. pics after deleting: %3d\n"), cam->num_pics);
01461 printf (_(" Should delete : %3d\n\n"), picNumbers);
01462 printf (_(" Did delete only : %3d !\n"),
01463 cam_numPics - cam->num_pics);
01464 }
01465 return SUCCESS;
01466 }
01467
01468
01469
01470
01471
01472
01482 int
01483 hp_delete_all_pics(t_camera *cam)
01484 {
01485
01486 unsigned char buffer[] = HP_CMD_DELETE_PICS;
01487 unsigned char msg[10];
01488 int i;
01489
01490
01491 for (i=0; i<10; i++) msg[i] = '\0';
01492
01493
01494 i = usb_bulk_write (cam->dh, 0x04, buffer, 12, TIMEOUT);
01495 if (i!=12)
01496 {
01497 dprint (_("Failed: Could not write 12 bytes!\n"));
01498 fprintf (stderr, _("ERROR: Failed to delete pictures from camera!\n"));
01499 return FAIL;
01500 }
01501
01502
01503 if (hp_rcv_ack(cam, 0x83))
01504 {
01505 return FAIL;
01506 }
01507
01508
01509 i = usb_bulk_read (cam->dh, 0x83, msg, 10, TIMEOUT);
01510 if (i!=10)
01511 {
01512 dprint (_("Failed: Could not read 10 bytes!\n"));
01513 return FAIL;
01514 }
01515
01516 if (hp_send_ack(cam, 0x04))
01517 {
01518 return FAIL;
01519 }
01520
01521
01522
01523 hp_get_photo_album (cam);
01524
01525
01526 if (cam->num_pics != 0)
01527 {
01528 fprintf (stderr, _("ERROR: Deleting all pictures. Pictures remaining: %d !\n"),
01529 cam->num_pics);
01530 return (0);
01531 }
01532
01533 printf (_("Deleted all pictures from camera.\n"));
01534
01535 return SUCCESS;
01536 }
01537
01538
01539
01540
01541
01542
01562 void
01563 hp_create_html_page(t_camera *cam, int picNumbers, int picNumber[MAX_PICS],
01564 char *subDir, int prev, int pics, int subDirFull)
01565 {
01566 FILE *fp;
01567 int cnt;
01568 char *filename;
01569
01570 filename = (char *) malloc (sizeof (char) * (strlen (subDir)+256) );
01571 if (filename == NULL)
01572 {
01573 printf (_("ERROR: Out of memory!\n"));
01574 printf (_(" For filename in hp_create_html_page !\n"));
01575 myExit (-1, 1);
01576 }
01577 sprintf (filename, "%s/index.html", subDir);
01578
01579
01580 fp = fopen (filename, "w");
01581 if (fp == NULL)
01582 {
01583 fprintf (stderr, _("ERROR: Opening %s for write!\n"), filename);
01584 myExit (-1, 1);
01585 }
01586
01587
01588 fprintf (fp, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
01589 fprintf (fp, "\n");
01590 fprintf (fp, "<HTML>\n");
01591 fprintf (fp, " <HEAD>\n");
01592 fprintf (fp, " <TITLE>\n");
01593 fprintf (fp, " HP photosmart 215: Pictures\n");
01594 fprintf (fp, " </TITLE>\n");
01595 fprintf (fp, "\n");
01596 fprintf (fp, " <style type=\"text/css\">\n");
01597 fprintf (fp, " <!--\n");
01598 fprintf (fp, "\n");
01599 fprintf (fp, "tr.a { background-color : #999999; }\n");
01600 fprintf (fp, "td.a { vertical-align : top; \n");
01601 fprintf (fp, " text-align : center; }\n");
01602 fprintf (fp, " -->\n");
01603 fprintf (fp, " </style>\n");
01604 fprintf (fp, "\n");
01605 fprintf (fp, " </HEAD>\n");
01606 fprintf (fp, "\n");
01607 fprintf (fp, "\n");
01608 fprintf (fp, " <BODY BGCOLOR=\"#FFFFFF\">\n");
01609 fprintf (fp, "\n");
01610 fprintf (fp, "\n");
01611 fprintf (fp, " <CENTER>\n");
01612 fprintf (fp, "\n");
01613 fprintf (fp, " <table class=\"ueber\" width=\"100%%\" cellspacing=\"2\" border=\"1\" cellpadding=\"2\" bgcolor=\"#000000\" frame=\"border\">\n");
01614 fprintf (fp, " <tr class=\"a\" >\n");
01615
01616
01617 for (cnt=0; cnt<picNumbers; cnt++)
01618 {
01619 printf (_("Adding picture %d to webpage \n"), picNumber[cnt]);
01620
01621 fprintf (fp, " <td class=\"a\">\n");
01622 fprintf (fp, " <b>%d.</b>\n", picNumber[cnt]);
01623 if (pics == 1)
01624 fprintf (fp, " <a href=\"%s.html\">\n", cam->pic[cnt+1]->name_nsd);
01625 if (prev == 1)
01626 fprintf (fp, " <img src=\"%s\" alt=\"Picture: %d\" align=\"top\" border=\"0\">\n", cam->pic[cnt+1]->preview_name_nsd, picNumber[cnt]);
01627 else
01628 fprintf (fp, " %s \n", cam->pic[cnt+1]->preview_name_nsd);
01629 fprintf (fp, " <br>\n");
01630 if (pics == 1)
01631 fprintf (fp, " </a>\n");
01632 fprintf (fp, " %02d. %s. %04d %02d:%02d\n",
01633 (cam->pic[cnt+1])->date.day, monNameLong[(cam->pic[cnt+1])->date.month-1],
01634 (cam->pic[cnt+1])->date.year, (cam->pic[cnt+1])->date.hour, (cam->pic[cnt+1])->date.min);
01635 fprintf (fp, " </td>\n");
01636
01637 if ( (cnt+1) %4 == 0 )
01638 {
01639 fprintf (fp, " </tr>\n");
01640 fprintf (fp, "\n");
01641 fprintf (fp, " <tr class=\"a\" >\n");
01642 }
01643
01644 }
01645
01646
01647 fprintf (fp, " </tr>\n");
01648 fprintf (fp, " </table>\n");
01649 fprintf (fp, " </CENTER>\n");
01650
01651 fprintf (fp, " <BODY>\n");
01652 fprintf (fp, "</HTML>\n");
01653
01654
01655 fclose (fp);
01656
01657
01658
01659
01660
01661
01662
01663 if (pics == 1)
01664 {
01665
01666 for (cnt=0; cnt<picNumbers; cnt++)
01667 {
01668
01669 sprintf (filename, "%s/%s.html", subDir, cam->pic[cnt+1]->name_nsd);
01670
01671
01672 fp = fopen (filename, "w");
01673 if (fp == NULL)
01674 {
01675 fprintf (stderr, _("ERROR: Opening %s for write!\n"), filename);
01676 myExit (-1, 1);
01677 }
01678
01679
01680 fprintf (fp, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
01681 fprintf (fp, "\n");
01682 fprintf (fp, "<HTML>\n");
01683 fprintf (fp, " <HEAD>\n");
01684 fprintf (fp, " <TITLE>\n");
01685 fprintf (fp, " HP photosmart 215: Picture %d: %s\n", picNumber[cnt], cam->pic[cnt+1]->name_nsd);
01686 fprintf (fp, " </TITLE>\n");
01687 fprintf (fp, "\n");
01688 fprintf (fp, " <style type=\"text/css\">\n");
01689 fprintf (fp, " <!--\n");
01690 fprintf (fp, "\n");
01691 fprintf (fp, "tr.a { background-color : #999999; }\n");
01692 fprintf (fp, "td.a { vertical-align : top; \n");
01693 fprintf (fp, " text-align : center; }\n");
01694 fprintf (fp, " -->\n");
01695 fprintf (fp, " </style>\n");
01696 fprintf (fp, "\n");
01697 fprintf (fp, " </HEAD>\n");
01698 fprintf (fp, "\n");
01699 fprintf (fp, "\n");
01700 fprintf (fp, " <BODY BGCOLOR=\"#FFFFFF\">\n");
01701 fprintf (fp, "\n");
01702 fprintf (fp, "\n");
01703 fprintf (fp, " <CENTER>\n");
01704 fprintf (fp, "\n");
01705 if (picNumbers != cnt+1)
01706 {
01707 if (subDirFull == 0)
01708 fprintf (fp, " <a href=\"%s.html\">\n", cam->pic[cnt+1+1]->name_nsd);
01709 else
01710 fprintf (fp, " <a href=\"../%s.html\">\n", cam->pic[cnt+1+1]->name_nsd);
01711 }
01712 else
01713 {
01714 if (subDirFull == 0)
01715 fprintf (fp, " <a href=\"index.html\">\n");
01716 else
01717 fprintf (fp, " <a href=\"../index.html\">\n");
01718 }
01719
01720
01721 if (subDirFull == 0)
01722 fprintf (fp, " <img src=\"%s\" alt=\"Picture: %d\" align=\"top\" border=\"0\">\n", cam->pic[cnt+1]->name_nsd, picNumber[cnt]);
01723 else
01724 fprintf (fp, " <img src=\"../%s\" alt=\"Picture: %d\" align=\"top\" border=\"0\">\n", cam->pic[cnt+1]->name_nsd, picNumber[cnt]);
01725
01726 fprintf (fp, " </a>\n");
01727
01728 fprintf (fp, " </CENTER>\n");
01729
01730 fprintf (fp, " <BODY>\n");
01731 fprintf (fp, "</HTML>\n");
01732
01733
01734 fclose (fp);
01735 }
01736 }
01737
01738 }
01739
01740
01741
01742
01743
01744
01754 void
01755 read_ini (t_mode *mode)
01756 {
01757 FILE *fini;
01758 char buf[1024];
01759 int strlenBuf;
01760 char **argv, **mem_argv;
01761 int i, j, start, stop, num, brk, found;
01762 int found_dd, found_d;
01763 int lineCounter=0;
01764
01765
01766
01767 if (strlen (getenv("HOME")) > 1000)
01768 {
01769 printf (_("WARNING: Can not open ini file because of the long home path!\n"));
01770 printf (_(" Can only read home path with 1000 characters.\n"));
01771 printf (_(" Will continue without an ini-file.\n"));
01772
01773 return ;
01774 }
01775
01776
01777 sprintf (buf, "%s/.hp215", getenv("HOME"));
01778
01779
01780 fini = fopen (buf, "r");
01781
01782
01783 if (fini == NULL)
01784 {
01785
01786 return;
01787 }
01788
01789
01790
01791 while (! feof(fini) )
01792 {
01793
01794 fgets (buf, 1023, fini);
01795
01796 if (feof(fini) == 0)
01797 {
01798
01799 strlenBuf = strlen (buf);
01800
01801
01802 ini_delComment (buf);
01803
01804
01805 ini_getNoElements (&num, buf);
01806
01807
01808
01809 found_dd = 0;
01810 found_d = 0;
01811
01812
01813
01814 argv = (char **) malloc (sizeof (char *) * num);
01815 if (argv == 0)
01816 {
01817 printf (_("ERROR: Can not allocate memory for ini-file reading (argv)!\n"));
01818 myExit (-1, 0);
01819 }
01820
01821
01822 i=0; brk=0; num=0; found=0;start=0; stop=0;
01823 while (i<strlenBuf && brk == 0)
01824 {
01825
01826 if (buf[i] == '\"')
01827 {
01828 if (found_dd == 1)
01829 {
01830 found_dd = 0;
01831
01832
01833 for (j=i; j<strlenBuf; j++)
01834 {
01835 buf[j]=buf[j+1];
01836 }
01837 strlenBuf--;
01838 i--;
01839 }
01840 else found_dd = 1;
01841 }
01842
01843 else if (buf[i] == '\'')
01844 {
01845 if (found_d == 1)
01846 {
01847 found_d = 0;
01848
01849
01850 for (j=i; j<strlenBuf; j++)
01851 {
01852 buf[j]=buf[j+1];
01853 }
01854 strlenBuf--;
01855 i--;
01856 }
01857 else found_d = 1;
01858 }
01859
01860 else if (buf[i] != ' ')
01861 {
01862
01863 if (found == 0)
01864 {
01865 found = 1;
01866 start = i;
01867 }
01868 }
01869 else
01870 {
01871
01872 if ((found == 1) && (found_dd == 0) && (found_d == 0) )
01873 {
01874 found = 0;
01875 stop = i;
01876
01877
01878 argv[num] = (char *) malloc (sizeof (char) * (stop-start+2));
01879 if (argv[num] == 0)
01880 {
01881 printf (_("ERROR: Can not allocate memory for ini-file reading (argv[num]).\n"));
01882 myExit (-1, 0);
01883 }
01884
01885
01886 for (j=start; j<stop; j++)
01887 {
01888 argv[num][j-start] = buf[j];
01889 }
01890 argv[num][j-start] ='\0';
01891 num++;
01892 }
01893 }
01894 i++;
01895 }
01896
01897
01898
01899 if (num > 0)
01900 {
01901
01902 mem_argv = argv;
01903 acceptOptions (mode, &num, &argv, 0);
01904
01905
01906 for (i=0; i<num; i++)
01907 {
01908
01909 free (mem_argv[i]);
01910 }
01911
01912
01913 free (mem_argv);
01914 }
01915
01916 lineCounter++;
01917
01918
01919 }
01920 }
01921
01922 }
01923
01924
01925
01926
01927
01938 void
01939 ini_delComment (char *buf)
01940 {
01941 int i, brk, strlenBuf;
01942 int found_dd, found_d;
01943
01944
01945 found_dd = 0;
01946 found_d = 0;
01947
01948 strlenBuf=strlen (buf);
01949
01950
01951 i=0; brk=0;
01952 while (i<strlenBuf && brk == 0)
01953 {
01954
01955 if ( (buf[i] == '#') && (found_dd == 0) && (found_d == 0) )
01956 {
01957 buf[i] = '\0';
01958 brk = 1;
01959 }
01960
01961 else if (buf[i] == '\n')
01962 {
01963 buf[i] = ' ';
01964 buf[i+1] = '\0';
01965 brk = 1;
01966 }
01967
01968 else if (buf[i] == '\"')
01969 {
01970 if (found_dd == 1) found_dd = 0;
01971 else found_dd = 1;
01972 }
01973
01974 else if (buf[i] == '\'')
01975 {
01976 if (found_d == 1) found_d = 0;
01977 else found_d = 1;
01978 }
01979
01980 i++;
01981 }
01982
01983 }
01984
01985
01986
01987
01988
01989
02000 void
02001 ini_getNoElements (int *no, char *buf)
02002 {
02003 int i, brk, found;
02004 int found_dd, found_d;
02005
02006
02007 found_dd = 0;
02008 found_d = 0;
02009
02010
02011 i=0; brk=0; *no=0; found=0;
02012 while (i<(signed)strlen (buf) && brk == 0)
02013 {
02014
02015 if (buf[i] == '\"')
02016 {
02017 if (found_dd == 1) found_dd = 0;
02018 else found_dd = 1;
02019 }
02020
02021 else if (buf[i] == '\'')
02022 {
02023 if (found_d == 1) found_d = 0;
02024 else found_d = 1;
02025 }
02026 else if (buf[i] != ' ')
02027 {
02028
02029 if (found == 0)
02030 {
02031 found = 1;
02032 (*no)++;
02033 }
02034 }
02035 else
02036 {
02037 if ( (found == 1) && (found_dd == 0) && (found_d == 0) )
02038 {
02039 found = 0;
02040 }
02041 }
02042 i++;
02043 }
02044
02045 }
02046
02047
02048
02049
02050
02051
02061 void
02062 init_modeValues (t_mode *mode)
02063 {
02064
02065 TIMEOUT = 4000;
02066
02067 mode->main = 0;
02068 mode->dateCam = 0;
02069 mode->albm = 0;
02070 mode->datePics = 0;
02071 mode->prev = 0;
02072 mode->pics = 0;
02073 mode->delt = 0;
02074 mode->html = 0;
02075 mode->tmp_html = 1;
02076
02077 mode->tryInitCamTwice = 0;
02078 mode->forceDeletion = 0;
02079
02080 mode->picNumbers = -1;
02081 mode->picNumbersAll = 0;
02082
02083 mode->picNumbersRL = -1;
02084 mode->picNumbersRR = -1;
02085 mode->picNumbersRH = -1;
02086
02087 mode->picNumberRL[0] = 0;
02088 mode->picNumberRR[0] = 0;
02089 mode->picNumberRH[0] = 0;
02090
02091 mode->subDirPrev = 1;
02092 mode->subDirFull = 0;
02093
02094 strcpy (mode->dateStr, "%2._%d.%b.%Y_%H%M");
02095
02096 mode->dateInPic = 0;
02097
02098 #ifndef HAVE_CONVERT
02099 mode->dateInPic = 0;
02100 #endif
02101 #ifndef HAVE_IDENTIFY
02102 mode->dateInPic = 0;
02103 #endif
02104
02105 strcpy (mode->dateInPicStr, "%f. %B. %Y %H:%M");
02106
02107
02108 strcpy (monNameLong[0], _("January"));
02109 strcpy (monNameShort[0], _("Jan"));
02110
02111 strcpy (monNameLong[1], _("February"));
02112 strcpy (monNameShort[1], _("Feb"));
02113
02114 strcpy (monNameLong[2], _("March"));
02115 strcpy (monNameShort[2], _("Mar"));
02116
02117 strcpy (monNameLong[3], _("April"));
02118 strcpy (monNameShort[3], _("Apr"));
02119
02120 strcpy (monNameLong[4], _("May"));
02121 strcpy (monNameShort[4], _("May"));
02122
02123 strcpy (monNameLong[5], _("June"));
02124 strcpy (monNameShort[5], _("Jun"));
02125
02126 strcpy (monNameLong[6], _("July"));
02127 strcpy (monNameShort[6], _("Jul"));
02128
02129 strcpy (monNameLong[7], _("August"));
02130 strcpy (monNameShort[7], _("Aug"));
02131
02132 strcpy (monNameLong[8], _("September"));
02133 strcpy (monNameShort[8], _("Sep"));
02134
02135 strcpy (monNameLong[9], _("October"));
02136 strcpy (monNameShort[9], _("Oct"));
02137
02138 strcpy (monNameLong[10], _("November"));
02139 strcpy (monNameShort[10], _("Nov"));
02140
02141 strcpy (monNameLong[11], _("December"));
02142 strcpy (monNameShort[11], _("Dec"));
02143 }
02144
02145
02146
02147
02148
02149
02150
02151
02163 void
02164 read_cmd (int *argc, char ***argv, t_mode *mode)
02165 {
02166
02167
02168
02169 (*argv)++;
02170 (*argc)--;
02171
02172 if (*argc == 0)
02173 {
02174 usage ();
02175 myExit (-1, 0);
02176 }
02177
02178
02179 acceptOptions (mode, argc, argv, 1);
02180
02181
02182
02183 if (mode->main == 0)
02184 {
02185 fprintf (stderr, _("ERROR: No mode was selected!\n"));
02186 fprintf (stderr, _(" Modes are: -gdc, -gn, gdp, -gt, -gp, -dp or -a \n"));
02187 fprintf (stderr, _(" Look at ./hp215 --help\n"));
02188 myExit (-1, 0);
02189 }
02190
02191
02192
02193 if ( (mode->tmp_html == 1) && (mode->html == 1) ) mode->html = 1;
02194 else mode->html = 0;
02195 }
02196
02197
02198
02199
02200
02201
02216 void
02217 acceptOptions (t_mode *mode, int *argc, char **argv[], int callmode)
02218 {
02219 int founded;
02220
02221
02222
02223 do
02224 {
02225
02226 founded = 0;
02227
02228
02229
02230
02231 if ((strcmp (**argv, "--debug") == 0) || (strcmp (**argv, "-d") == 0))
02232 {
02233 DEBUG = 1;
02234 (*argv)++;
02235 (*argc)--;
02236 founded = 1;
02237 }
02238
02239 else if ((strcmp (**argv, "--debug-hexdump") == 0) || (strcmp (**argv, "-dh") == 0))
02240 {
02241 DEBUG_HEXDUMP = 1;
02242 (*argv)++;
02243 (*argc)--;
02244 founded = 1;
02245 }
02246
02247 else if (strcmp (**argv, "-ds") == 0)
02248 {
02249 (*argv)++;
02250 (*argc)--;
02251
02252 if (*argc < 1)
02253 {
02254 printf (_("ERROR: Too few argument for -ds !\n"));
02255 myExit (-1, 0);
02256 }
02257
02258 if (strlen (**argv) >= MAX_DS_STRLEN)
02259 {
02260 printf (_("ERROR: To long -ds format string !\n"));
02261 myExit (-1, 0);
02262 }
02263
02264 strcpy (mode->dateStr, **argv);
02265 (*argv)++;
02266 (*argc)--;
02267
02268 founded = 1;
02269 }
02270 #ifdef HAVE_CONVERT
02271 #ifdef HAVE_IDENTIFY
02272
02273 else if (strcmp (**argv, "-at") == 0)
02274 {
02275 (*argv)++;
02276 (*argc)--;
02277
02278 mode->dateInPic = 1;
02279
02280 founded = 1;
02281 }
02282
02283 else if (strcmp (**argv, "-atds") == 0)
02284 {
02285 (*argv)++;
02286 (*argc)--;
02287
02288 if (*argc < 1)
02289 {
02290 printf (_("ERROR: Too few argument for -atds !\n"));
02291 myExit (-1, 0);
02292 }
02293
02294 if (strlen (**argv) >= MAX_DS_STRLEN)
02295 {
02296 printf (_("ERROR: To long -atds format string !\n"));
02297 myExit (-1, 0);
02298 }
02299
02300
02301
02302 strcpy (mode->dateInPicStr, **argv);
02303 (*argv)++;
02304 (*argc)--;
02305
02306 founded = 1;
02307 }
02308 #endif
02309 #endif
02310
02311 else if ( (strcmp (**argv, "-to") == 0) || (strcmp (**argv, "--timeout") == 0) )
02312 {
02313 (*argv)++;
02314 (*argc)--;
02315
02316 if (*argc < 1)
02317 {
02318 fprintf (stderr, _("ERROR: Too few argument for --timeout !\n"));
02319 myExit (-1, 0);
02320 }
02321
02322 TIMEOUT = atoi (**argv);
02323
02324 printf (_("Found option: TIMEOUT: %d\n"), TIMEOUT);
02325 (*argv)++;
02326 (*argc)--;
02327
02328 printf ("%d\n", *argc);
02329 founded = 1;
02330 }
02331
02332 else if (strcmp (**argv, "-wp") == 0)
02333 {
02334 (*argv)++;
02335 (*argc)--;
02336
02337 mode->tmp_html = 1;
02338
02339 founded = 1;
02340 }
02341
02342 else if (strcmp (**argv, "-nwp") == 0)
02343 {
02344 (*argv)++;
02345 (*argc)--;
02346
02347 mode->tmp_html = 0;
02348
02349 founded = 1;
02350 }
02351
02352 else if ( (strcmp (**argv, "-2") == 0) || (strcmp (**argv, "--open-cam-twice") == 0) )
02353 {
02354 (*argv)++;
02355 (*argc)--;
02356
02357 mode->tryInitCamTwice = 1;
02358
02359 founded = 1;
02360 }
02361
02362 else if ( (strcmp (**argv, "-f") == 0) || (strcmp (**argv, "--force-deletion") == 0) )
02363 {
02364 (*argv)++;
02365 (*argc)--;
02366
02367 mode->forceDeletion = 1;
02368
02369 founded = 1;
02370 }
02371
02372 else if (strcmp (**argv, "-sdp") == 0)
02373 {
02374 (*argv)++;
02375 (*argc)--;
02376
02377 mode->subDirPrev = 1;
02378
02379 founded = 1;
02380 }
02381
02382 else if (strcmp (**argv, "-nsdp") == 0)
02383 {
02384 (*argv)++;
02385 (*argc)--;
02386
02387 mode->subDirPrev = 0;
02388
02389 founded = 1;
02390 }
02391
02392 else if (strcmp (**argv, "-sdf") == 0)
02393 {
02394 (*argv)++;
02395 (*argc)--;
02396
02397 mode->subDirFull = 1;
02398
02399 founded = 1;
02400 }
02401
02402 else if (strcmp (**argv, "-nsdf") == 0)
02403 {
02404 (*argv)++;
02405 (*argc)--;
02406
02407 mode->subDirFull = 0;
02408
02409 founded = 1;
02410 }
02411
02412
02413
02414
02415 if ((callmode == 1) && (founded != 1))
02416 {
02417
02418 if ( (strcmp (**argv, "--version") == 0) || (strcmp (**argv, "-v") == 0) )
02419 {
02420 printf ("\n");
02421 printf (_(" Programm hp215. Version %s\n"), VERSION);
02422 printf ("\n");
02423 printf (_(" 1. Actual maintainer : Enno Bartels <ennobartels@t-online.de>\n"));
02424 printf (_(" (automake/-conf, doxygen, options, single \n"));
02425 printf (_(" picture mode, single picture deleting etc.) in 2002/2003\n"));
02426 printf (_(" 2. Orginal author : Jason Surprise <thesurprises1@attbi.com> in 2002.\n"));
02427 printf (_(" 3. Checksum additions: Roberto Ragusa <r.ragusa@libero.it> (checksum) in 2002/2003\n"));
02428
02429 printf (" \n\n");
02430 (*argv)++;
02431 (*argc)--;
02432 founded = 1;
02433 myExit (0, 0);
02434 }
02435
02436 else if ((strcmp (**argv, "--help") == 0) || (strcmp (**argv, "-h") == 0))
02437 {
02438 usage ();
02439 (*argv)++;
02440 (*argc)--;
02441 founded = 1;
02442 myExit (0, 0);
02443 }
02444
02445 else if (strcmp (**argv, "-tds") == 0)
02446 {
02447 mode->main = TSTDAT_MODE;
02448 (*argv)++;
02449 (*argc)--;
02450
02451 founded = 1;
02452 }
02453
02454 else if ((strcmp (**argv, "--print_cmd") == 0) || (strcmp (**argv, "-pc") == 0))
02455 {
02456 mode->main = PRTCMD_MODE;
02457 (*argv)++;
02458 (*argc)--;
02459
02460 if (*argc < 2)
02461 {
02462 fprintf (stderr, _("ERROR: Too few argument for --print_cmd !\n"));
02463 myExit (-1, 0);
02464 }
02465
02466 mode->printCmd_cmd = atoi (**argv);
02467 (*argv)++;
02468 (*argc)--;
02469
02470 mode->printCmd_picNo = atoi (**argv);
02471 (*argv)++;
02472 (*argc)--;
02473 printf (_("Option print_cmd pic:<%d=%xx> cmd:<%d=%xx>\n"), mode->printCmd_picNo, mode->printCmd_picNo, mode->printCmd_cmd, mode->printCmd_cmd);
02474 founded = 1;
02475 }
02476
02477 else if (strcmp (**argv, "-gdc") == 0)
02478 {
02479 (*argv)++;
02480 (*argc)--;
02481
02482 mode->main = NORMAL_MODE;
02483 mode->dateCam = 1;
02484
02485 founded = 1;
02486 }
02487
02488 else if (strcmp (**argv, "-gn") == 0)
02489 {
02490 (*argv)++;
02491 (*argc)--;
02492
02493 mode->main = NORMAL_MODE;
02494 mode->albm = 1;
02495
02496 founded = 1;
02497 }
02498
02499 else if (strcmp (**argv, "-no") == 0)
02500 {
02501 (*argv)++;
02502 (*argc)--;
02503
02504 if (*argc < 1)
02505 {
02506 fprintf (stderr, _("ERROR: Too few argument for -no !\n"));
02507 myExit (-1, 0);
02508 }
02509
02510
02511 read_number (&mode->picNumbers, mode->picNumber, **argv);
02512
02513 (*argv)++;
02514 (*argc)--;
02515 founded = 1;
02516 }
02517 #ifdef HAVE_CONVERT
02518
02519 else if (strcmp (**argv, "-rl") == 0)
02520 {
02521 (*argv)++;
02522 (*argc)--;
02523
02524 if (*argc < 1)
02525 {
02526 fprintf (stderr, _("ERROR: Too few argument for -rl !\n"));
02527 myExit (-1, 0);
02528 }
02529
02530 read_number (&mode->picNumbersRL, mode->picNumberRL, **argv);
02531
02532 (*argv)++;
02533 (*argc)--;
02534 founded = 1;
02535 }
02536
02537 else if (strcmp (**argv, "-rr") == 0)
02538 {
02539 (*argv)++;
02540 (*argc)--;
02541
02542 if (*argc < 1)
02543 {
02544 fprintf (stderr, _("ERROR: Too few argument for -rr !\n"));
02545 myExit (-1, 0);
02546 }
02547
02548 read_number (&mode->picNumbersRR, mode->picNumberRR, **argv);
02549
02550 (*argv)++;
02551 (*argc)--;
02552 founded = 1;
02553 }
02554
02555 else if (strcmp (**argv, "-rh") == 0)
02556 {
02557 (*argv)++;
02558 (*argc)--;
02559
02560 if (*argc < 1)
02561 {
02562 fprintf (stderr, _("ERROR: Too few argument for -rh !\n"));
02563 myExit (-1, 0);
02564 }
02565
02566 read_number (&mode->picNumbersRH, mode->picNumberRH, **argv);
02567
02568 (*argv)++;
02569 (*argc)--;
02570 founded = 1;
02571 }
02572 #endif
02573
02574 else if (strcmp (**argv, "-gdp") == 0)
02575 {
02576 (*argv)++;
02577 (*argc)--;
02578
02579 mode->main = NORMAL_MODE;
02580 mode->albm = 1;
02581 mode->datePics = 1;
02582 mode->html = 1;
02583
02584 printf (_("Found option: Get date/time of the pictures\n"));
02585
02586 founded = 1;
02587 }
02588
02589 else if (strcmp (**argv, "-gt") == 0)
02590 {
02591 (*argv)++;
02592 (*argc)--;
02593
02594 mode->main = NORMAL_MODE;
02595 mode->albm = 1;
02596 mode->prev = 1;
02597 mode->html = 1;
02598
02599 printf (_("Found option: Get all thumbs\n"));
02600
02601 founded = 1;
02602 }
02603
02604 else if (strcmp (**argv, "-gp") == 0)
02605 {
02606 (*argv)++;
02607 (*argc)--;
02608
02609 mode->main = NORMAL_MODE;
02610 mode->pics = 1;
02611 mode->albm = 1;
02612 mode->html = 1;
02613
02614 printf (_("Found option: Get pictures\n"));
02615
02616 founded = 1;
02617 }
02618
02619 else if (strcmp (**argv, "-dp") == 0)
02620 {
02621 (*argv)++;
02622 (*argc)--;
02623
02624 mode->main = NORMAL_MODE;
02625 mode->albm = 1;
02626 mode->delt = 1;
02627
02628 printf (_("Found option: Delete pictures\n"));
02629
02630 founded = 1;
02631 }
02632
02633 else if (strcmp (**argv, "-a") == 0)
02634 {
02635 (*argv)++;
02636 (*argc)--;
02637
02638 mode->main = NORMAL_MODE;
02639 mode->dateCam = 1;
02640 mode->albm = 1;
02641 mode->datePics= 1;
02642 mode->prev = 1;
02643 mode->pics = 1;
02644 mode->delt = 1;
02645 mode->html = 1;
02646
02647 printf (_("Found option: Do all steps\n"));
02648
02649 founded = 1;
02650 }
02651
02652 else if ((strcmp (**argv, "-puu") == 0) || (strcmp (**argv, "--print-usb-usermap") == 0))
02653 {
02654 (*argv)++;
02655 (*argc)--;
02656
02657 printf ("# Hewlett Packard Photosmart 215 digicam\n");
02658 printf ("usbcam 0x0003 0x03f0 0x6202 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000\n");
02659
02660 printf ("\n");
02661 printf (_("ATTENTION: On a SuSE 8.2 distro please use the following 2 lines :\n\n"));
02662 printf ("# Hewlett Packard Photosmart 215 digicam\n");
02663 printf ("desktopdev 0x0003 0x03f0 0x6202 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000\n");
02664
02665 myExit (0, 0);
02666 founded = 1;
02667 }
02668 }
02669
02670
02671
02672
02673 if (founded == 0)
02674 {
02675 if (callmode == 0)
02676 {
02677 printf (_("Unknown option in the ini file ~/.hp215 : "));
02678 }
02679 else
02680 {
02681 printf (_("Unknown option on the commandline : "));
02682 }
02683 printf ("%s\n\n", **argv);
02684 printf (_("To see all possible options use \n"));
02685 printf (_("hp215 --help\n"));
02686 myExit (-1, 0);
02687 }
02688 }
02689 while (*argc > 0 );
02690
02691
02692 }
02693
02694
02695
02696
02697
02698
02708 void
02709 gen_subDirName (char subdir[100])
02710 {
02711 struct tm *timeM;
02712 time_t timep;
02713
02714
02715
02716 time (&timep);
02717 timeM = gmtime (&timep);
02718
02719
02720 sprintf (subdir, "%02d.%s.%04d_%02d-%02d-%02d",
02721 timeM->tm_mday, monNameShort[timeM->tm_mon], timeM->tm_year+1900,
02722 timeM->tm_hour, timeM->tm_min, timeM->tm_sec);
02723
02724 }
02725
02726
02727
02728
02729
02739 void
02740 gen_subDir (char subdir[100])
02741 {
02742 int back;
02743 mode_t subDirMode = 0755;
02744
02745
02746 back = mkdir (subdir, subDirMode);
02747 if (back != 0)
02748 {
02749 fprintf (stderr, _("ERROR: Cannot create subdir <%s> !\n"), subdir);
02750 myExit (-1, 1);
02751 }
02752
02753
02754 printf (_("Subdir name in gen_subDir: >%s< created.\n"), subdir);
02755
02756
02757 }
02758
02759
02760
02761
02762
02763
02782 int
02783 hp_get_timeDate_pics (t_camera *cam, int picNumbers, int picNumber[MAX_PICS],
02784 char *subDir, char *dateStr, int subDirPrev, int subDirFull)
02785 {
02786 int cnt, i;
02787 char picStr[MAX_DS_STRLEN];
02788 unsigned char msg[0x01000];
02789 unsigned char buffer[12];
02790 int offset =13;
02791
02792
02793 for (i=0; i<0x1000; i++) msg[i] = '\0';
02794
02795
02796 for (cnt=0; cnt<picNumbers; cnt++)
02797 {
02798
02799
02800 cam->pic[cnt+1]=NULL;
02801
02802
02803 hp_new_file(&cam->pic[cnt+1]);
02804
02805
02806 if (DEBUG )
02807 {
02808 printf (_("-D- Get date/time of picture %d\n"), picNumber[cnt]);
02809 }
02810
02811
02812 dprint (_("Sending date/time request ... "));
02813
02814
02815 hp_gen_cmd (0xc5, picNumber[cnt], buffer);
02816
02817
02818 i = usb_bulk_write (cam->dh, 0x04, buffer, 0x0c, TIMEOUT);
02819 if (i != 0x0c)
02820 {
02821 dprint (_("FAILED: Could not write 0x0c bytes!\n"));
02822 fprintf (stderr, _("ERROR: Attempted write of 0x0c bytes, only sent: %d !\n"), i);
02823 return FAIL;
02824 }
02825 dprint("OK\n");
02826
02827
02828 if (hp_rcv_ack (cam, 0x83))
02829 {
02830 return FAIL;
02831 }
02832
02833
02834 dprint (_("Receiving date/time ... "));
02835 i = usb_bulk_read (cam->dh, 0x83, msg, 0x3e, TIMEOUT);
02836 if (i != 0x3e)
02837 {
02838 dprint (_("FAILED: Could not read 0x3e bytes!\n"));
02839 fprintf (stderr, _("ERROR: Read only %d bytes.\n"), i);
02840 return FAIL;
02841 }
02842
02843
02844
02845 if (msg[0] != 0x02)
02846 {
02847 fprintf (stderr, _("ERROR: Start or stop code missing!\n"));
02848 return FAIL;
02849 }
02850
02851
02852 if (msg[0x3d] != 0x03)
02853 {
02854 fprintf (stderr, _("ERROR: Start or stop code missing!\n"));
02855 return FAIL;
02856 }
02857 dprint(_("OK!\n"));
02858
02859
02860
02861 strcpy ((cam->pic[cnt+1])->date_time, &msg[0x0d]);
02862
02863 hex_dump (msg, 20, _("Receiving date/time ..."));
02864
02865
02866 (cam->pic[cnt+1])->date.day = (msg[3+offset]-48)*10 + (msg[4+offset]-48);
02867 (cam->pic[cnt+1])->date.month = (msg[0+offset]-48)*10 + (msg[1+offset]-48);
02868 (cam->pic[cnt+1])->date.year = 2000 + (msg[6+offset]-48)*10 + (msg[7+offset]-48);
02869
02870 (cam->pic[cnt+1])->date.hour = (msg[ 9+offset]-48)*10 + (msg[10+offset]-48);
02871 (cam->pic[cnt+1])->date.min = (msg[12+offset]-48)*10 + (msg[13+offset]-48);
02872
02873 printf (_("Get date of picture %2d: %02d.%s. %04d %02d:%02d \n"),
02874 picNumber[cnt], (cam->pic[cnt+1])->date.day, monNameShort[(cam->pic[cnt+1])->date.month-1],
02875 (cam->pic[cnt+1])->date.year, (cam->pic[cnt+1])->date.hour, (cam->pic[cnt+1])->date.min);
02876
02877 hex_dump (msg, 0x3e, _("Receiving date/time ... "));
02878
02879
02880
02881 if (hp_send_ack(cam, 0x04))
02882 {
02883 return FAIL;
02884 }
02885
02886
02887
02888 getDateStr (dateStr, picNumbers, picNumber[cnt], (cam->pic[cnt+1])->date,
02889 picStr, MUST_USE_A_PICTURE_NUMBER);
02890
02891 if (subDirFull == 1)
02892 {
02893
02894 sprintf ( (cam->pic[cnt+1])->name,
02895 "%s/%s/%s.jpg", subDir, FULLSIZE_DIR, picStr);
02896
02897
02898 sprintf ( (cam->pic[cnt+1])->name_nsd,
02899 "%s/%s.jpg", FULLSIZE_DIR, picStr);
02900 }
02901 else
02902 {
02903
02904 sprintf ( (cam->pic[cnt+1])->name,
02905 "%s/%s.jpg", subDir, picStr);
02906
02907
02908 sprintf ( (cam->pic[cnt+1])->name_nsd,
02909 "%s.jpg", picStr);
02910 }
02911
02912
02913 if (subDirPrev == 1)
02914 {
02915
02916 sprintf ( (cam->pic[cnt+1])->preview_name,
02917 "%s/%s/%s_thumb.jpg", subDir, PREVIEW_DIR, picStr);
02918
02919
02920 sprintf ( (cam->pic[cnt+1])->preview_name_nsd,
02921 "%s/%s_thumb.jpg", PREVIEW_DIR, picStr);
02922 }
02923 else
02924 {
02925
02926 sprintf ( (cam->pic[cnt+1])->preview_name,
02927 "%s/%s_thumb.jpg", subDir, picStr);
02928
02929
02930 sprintf ( (cam->pic[cnt+1])->preview_name_nsd,
02931 "%s_thumb.jpg", picStr);
02932 }
02933
02934
02935
02936
02937
02938
02939 if (DEBUG )
02940 {
02941 printf (_("-D- cam pic name: %s\n"), (cam->pic[cnt+1])->name);
02942 printf (_("-D- cam prev name: %s\n"), (cam->pic[cnt+1])->preview_name);
02943 printf ("\n");
02944 }
02945 }
02946
02947 return SUCCESS;
02948 }
02949
02950
02951
02952
02953
02954
02955
02967 void
02968 read_number (int *picNumbers, int picNumber[MAX_PICS], char *noStr)
02969 {
02970 int value[2], noMode, valNo, strMode;
02971 int i, i1, i2;
02972 int tmp;
02973
02974
02975 *picNumbers=0;
02976
02977
02978 value[0]=0; value[1]=0;
02979 valNo = 0;
02980 strMode = 0;
02981 noMode = 0;
02982
02983 for (i=0; i < (signed) strlen(noStr); i++)
02984 {
02985 if (DEBUG) printf ("-D- %c\n", noStr[i]);
02986
02987 if (noStr[i] == ',')
02988 {
02989
02990 if (noMode == 0)
02991 {
02992 fprintf (stderr, _("ERROR: Must begin with a value (%c)!\n"),
02993 noStr[i]);
02994 myExit (-1, 0);
02995 }
02996
02997 else if (noMode == 3)
02998 {
02999 fprintf (stderr, _("ERROR: Value missing! x-, not allowed!\n"));
03000 myExit (-1, 0);
03001 }
03002
03003
03004 noMode = 2;
03005
03006
03007 if (strMode == 1)
03008 {
03009
03010 if (value[0] >= value[1])
03011 {
03012 fprintf (stderr,
03013 _("ERROR: a-b -> b must be greater then a (%d-%d)!\n"),
03014 value[0],value[1]);
03015 myExit (-1, 0);
03016 }
03017
03018
03019 for (i1=value[0]; i1<=value[1]; i1++)
03020 {
03021 picNumber[*picNumbers] = i1;
03022 (*picNumbers)++;
03023 }
03024
03025 strMode = 0;
03026 value[0]=0;
03027 value[1]=0;
03028 valNo=0;
03029 }
03030 else
03031 {
03032
03033 picNumber[*picNumbers] = value[valNo];
03034
03035
03036 (*picNumbers)++;
03037
03038
03039 value[valNo]=0;
03040 }
03041
03042 }
03043
03044 else if (noStr[i] == '-')
03045 {
03046
03047 if (noMode == 0)
03048 {
03049 fprintf (stderr, _("ERROR: Must begin with a value (%c)!\n"),
03050 noStr[i]);
03051 myExit (-1, 0);
03052 }
03053
03054 else if (noMode == 2)
03055 {
03056 fprintf (stderr, _("ERROR: Value missing! x-, not allowed!\n"));
03057 myExit (-1, 0);
03058 }
03059
03060
03061 noMode = 3;
03062
03063 strMode = 1;
03064
03065 valNo++;
03066
03067
03068 if (valNo > 1)
03069 {
03070 fprintf (stderr, _("ERROR: twice - (x-y-z) detected!\n"));
03071 myExit (-1, 0);
03072 }
03073 }
03074
03075 else if (isdigit(noStr[i]))
03076 {
03077
03078 noMode = 1;
03079
03080 value[valNo]= value[valNo]*10 + noStr[i] - 48;
03081 }
03082
03083 else
03084 {
03085 fprintf (stderr, _("ERROR: Unknown token (%c)!\n"), noStr[i]);
03086 myExit (-1, 0);
03087 }
03088 }
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098 if (strMode == 1)
03099 {
03100
03101 if (value[0] >= value[1])
03102 {
03103 fprintf (stderr, "ERROR: a-b -> b must be greater then a (%d-%d)!\n",
03104 value[0], value[1]);
03105 myExit (-1, 0);
03106 }
03107
03108
03109 for (i1=value[0]; i1<=value[1]; i1++)
03110 {
03111 picNumber[*picNumbers] = i1;
03112 (*picNumbers)++;
03113 }
03114
03115
03116 strMode = 0;
03117 value[0]=0;
03118 value[1]=0;
03119 valNo=0;
03120 }
03121 else
03122 {
03123
03124 picNumber[*picNumbers] = value[valNo];
03125
03126
03127 (*picNumbers)++;
03128
03129
03130 value[valNo]=0;
03131 }
03132
03133
03134
03135 for (i1=0; i1<*picNumbers-1; i1++)
03136 {
03137 for (i2=i1+1; i2<*picNumbers; i2++)
03138 {
03139 if ( picNumber[i1] > picNumber[i2] )
03140 {
03141 tmp = picNumber[i2];
03142 picNumber[i2] = picNumber[i1];
03143 picNumber[i1] = tmp;
03144 }
03145 }
03146 }
03147
03148
03149
03150 for (i1=0; i1<*picNumbers-1; i1++)
03151 {
03152
03153 if (picNumber[i1] == 0 )
03154 {
03155 fprintf (stderr, _("ERROR: Picture number 0 not allowed (starting with \n"));
03156 myExit (-1, 0);
03157 }
03158
03159
03160 if ( picNumber[i1] == picNumber[i1+1] )
03161 {
03162 fprintf (stderr, _("ERROR: Double value detected!\n"));
03163 myExit (-1, 0);
03164 }
03165 }
03166
03167
03168
03169
03170 if (DEBUG)
03171 {
03172 for (i1=0; i1<*picNumbers; i1++)
03173 {
03174 printf (_("-D- read_number: %d. pic number: %d\n"), i1, picNumber[i1]);
03175 }
03176 }
03177
03178
03179 }
03180
03181
03182
03183
03184
03185
03242 void
03243 getDateStr (char *inStr, unsigned int picSum, unsigned int picNo,
03244 t_date date, char *picStr, int mode)
03245 {
03246 int i, no;
03247 int type [MAX_ITEMS];
03248 unsigned char item [MAX_ITEMS];
03249 int noUsed = 0;
03250 char dd[100];
03251
03252 no=0;
03253 i=0;
03254 do
03255 {
03256 if (inStr[i] == '%')
03257 {
03258 i++;
03259
03260 if (inStr[i] == 'B')
03261 {
03262 type[no] = DATE;
03263 item[no] = M_LONG;
03264 no++;
03265 }
03266
03267 else if (inStr[i] == 'y')
03268 {
03269 type[no] = DATE;
03270 item[no] = Y_02;
03271 no++;
03272 }
03273
03274 else if (inStr[i] == 'Y')
03275 {
03276 type[no] = DATE;
03277 item[no] = Y_04;
03278 no++;
03279 }
03280
03281 else if (inStr[i] == 'H')
03282 {
03283 type[no] = DATE;
03284 item[no] = H_02_24;
03285 no++;
03286 }
03287
03288 else if (inStr[i] == 'I')
03289 {
03290 type[no] = DATE;
03291 item[no] = H_02_12;
03292 no++;
03293 }
03294
03295 else if (inStr[i] == 'J')
03296 {
03297 type[no] = DATE;
03298 item[no] = H____24;
03299 no++;
03300 }
03301
03302 else if (inStr[i] == 'K')
03303 {
03304 type[no] = DATE;
03305 item[no] = H____12;
03306 no++;
03307 }
03308
03309 else if (inStr[i] == 'p')
03310 {
03311 type[no] = DATE;
03312 item[no] = H_AMPM;
03313 no++;
03314 }
03315
03316 else if (inStr[i] == 'M')
03317 {
03318 type[no] = DATE;
03319 item[no] = K_02;
03320 no++;
03321 }
03322
03323 else if (inStr[i] == 'b')
03324 {
03325 type[no] = DATE;
03326 item[no] = M_SHORT;
03327 no++;
03328 }
03329
03330 else if (inStr[i] == 'm')
03331 {
03332 type[no] = DATE;
03333 item[no] = M_02;
03334 no++;
03335 }
03336
03337 else if (inStr[i] == 'd')
03338 {
03339 type[no] = DATE;
03340 item[no] = D_02;
03341 no++;
03342 }
03343
03344 else if (inStr[i] == 'f')
03345 {
03346 type[no] = DATE;
03347 item[no] = M_;
03348 no++;
03349 }
03350
03351 else if (inStr[i] == '1')
03352 {
03353 type[no] = DATE;
03354 item[no] = N_02;
03355 noUsed = 1;
03356 no++;
03357 }
03358
03359 else if (inStr[i] == '2')
03360 {
03361 type[no] = DATE;
03362 item[no] = N_03;
03363 noUsed = 1;
03364 no++;
03365 }
03366
03367 else if (inStr[i] == '3')
03368 {
03369 type[no] = DATE;
03370 item[no] = N_02_PLUS1;
03371 noUsed = 1;
03372 no++;
03373 }
03374
03375 else if (inStr[i] == '4')
03376 {
03377 type[no] = DATE;
03378 item[no] = N_03_PLUS1;
03379 noUsed = 1;
03380 no++;
03381 }
03382
03383 else if (inStr[i] == 'q')
03384 {
03385 type[no] = DATE;
03386 item[no] = SUM_PICS_02;
03387 no++;
03388 }
03389
03390 else if (inStr[i] == 'Q')
03391 {
03392 type[no] = DATE;
03393 item[no] = SUM_PICS_03;
03394 no++;
03395 }
03396
03397 else if (inStr[i] == '%')
03398 {
03399 type[no] = ASCII;
03400 item[no] = inStr[i];
03401 no++;
03402 }
03403 else
03404 {
03405 printf (_("ERROR: Unknown (%%%c)-element in date string: (%s)\n"),
03406 inStr[i],inStr);
03407 printf (_(" Position in date string: %d.\n"),
03408 i);
03409 myExit (-1, 1);
03410 }
03411 }
03412 else
03413 {
03414 type[no] = ASCII;
03415 item[no] = inStr[i];
03416 no++;
03417 }
03418
03419 if (no >=MAX_ITEMS)
03420 {
03421 printf (_("ERROR: Maximal %d different items allowed!\n"), MAX_ITEMS);
03422 myExit (-1, 1);
03423 }
03424 i++;
03425 }
03426 while (i< (signed)strlen (inStr));
03427
03428
03429 if ((mode == MUST_USE_A_PICTURE_NUMBER) && (noUsed == 0))
03430 {
03431 fprintf (stderr, _("ERROR: You must use the number of the picture at least!\n"));
03432 fprintf (stderr, _(" That are: %%1, %%2, %%3 or %%4\n"));
03433 myExit (-1, 1);
03434 }
03435
03436
03437
03438 picStr[0] = '\0';
03439
03440 for (i=0; i<no; i++)
03441 {
03442
03443 if (type[i] == DATE)
03444 {
03445
03446 if (item[i] == M_LONG)
03447 {
03448 sprintf (dd, "%s", monNameLong[date.month-1]);
03449 strcat (picStr, dd);
03450 }
03451
03452 else if (item[i] == M_SHORT)
03453 {
03454 sprintf (dd, "%s", monNameShort[date.month-1]);
03455 strcat (picStr, dd);
03456 }
03457
03458 else if (item[i] == M_02)
03459 {
03460 sprintf (dd, "%02d", date.month);
03461 strcat (picStr, dd);
03462 }
03463
03464 else if (item[i] == M_)
03465 {
03466 sprintf (dd, "%d", date.month);
03467 strcat (picStr, dd);
03468 }
03469
03470 else if (item[i] == D_02)
03471 {
03472 sprintf (dd, "%02d", date.day);
03473 strcat (picStr, dd);
03474 }
03475
03476 else if (item[i] == N_02)
03477 {
03478 sprintf (dd, "%02d", picNo);
03479 strcat (picStr, dd);
03480 }
03481
03482 else if (item[i] == N_03)
03483 {
03484 sprintf (dd, "%03d", picNo);
03485 strcat (picStr, dd);
03486 }
03487
03488 else if (item[i] == N_02_PLUS1)
03489 {
03490 sprintf (dd, "%02d", picNo+1);
03491 strcat (picStr, dd);
03492 }
03493
03494 else if (item[i] == N_03_PLUS1)
03495 {
03496 sprintf (dd, "%03d", picNo+1);
03497 strcat (picStr, dd);
03498 }
03499
03500 else if (item[i] == Y_02)
03501 {
03502 sprintf (dd, "%02d", date.year%100);
03503 strcat (picStr, dd);
03504 }
03505
03506 else if (item[i] == Y_04)
03507 {
03508 sprintf (dd, "%04d", date.year);
03509 strcat (picStr, dd);
03510 }
03511
03512 else if (item[i] == H_02_12)
03513 {
03514 if (date.hour > 12)
03515 {
03516 sprintf (dd, "%02d", date.hour-12);
03517 strcat (picStr, dd);
03518 }
03519 else
03520 {
03521 sprintf (dd, "%02d", date.hour);
03522 strcat (picStr, dd);
03523 }
03524 }
03525
03526 else if (item[i] == H_02_24)
03527 {
03528 sprintf (dd, "%02d", date.hour);
03529 strcat (picStr, dd);
03530 }
03531
03532 else if (item[i] == H____12)
03533 {
03534 if (date.hour > 12)
03535 {
03536 sprintf (dd, "%2d", date.hour-12);
03537 strcat (picStr, dd);
03538 }
03539 else
03540 {
03541 sprintf (dd, "%2d", date.hour);
03542 strcat (picStr, dd);
03543 }
03544 }
03545
03546 else if (item[i] == H____24)
03547 {
03548 sprintf (dd, "%2d", date.hour);
03549 strcat (picStr, dd);
03550 }
03551
03552 else if (item[i] == K_02)
03553 {
03554 sprintf (dd, "%02d", date.min);
03555 strcat (picStr, dd);
03556 }
03557
03558 else if (item[i] == SUM_PICS_02)
03559 {
03560 sprintf (dd, "%02d", picSum);
03561 strcat (picStr, dd);
03562 }
03563
03564 else if (item[i] == SUM_PICS_03)
03565 {
03566 sprintf (dd, "%03d", picSum);
03567 strcat (picStr, dd);
03568 }
03569
03570 else if (item[i] == H_AMPM)
03571 {
03572 if (date.hour > 12)
03573 {
03574 sprintf (dd, "AM");
03575 strcat (picStr, dd);
03576 }
03577 else
03578 {
03579 sprintf (dd, "PM");
03580 strcat (picStr, dd);
03581 }
03582 }
03583 }
03584
03585 else if (type[i] == ASCII)
03586 {
03587 sprintf (dd, "%c", item[i]);
03588 strcat (picStr, dd);
03589 }
03590
03591
03592 if (strlen (picStr) > MAX_DS_STRLEN-50)
03593 {
03594 printf (_("ERROR: To long format string given !\n"));
03595 printf (_(" Please retry it with a shorter one!\n"));
03596 myExit (-1, 1);
03597 }
03598 }
03599
03600 }
03601
03602
03603
03604
03605
03606
03607
03620 void
03621 test_dateString (char *dateStr)
03622 {
03623 int picNo, picSum;
03624 char picStr[MAX_DS_STRLEN];
03625 t_date date;
03626
03627
03628 picSum = 200;
03629 picNo = 2;
03630
03631 date.day = 19;
03632 date.month = 2;
03633 date.year = 2003;
03634 date.hour = 23;
03635 date.min = 16;
03636 date.sec = 30;
03637
03638
03639 printf ("\n");
03640 printf (_("Example data:\n"));
03641 printf (_(" Number of pictures: %4d\n"), picSum);
03642 printf (_(" Picture number : %4d\n"), picNo);
03643 printf (_(" Day of month : %4d\n"), date.day);
03644 printf (_(" Month : %4d\n"), date.month);
03645 printf (_(" Year : %4d\n"), date.year);
03646 printf (_(" Hour : %4d\n"), date.hour);
03647 printf (_(" Minute : %4d\n"), date.min);
03648 printf ("\n");
03649 printf (_(" Input String : %s\n"), dateStr);
03650
03651
03652 getDateStr (dateStr, picSum, picNo, date, picStr,
03653 MUST_NOT_USE_A_PICTURE_NUMBER);
03654
03655 printf ("\n");
03656
03657 printf (_(" Output : %s\n"), picStr);
03658
03659 }
03660
03661
03662
03663
03664
03675 void
03676 check_dateStr (char *dateStr)
03677 {
03678 char picStr[MAX_DS_STRLEN];
03679 t_date date;
03680
03681
03682 date.day = 19;
03683 date.month = 2;
03684 date.year = 2003;
03685 date.hour = 23;
03686 date.min = 16;
03687 date.sec = 30;
03688
03689
03690 getDateStr (dateStr, 200, 20, date, picStr, MUST_NOT_USE_A_PICTURE_NUMBER);
03691
03692 }
03693
03694
03695
03696
03697
03698
03708 void
03709 test_cmd (t_mode mode )
03710 {
03711 unsigned char buffer[12];
03712 int back;
03713
03714
03715 DEBUG_HEXDUMP = 1;
03716
03717
03718 back = hp_gen_cmd (mode.printCmd_cmd, mode.printCmd_picNo, buffer);
03719 if (back == SUCCESS)
03720 {
03721 hex_dump (buffer, 12, _("Print command"));
03722 }
03723 }
03724
03725
03726
03727
03728
03729
03739 void checkPid (void)
03740 {
03741 FILE *fp, *fp2;
03742 int pidValue, numbers = -1;
03743 char tmp[1024];
03744
03745
03746 fp = fopen ("/tmp/.hp215-lock", "r");
03747 if (fp != NULL)
03748 {
03749
03750 fscanf (fp, "%d", &pidValue);
03751
03752 fclose (fp);
03753
03754
03755
03756
03757 sprintf (tmp, "ps -ef | grep %d | grep hp215 | grep -v grep | wc > /tmp/.hp215-lock-info", pidValue);
03758 system (tmp);
03759
03760
03761 fp2 = fopen ("/tmp/.hp215-lock-info", "r");
03762 if (fp2 == NULL)
03763 {
03764 fprintf (stderr, _("WARNUNG: Can't open info-lock file for reading: %s \n"), "/tmp/.hp215-lock-info");
03765 }
03766 else
03767 {
03768 fscanf (fp2, "%d", &numbers);
03769 fclose (fp2);
03770
03771 if (numbers == 0)
03772 {
03773
03774 dprint (_("-D- Delete dead lock file.\n"));
03775 removeLockFile();
03776 }
03777
03778 }
03779
03780
03781 if (numbers != 0)
03782 {
03783 fprintf (stderr, _("ERROR: There is a hp215 programm already running. With the pid: %d !\n"),pidValue);
03784 fprintf (stderr, _(" Can't start it more then once!\n"));
03785 exit(-1);
03786 }
03787
03788 }
03789
03790
03791 fp = fopen ("/tmp/.hp215-lock", "w");
03792 if (fp == NULL)
03793 {
03794 fprintf (stderr, _("WARNING: Can't open a lock-file for writing: %s\n"),
03795 "/tmp/.hp215-lock");
03796 fprintf (stderr, _(" Will continue without lockfile!\n"));
03797
03798 }
03799
03800
03801 if (DEBUG) printf (_("-D- My pid is: %d\n"), getpid());
03802 fprintf (fp, "%d\n", getpid());
03803 fclose (fp);
03804
03805 dprint (_("-D- Did create new lock file.\n"));
03806
03807
03808 }
03809
03810
03811
03812
03813
03822 void removeLockFile (void)
03823 {
03824 FILE *fp;
03825 int back;
03826
03827
03828 fp = fopen ("/tmp/.hp215-lock", "r");
03829 if (fp == NULL)
03830 {
03831 fprintf (stderr, _("ERROR: Couldn't find my lock file: %s!\n"),
03832 "/tmp/.hp215-lock");
03833 }
03834 else
03835 {
03836 fclose (fp);
03837
03838
03839
03840 back = remove ("/tmp/.hp215-lock");
03841 if (back != 0)
03842 {
03843 fprintf (stderr, _("WARNING: Couldn't delete the lock file: %s\n"),
03844 "/tmp/.hp215-lock");
03845 }
03846 else
03847 {
03848 dprint (_("-D- Did delete my own lock file.\n"));
03849 }
03850
03851
03852 }
03853
03854
03855 }
03856
03857
03858
03859
03860
03870 void myExit (int value, int doRemoveLockFile)
03871 {
03872
03873 if (doRemoveLockFile == 1)
03874 {
03875
03876 removeLockFile ();
03877 }
03878
03879 exit (value);
03880
03881 }
03882
03883
03884
03885
03886
03887
03896 void usage (void)
03897 {
03898 printf ("\n\n");
03899 printf (_("usage: hp215 [Options] \n"));
03900 printf ("\n");
03901 printf (_(" 1. Camera modes:\n"));
03902 printf (_(" -----------------\n"));
03903 printf (_(" -gdc = Get the actual time/date of the camera.\n"));
03904 printf ("\n");
03905 printf (_(" -gn = Get the number of pictures.\n"));
03906 printf ("\n");
03907 printf (_(" -gdp = Get the time of the pictures.\n"));
03908 printf ("\n");
03909 printf (_(" -gt = Get the preview/thumb pictures.\n"));
03910 printf ("\n");
03911 printf (_(" -gp = Get the pictures.\n"));
03912 printf ("\n");
03913 printf (_(" -dp = Delete pictures.\n"));
03914 printf ("\n");
03915 printf (_(" -a = Do all steps:\n"));
03916 printf (_(" 1. Get the date+time of the cam.\n"));
03917 printf (_(" 2. Get the number of pictures.\n"));
03918 printf (_(" 3. Get the time+date of the pictures.\n"));
03919 printf (_(" 4. Get preview/thumb pictures.\n"));
03920 printf (_(" 5. Get pictures.\n"));
03921 printf (_(" 6. Delete pictures.\n"));
03922 printf (_(" 7. Create html page.\n"));
03923 printf ("\n\n");
03924 printf (_(" 2. Single picture mode:\n"));
03925 printf (_(" ------------------------\n"));
03926 printf (_(" -no xxx = Which picture numbers !?\n"));
03927 printf (_(" Example: -no 1,2,5-6,17 \n"));
03928 printf (_(" DEFAULT: all pictures \n"));
03929 printf (_(" Numbering will start with 1 !"));
03930 printf ("\n\n");
03931 printf (_(" Picture/preview file name format:\n"));
03932 printf (_(" ----------------------------------\n"));
03933 printf (_(" -ds <format string> = Date/time string for preview and picture.\n"));
03934 printf (_(" %%b Month as short text: Jan..Dec\n"));
03935 printf (_(" %%B Month as long text: Januar..December\n"));
03936 printf (_(" %%d Day of month : 01..31\n"));
03937 printf (_(" %%f Day of month : 1..31\n"));
03938 printf (_(" %%H Hour : 00..23\n"));
03939 printf (_(" %%I Hour : 01..12\n"));
03940 printf (_(" %%J Hour : 0..23\n"));
03941 printf (_(" %%K Hour : 1..12\n"));
03942 printf (_(" %%m Month : 01..12 \n"));
03943 printf (_(" %%M Minute : 00..59\n"));
03944 printf (_(" %%p Timespace : AM/PM\n"));
03945 printf (_(" %%y Year : 00..99\n"));
03946 printf (_(" %%Y Year : 2000..\n"));
03947 printf (_(" %%1 Picture number : 00-xx\n"));
03948 printf (_(" %%2 Picture number : 000-xxx\n"));
03949 printf (_(" %%3 Picture number : 01-xx\n"));
03950 printf (_(" %%4 Picture number : 001-xxx\n"));
03951 printf (_(" %%q Sum of pics : 01-xx\n"));
03952 printf (_(" %%Q Sum of pics : 001-xxx\n"));
03953 printf ("\n");
03954 printf (_(" Default : %%2._%%d.%%b.%%Y_%%H%%M\n"));
03955 printf (_(" Default example: 001._08.Jan.2003_1632\n"));
03956 printf ("\n");
03957 printf (_(" -tds = Test date time string with example date.\n"));
03958 printf (_(" Nothing will be done with the camera!\n"));
03959
03960 printf ("\n\n");
03961 printf (_(" 3. Html page creation:\n"));
03962 printf (_(" ----------------------\n"));
03963 printf ("\n");
03964 printf (_(" -wp = Add html pages to the picture\n"));
03965 printf (_(" This is default.\n"));
03966 printf (_(" Html pages will only be created in\n"));
03967 printf (_(" this modes: -a, -gt or -gp.\n"));
03968 printf (_(" -nwp = No html pages.\n"));
03969
03970 printf ("\n\n");
03971 printf (_(" 4. Sub directorys:\n"));
03972 printf (_(" ------------------\n"));
03973 printf ("\n");
03974 printf (_(" -sdp = Create the subdir \"preview\" for the preview pictures\n"));
03975 printf (_(" -nsdp = Do not create the subdir \"preview\" \n"));
03976 printf (_(" Default: -sdp\n"));
03977 printf ("\n");
03978 printf (_(" -sdf = Create the subdir \"fullsize\" for the fullsize pictures\n"));
03979 printf (_(" -nsdf = Do not create the subdir \"fullsize\" \n"));
03980 printf (_(" Default: -nsdf\n"));
03981
03982
03983 printf ("\n\n");
03984 printf (_(" 5. Post-editing:\n"));
03985 printf (_(" ----------------\n"));
03986 printf ("\n");
03987 printf (_(" -rl xxx = Rotate picture 90 degrees left\n"));
03988 printf (_(" Example: -rl 1,2,5-6,17 \n"));
03989 printf (_(" Numbering will start with 1 !\n"));
03990 printf ("\n");
03991 printf (_(" -rr xxx = Rotate picture 90 degrees right\n"));
03992 printf (_(" Example: -rr 1,2,5-6,17 \n"));
03993 printf (_(" Numbering will start with 1 !\n"));
03994 printf ("\n");
03995 printf (_(" -rh xxx = Rotate picture 180 degrees \n"));
03996 printf (_(" Example: -rh 1,2,5-6,17 \n"));
03997 printf (_(" Numbering will start with 1 !\n"));
03998 printf ("\n");
03999 #ifndef HAVE_CONVERT
04000 printf (_("ATTENTION: Options -rl, -rr and -rh will not work because \n"));
04001 printf (_(" imagemagick is missing\n"));
04002 #endif
04003
04004 printf ("\n");
04005 printf (_(" -at = Add date/time string below inside the picture\n"));
04006 printf (_(" If you use this option. A security copy of the pictures"));
04007 printf (_(" will be done without the date/time string.\n"));
04008 printf ("\n");
04009 printf (_(" -atds <format string> = Date/time string format inside the picture.\n"));
04010 printf (_(" = Look at -ds for options.\n"));
04011 printf (_(" Default : %%f. %%B. %%Y %%H:%%M\n"));
04012 printf (_(" Default example: 8. Januar. 2003 - 16:32\n"));
04013 printf ("\n");
04014 #ifndef HAVE_CONVERT
04015 printf (_("ATTENTION: Options -at will not work because\n"));
04016 printf (_(" imagemagick (convert) is missing\n"));
04017 #endif
04018 #ifndef HAVE_IDENTIFY
04019 printf (_("ATTENTION: Options -at will not work because\n"));
04020 printf (_(" imagemagick (identify) is missing\n"));
04021 #endif
04022
04023 printf ("\n\n");
04024 printf (_(" 6. General options:\n"));
04025 printf (_(" -------------------\n"));
04026 printf ("\n");
04027 printf (_(" -h , --help = Prints this page and exit.\n"));
04028 printf (_(" -v , --version = Prints the actual version of hp215 and exit.\n"));
04029 printf ("\n");
04030 printf (_(" -d , --debug = Print debug output. \n"));
04031 printf (_(" -dh , --debug-hexdump = Print debug hexdump of the usb messages.\n"));
04032 printf (_(" ! Put --debug and/or --debug-hexdump at first place after the command - \n"));
04033 printf (_(" then the other option - for debug output as early as possible!\n"));
04034 printf ("\n");
04035 printf (_(" -to , --timeout x = Usb timeout in ms. default 4000.\n"));
04036 printf ("\n");
04037 printf (_(" -2 , --open-cam-twice = Try opening camera twice.\n"));
04038 printf (_(" In some casses necessary:\n"));
04039 printf (_(" (If your camera hang after only one init!\n"));
04040 printf ("\n");
04041 printf (_(" -f , --force-deletion = If you add this option and \n"));
04042 printf (_(" deleting of pictures was an option (-a or -dp)\n"));
04043 printf (_(" then NO safety query to you will be done\n"));
04044 printf (_(" to delete the pictures !!\n"));
04045 printf ("\n");
04046 printf (_(" -pc , --print-cmd <cmd> <picno>\n"));
04047 printf (_(" = Print only the command code for this command.\n"));
04048 printf (_(" cmd's: 179(b3)=GetPreview, 180(b3)=GetPic,\n"));
04049 printf (_(" 197(c5)=getPicDate, 177(b1)=Delete\n"));
04050 printf (_(" Nothing will be done with the camera!\n"));
04051 printf ("\n");
04052 printf (_(" -puu , --print-usb-usermap = Print only the usb usermap for hotplug\n"));
04053 printf (_(" Nothing will be done with the camera!\n"));
04054 printf ("\n\n");
04055 printf (_(" 7. Ini file usage:\n"));
04056 printf (_(" ------------------\n"));
04057 printf (_(" You can add a ini file .hp215 in your home directory and fill it with some of\n"));
04058 printf (_(" the commandline option, you want to have by default:\n"));
04059 printf (_(" Please use one option per line. \n"));
04060 printf (_(" Possible options are: \n"));
04061 printf (_(" -ds x, -wp, -nwp, -d, -dh, -to, -2, -f, -sdp, -nsdp, -sdf, -nsdf, -at, -atds \n\n"));
04062 printf (_(" Example file: \n"));
04063 printf (" -ds %%Y.%%m.%%d_%%H%%M_picture \n");
04064 printf (" -d\n");
04065 printf (" -dh\n");
04066 printf ("\n\n");
04067
04068 }
04069
04070
04071
04072
04088 void add_dateInsidePicture (char *dateInPicStr,
04089 int picNumbers,
04090 int picNumber[MAX_PICS],
04091 t_camera *myCam)
04092 {
04093 int cnt1, height;
04094 char command[1025], picStr[MAX_DS_STRLEN];
04095 FILE *fp;
04096
04097 for (cnt1=0; cnt1<picNumbers; cnt1++)
04098 {
04099
04100 sprintf (command, "cp %s %s.noDiP.jpg ", myCam->pic[cnt1+1]->name, myCam->pic[cnt1+1]->name);
04101 system (command);
04102
04103
04104 sprintf (command, "identify %s | cut -d' ' -f3 | cut -d'x' -f2 | cut -d'+' -f1 > /tmp/.hp215-picture-identify",
04105 myCam->pic[cnt1+1]->name);
04106 system (command);
04107
04108
04109 fp = fopen ("/tmp/.hp215-picture-identify", "r");
04110 if (fp==NULL)
04111 {
04112 fprintf (stderr, _("ERROR: Can't open the picture size info file: %s\n"),
04113 "/tmp/.hp215-picture-identify");
04114 }
04115 else
04116 {
04117 fscanf (fp, "%d", &height);
04118 fclose (fp);
04119
04120 if (DEBUG) printf (_("-D- Picture height: %d\n"), height);
04121 printf (_("Adding time/date into picture %d\n"), cnt1+1);
04122
04123
04124 getDateStr (dateInPicStr, picNumbers, picNumber[cnt1], (myCam->pic[cnt1+1])->date,
04125 picStr, MUST_NOT_USE_A_PICTURE_NUMBER);
04126
04127
04128 sprintf (command, "convert -font -adobe-times-bold-i-normal--14-140-75-75-p-77-iso8859-9 -fill \"#B8B8B8\" -draw 'text 12,%d \"%s\"' -fill blue -draw 'text 9,%d \"%s\"' %s %s",
04129 height-27, picStr,
04130 height-30, picStr,
04131 myCam->pic[cnt1+1]->name, myCam->pic[cnt1+1]->name);
04132 system (command);
04133
04134 }
04135 }
04136 }
04137
04138
04139 int main (int argc, char *argv[] )
04140 {
04141 t_camera myCam;
04142 t_mode mode;
04143 char doDel[256], command[1025], tmp[1024];
04144 int i;
04145 int found, e1, e2, cnt1, cnt2;
04146
04147
04148
04149 setlocale (LC_ALL, "");
04150 bindtextdomain (PACKAGE, LOCALEDIR);
04151 textdomain (PACKAGE);
04152
04153
04154
04155 myCam.num_pics = 0;
04156
04157
04158 init_modeValues (&mode);
04159
04160
04161 read_ini (&mode);
04162
04163
04164 read_cmd (&argc, &argv, &mode);
04165
04166
04167 check_dateStr (mode.dateStr);
04168
04169
04170 checkPid ();
04171
04172
04173
04174 if (mode.main == PRTCMD_MODE)
04175 {
04176 test_cmd (mode);
04177 myExit (1, 1);
04178 }
04179
04180
04181 if (mode.main == TSTDAT_MODE)
04182 {
04183 test_dateString (mode.dateStr);
04184 myExit (1, 1);
04185 }
04186
04187
04188
04189
04190
04191 if (hp_open(&myCam, mode.tryInitCamTwice))
04192 {
04193 fprintf (stderr, _("ERROR: Failed to open camera, make sure it is plugged in and turned on!\n"));
04194 myExit (0, 1);
04195 }
04196
04197
04198 hp_init_sequence (&myCam);
04199
04200
04201
04202 if (mode.dateCam == 1)
04203 {
04204 hp_get_timeDate_cam (&myCam);
04205 }
04206
04207
04208
04209 if (mode.albm == 1)
04210 {
04211 hp_get_photo_album (&myCam);
04212 }
04213
04214
04215
04216 if (myCam.num_pics > 0)
04217 {
04218
04219 if ( (mode.prev == 1) || (mode.pics == 1) ||
04220 (mode.delt == 1) || (mode.datePics == 1) )
04221 {
04222
04223 if (mode.picNumbers == -1)
04224 {
04225
04226 mode.picNumbers=0;
04227 for (i=0; i<myCam.num_pics; i++)
04228 {
04229 mode.picNumber[mode.picNumbers] = i+1;
04230 mode.picNumbers++;
04231 }
04232 }
04233 else
04234 {
04235
04236 if (mode.picNumber[mode.picNumbers-1] > myCam.num_pics)
04237 {
04238 fprintf (stderr, _("ERROR: Given picture number %d is greater then\n"),
04239 mode.picNumber[mode.picNumbers-1]);
04240 fprintf (stderr, _(" the number of pictures on camera (=%d)!\n"),
04241 myCam.num_pics);
04242 myExit (-1, 1);
04243 }
04244
04245 else if (mode.picNumber[0] < 1)
04246 {
04247 fprintf (stderr, _("ERROR: Given number %d is less then \n"),
04248 mode.picNumber[0]);
04249 fprintf (stderr, _(" the numbering start (=1)!\n"));
04250 myExit (-1, 1);
04251 }
04252 }
04253
04254
04255 if (mode.picNumbers == myCam.num_pics)
04256 {
04257 mode.picNumbersAll = 1;
04258 printf (_("All pictures selected !! \n"));
04259 }
04260
04261
04262 printf (_("Selected photos: "));
04263
04264 if (mode.picNumbersAll == 1)
04265 {
04266 printf (_(" Number 1-%d\n"), mode.picNumbers);
04267 }
04268 else
04269 {
04270 printf ("\n");
04271 for (i=0; i<mode.picNumbers; i++)
04272 {
04273 printf (_(" %2d. Picture number: %d\n"), i, mode.picNumber[i]);
04274 }
04275 }
04276 printf ("\n");
04277
04278
04279
04280 if (mode.picNumbersRR != -1)
04281 {
04282 if (mode.picNumberRR[mode.picNumbersRR-1] > mode.picNumber[mode.picNumbers-1])
04283 {
04284 fprintf (stderr, _("ERROR: Last picture for right rotation ist greater then\n"));
04285 fprintf (stderr, _(" the last picture number!\n"));
04286 myExit (-1, 1);
04287 }
04288 else
04289 {
04290 for (e2=0; e2<mode.picNumbersRR;e2++)
04291 {
04292 found = 0;
04293 for (e1=0; e1<mode.picNumbers;e1++)
04294 {
04295 if (mode.picNumberRR[e2] == mode.picNumber[e1]) found = 1;
04296 }
04297
04298 if (found == 0)
04299 {
04300 fprintf (stderr, _("ERROR: Given right rotaten Picture (%d) is!\n"), mode.picNumberRR[e2]);
04301 fprintf (stderr, _(" not inside the selected pictures !\n"));
04302 myExit (-1, 1);
04303 }
04304 }
04305 }
04306 }
04307
04308
04309
04310 if (mode.picNumbersRL != -1)
04311 {
04312 if (mode.picNumberRL[mode.picNumbersRL-1] > mode.picNumber[mode.picNumbers-1])
04313 {
04314 fprintf (stderr, _("ERROR: Last picture for left rotation ist greater then\n"));
04315 fprintf (stderr, _(" the last picture number!\n"));
04316 myExit (-1, 1);
04317 }
04318 else
04319 {
04320 for (e2=0; e2<mode.picNumbersRL;e2++)
04321 {
04322 found = 0;
04323 for (e1=0; e1<mode.picNumbers;e1++)
04324 {
04325 if (mode.picNumberRL[e2] == mode.picNumber[e1]) found = 1;
04326 }
04327
04328 if (found == 0)
04329 {
04330 fprintf (stderr, _("ERROR: Given left rotaten picture (%d) is!\n"), mode.picNumberRL[e2]);
04331 fprintf (stderr, _(" not inside the selected pictures !\n"));
04332 myExit (-1, 1);
04333 }
04334 }
04335 }
04336 }
04337
04338
04339 if (mode.picNumbersRH != -1)
04340 {
04341 if (mode.picNumberRH[mode.picNumbersRH-1] > mode.picNumber[mode.picNumbers-1])
04342 {
04343 fprintf (stderr, _("ERROR: Last picture for 180 degree rotation ist greater then\n"));
04344 fprintf (stderr, _(" the last picture number!\n"));
04345 myExit (-1, 1);
04346 }
04347 else
04348 {
04349 for (e2=0; e2<mode.picNumbersRH;e2++)
04350 {
04351 found = 0;
04352 for (e1=0; e1<mode.picNumbers;e1++)
04353 {
04354 if (mode.picNumberRH[e2] == mode.picNumber[e1]) found = 1;
04355 }
04356
04357 if (found == 0)
04358 {
04359 fprintf (stderr, _("ERROR: Given 180 degree rotaten picture (%d) is!\n"),
04360 mode.picNumberRH[e2]);
04361 fprintf (stderr, _(" not inside the selected pictures !\n"));
04362 myExit (-1, 1);
04363 }
04364 }
04365 }
04366 }
04367 }
04368
04369
04370
04371
04372
04373 if ( (mode.datePics == 1) || (mode.prev == 1) || (mode.pics == 1) )
04374 {
04375
04376 gen_subDirName (mode.subDir);
04377
04378
04379 hp_get_timeDate_pics (&myCam, mode.picNumbers, mode.picNumber,
04380 mode.subDir, mode.dateStr, mode.subDirPrev, mode.subDirFull);
04381 printf ("\n");
04382 }
04383
04384
04385
04386 if ( (mode.prev == 1) || (mode.pics == 1) )
04387 {
04388
04389 gen_subDir (mode.subDir);
04390 if (mode.subDirPrev)
04391 {
04392 sprintf (tmp, "%s/%s", mode.subDir, PREVIEW_DIR);
04393 gen_subDir(tmp);
04394 }
04395 if (mode.subDirFull)
04396 {
04397 sprintf (tmp, "%s/%s", mode.subDir, FULLSIZE_DIR);
04398 gen_subDir(tmp);
04399 }
04400
04401 printf ("\n");
04402 }
04403
04404
04405
04406
04407 if (mode.prev == 1)
04408 {
04409
04410 hp_get_previews (&myCam, mode.picNumbers, mode.picNumber, mode.subDir);
04411
04412
04413 hp_write_previews (&myCam, mode.picNumbers, mode.picNumber);
04414 }
04415
04416
04417
04418
04419 if (mode.pics == 1)
04420 {
04421 hp_get_write_pics (&myCam, mode.picNumbers, mode.picNumber, mode.subDir);
04422 }
04423
04424
04425
04426
04427 if (mode.delt == 1)
04428 {
04429
04430 if (mode.forceDeletion == 1)
04431 {
04432 printf (_("\nForced deleting\n"));
04433 hp_delete_pics (&myCam, mode.picNumbersAll,
04434 mode.picNumbers, mode.picNumber);
04435 }
04436 else
04437 {
04438 if (mode.picNumbersAll == 1)
04439 {
04440 printf (_("\nWill delete all %d pictures: "), mode.picNumbers);
04441 }
04442 else
04443 {
04444 printf (_("\nWill delete following %d pictures: "), mode.picNumbers);
04445 for (i=0; i<mode.picNumbers; i++)
04446 {
04447 printf ("%d ", mode.picNumber[i]);
04448 }
04449 }
04450 printf ("\n");
04451 printf (_("Should I really delete those pictures ? (yes/NO)\n"));
04452 scanf ("%20s", doDel);
04453 if (strcmp (doDel, "yes") == 0)
04454 {
04455 printf (_("Deletion of pictures started !\n"));
04456 hp_delete_pics (&myCam, mode.picNumbersAll,
04457 mode.picNumbers, mode.picNumber);
04458 }
04459 else
04460 {
04461 printf (_("Deletion of pictures canceled !\n"));
04462 }
04463 }
04464 }
04465
04466
04467
04468 if (mode.html == 1)
04469 {
04470 hp_create_html_page (&myCam, mode.picNumbers, mode.picNumber,
04471 mode.subDir, mode.prev, mode.pics, mode.subDirFull);
04472 }
04473
04474
04475 if (mode.picNumbersRL != -1)
04476 {
04477 if (DEBUG) printf ("-D- RLs: %d\n", mode.picNumbersRL);
04478
04479 for (cnt1=0; cnt1<mode.picNumbers; cnt1++)
04480 {
04481 for (cnt2=0; cnt2<mode.picNumbersRL; cnt2++)
04482 {
04483 if (mode.picNumber[cnt1] == mode.picNumberRL[cnt2])
04484 {
04485 printf (_("Rotate picture %d left.\n"),
04486 mode.picNumber[cnt1]);
04487
04488 sprintf (command, "convert -rotate 270 %s %s.tmp",
04489 myCam.pic[cnt1+1]->preview_name,
04490 myCam.pic[cnt1+1]->preview_name);
04491 system (command);
04492 if (DEBUG) printf ("-D- rl %d -> %s\n", cnt1+1, command);
04493
04494 sprintf (command, "mv %s.tmp %s",
04495 myCam.pic[cnt1+1]->preview_name,
04496 myCam.pic[cnt1+1]->preview_name);
04497 system (command);
04498 if (DEBUG) printf ("-D- rl %d -> %s\n", cnt1+1, command);
04499
04500 sprintf (command, "convert -rotate 270 %s %s.tmp",
04501 myCam.pic[cnt1+1]->name,
04502 myCam.pic[cnt1+1]->name);
04503 system (command);
04504 if (DEBUG) printf ("-D- rl %d -> %s\n", cnt1+1, command);
04505 sprintf (command, "mv %s.tmp %s",
04506 myCam.pic[cnt1+1]->name,
04507 myCam.pic[cnt1+1]->name);
04508 system (command);
04509 if (DEBUG) printf ("-D- rl %d -> %s\n", cnt1+1, command);
04510 }
04511 }
04512 }
04513 }
04514
04515
04516
04517 if (mode.picNumbersRR != -1)
04518 {
04519 if (DEBUG) printf ("-D- RRs: %d\n", mode.picNumbersRR);
04520 for (cnt1=0; cnt1<mode.picNumbers; cnt1++)
04521 {
04522 for (cnt2=0; cnt2<mode.picNumbersRR; cnt2++)
04523 {
04524 if (mode.picNumber[cnt1] == mode.picNumberRR[cnt2])
04525 {
04526 printf (_("Rotate picture %d right.\n"),
04527 mode.picNumber[cnt1]);
04528
04529 sprintf (command, "convert -rotate 90 %s %s.tmp",
04530 myCam.pic[cnt1+1]->preview_name,
04531 myCam.pic[cnt1+1]->preview_name);
04532 system (command);
04533 if (DEBUG) printf ("-D- rr %d -> %s\n", cnt1+1, command);
04534 sprintf (command, "mv %s.tmp %s",
04535 myCam.pic[cnt1+1]->preview_name,
04536 myCam.pic[cnt1+1]->preview_name);
04537 system (command);
04538 if (DEBUG) printf ("-D- rr %d -> %s\n", cnt1+1, command);
04539
04540 sprintf (command, "convert -rotate 90 %s %s.tmp",
04541 myCam.pic[cnt1+1]->name,
04542 myCam.pic[cnt1+1]->name);
04543 system (command);
04544 if (DEBUG) printf ("-D- rr %d -> %s\n", cnt1+1, command);
04545 sprintf (command, "mv %s.tmp %s",
04546 myCam.pic[cnt1+1]->name,
04547 myCam.pic[cnt1+1]->name);
04548 system (command);
04549 if (DEBUG) printf ("-D- rr %d -> %s\n", cnt1+1, command);
04550 }
04551 }
04552 }
04553 }
04554
04555
04556 if (mode.picNumbersRH != -1)
04557 {
04558 if (DEBUG) printf ("-D- RHs: %d\n", mode.picNumbersRH);
04559
04560 for (cnt1=0; cnt1<mode.picNumbers; cnt1++)
04561 {
04562 for (cnt2=0; cnt2<mode.picNumbersRH; cnt2++)
04563 {
04564 if (mode.picNumber[cnt1] == mode.picNumberRH[cnt2])
04565 {
04566 printf (_("Rotate picture %d 180 degrees.\n"),
04567 mode.picNumber[cnt1]);
04568
04569 sprintf (command, "convert -rotate 180 %s %s.tmp",
04570 myCam.pic[cnt1+1]->preview_name,
04571 myCam.pic[cnt1+1]->preview_name);
04572 system (command);
04573 if (DEBUG) printf ("-D- rh %d -> %s\n", cnt1+1, command);
04574
04575 sprintf (command, "mv %s.tmp %s",
04576 myCam.pic[cnt1+1]->preview_name,
04577 myCam.pic[cnt1+1]->preview_name);
04578 system (command);
04579 if (DEBUG) printf ("-D- rh %d -> %s\n", cnt1+1, command);
04580
04581 sprintf (command, "convert -rotate 180 %s %s.tmp",
04582 myCam.pic[cnt1+1]->name,
04583 myCam.pic[cnt1+1]->name);
04584 system (command);
04585 if (DEBUG) printf ("-D- rh %d -> %s\n", cnt1+1, command);
04586
04587 sprintf (command, "mv %s.tmp %s",
04588 myCam.pic[cnt1+1]->name,
04589 myCam.pic[cnt1+1]->name);
04590 system (command);
04591 if (DEBUG) printf ("-D- rd %d -> %s\n", cnt1+1, command);
04592 }
04593 }
04594 }
04595 }
04596
04597
04598 if ((mode.dateInPic == 1) && (mode.pics == 1))
04599 {
04600 add_dateInsidePicture (mode.dateInPicStr, mode.picNumbers, mode.picNumber,
04601 &myCam);
04602 }
04603
04604
04605 }
04606
04607
04608 usb_close(myCam.dh);
04609
04610
04611 removeLockFile ();
04612
04613 printf (_("Finished\n"));
04614
04615 return 1;
04616 }
04617
04618