summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-04-29 04:50:52 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-04-29 04:50:52 +0200
commitab46db4c388d126095e8e4d8fc3d7aa191a3d649 (patch)
tree0e1e7ba97bae7c49849e76c44e4cfe2576807955
parentc177a207d4c1a02d9093b03fdd64533d2dbfa9b6 (diff)
downloadipecamera-ab46db4c388d126095e8e4d8fc3d7aa191a3d649.tar.gz
ipecamera-ab46db4c388d126095e8e4d8fc3d7aa191a3d649.tar.bz2
ipecamera-ab46db4c388d126095e8e4d8fc3d7aa191a3d649.tar.xz
ipecamera-ab46db4c388d126095e8e4d8fc3d7aa191a3d649.zip
Added a small grabbing example
-rw-r--r--.bzrignore1
-rw-r--r--CMakeLists.txt2
-rw-r--r--apps/CMakeLists.txt13
-rw-r--r--apps/grab.c49
-rw-r--r--base.c2
5 files changed, 66 insertions, 1 deletions
diff --git a/.bzrignore b/.bzrignore
index 164f343..d08bc93 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -3,3 +3,4 @@ Makefile
cmake_install.cmake
CMakeCache.txt
install_manifest.txt
+grab
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65db8c9..2bcfc15 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@ pkg_check_modules(UFODECODE ufodecode>=0.3 REQUIRED)
pkg_check_modules(PCILIB pcitool>=0.2 REQUIRED)
exec_program("pkg-config --variable=plugindir pcitool" OUTPUT_VARIABLE PCILIB_PLUGIN_DIR)
+add_subdirectory(apps)
+
include_directories(
${CMAKE_SOURCE_DIR}
${UFODECODE_INCLUDE_DIRS}
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
new file mode 100644
index 0000000..761bb2b
--- /dev/null
+++ b/apps/CMakeLists.txt
@@ -0,0 +1,13 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${PCILIB_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${CMAKE_BINARY_DIR}
+ ${PCILIB_LIBRARY_DIRS}
+)
+
+
+add_executable(grab grab.c)
+target_link_libraries(grab ${PCILIB_LIBRARIES} ipecamera)
diff --git a/apps/grab.c b/apps/grab.c
new file mode 100644
index 0000000..0f90e71
--- /dev/null
+++ b/apps/grab.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+
+#include <pcilib.h>
+#include <pcilib/error.h>
+
+#include <ipecamera.h>
+
+int main() {
+ int err;
+ pcilib_event_id_t evid;
+ ipecamera_event_info_t info;
+ ipecamera_t *ipecamera;
+ size_t size;
+ void *data;
+ FILE *f;
+
+ pcilib_t *pcilib = pcilib_open("/dev/fpga0", "ipecamera");
+ if (!pcilib) pcilib_error("Error opening device");
+
+ ipecamera = (ipecamera_t*)pcilib_get_event_engine(pcilib);
+ if (!ipecamera) pcilib_error("Failed to get ipecamera event engine");
+
+ err = ipecamera_set_buffer_size(ipecamera, 8);
+ if (err) pcilib_error("Error (%i) setting buffer size", err);
+
+ err = pcilib_start(pcilib, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
+ if (err) pcilib_error("Error (%i) starting event engine", err);
+
+ err = pcilib_trigger(pcilib, PCILIB_EVENT0, 0, NULL);
+ if (err) pcilib_error("Error (%i) triggering event", err);
+
+ err = pcilib_get_next_event(pcilib, 100000, &evid, sizeof(info), (pcilib_event_info_t*)&info);
+ if (err) pcilib_error("Error (%i) while waiting for event", err);
+
+ data = pcilib_get_data(pcilib, evid, PCILIB_EVENT_DATA, &size);
+ if (!data) pcilib_error("Error getting event data");
+
+ printf("Writting %zu bytes to /dev/null\n", size);
+ f = fopen("/dev/null", "w");
+ if (f) {
+ fwrite(data, 1, size, f);
+ fclose(f);
+ }
+
+ err = pcilib_return_data(pcilib, evid, PCILIB_EVENT_DATA, data);
+ if (err) pcilib_error("Error returning data, data is possibly corrupted");
+
+ pcilib_stop(pcilib, PCILIB_EVENT_FLAGS_DEFAULT);
+}
diff --git a/base.c b/base.c
index 29363c1..6a24bda 100644
--- a/base.c
+++ b/base.c
@@ -179,7 +179,7 @@ int ipecamera_set_buffer_size(ipecamera_t *ctx, int size) {
return PCILIB_ERROR_INVALID_REQUEST;
}
- if (((size^(size-1)) < size) < size) {
+ if ((size^(size-1)) < size) {
pcilib_error("The buffer size is not power of 2");
}