COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
A35 library function declarations
Collaboration diagram for A35 library function declarations:

Functions

bool InitCamera (uint16_t width, uint16_t height, gige_handle *handle)
 
bool GetCameraFrame (gige_handle *handle, uint16_t *A35FrameBuffer, uint32_t ImageSize)
 
void StartCamera (gige_handle *handle)
 
int ShutdownCamera (gige_handle *handle)
 
bool ResetCamera (gige_handle *handle)
 
bool AutoFFC (gige_handle *handle)
 
bool ManualFFC (gige_handle *handle)
 
bool DoFFC (gige_handle *handle)
 
bool GetTemperature (gige_handle *handle)
 
bool SetFramesToSkip (int FramesToSkip, gige_handle *handle)
 
bool SetPacketDelay (int PacketDelay, gige_handle *handle)
 
void WriteRegister (gige_handle *handle, int16_t command, int16_t param1, int16_t param2, int16_t param3)
 
bool SetFramesToSkip (gige_handle *handle, int FramesToSkip)
 
bool SetPacketDelay (gige_handle *handle, int PacketDelay)
 

Detailed Description

Function Documentation

bool InitCamera ( uint16_t  width,
uint16_t  height,
gige_handle handle 
)
58 {
59  uint16_t i;
60  int16_t a35Index;
61 // uint32_t myip;
62  vector<gige_acknowledge_ack> gige_list;
63 // struct timeval StartTime;
64 // struct timeval PresentTime;
65 // int64_t Duration, seconds, useconds;
66 
67  // Get time for timeout
68 // gettimeofday(&StartTime, NULL);
70  et.start();
71 
72  do
73  {
74  gige_list = gige_discover();
75  if(!gige_list.empty())
76  {
77  break;
78  }
79 
80  // 2000ms timeout
81 // gettimeofday(&PresentTime, NULL);
82 // seconds = PresentTime.tv_sec - StartTime.tv_sec;
83 // useconds = PresentTime.tv_usec - StartTime.tv_usec;
84 // Duration = seconds*1000000.0 + useconds;
85 // if(Duration > 2000000) break; // Timeout
86  if (et.lap() > 2.) break;
87  } while(true);
88 
89 
90  if(gige_list.empty())
91  {
92  printf("No Cameras found.");
93  exit(-10);
94  }
95 
96 
97  // Determine which item in the list is the A35.
98  a35Index = -1;
99  for(i=0 ; i<gige_list.size() ; i++)
100  {
101  if( strncmp(gige_list[i].model, "FLIR AX5", 8) == 0 )
102  {
103  a35Index = i;
104  }
105  }
106  if(a35Index == -1)
107  {
108  printf("No A35 camera found.\n");
109  exit(-11);
110  }
111 
112 
113  handle = gige_open(gige_value_to_address(gige_list[a35Index].address),0x02,10000,15000,1000000);
114 
115 
116  printf("Found %s @ %s\n" , gige_list[a35Index].model, handle->stream.address);
117 
118  if (handle == NULL)
119  {
120  printf("Couldn't open camera\n");
121  exit(-12);
122  }
123 
124  handle->maxwidth = 350;
125  handle->maxheight = 256;
126 
127  // Set width & height of camera image
128  if (width > handle->maxwidth)
129  {
130  handle->width = handle->maxwidth;
131  }
132  else
133  {
134  handle->width = width;
135  }
136  gige_writereg(handle, A35_WIDTH, handle->width); // Set Desired Width
137 
138  if (height > handle->maxheight)
139  {
140  handle->height = handle->maxheight;
141  }
142  else
143  {
144  handle->height = height;
145  }
146  gige_writereg(handle, A35_HEIGHT, handle->height); // Set Desired height
147 
148  handle->bestsize = 4 * handle->width + 28 +8;
149  gige_writereg(handle, GIGE_REG_SCPS, handle->bestsize);
150 
151  gige_writereg(handle,0xE984, 3); // Set to 14 bit mode
152  gige_writereg(handle,0xD308, 0x01100025); // Set pixels to 14 bit
153 
154  // Set shutter to manual
155  gige_writereg(handle, A35_FFCMODE, 0); // Set FFC to manual
156  gige_writereg(handle,0xE938,0); // Do Shutter
157 
158  // Set digital output to 14 bit
160 
161  //if(FrameRate==60)
162 // {
163  // gige_writereg(handle,A35_SENSORVIDEOSTANDARD,A35_SENSORVIDEOSTANDARD_60HZ);
164  //} else
165 // {
166 
167  // Set frame rate 30 Hz
169  //}
170 
171  // Set the number of frames to skip (i.e. A35_SKIP1 means skip every other frame).
172  gige_writereg(handle, A35_FRAMESTOSKIP, A35_SKIP0); // Set Desired Width
173 
174 
175  // Set LVDSMode to disabled
176  //gige_writereg(handle,A35_LVDSMODE,0); // Disable LVDS (shouldn't be neccessary)
177  // Set XPMode to CMOS
178  //gige_writereg(handle,A35_XPMODE,A35_XPMODE_CMOS); // Set XPMODE to CMOS (shouldn't be neccessary)
179 
180 
181  // *****************************************************************************
182  // *****************************************************************************
183  // ********************** Second Port for Data ***************************
184  // *****************************************************************************
185  // *****************************************************************************
186  printf("Done Init\n");
187  return(true);
188 }
#define A35_SKIP0
Definition: gige_lib.h:453
int i
Definition: rw_test.cpp:37
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
vector< gige_acknowledge_ack > gige_discover()
Discover GIGE Camera.
Definition: gige_lib.cpp:332
char address[17]
Definition: socketlib.h:134
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
#define A35_PIXELFORMAT
Definition: gige_lib.h:420
char address[]
Definition: netperf_listen.cpp:69
#define A35_SENSORVIDEOSTANDARD_30HZ
Definition: gige_lib.h:447
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203
static uint16_t model
Definition: add_radio.cpp:19
double lap()
Lap Time.
Definition: elapsedtime.cpp:145
char * gige_value_to_address(uint32_t value)
IP Value to address.
Definition: gige_lib.cpp:418
Definition: elapsedtime.h:62
#define A35_FFCMODE
Definition: gige_lib.h:429
uint16_t maxheight
Detector Height.
Definition: gige_lib.h:363
#define A35_HEIGHT
Definition: gige_lib.h:419
socket_channel stream
Stream channel.
Definition: gige_lib.h:341
gige_handle * gige_open(char address[18], uint8_t privilege, uint32_t heartbeat_msec, uint32_t socket_usec, uint32_t streambps)
Connect to camera.
Definition: gige_lib.cpp:64
#define A35_WIDTH
Definition: gige_lib.h:418
uint16_t height
Requested Height.
Definition: gige_lib.h:367
#define GIGE_REG_SCPS
Definition: gige_lib.h:139
#define A35_FRAMESTOSKIP
Definition: gige_lib.h:417
uint16_t width
Requested Width.
Definition: gige_lib.h:365
#define A35_SENSORVIDEOSTANDARD
Definition: gige_lib.h:430
#define A35_PIXELFORMAT_14BIT
Definition: gige_lib.h:444
uint16_t bestsize
Best packet size.
Definition: gige_lib.h:359
uint16_t maxwidth
Detector Width.
Definition: gige_lib.h:361
bool GetCameraFrame ( gige_handle handle,
uint16_t *  A35FrameBuffer,
uint32_t  ImageSize 
)
193 {
194 // int16_t iretn;
195  uint8_t bufferin[GIGE_MAX_PACKET];
196  uint8_t *TempBuf;
197  //uint8_t NumSteps;
198  //uint16_t ImageNum;
199  //uint16_t RemainingBytes;
200  int16_t bytes_recieved=0;
201  uint32_t PacketNum=0;
202  uint32_t MaxPacketNum;
203  uint32_t FrameNum;
204  static uint32_t FrameCount=0;
205 // static int32_t LastPacketCount=-1;
206  static uint32_t PacketCount;
207  uint32_t bsize=GIGE_MAX_PACKET;
208  uint8_t PacketType;
209  uint32_t PayloadSize, FramePtr;
210 // struct timeval StartTime;
211 // struct timeval PresentTime;
212 // int64_t Duration, seconds, useconds;
213 
214 
215  PacketCount = 0;
216  PayloadSize = PacketSize-28-8;
217  MaxPacketNum = ImageSize*sizeof(uint16_t)/PayloadSize;
218  TempBuf = (uint8_t*)A35FrameBuffer;
219 
220  //printf("Entering data acquisition routine.\n");
221 
222  // Handshake with camera every 1.5 seconds (30 fps)
223  FrameCount++;
224  if( (FrameCount%15) == 0 )
225  {
226  gige_writereg(handle,GIGE_REG_CCP, 2);
227  }
228 
229  // Get time for timeout
230 // gettimeofday(&StartTime, NULL);
231  ElapsedTime et;
232  et.start();
233 
234 
235 
236  // Loop untill we get the tail packet (then we return)
237  do
238  {
239  // Loop untill we get a packet
240  bytes_recieved=0;
241 
242  while(bytes_recieved <= 0)
243  {
244  bytes_recieved=recvfrom(handle->stream.cudp,(char *)bufferin,bsize,0,static_cast<struct sockaddr *>(nullptr),static_cast<socklen_t *>(nullptr));
245 // printf("br=%d " , bytes_recieved);
246 
247  if(bytes_recieved==-1)
248  {
249  COSMOS_USLEEP(5000);
250 
251  // 500ms timeout
252 // gettimeofday(&PresentTime, NULL);
253 // seconds = PresentTime.tv_sec - StartTime.tv_sec;
254 // useconds = PresentTime.tv_usec - StartTime.tv_usec;
255 // Duration = seconds*1000000.0 + useconds;
256 // if(Duration > 1000000)
257  if (et.lap() > 1.)
258  {
259  printf("Timeout2\n");
260  return(false); // Timeout
261  }
262  }
263  }
264 
265  FrameNum = (bufferin[2]<<8) + bufferin[3]; // Get image number
266  PacketType = bufferin[4];
267  PacketNum = (bufferin[5]<<16) + (bufferin[6]<<8) + bufferin[7]; // Get image number
268 // printf("\n>>PCount=%u, PNum=%u , Type=%u<< ", PacketCount , PacketNum , PacketType);
269 
270  // If lost packets. (The present packet is more than the PacketCount)
271  if (PacketNum > PacketCount)
272  {
273  // If we only missed the header packet, just set the PacketCount
274  // Oterwise fill lost data with zeros
275 
276  printf("Lost Packet. PNum=%u, PCount=%u\n" , PacketNum, PacketCount);
277  if(PacketNum>1)
278  {
279  if(PacketCount==0)
280  {
281  // Since packet 0 is header, we need to handle differently.
282  TempBuf = (uint8_t*)A35FrameBuffer;
283  memset(TempBuf, 0, PayloadSize * (PacketNum-1));
284  TempBuf+=(PayloadSize * (PacketNum-1));
285  }
286  else
287  {
288  FramePtr = (PacketCount-1)*PayloadSize;
289  TempBuf = (uint8_t*)A35FrameBuffer + FramePtr;
290  memset(TempBuf, 0, PayloadSize * (PacketNum-PacketCount));
291  TempBuf+=PayloadSize;
292  }
293  }
294  PacketCount = PacketNum;
295  }
296 
297  // If packetCount is greater than the recieved packet number, we missed the tail packet (and are recieving the next frame).
298  // Zero out lost packets and exit (for now lose the data from the new packet)
299  if(PacketNum < PacketCount)
300  {
301  printf("Lost Tail Packet. PNum=%u, PCount=%u\n" , PacketNum, PacketCount);
302  FramePtr = (PacketCount-1)*PayloadSize;
303  TempBuf = (uint8_t*)A35FrameBuffer + FramePtr;
304  memset(TempBuf, 0, PayloadSize * (MaxPacketNum-PacketCount));
305  return(true);
306  }
307 
308  switch(PacketType)
309  {
310  case 1: // Start packet
311 // printf("Start packet. FrameNum=%u -> " , FrameNum);
312  break;
313  case 2: // Tail packet
314  // Exit if tail packet
315 // printf("Tail packet FrameNum=%u, PackCnt=%d\n" , FrameNum, PacketCount);
316  return(true);
317  case 3: // Data packet
318 // printf("Data: FrameNum=%u, FrmCnt=%u, PkNum=%u, BytesRcvd=%d\n" , FrameNum, FrameCount, PacketNum, bytes_recieved);
319  // get packet data.
320  if(bytes_recieved<8)
321  {
322  printf("Error recieving frame\n");
323  return(true);
324  }
325 
326  // Copy camera image into A35FrameBuffer
327  memcpy(TempBuf, &bufferin[8], bytes_recieved-8);
328  TempBuf += bytes_recieved-8;
329  /*
330  for(i=0 ; i<bytes_recieved-8 ; i++)
331  {
332  *TempBuf = bufferin[8+i];
333  TempBuf++;
334  }
335  */
336  break;
337  default:
338  printf("\n\n>>>>> Unknown PackType=%u, PackNum=%u, FrameNum=%u, FrmCnt=%u, \n" , PacketType, PacketNum, FrameNum, FrameCount);
339  return(false);
340  }
341 
342 // LastPacketCount = PacketCount;
343  PacketCount++;
344 
345  } while(true);
346 
347  return(true);
348 }
uint16_t bsize
Definition: netperf_listen.cpp:71
int32_t ImageSize
#define GIGE_MAX_PACKET
Definition: gige_lib.h:162
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203
int32_t cudp
Definition: socketlib.h:120
double lap()
Lap Time.
Definition: elapsedtime.cpp:145
#define GIGE_REG_CCP
Definition: gige_lib.h:126
Definition: elapsedtime.h:62
unsigned int PacketSize
Definition: acq_a35.cpp:51
socket_channel stream
Stream channel.
Definition: gige_lib.h:341
void StartCamera ( gige_handle handle)
354 {
355  // Start Grabbing Frames
358 
359  gige_writereg(handle, A35_ACQUISITIONSTART, 0x1);
360 }
#define GIGE_REG_SCDA
Definition: gige_lib.h:143
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
char address[17]
Definition: socketlib.h:134
uint16_t cport
Definition: socketlib.h:130
#define A35_ACQUISITIONSTART
Definition: gige_lib.h:421
socket_channel stream
Stream channel.
Definition: gige_lib.h:341
uint32_t gige_address_to_value(char *address)
IP Address to value.
Definition: gige_lib.cpp:400
#define GIGE_REG_STREAM_CHANNEL_PORT
Definition: gige_lib.h:136
int ShutdownCamera ( gige_handle handle)
365 {
366  // Stop Grabbing Frames
367  gige_writereg(handle, A35_ACQUISITIONSTOP, 0x1);
368  gige_writereg(handle,GIGE_REG_SCP,0);
369 
370  gige_close(handle);
371  return(0);
372 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define GIGE_REG_SCP
Definition: gige_lib.h:137
#define A35_ACQUISITIONSTOP
Definition: gige_lib.h:422
void gige_close(gige_handle *handle)
Close GigE Camera.
Definition: gige_lib.cpp:177
bool ResetCamera ( gige_handle handle)
378 {
379  gige_writereg(handle, A35_CAMERAHEADRESET, 0); // Set FFC to Auto
380  return(true);
381 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define A35_CAMERAHEADRESET
Definition: gige_lib.h:425
bool AutoFFC ( gige_handle handle)
388 {
389  gige_writereg(handle, A35_FFCMODE, A35_FFCMODE_AUTO); // Set FFC to Auto
390  return(true);
391 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define A35_FFCMODE
Definition: gige_lib.h:429
#define A35_FFCMODE_AUTO
Definition: gige_lib.h:450
bool ManualFFC ( gige_handle handle)
397 {
398  gige_writereg(handle, A35_FFCMODE, A35_FFCMODE_MANUAL); // Set FFC to manual
399  return(true);
400 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define A35_FFCMODE_MANUAL
Definition: gige_lib.h:449
#define A35_FFCMODE
Definition: gige_lib.h:429
bool DoFFC ( gige_handle handle)
405 {
406  gige_writereg(handle,A35_COMMAND_DOFFC,0); // Do Shutter
407  return(true);
408 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define A35_COMMAND_DOFFC
Definition: gige_lib.h:428
bool GetTemperature ( gige_handle handle)
411 {
412  gige_writereg(handle,A35_TEMPERATUREFPA,0); // Get temperature
413  return(true);
414 }
#define A35_TEMPERATUREFPA
Definition: gige_lib.h:427
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
bool SetFramesToSkip ( int  FramesToSkip,
gige_handle handle 
)
417 {
418  FramesToSkip = (FramesToSkip << 16) & 0xFFF0000;
419  gige_writereg(handle, A35_FRAMESTOSKIP, FramesToSkip);
420  return(true);
421 }
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
#define A35_FRAMESTOSKIP
Definition: gige_lib.h:417
bool SetPacketDelay ( int  PacketDelay,
gige_handle handle 
)
424 {
425  gige_writereg(handle, A35_PACKETDELAY, PacketDelay); // Get temperature
426  return(true);
427 }
#define A35_PACKETDELAY
Definition: gige_lib.h:415
int gige_writereg(gige_handle *handle, uint32_t address, uint32_t data)
Write Register.
Definition: gige_lib.cpp:192
void WriteRegister ( gige_handle handle,
int16_t  command,
int16_t  param1,
int16_t  param2,
int16_t  param3 
)
bool SetFramesToSkip ( gige_handle handle,
int  FramesToSkip 
)
bool SetPacketDelay ( gige_handle handle,
int  PacketDelay 
)