Macros | Functions
wge100lib.c File Reference
#include "wge100_camera/wge100lib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <net/if.h>
#include <ifaddrs.h>
#include "wge100_camera/host_netutil.h"
#include "wge100_camera/ipcam_packet.h"
Include dependency graph for wge100lib.c:

Go to the source code of this file.

Macros

#define LINE_NUMBER_MASK   0x3FF
 
#define MAX_HORIZ_RESOLUTION   752
 
#define STD_REPLY_TIMEOUT   SEC_TO_USEC(0.2)
 Amount of time in microseconds that the host should wait for packet replies. More...
 
#define STOP_REPLY_TIMEOUT   SEC_TO_USEC(0.001)
 

Functions

int wge100Configure (IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
 
int wge100ConfigureBoard (const IpCamList *camInfo, uint32_t serial, MACAddress *mac)
 
int wge100Discover (const char *ifName, IpCamList *ipCamList, const char *ipAddress, unsigned wait_us)
 
static int wge100DiscoverSend (const char *ifName, const char *ipAddress)
 
int wge100FindByUrl (const char *url, IpCamList *camera, unsigned wait_us, const char **errmsg)
 
int wge100FlashRead (const IpCamList *camInfo, uint32_t address, uint8_t *pageDataOut)
 
int wge100FlashWrite (const IpCamList *camInfo, uint32_t address, const uint8_t *pageDataIn)
 
int wge100GetTimer (const IpCamList *camInfo, uint64_t *time_us)
 
int wge100ImagerModeSelect (const IpCamList *camInfo, uint32_t mode)
 
int wge100ImagerSetRes (const IpCamList *camInfo, uint16_t horizontal, uint16_t vertical)
 
int wge100libVersion ()
 
int wge100ReconfigureFPGA (IpCamList *camInfo)
 
int wge100ReliableFlashRead (const IpCamList *camInfo, uint32_t address, uint8_t *pageDataOut, int *retries)
 
int wge100ReliableFlashWrite (const IpCamList *camInfo, uint32_t address, const uint8_t *pageDataIn, int *retries)
 
int wge100ReliableSensorRead (const IpCamList *camInfo, uint8_t reg, uint16_t *data, int *retries)
 
int wge100ReliableSensorWrite (const IpCamList *camInfo, uint8_t reg, uint16_t data, int *retries)
 
int wge100Reset (IpCamList *camInfo)
 
int wge100SensorRead (const IpCamList *camInfo, uint8_t reg, uint16_t *data)
 
int wge100SensorSelect (const IpCamList *camInfo, uint8_t index, uint32_t reg)
 
int wge100SensorWrite (const IpCamList *camInfo, uint8_t reg, uint16_t data)
 
int wge100StartVid (const IpCamList *camInfo, const uint8_t mac[6], const char *ipAddress, uint16_t port)
 
int wge100StatusWait (int s, uint32_t wait_us, uint32_t *type, uint32_t *code)
 
int wge100StopVid (const IpCamList *camInfo)
 
int wge100TriggerControl (const IpCamList *camInfo, uint32_t triggerType)
 
int wge100VidReceive (const char *ifName, uint16_t port, size_t height, size_t width, FrameHandler frameHandler, void *userData)
 
int wge100VidReceiveAuto (IpCamList *camera, size_t height, size_t width, FrameHandler frameHandler, void *userData)
 
int wge100VidReceiveSocket (int s, size_t height, size_t width, FrameHandler frameHandler, void *userData)
 
static void xormem (uint8_t *dst, uint8_t *src, size_t w)
 

Macro Definition Documentation

#define LINE_NUMBER_MASK   0x3FF

Definition at line 1593 of file wge100lib.c.

#define MAX_HORIZ_RESOLUTION   752

Definition at line 1592 of file wge100lib.c.

#define STD_REPLY_TIMEOUT   SEC_TO_USEC(0.2)

Amount of time in microseconds that the host should wait for packet replies.

Definition at line 50 of file wge100lib.c.

#define STOP_REPLY_TIMEOUT   SEC_TO_USEC(0.001)

Definition at line 51 of file wge100lib.c.

Function Documentation

int wge100Configure ( IpCamList camInfo,
const char *  ipAddress,
unsigned  wait_us 
)

Configures the IP address of one specific camera.

Parameters
camInfoStructure describing the camera to configure
ipAddressAn ASCII string containing the new IP address to assign (e.g., "192.168.0.5"). If it is NULL or empty, the address in camInfo is used, and the configure packet is not broadcast.
wait_usThe number of microseconds to wait for a reply from the camera
Returns
Returns -1 with errno set for system call failures. Returns 0 for success Returns ERR_TIMEOUT if no reply is received before the timeout expires

Definition at line 532 of file wge100lib.c.

int wge100ConfigureBoard ( const IpCamList camInfo,
uint32_t  serial,
MACAddress mac 
)

Sets the permanent serial number and MAC configuration for one camera

Warning
: This command can only be sent once per camera. The changes are permanent.
Parameters
camInfoDescribes the camera to connect to
serialIs the 32-bit unique serial number to assign (the product ID portion is already fixed)
macIs the 48-bit unique MAC address to assign to the board
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1194 of file wge100lib.c.

int wge100Discover ( const char *  ifName,
IpCamList ipCamList,
const char *  ipAddress,
unsigned  wait_us 
)

Discovers all WGE100 cameras that are connected to the 'ifName' ethernet interface and adds new ones to the 'ipCamList' list.

Parameters
ifNameThe ethernet interface name to use. Null terminated string (e.g., "eth0"). Empty means to query all interfaces.
ipCamListThe list to which the new cameras should be added
wait_usThe number of microseconds to wait for replies
Returns
Returns -1 with errno set for system call errors. Otherwise returns number of new cameras found.

Definition at line 372 of file wge100lib.c.

static int wge100DiscoverSend ( const char *  ifName,
const char *  ipAddress 
)
static
Todo:
We guess an IP by flipping the host bits of the local IP. Horrible, but won't usually be a problem even if we hit an IP that is already in use.

Definition at line 314 of file wge100lib.c.

int wge100FindByUrl ( const char *  url,
IpCamList camera,
unsigned  wait_us,
const char **  errmsg 
)

Finds a camera matching the given name

Names are of the form:

name://camera_name[@camera_ip][#local_interface]
serial://serial_number[@camera_ip][#local_interface]
any://[@camera_ip][#local_interface] 

A name URL indicates the name of the camera to be found. A serial URL indicates the serial number of the camera to be found. An any URL will match any camera, but if more than one camera is found, it will fail.

Optionally, the ip address that the camera should be set to can be specified by prefixing it with a @ sign, and the interface through which to access the camera can be specified by prefixing it with a # sign.

When an ip address is specified, it will be copied into the camera struct.

Parameters
urlThe url of the camera to find
cameraThe structure to fill the camera information into
wait_usThe number of microseconds to wait before timing out
errmsgString containing a descriptive parse error message
Returns
Returns 0 if a camera was found, -1 and sets errmsg if an error occurred.

Definition at line 94 of file wge100lib.c.

int wge100FlashRead ( const IpCamList camInfo,
uint32_t  address,
uint8_t *  pageDataOut 
)

Reads one FLASH_PAGE_SIZE byte page of the camera's onboard Atmel dataflash.

Parameters
camInfoDescribes the camera to connect to.
addressSpecifies the 12-bit flash page address to read (0-4095)
pageDataOutPoints to at least FLASH_PAGE_SIZE bytes of storage in which to place the flash data.
retriesIndicates the maximum allowed number of retries.
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 940 of file wge100lib.c.

int wge100FlashWrite ( const IpCamList camInfo,
uint32_t  address,
const uint8_t *  pageDataIn 
)

Writes one FLASH_PAGE_SIZE byte page to the camera's onboard Atmel dataflash.

Parameters
camInfoDescribes the camera to connect to.
addressSpecifies the 12-bit flash page address to write (0-4095)
pageDataOutPoints to at least FLASH_PAGE_SIZE bytes of storage from which to get the flash data.
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1077 of file wge100lib.c.

int wge100GetTimer ( const IpCamList camInfo,
uint64_t *  time_us 
)

Gets the system time of a specified camera.

In the camera, system time is tracked as a number of clock 'ticks' since the last hard reset. This function receives the number of 'ticks' as well as a 'ticks_per_sec' conversion factor to return a 64-bit time result in microseconds.

Parameters
camInfoDescribes the camera to connect to
time_usPoints to the location to store the system time in us
Returns
Returns 0 for success, -1 for system error, or 1 for protocol error.

Definition at line 832 of file wge100lib.c.

int wge100ImagerModeSelect ( const IpCamList camInfo,
uint32_t  mode 
)

Selects one of the 10 pre-programmed imager modes in the specified camera.

Parameters
camInfoDescribes the camera to connect to
modeThe mode number to select, range (0..9)
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1491 of file wge100lib.c.

int wge100ImagerSetRes ( const IpCamList camInfo,
uint16_t  horizontal,
uint16_t  vertical 
)

Provides for manually setting non-standard imager modes. Use only with extreme caution.

Warning
The imager frame size set by I2C must match the one used by the firmware, or system failure could result.
Parameters
camInfoDescribes the camera to connect to
horizontalThe number of 8-bit image pixels per line of video. Maximum value 752.
verticalThe number of video lines per frame.
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1548 of file wge100lib.c.

int wge100libVersion ( )

Returns the version information for the library

Returns
Returns the the library as an integer 0x0000MMNN, where MM = Major version and NN = Minor version

Definition at line 59 of file wge100lib.c.

int wge100ReconfigureFPGA ( IpCamList camInfo)

Instructs one camera to reconfigure its FPGA.

Parameters
camInfoDescribes the camera that should reconfigure its FPGA.
Returns
Returns 0 for success Returns -1 for system errors

Definition at line 750 of file wge100lib.c.

int wge100ReliableFlashRead ( const IpCamList camInfo,
uint32_t  address,
uint8_t *  pageDataOut,
int *  retries 
)

Reads one FLASH_PAGE_SIZE byte page of the camera's onboard Atmel dataflash. Does repeated attempts if an error occurs.

Parameters
camInfoDescribes the camera to connect to.
addressSpecifies the 12-bit flash page address to read (0-4095)
pageDataOutPoints to at least FLASH_PAGE_SIZE bytes of storage in which to place the flash data.
retriesMaximum number of retries. Decremented for each retry. NULL does 10 retries.
Returns
Returns 0 for success Returns -2 for out of retries Returns -1 for system error Returns 1 for protocol error

Definition at line 906 of file wge100lib.c.

int wge100ReliableFlashWrite ( const IpCamList camInfo,
uint32_t  address,
const uint8_t *  pageDataIn,
int *  retries 
)

Writes one FLASH_PAGE_SIZE byte page to the camera's onboard Atmel dataflash. Repeats the write until the written value matches, and reads back the written page to check that it has been correctly written.

Parameters
camInfoDescribes the camera to connect to.
addressSpecifies the 12-bit flash page address to write (0-4095)
pageDataOutPoints to at least FLASH_PAGE_SIZE bytes of storage from which to get the flash data.
retriesMaximum number of retries. Decremented for each retry. NULL does 10 retries.
Returns
Returns 0 for success Returns -2 for out of retries Returns -1 for system error Returns 1 for protocol error

Definition at line 1014 of file wge100lib.c.

int wge100ReliableSensorRead ( const IpCamList camInfo,
uint8_t  reg,
uint16_t *  data,
int *  retries 
)

Reads the value of one image sensor I2C register on one camera. Retries if there are any errors.

Parameters
camInfoDescribes the camera to connect to
regThe 8-bit register address to read from data Pointer to 16 bits of storage to write the value to
retriesMaximum number of retries. Decremented for each retry. NULL does 10 retries.
Returns
Returns 0 for success Returns -2 for out of retries Returns -1 for system error Returns 1 for protocol error

Definition at line 1349 of file wge100lib.c.

int wge100ReliableSensorWrite ( const IpCamList camInfo,
uint8_t  reg,
uint16_t  data,
int *  retries 
)

Writes to one image sensor I2C register on one camera. Repeats reads and reads back written value until it gets a match.

Parameters
camInfoDescribes the camera to connect to
regThe 8-bit register address to write into data 16-bit value to write into the register
retriesMaximum number of retries. Decremented for each retry. NULL does 10 retries.
Returns
Returns 0 for success Returns -2 for out of retries Returns -1 for system error Returns 1 for protocol error

Definition at line 1252 of file wge100lib.c.

int wge100Reset ( IpCamList camInfo)

Instructs one camera to execute a soft reset.

Parameters
camInfoDescribes the camera to reset.
Returns
Returns 0 for success Returns -1 for system errors

Definition at line 788 of file wge100lib.c.

int wge100SensorRead ( const IpCamList camInfo,
uint8_t  reg,
uint16_t *  data 
)

Reads the value of one image sensor I2C register on one camera.

Parameters
camInfoDescribes the camera to connect to
regThe 8-bit register address to read from data Pointer to 16 bits of storage to write the value to
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1378 of file wge100lib.c.

int wge100SensorSelect ( const IpCamList camInfo,
uint8_t  index,
uint32_t  reg 
)

Sets the address of one of the four automatically read I2C registers on one camera.

Parameters
camInfoDescribes the camera to connect to
indexThe index (0..3) of the register to set
regThe 8-bit address of the register to read at position 'index', or I2C_AUTO_REG_UNUSED.
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1438 of file wge100lib.c.

int wge100SensorWrite ( const IpCamList camInfo,
uint8_t  reg,
uint16_t  data 
)

Writes to one image sensor I2C register on one camera.

Parameters
camInfoDescribes the camera to connect to
regThe 8-bit register address to write into data 16-bit value to write into the register
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1291 of file wge100lib.c.

int wge100StartVid ( const IpCamList camInfo,
const uint8_t  mac[6],
const char *  ipAddress,
uint16_t  port 
)

Instructs one camera to begin streaming video to the host/port specified.

Parameters
camInfoStructure that describes the camera to contact
macContains the MAC address of the host that will receive the video
ipAddressAn ASCII string in dotted quad form containing the IP address of the host that will receive the video (e.g., "192.168.0.5")
portThe port number that the video should be sent to. Host byte order.
Returns
Returns -1 with errno set for system call failures Returns 0 for success Returns 1 for protocol failures (timeout, etc)

Definition at line 638 of file wge100lib.c.

int wge100StatusWait ( int  s,
uint32_t  wait_us,
uint32_t *  type,
uint32_t *  code 
)

Waits for a WGE100 StatusPacket on the specified socket for a specified duration.

The Status type and code will be reported back to the called via the 'type' & 'code' arguments. If the timeout expires before a valid status packet is received, then the function will still return zero but will indicate that a TIMEOUT error has occurred.

Parameters
sThe open, bound & 'connected' socket to listen on
wait_usThe number of microseconds to wait before timing out
typePoints to the location to store the type of status packet
codePoints to the location to store the subtype/error code
Returns
Returns 0 if no system errors occured. -1 with errno set otherwise.

Definition at line 287 of file wge100lib.c.

int wge100StopVid ( const IpCamList camInfo)

Instructs one camera to stop sending video.

Parameters
camInfoDescribes the camera to send the stop to.
Returns
Returns 0 for success Returns -1 with errno set for system errors Returns 1 for protocol errors

Definition at line 700 of file wge100lib.c.

int wge100TriggerControl ( const IpCamList camInfo,
uint32_t  triggerType 
)

Sets the trigger type (internal or external) for one camera.

Parameters
camInfoDescribes the camera to connect to
triggerTypeCan be either TRIG_STATE_INTERNAL or TRIG_STATE_EXTERNAL
Returns
Returns 0 for success Returns -1 for system error Returns 1 for protocol error

Definition at line 1135 of file wge100lib.c.

int wge100VidReceive ( const char *  ifName,
uint16_t  port,
size_t  height,
size_t  width,
FrameHandler  frameHandler,
void *  userData 
)

Definition at line 1889 of file wge100lib.c.

int wge100VidReceiveAuto ( IpCamList camera,
size_t  height,
size_t  width,
FrameHandler  frameHandler,
void *  userData 
)

Definition at line 1908 of file wge100lib.c.

int wge100VidReceiveSocket ( int  s,
size_t  height,
size_t  width,
FrameHandler  frameHandler,
void *  userData 
)

Definition at line 1595 of file wge100lib.c.

static void xormem ( uint8_t *  dst,
uint8_t *  src,
size_t  w 
)
static

Definition at line 308 of file wge100lib.c.



wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Mon Jun 10 2019 15:44:16