1 | #if 0
|
---|
2 | V4L INDI Driver
|
---|
3 | INDI Interface for V4L devices
|
---|
4 | Copyright (C) 2003-2005 Jasem Mutlaq (mutlaqja@ikarustech.com)
|
---|
5 |
|
---|
6 | This library is free software; you can redistribute it and/or
|
---|
7 | modify it under the terms of the GNU Lesser General Public
|
---|
8 | License as published by the Free Software Foundation; either
|
---|
9 | version 2.1 of the License, or (at your option) any later version.
|
---|
10 |
|
---|
11 | This library is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | Lesser General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU Lesser General Public
|
---|
17 | License along with this library; if not, write to the Free Software
|
---|
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
19 |
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | #ifndef V4L_DRIVER_H
|
---|
23 | #define V4L_DRIVER_H
|
---|
24 |
|
---|
25 | #include <stdio.h>
|
---|
26 | #include <stdlib.h>
|
---|
27 | #include <string.h>
|
---|
28 | #include <stdarg.h>
|
---|
29 | #include <math.h>
|
---|
30 | #include <unistd.h>
|
---|
31 | #include <time.h>
|
---|
32 | #include <fcntl.h>
|
---|
33 | #include <signal.h>
|
---|
34 | #include <errno.h>
|
---|
35 | #include <sys/stat.h>
|
---|
36 | #include <sys/time.h>
|
---|
37 | #include <sys/types.h>
|
---|
38 | #include <sys/socket.h>
|
---|
39 | #include <netinet/in.h>
|
---|
40 | #include <netdb.h>
|
---|
41 | #include <zlib.h>
|
---|
42 | #include <asm/types.h>
|
---|
43 |
|
---|
44 | #include "indidevapi.h"
|
---|
45 | #include "indicom.h"
|
---|
46 | #include <fitsio.h>
|
---|
47 | #include "eventloop.h"
|
---|
48 |
|
---|
49 | #include <config.h>
|
---|
50 |
|
---|
51 | #ifdef HAVE_LINUX_VIDEODEV2_H
|
---|
52 | #include "webcam/v4l2_base.h"
|
---|
53 | #else
|
---|
54 | #include "webcam/v4l1_base.h"
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #define COMM_GROUP "Main Control"
|
---|
58 | #define IMAGE_CONTROL "Image Control"
|
---|
59 | #define IMAGE_GROUP "Image Settings"
|
---|
60 |
|
---|
61 | #define MAX_PIXELS 4096 /* Max number of pixels in one dimension */
|
---|
62 | #define ERRMSGSIZ 1024
|
---|
63 |
|
---|
64 | #define TEMPFILE_LEN 16
|
---|
65 |
|
---|
66 |
|
---|
67 | class V4L_Driver
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | V4L_Driver();
|
---|
71 | virtual ~V4L_Driver();
|
---|
72 |
|
---|
73 | /* INDI Functions that must be called from indidrivermain */
|
---|
74 | virtual void ISGetProperties (const char *dev);
|
---|
75 | virtual void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
|
---|
76 | virtual void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
|
---|
77 | virtual void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
|
---|
78 |
|
---|
79 | virtual void initCamBase();
|
---|
80 | virtual void initProperties(const char *dev);
|
---|
81 |
|
---|
82 | static void newFrame(void *p);
|
---|
83 | void updateFrame();
|
---|
84 |
|
---|
85 | protected:
|
---|
86 |
|
---|
87 | /* Structs */
|
---|
88 | typedef struct {
|
---|
89 | int width;
|
---|
90 | int height;
|
---|
91 | int expose;
|
---|
92 | unsigned char *Y;
|
---|
93 | unsigned char *U;
|
---|
94 | unsigned char *V;
|
---|
95 | unsigned char *colorBuffer;
|
---|
96 | unsigned char *compressedFrame;
|
---|
97 | } img_t;
|
---|
98 |
|
---|
99 |
|
---|
100 | /* Switches */
|
---|
101 | ISwitch PowerS[2];
|
---|
102 | ISwitch StreamS[2];
|
---|
103 | ISwitch CompressS[2];
|
---|
104 | ISwitch ImageTypeS[2];
|
---|
105 |
|
---|
106 | /* Texts */
|
---|
107 | IText PortT[1];
|
---|
108 | IText camNameT[1];
|
---|
109 |
|
---|
110 | /* Numbers */
|
---|
111 | INumber ExposeTimeN[1];
|
---|
112 | INumber FrameRateN[1];
|
---|
113 | INumber FrameN[4];
|
---|
114 | #ifndef HAVE_LINUX_VIDEODEV2_H
|
---|
115 | INumber ImageAdjustN[5];
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | /* BLOBs */
|
---|
119 | IBLOB imageB;
|
---|
120 |
|
---|
121 | /* Switch vectors */
|
---|
122 | ISwitchVectorProperty PowerSP; /* Connection switch */
|
---|
123 | ISwitchVectorProperty StreamSP; /* Stream switch */
|
---|
124 | ISwitchVectorProperty CompressSP; /* Compress stream switch */
|
---|
125 | ISwitchVectorProperty ImageTypeSP; /* Color or grey switch */
|
---|
126 |
|
---|
127 | /* Number vectors */
|
---|
128 | INumberVectorProperty ExposeTimeNP; /* Exposure */
|
---|
129 | INumberVectorProperty FrameRateNP; /* Frame rate */
|
---|
130 | INumberVectorProperty FrameNP; /* Stream dimenstion */
|
---|
131 | INumberVectorProperty ImageAdjustNP; /* Image controls */
|
---|
132 |
|
---|
133 | /* Text vectors */
|
---|
134 | ITextVectorProperty PortTP;
|
---|
135 | ITextVectorProperty camNameTP;
|
---|
136 |
|
---|
137 | /* BLOB vectors */
|
---|
138 | IBLOBVectorProperty imageBP; /* Data stream */
|
---|
139 |
|
---|
140 | /* Initilization functions */
|
---|
141 | virtual void connectCamera(void);
|
---|
142 | virtual void getBasicData(void);
|
---|
143 |
|
---|
144 | /* Stream/FITS functions */
|
---|
145 | void updateStream();
|
---|
146 | void uploadFile(const char * filename);
|
---|
147 | int writeFITS(const char *filename, char errmsg[]);
|
---|
148 | int grabImage(void);
|
---|
149 | void addFITSKeywords(fitsfile *fptr);
|
---|
150 | void allocateBuffers();
|
---|
151 | void releaseBuffers();
|
---|
152 |
|
---|
153 | /* Helper functions */
|
---|
154 | int checkPowerN(INumberVectorProperty *np);
|
---|
155 | int checkPowerS(ISwitchVectorProperty *sp);
|
---|
156 | int checkPowerT(ITextVectorProperty *tp);
|
---|
157 |
|
---|
158 | #ifndef HAVE_LINUX_VIDEODEV2_H
|
---|
159 | virtual void updateV4L1Controls();
|
---|
160 | V4L1_Base *v4l_base;
|
---|
161 | #else
|
---|
162 | virtual void updateV4L2Controls();
|
---|
163 | V4L2_Base *v4l_base;
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | char device_name[MAXINDIDEVICE];
|
---|
167 | unsigned char *fitsData; /* Buffer to hold the FITS file */
|
---|
168 | int frameCount; /* For debugging */
|
---|
169 | double divider; /* For limits */
|
---|
170 | img_t * V4LFrame; /* Video frame */
|
---|
171 |
|
---|
172 | time_t capture_start; /* To calculate how long a frame take */
|
---|
173 | time_t capture_end;
|
---|
174 |
|
---|
175 | };
|
---|
176 |
|
---|
177 | #endif
|
---|