Remove whitespace, update email addresses and URLs.
[kodak.git] / main.cpp
1 //+----------------------------------------------------------------------------
2 //
3 // File:     main.cpp
4 //
5 // Module:   Kodak DC210 plus communication program
6 //
7 // Synopsis: Program entry point.
8 //
9 // Copyright (c) 1999 Scott Gasch 
10 // All rights reserved.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions
14 // are met:
15 // 1. Redistributions of source code must retain the above copyright
16 //    notice, this list of conditions and the following disclaimer.
17 // 2. Redistributions in binary form must reproduce the above copyright
18 //    notice, this list of conditions and the following disclaimer in the
19 //    documentation and/or other materials provided with the distribution.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 // SUCH DAMAGE.
32 //
33 //  $Id: main.cpp,v 1.3 2000/01/15 18:34:30 scott Exp scott $
34 //
35 // Author:       sgasch
36 //
37 // Created    4 Jun 1999
38 //
39 //+----------------------------------------------------------------------------
40
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <unistd.h>
44 #include <fcntl.h>
45 #include <string.h>
46 #include <math.h>
47
48 #include "global.h"
49 #include "utils.h"
50 #include "trace.h"
51 #include "debug.h"
52 #include "dc210camera.h"
53 #include "dc210photo.h"
54
55 CKodakDC210 camera("/dev/cuaa0", 38400);
56
57 //
58 // Needed for getopt.
59 //
60 extern char *optarg;
61 extern int optind;
62
63 //+----------------------------------------------------------------------------
64 //
65 // Function:  Usage
66 //
67 // Synopsis:  Print out a brief description of command syntax and exit.
68 //
69 // Arguments: void
70 //            
71 // Returns:   void
72 //
73 // History:   sgasch Created Header    22 Jun 1999
74 //
75 //+----------------------------------------------------------------------------
76 void Usage(void)
77 {
78         printf("usage:\n\n"
79                    "camera [-d][-p serial-device][-BYTE baud-rate] command "
80                    "[arguments]\n"
81                    "camera [-h]\n\n");
82         exit(0);
83 }
84
85
86 //+----------------------------------------------------------------------------
87 //
88 // Function:  main
89 //
90 // Synopsis:  Main entry point; parse arguments and control camera.
91 //
92 // Arguments: int argc - arg count
93 //            char *argv[] - arguments
94 //            
95 // Returns:   int - status to OS
96 //
97 // History:   sgasch Created Header    22 Jun 1999
98 //
99 //+----------------------------------------------------------------------------
100 int main(int argc, char *argv[])
101 {
102         char ch;
103         char szCommand[256];
104
105         while ((ch = getopt(argc, argv, "p:b:d?h")) != -1)
106         {
107                 switch (ch) 
108                 {
109                         //
110                         // We are in debug mode -- extra tracing and more retries.
111                         //
112                     case 'd':
113                             g_iMaxAttempts = 10;
114                                 break;
115                         case 'b':
116                                 g_iSpeed = atoi(optarg);
117                                 if ((g_iSpeed != 9600) && (g_iSpeed != 19200) &&
118                                         (g_iSpeed != 38400) && (g_iSpeed != 57600) &&
119                                         (g_iSpeed != 115200))
120                                 {
121                                         Trace("main: Illegal speed (%d) specified; legal speeds "
122                                                   "are:\n\n"
123                                                   "9600, 19200, 38400, 57600, and 115200.\n\n"
124                                                   "main: Defaulting to to 9600 baud.\n", g_iSpeed);
125                                         g_iSpeed = 9600;
126                                 }
127                                 break;
128                         case 'p':
129                                 memset(g_szCameraSerialPort, 0, PATH_MAX);
130                                 strncpy(g_szCameraSerialPort, optarg, PATH_MAX);
131                                 break;
132                         case '?':
133                         case 'h':
134                         default:
135                                 Usage();
136                                 return(0);
137                 }
138                 argc -= optind;
139                 argv += optind;
140         }
141
142         do
143         {
144                 if (NULL == (gets(szCommand)))
145                 {
146                         break;
147                 }
148
149                 if (!strcasecmp("snap", szCommand))
150                 {
151                         Trace("Snapping...\n");
152                         (void) camera.TakePicture();
153                 }
154         }
155         while(1);
156
157         return(0);
158 }
159
160
161