WPILib 2012
WPILibRoboticsLibraryforFRC
Vision/AxisCamera.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef __AXIS_CAMERA_H__
00008 #define __AXIS_CAMERA_H__
00009 
00010 #include <taskLib.h>
00011 #include <vxWorks.h> 
00012 #include <sockLib.h> 
00013 #include <inetLib.h>
00014 
00015 #include "Vision/AxisCameraParams.h"
00016 #if JAVA_CAMERA_LIB != 1
00017 #include "Vision/ColorImage.h"
00018 #include "Vision/HSLImage.h"
00019 #endif
00020 #include "nivision.h"
00021 #include <set>
00022 #include "Task.h"
00023 
00024 class PCVideoServer;
00025 
00034 class AxisCamera : public AxisCameraParams
00035 {
00036 private:
00037         explicit AxisCamera(const char *cameraIP);
00038 public:
00039         virtual ~AxisCamera();
00040         static AxisCamera& GetInstance(const char *cameraIP = NULL);
00041         static void DeleteInstance();
00042 
00043         bool IsFreshImage();
00044         SEM_ID GetNewImageSem();
00045 
00046         int GetImage(Image *imaqImage);
00047 #if JAVA_CAMERA_LIB != 1
00048         int GetImage(ColorImage *image);
00049         HSLImage *GetImage();
00050 #endif
00051 
00052         int CopyJPEG(char **destImage, int &destImageSize, int &destImageBufferSize);
00053 
00054 private:
00055         static int s_ImageStreamTaskFunction(AxisCamera *thisPtr);
00056         int ImageStreamTaskFunction();
00057 
00058         int ReadImagesFromCamera();
00059         void UpdatePublicImageFromCamera(char *imgBuffer, int imgSize);
00060 
00061         virtual void RestartCameraTask();
00062 
00063         static AxisCamera *_instance;
00064         int m_cameraSocket;
00065         typedef std::set<SEM_ID> SemSet_t;
00066         SemSet_t m_newImageSemSet;
00067 
00068         char* m_protectedImageBuffer;
00069         int m_protectedImageBufferLength;
00070         int m_protectedImageSize;
00071         SEM_ID m_protectedImageSem;
00072         bool m_freshImage;
00073 
00074         Task m_imageStreamTask;
00075 
00076         PCVideoServer *m_videoServer;
00077 };
00078 
00079 #if JAVA_CAMERA_LIB == 1
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083         void AxisCameraStart(const char *IPAddress);
00084         int AxisCameraGetImage(Image *image);
00085         void AxisCameraDeleteInstance();
00086         int AxisCameraFreshImage();
00087 
00088         // Mid-stream gets & writes
00089         void AxisCameraWriteBrightness(int brightness);
00090         int AxisCameraGetBrightness();
00091         void AxisCameraWriteWhiteBalance(AxisCameraParams::WhiteBalance_t whiteBalance);
00092         AxisCameraParams::WhiteBalance_t AxisCameraGetWhiteBalance();
00093         void AxisCameraWriteColorLevel(int colorLevel);
00094         int AxisCameraGetColorLevel();
00095         void AxisCameraWriteExposureControl(AxisCameraParams::Exposure_t exposure);
00096         AxisCameraParams::Exposure_t AxisCameraGetExposureControl();
00097         void AxisCameraWriteExposurePriority(int exposurePriority);
00098         int AxisCameraGetExposurePriority();
00099         void AxisCameraWriteMaxFPS(int maxFPS);
00100         int AxisCameraGetMaxFPS();
00101 
00102         // New-Stream gets & writes
00103         void AxisCameraWriteResolution(AxisCameraParams::Resolution_t resolution);
00104         AxisCameraParams::Resolution_t AxisCameraGetResolution();
00105         void AxisCameraWriteCompression(int compression);
00106         int AxisCameraGetCompression();
00107         void AxisCameraWriteRotation(AxisCameraParams::Rotation_t rotation);
00108         AxisCameraParams::Rotation_t AxisCameraGetRotation();
00109 #ifdef __cplusplus
00110 }
00111 #endif
00112 #endif // JAVA_CAMERA_LIB == 1
00113 
00114 #endif
 All Classes Functions Variables