Commit 1e7b958c authored by Arnaud Blanchard's avatar Arnaud Blanchard
parents 5f03993f b4fd4932
......@@ -37,6 +37,8 @@ set_target_properties(static_blc_channel PROPERTIES OUTPUT_NAME blc_channel)
install(DIRECTORY include/ DESTINATION include/blc_channel)
install(TARGETS blc_channel static_blc_channel DESTINATION lib)
install(FILES blc_channel-config.cmake DESTINATION share/blc_channel)
install(FILES blpy_channel.py DESTINATION lib/bl_python)
#Package
set(CPACK_GENERATOR "DEB")
......
import os
import ctypes
from ctypes import *
from ctypes.util import find_library
class BlcDim(Structure):
_fields_ = [("length", c_size_t), ("step", c_size_t)]
class BlcChannel:
"""
blc_channel wrapper.
"""
# Bind blc_channel methods
lib_path = find_library("blc_channel")
lib = CDLL(lib_path)
lib.blc_channel_new.restype = c_void_p
lib.blc_channel_delete.argtypes = [ c_void_p ]
lib.blc_channel_get_data.argtypes = [ c_void_p ]
lib.blc_channel_get_data.restype = c_void_p
lib.blc_channel_get_type.argtypes = [ c_void_p ]
lib.blc_channel_get_type.restype = c_uint32
lib.blc_channel_get_format.argtypes = [ c_void_p ]
lib.blc_channel_get_format.restype = c_uint32
lib.blc_channel_get_dims_nb.argtypes= [ c_void_p ]
lib.blc_channel_get_dims_nb.restype = c_int
lib.blc_channel_get_dims.argtypes = [ c_void_p ]
lib.blc_channel_wait_new_data.argtypes = [ c_void_p ]
lib.blc_channel_wait_ack_data.argtypes = [ c_void_p ]
lib.blc_channel_post_new_data.argtypes = [ c_void_p ]
lib.blc_channel_post_ack_data.argtypes = [ c_void_p ]
types={ 'UIN8': c_uint8, 'INT8': c_int8, 'UI16': c_uint16, 'INT16': c_int16, 'UI32': c_uint32, 'IN32': c_int32, 'UI64': c_uint64, 'IN64': c_int64, 'FL32': c_float, 'FL64': c_double}
def __init__(
self, name, mode, data_type=None,format_type=None, dims=None
):
"""
Creates or reopens a given blc_channel.
:param name: Name of the blc_channel (with sync/async identifier). Example: "/data"
:param mode: RW mode. Example: os.O_RDWR
TODO
"""
self.name = name
self.mode = mode
self.type = data_type
self.format = format_type
self.dims = dims
if (dims): #Creates
dim_types = [c_int] * len(dims)
BlcChannel.lib.blc_channel_new.argtypes = [
c_char_p,
c_int,
c_uint32,
c_uint32,
c_int,
*dim_types
]
# Create a new channel
self.channel = BlcChannel.lib.blc_channel_new(
name.encode(),
mode,
int.from_bytes(data_type.encode(), "big"),
int.from_bytes(format_type.encode(), "big"),
len(dims),
*dims
)
else: #Open
BlcChannel.lib.blc_channel_new.argtypes = [
c_char_p,
c_int,
c_uint32,
c_uint32,
c_int,
c_int
]
self.channel = BlcChannel.lib.blc_channel_new(
name.encode(),
mode,
0,
0,
0,
0
)
self.type=BlcChannel.lib.blc_channel_get_type(self.channel).to_bytes(4, "big").decode()
self.format=BlcChannel.lib.blc_channel_get_format(self.channel).to_bytes(4, "big").decode()
dims_nb=BlcChannel.lib.blc_channel_get_dims_nb(self.channel)
BlcChannel.lib.blc_channel_get_dims.restype = POINTER(BlcDim * dims_nb)
blc_dims=BlcChannel.lib.blc_channel_get_dims(self.channel)
dims=[]
for i in range(dims_nb):
dims.append(blc_dims[0][i].length) #dims[i]=
# Specify types for channel
self.total_length=1
for length in dims:
self.total_length *= length
self.ctype = BlcChannel.types[self.type]
self.array = cast(BlcChannel.lib.blc_channel_get_data(self.channel), POINTER(self.ctype))
def wait_new_data(self):
BlcChannel.lib.blc_channel_wait_new_data(self.channel)
def wait_ack_data(self):
BlcChannel.lib.blc_channel_wait_ack_data(self.channel)
def post_new_data(self):
BlcChannel.lib.blc_channel_post_new_data(self.channel)
def post_ack_data(self):
BlcChannel.lib.blc_channel_post_ack_data(self.channel)
def __del__(self):
BlcChannel.lib.blc_channel_delete(self.channel)
@property
def list(self):
#cast it from
data_list = list(self.array[:self.total_length])
return data_list
if __name__ == "__main__":
# EXEMPLE
channel = BlcChannel("/python_test", os.O_RDWR, 'UIN8', 'RGB3', [3, 2])
#channel.wait_new_data() #This needs data to be named .data
channel_read = BlcChannel("/python_test", os.O_RDONLY)
print("type",channel_read.type, "format", channel_read.format, "length", channel_read.total_length)
print(channel_read.array[:channel.total_length])
......@@ -7,12 +7,12 @@
This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
 users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
 In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
 that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured
 and, more generally, to use and operate it in the same conditions as regards security.
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. *
and, more generally, to use and operate it in the same conditions as regards security.
The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. *
Created on: Oct 9, 2014
......@@ -35,6 +35,7 @@
#include "blc_core.h"
#include <stack>
#include <vector>
#include <tuple>
#define TMP_BUFFER_SIZE 4096
#define BLC_CHANNELS_LIST_PATH "/tmp/blc_channels.txt"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment