#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"
Go to the source code of this file.
Defines | |
#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. | |
#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) |
#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.
int wge100Configure | ( | IpCamList * | camInfo, |
const char * | ipAddress, | ||
unsigned | wait_us | ||
) |
Configures the IP address of one specific camera.
camInfo | Structure describing the camera to configure |
ipAddress | An 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_us | The number of microseconds to wait for a reply from the camera |
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
camInfo | Describes the camera to connect to |
serial | Is the 32-bit unique serial number to assign (the product ID portion is already fixed) |
mac | Is the 48-bit unique MAC address to assign to the board |
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.
ifName | The ethernet interface name to use. Null terminated string (e.g., "eth0"). Empty means to query all interfaces. |
ipCamList | The list to which the new cameras should be added |
wait_us | The number of microseconds to wait for replies |
Definition at line 372 of file wge100lib.c.
static int wge100DiscoverSend | ( | const char * | ifName, |
const char * | ipAddress | ||
) | [static] |
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.
url | The url of the camera to find |
camera | The structure to fill the camera information into |
wait_us | The number of microseconds to wait before timing out |
errmsg | String containing a descriptive parse error message |
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.
camInfo | Describes the camera to connect to. |
address | Specifies the 12-bit flash page address to read (0-4095) |
pageDataOut | Points to at least FLASH_PAGE_SIZE bytes of storage in which to place the flash data. |
retries | Indicates the maximum allowed number of retries. |
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.
camInfo | Describes the camera to connect to. |
address | Specifies the 12-bit flash page address to write (0-4095) |
pageDataOut | Points to at least FLASH_PAGE_SIZE bytes of storage from which to get the flash data. |
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.
camInfo | Describes the camera to connect to |
time_us | Points to the location to store the system time in us |
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.
camInfo | Describes the camera to connect to |
mode | The mode number to select, range (0..9) |
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.
camInfo | Describes the camera to connect to |
horizontal | The number of 8-bit image pixels per line of video. Maximum value 752. |
vertical | The number of video lines per frame. |
Definition at line 1548 of file wge100lib.c.
int wge100libVersion | ( | ) |
Returns the version information for the library
Definition at line 59 of file wge100lib.c.
int wge100ReconfigureFPGA | ( | IpCamList * | camInfo | ) |
Instructs one camera to reconfigure its FPGA.
camInfo | Describes the camera that should reconfigure its FPGA. |
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.
camInfo | Describes the camera to connect to. |
address | Specifies the 12-bit flash page address to read (0-4095) |
pageDataOut | Points to at least FLASH_PAGE_SIZE bytes of storage in which to place the flash data. |
retries | Maximum number of retries. Decremented for each retry. NULL does 10 retries. |
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.
camInfo | Describes the camera to connect to. |
address | Specifies the 12-bit flash page address to write (0-4095) |
pageDataOut | Points to at least FLASH_PAGE_SIZE bytes of storage from which to get the flash data. |
retries | Maximum number of retries. Decremented for each retry. NULL does 10 retries. |
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.
camInfo | Describes the camera to connect to |
reg | The 8-bit register address to read from data Pointer to 16 bits of storage to write the value to |
retries | Maximum number of retries. Decremented for each retry. NULL does 10 retries. |
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.
camInfo | Describes the camera to connect to |
reg | The 8-bit register address to write into data 16-bit value to write into the register |
retries | Maximum number of retries. Decremented for each retry. NULL does 10 retries. |
Definition at line 1252 of file wge100lib.c.
int wge100Reset | ( | IpCamList * | camInfo | ) |
Instructs one camera to execute a soft reset.
camInfo | Describes the camera to reset. |
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.
camInfo | Describes the camera to connect to |
reg | The 8-bit register address to read from data Pointer to 16 bits of storage to write the value to |
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.
camInfo | Describes the camera to connect to |
index | The index (0..3) of the register to set |
reg | The 8-bit address of the register to read at position 'index', or I2C_AUTO_REG_UNUSED. |
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.
camInfo | Describes the camera to connect to |
reg | The 8-bit register address to write into data 16-bit value to write into the register |
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.
camInfo | Structure that describes the camera to contact |
mac | Contains the MAC address of the host that will receive the video |
ipAddress | An ASCII string in dotted quad form containing the IP address of the host that will receive the video (e.g., "192.168.0.5") |
port | The port number that the video should be sent to. Host byte order. |
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.
s | The open, bound & 'connected' socket to listen on |
wait_us | The number of microseconds to wait before timing out |
type | Points to the location to store the type of status packet |
code | Points to the location to store the subtype/error code |
Definition at line 287 of file wge100lib.c.
int wge100StopVid | ( | const IpCamList * | camInfo | ) |
Instructs one camera to stop sending video.
camInfo | Describes the camera to send the stop to. |
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.
camInfo | Describes the camera to connect to |
triggerType | Can be either TRIG_STATE_INTERNAL or TRIG_STATE_EXTERNAL |
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.