diff options
Diffstat (limited to 'lib/support/lib')
-rw-r--r-- | lib/support/lib/bobot_baseboard.lua | 393 | ||||
-rw-r--r-- | lib/support/lib/bobot_device.lua | 216 | ||||
-rw-r--r-- | lib/support/lib/comms_chotox.lua | 39 | ||||
-rw-r--r-- | lib/support/lib/comms_serial.lua | 94 | ||||
-rw-r--r-- | lib/support/lib/comms_usb.lua | 99 | ||||
-rwxr-xr-x | lib/support/lib/libluausb.so | bin | 17457 -> 0 bytes | |||
-rwxr-xr-x | lib/support/lib/lua_serialcomm.so | bin | 11599 -> 0 bytes | |||
-rwxr-xr-x | lib/support/lib/mime/core.so | bin | 12937 -> 0 bytes | |||
-rwxr-xr-x | lib/support/lib/socket/core.so | bin | 44755 -> 0 bytes |
9 files changed, 0 insertions, 841 deletions
diff --git a/lib/support/lib/bobot_baseboard.lua b/lib/support/lib/bobot_baseboard.lua deleted file mode 100644 index 757731a..0000000 --- a/lib/support/lib/bobot_baseboard.lua +++ /dev/null @@ -1,393 +0,0 @@ -#!/usr/bin/lua - ---module(..., package.seeall); - -local my_path = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] - -local bobot_device = require("bobot_device") -local bobot = require("bobot") - -local NULL_BYTE = string.char(0x00) -local DEFAULT_PACKET_SIZE = 0x04 -local GET_USER_MODULES_SIZE_COMMAND = string.char(0x05) -local GET_USER_MODULE_LINE_COMMAND = string.char(0x06) -local GET_HANDLER_SIZE_COMMAND = string.char(0x0A) -local GET_HANDLER_TYPE_COMMAND = string.char(0x0B) -local GET_LINES_RESPONSE_PACKET_SIZE = 5 -local GET_LINE_RESPONSE_PACKET_SIZE = 12 -local GET_HANDLER_TYPE_PACKET_SIZE = 5 -local GET_HANDLER_RESPONSE_PACKET_SIZE = 5 -- -local ADMIN_HANDLER_SEND_COMMAND = string.char(0x00) -local ADMIN_MODULE_IN_ENDPOINT = 0x01 -local ADMIN_MODULE_OUT_ENDPOINT = 0x81 -local GET_USER_MODULE_LINE_PACKET_SIZE = 0x05 -local CLOSEALL_BASE_BOARD_COMMAND = string.char(0x07) -local CLOSEALL_BASE_BOARD_RESPONSE_PACKET_SIZE = 5 -local TIMEOUT = 250 --ms -local MAX_RETRY = 5 - -local BaseBoard = {} - - ---executes s on the console and returns the output -local function run_shell (s) - local f = io.popen(s) -- runs command - local l = f:read("*a") -- read output of command - f:close() - return l -end - -openable = {} -hotplug = {} - -local function parse_drivers() - local driver_files=run_shell("sh -c 'ls "..my_path.."../drivers/*.lua 2> /dev/null'") - for filename in driver_files:gmatch('drivers%/(%S+)%.lua') do - --print ("Driver openable", filename) - openable[filename] = true - end - driver_files=run_shell("sh -c 'ls "..my_path.."../drivers/hotplug/*.lua 2> /dev/null'") - for filename in driver_files:gmatch('drivers%/hotplug%/(%S+)%.lua') do - --print ("Driver hotplug", filename) - hotplug[filename] = true - end -end -parse_drivers() - -local function load_modules(bb) - local retry = 0 - bb.modules = {} - - local n_modules=bb:get_user_modules_size() - while n_modules == nil and retry < MAX_RETRY do - n_modules=bb:get_user_modules_size() - bobot.debugprint("u4b:the module list size returned a nil value, trying to recover...") - retry = retry+1 - end - if not n_modules then return nil end - retry=0 - bobot.debugprint ("Reading modules:", n_modules) - for i = 1, n_modules do - local modulename=bb:get_user_module_line(i) - while modulename == nil and retry < MAX_RETRY do - bobot.debugprint("u4b:the module returned a nil value, trying to recover...") - modulename=bb:get_handler_type(i) - retry = retry+1 - end - if not modulename then return nil end - if openable[modulename] then - bb.modules[i]=modulename - local d = bobot_device:new({ - module=modulename, - --name=module, - baseboard=bb, - hotplug=false, - in_endpoint=0x01, out_endpoint=0x01, - }) -- in_endpoint=0x01, out_endpoint=0x01}) - bb.devices[d]=true - bb.devices[#bb.devices+1]=d - - bb.modules[modulename]=d - elseif hotplug[modulename] then - bb.modules[i]=modulename - bb.modules[modulename]=true - bb.hotplug = true -- bb has a hotplug module - else - bobot.debugprint("Loading modules: missing driver for",modulename) - end - end - return true -end - -local function load_module_handlers(bb) - local retry = 0 - - local n_module_handlers=bb:get_handler_size() - while n_module_handlers == nil and retry < MAX_RETRY do - n_module_handlers=bb:get_handler_size() - bobot.debugprint("u4b:the module handler list size returned a nil value, trying to recover...") - retry = retry+1 - end - if (not n_module_handlers) or (n_module_handlers > 32) then return nil end - retry=0 - bobot.debugprint ("Reading moduleshandlers:", n_module_handlers) - for i=1, n_module_handlers do - local t_handler = bb:get_handler_type(i) - while(t_handler == nil and retry < MAX_RETRY) do - bobot.debugprint("u4b:the module handler returned a nil value, trying to recover...") - t_handler = bb:get_handler_type(i) - retry = retry+1 - end - if not t_handler then return nil end - if t_handler<255 then - local modulename=bb.modules[t_handler+1] - local moduledev=bb.modules[modulename] - if type(moduledev)=='table' - and not moduledev.handler then - moduledev.handler=i-1 - elseif moduledev==true then - --name=name.."@"..(i-1) - local d = bobot_device:new({ - handler=i-1, - module=modulename, - --name=name, - baseboard=bb, - hotplug=(hotplug[modulename]), - in_endpoint=0x01, out_endpoint=0x01, - }) -- in_endpoint=0x01, out_endpoint=0x01}) - if d then - bb.devices[d]=true - bb.devices[#bb.devices+1]=d - end - else - bobot.debugprint ("No opened device!") - end - end - end - return true -end - - -function BaseBoard:refresh() - self.devices = {} - - if not load_modules(self) then - return nil,"failure reading modules" - end - - if not load_module_handlers(self) then - return nil,"failure reading module handlers" - end - return true -end - ---Instantiates BaseBoard object. ---Loads list of modules installed on baseboard -function BaseBoard:new(bb) - --parameters sanity check - assert(type(bb)=="table") - assert(type(bb.comms)=="table") - - --OO boilerplate - setmetatable(bb, self) - self.__index = self - - bb:refresh() - ---bobot.debugprint ('----------------') - --bb:force_close_all() ---bobot.debugprint ('================') - return bb -end - ---Closes all modules opened on baseboard -function BaseBoard:close() - --state sanity check - assert(type(self.devices)=="table") - - for _,d in ipairs(self.devices) do - if type(d.handler)=="number" then - bobot.debugprint ("closing", d.name, d.handler) - d:close() - end - end - - --TODO actually close the baseboard -end - ---returns number of modules present on baseboard -function BaseBoard:get_user_modules_size() - --state sanity check - assert(type(self.comms)=="table") - - local comms=self.comms - - -- In case of get_user_modules_size command is atended by admin module in handler 0 and send operation is 000 - - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. string.char(DEFAULT_PACKET_SIZE) .. NULL_BYTE - local admin_packet = GET_USER_MODULES_SIZE_COMMAND - local get_user_modules_size_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, get_user_modules_size_packet, TIMEOUT) - if write_res then - local data, err = comms.read(ADMIN_MODULE_OUT_ENDPOINT, GET_LINES_RESPONSE_PACKET_SIZE, TIMEOUT) - if not data then - bobot.debugprint("u4b:get_user_modules_size:comunication with I/O board read error", err) - return 0 - else - local user_modules_size = string.byte(data, 5) - return user_modules_size - end - else - bobot.debugprint("u4b:get_user_modules_size:comunication with I/O board write error", write_res) - return 0 - end -end - ---returns thename of a given (by a 1-based index)module -function BaseBoard:get_user_module_line(index) - --state & parameter sanity check - assert(type(index)=="number") - assert(index>0) - assert(type(self.comms)=="table") - - - local comms=self.comms - - -- In case of get_user_module_line command is atended by admin module in handler 0 and send operation is 000 - local get_user_module_line_packet_length = string.char(GET_USER_MODULE_LINE_PACKET_SIZE) - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. get_user_module_line_packet_length .. NULL_BYTE - local admin_packet = GET_USER_MODULE_LINE_COMMAND .. string.char(index-1) - local get_user_module_line_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, get_user_module_line_packet, TIMEOUT) - if write_res then - local data, err = comms.read(ADMIN_MODULE_OUT_ENDPOINT, GET_LINE_RESPONSE_PACKET_SIZE, TIMEOUT) - if not data then - bobot.debugprint("u4b:get_user_modules_line:comunication with I/O board read error", err) - return - end - --the name is between a header and a null - local end_mark = string.find(data, "\000", GET_USER_MODULE_LINE_PACKET_SIZE, true) - if not end_mark then - bobot.debugprint ("u4b:get_user_module_line:Error parsing module name") - return - end - local module_name = string.sub(data, GET_USER_MODULE_LINE_PACKET_SIZE, end_mark-1) - return module_name - else - bobot.debugprint("u4b:get_user_module_line:comunication with I/O board write error", write_res) - end -end - -function BaseBoard:get_handler_size() ------ NEW LISTI ------ - --state sanity check - assert(type(self.comms)=="table") - - local comms=self.comms - - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. string.char(DEFAULT_PACKET_SIZE) .. NULL_BYTE - local admin_packet = GET_HANDLER_SIZE_COMMAND - local get_handler_size_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, get_handler_size_packet, TIMEOUT) - if write_res then - local data, err = comms.read(ADMIN_MODULE_OUT_ENDPOINT, GET_HANDLER_RESPONSE_PACKET_SIZE, TIMEOUT) - if not data then - bobot.debugprint("u4b:get_handler_size:comunication with I/O board read error", err) - return 0 - else - local handler_size = string.byte(data, 5) - return handler_size - end - else - bobot.debugprint("u4b:get_handler_type:comunication with I/O board write error", write_res) - end -end -function BaseBoard:get_handler_type(index) ------ NEW LISTI ------ - --state & parameter sanity check - assert(type(index)=="number") - assert(index>0) - assert(type(self.comms)=="table") - - local comms=self.comms - - -- In case of get_handler_type command is atended by admin module in handler 0 and send operation is 000 - local get_handler_type_packet_length = string.char(GET_HANDLER_TYPE_PACKET_SIZE) --GET_USER_MODULE_LINE_PACKET_SIZE - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. get_handler_type_packet_length .. NULL_BYTE - local admin_packet = GET_HANDLER_TYPE_COMMAND .. string.char(index-1) - local get_handler_type_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, get_handler_type_packet, TIMEOUT) - if write_res then - local data, err = comms.read(ADMIN_MODULE_OUT_ENDPOINT, GET_HANDLER_RESPONSE_PACKET_SIZE, TIMEOUT) - if not data then - bobot.debugprint("u4b:get_handler_type:comunication with I/O board read error", err) - return 0 - else - local handler_type = string.byte(data, 5) - return handler_type - end - else - bobot.debugprint("u4b:get_handler_type:comunication with I/O board write error", write_res) - end -end - --- resets the baseboard, after this operation the baseboard will claim reenumeration to the operative system --- this function is deprecated by force_close_all -function BaseBoard:close_all() - for _,d in ipairs(self.devices) do - --bobot.debugprint ("===", d.name,d.handler) - if d.handler then d:close() end - end -end - --- switch the baseboard to the bootloader program implementend as a usb4all command to the admin module -function BaseBoard:switch_to_bootloader() - --state & parameter sanity check - assert(type(self.comms)=="table") - - local comms=self.comms - -- In case of reset_base_board command is atended by admin module in handler 0 and send operation is 000 - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. string.char(DEFAULT_PACKET_SIZE) .. NULL_BYTE - local admin_packet = string.char(0x09) --SWITCH_TO_BOOT_BASE_BOARD_COMMAND - local boot_base_board_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, boot_base_board_packet, TIMEOUT) - --from this moment the board is reseted, so there is nothing more to do -end - -function BaseBoard:reset() - --state & parameter sanity check - assert(type(self.comms)=="table") - - local comms=self.comms - -- In case of reset_base_board command is atended by admin module in handler 0 and send operation is 000 - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. string.char(DEFAULT_PACKET_SIZE) .. NULL_BYTE - local admin_packet = string.char(0xFF) --RESET_BASE_BOARD_COMMAND - local reset_base_board_packet = handler_packet .. admin_packet - - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, reset_base_board_packet, TIMEOUT) - if write_res then - -- no tego que leer respuesta porque se reseteo - --libusb.close(libusb_handler) - --self.libusb_handler=nil - --for d_name,d in pairs(self.devices) do - --bobot.debugprint ("===", d.name,d.handler) - -- d.handler=nil - --end - else - bobot.debugprint("u4b:reset:comunication with I/O board write error", write_res) - end -end - -function BaseBoard:force_close_all() - --state & parameter sanity check - assert(type(self.comms)=="table") - - local comms=self.comms - -- In case of reset_base_board command is atended by admin module in handler 0 and send operation is 000 - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. string.char(DEFAULT_PACKET_SIZE) .. NULL_BYTE - local admin_packet = CLOSEALL_BASE_BOARD_COMMAND - local reset_base_board_packet = handler_packet .. admin_packet - ---bobot.debugprint ('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') - local write_res = comms.send(ADMIN_MODULE_IN_ENDPOINT, reset_base_board_packet, TIMEOUT) ---bobot.debugprint ('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') - if write_res then - local data, err = comms.read(ADMIN_MODULE_OUT_ENDPOINT, CLOSEALL_BASE_BOARD_RESPONSE_PACKET_SIZE, TIMEOUT) - if err then - bobot.debugprint("u4b:force_close_all:comunication with I/O board read error",err) - else - --bobot.debugprint("u4b:force_close_all:libusb read",string.byte(data,1,string.len(data))) - end - for _,d in ipairs(self.devices) do - --bobot.debugprint ("===", d.name,d.handler) - d.handler=nil - end - else - bobot.debugprint("u4b:force_close_all:comunication with I/O board write error", write_res) - end -end - -return BaseBoard diff --git a/lib/support/lib/bobot_device.lua b/lib/support/lib/bobot_device.lua deleted file mode 100644 index b560255..0000000 --- a/lib/support/lib/bobot_device.lua +++ /dev/null @@ -1,216 +0,0 @@ ---module(..., package.seeall); - -local bobot = require("bobot") - -local string_char = string.char -local string_len = string.len -local string_byte = string.byte - -local OPEN_COMMAND = string_char(0x00) -local CLOSE_COMMAND = string_char(0x01) -local HEADER_PACKET_SIZE = 6 -local NULL_BYTE = string_char(0x00) -local ADMIN_MODULE_IN_ENDPOINT = 0x01 -local ADMIN_MODULE_OUT_ENDPOINT = 0x81 -local ADMIN_HANDLER_SEND_COMMAND = string_char(0x00) -local OPEN_RESPONSE_PACKET_SIZE = 5 -local CLOSE_RESPONSE_PACKET_SIZE = 2 -local TIMEOUT = 200 --ms - -local READ_HEADER_SIZE = 3 - -local my_path = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] - -local Device = { - --some usefull stuff for the drivers to use - string=string, - print=bobot.debugprint, - math=math, - tonumber=tonumber, - tostring=tostring -} - - -local drivers_cache = setmetatable({}, {__mode='kv'}) -local function load_driver(d) - local modulename=d.module - if drivers_cache[modulename] then return drivers_cache[modulename] end - - local drivername=string.match(modulename, '^(.-)%d*$') - local f, err - if d.hotplug then - f, err = loadfile(my_path.."../drivers/hotplug/"..drivername..".lua") - else - f, err = loadfile(my_path.."../drivers/"..drivername..".lua") - end - drivers_cache[modulename] = f - return f, err -end - ---Instantiates Device object. ---Attempts to load api from driver -function Device:new(d) - --parameters sanity check - assert(type(d)=="table") - --assert(type(d.name)=="string") - assert(type(d.module)=="string") - assert(type(d.baseboard)=="table") - assert(type(d.baseboard.comms)=="table") - assert(type(d.baseboard.comms.send)=="function") - assert(type(d.baseboard.comms.read)=="function") - - --OO boilerplate - setmetatable(d, self) - self.__index = self - - --store locally, save 2 indirections - d.comms_send = d.baseboard.comms.send - d.comms_read = d.baseboard.comms.read - - --attempt to load api from driver - local f, err = load_driver(d) - if f then - d._G=d - - setfenv(f, d) --the driver's environment is the device - local status, err=pcall(f) - if status then - bobot.debugprint("u4d:new:Success loading driver:", d.module) - else - bobot.debugprint("u4d:new:Error initializing driver:", tostring(err)) - end - else - bobot.debugprint("u4d:new:Error loading driver:", err) - return nil - end - - return d -end - ---opens the device. must be done before sending / reading / etc. ---receives endpoints, which can be ommited if they were provided at Device creation -function Device:open(in_endpoint, out_endpoint) - --state & parameter sanity check - assert(self.handler==nil) - --assert(type(self.name)=="string") - assert(type(in_endpoint)=="number" or type(self.in_endpoint)=="number") - assert(type(self.comms_send)=="function") - assert(type(self.comms_read)=="function") - assert(type(out_endpoint)=="number" or type(self.out_endpoint)=="number") - - --save for later use - if in_endpoint then self.in_endpoint = in_endpoint end - if out_endpoint then self.out_endpoint = out_endpoint end - - local module_name=self.module .."\000" -- usb4all expect null terminated names - - local open_packet_length = string_char(HEADER_PACKET_SIZE + string_len(module_name)) - - local module_in_endpoint = string_char(self.in_endpoint) - local module_out_endpoint = string_char(self.out_endpoint) - - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. open_packet_length .. NULL_BYTE - local admin_packet = OPEN_COMMAND .. module_in_endpoint .. module_out_endpoint .. module_name - local open_packet = handler_packet .. admin_packet - local write_res = self.comms_send(ADMIN_MODULE_IN_ENDPOINT, open_packet, TIMEOUT) - - if not write_res then - bobot.debugprint("u4d:open:comunication with I/O board write error", write_res) - return false - end - - local data, err = self.comms_read(ADMIN_MODULE_OUT_ENDPOINT, OPEN_RESPONSE_PACKET_SIZE, TIMEOUT) - if not data then - bobot.debugprint ("u4d:open:comunication with I/O boardread error", err) - return false - end - - local handler = string_byte(data, 5) - --hander -1 meand error - if handler==255 then - bobot.debugprint ("u4d:open:Already open!",self.module,self.handler) - return - else - bobot.debugprint ("u4d:open:Success!",self.module,handler) - self.handler = handler --self.handler set means device is open - return true - end - -end - ---closes the device -function Device:close() - if not self.handler then return end --already closed - - --state sanity check - assert(type(self.handler)=="number") - assert(type(self.comms_send)=="function") - assert(type(self.comms_read)=="function") - - local close_packet_length = string_char(0x04) --string.char(HEADER_PACKET_SIZE + string.len(module_name)) - local handler_packet = ADMIN_HANDLER_SEND_COMMAND .. close_packet_length .. NULL_BYTE - local admin_packet = CLOSE_COMMAND .. string_char(self.handler) - local close_packet = handler_packet .. admin_packet - - local write_res = self.comms_send(ADMIN_MODULE_IN_ENDPOINT, close_packet, TIMEOUT) - if not write_res then - bobot.debugprint("u4d:close:comunication with I/O board write error", write_res) - return - end - local data, err = self.comms_read(ADMIN_MODULE_OUT_ENDPOINT, CLOSE_RESPONSE_PACKET_SIZE, TIMEOUT) - - self.handler = nil -end - ---sends data (a string) to device -function Device:send(data) - --state & parameter sanity check - data=tostring(data) - assert(type(data)=="string") - assert(type(self.handler)=="number") - assert(type(self.in_endpoint)=="number") - assert(type(self.comms_send)=="function") - assert(type(self.comms_read)=="function") - - local len=string_len(data) - - local shifted_handler = self.handler * 8 - assert(shifted_handler<256, "u4d:send:shifted_handler vale " .. shifted_handler .. " excede el tamaƱo maximo representable en un byte (255)") - local user_module_handler_send_command = string_char(shifted_handler) - local send_packet_length = string_char(0x03 + len) - local send_packet = user_module_handler_send_command .. send_packet_length .. NULL_BYTE .. data - - --local tini=socket.gettime() - local write_res, err = self.comms_send(self.in_endpoint, send_packet, TIMEOUT) - --bobot.debugprint ('%%%%%%%%%%%%%%%% device send',socket.gettime()-tini) - - if not write_res then - bobot.debugprint("u4d:send:comunication with I/O board write error", err) - end - - return write_res, err -end - ---read data (len bytes max) from device -function Device:read(len) - len = len or 255 - --state & parameter sanity check - assert(type(len)=="number") - assert(type(self.handler)=="number") - assert(type(self.out_endpoint)=="number") - assert(type(self.comms_send)=="function") - assert(type(self.comms_read)=="function") - - local data, err = self.comms_read(self.out_endpoint, len+READ_HEADER_SIZE, TIMEOUT) - if not data then - bobot.debugprint("u4d:read:comunication with I/O board read error", err) - return nil, err - end - - local data_h = string.sub(data, READ_HEADER_SIZE+1, -1) --discard header - - return data_h, err -end - -return Device - diff --git a/lib/support/lib/comms_chotox.lua b/lib/support/lib/comms_chotox.lua deleted file mode 100644 index 18e02bf..0000000 --- a/lib/support/lib/comms_chotox.lua +++ /dev/null @@ -1,39 +0,0 @@ -local bobot_device = require("bobot_device") - -local comms_chotox = {} - -function comms_chotox.send(endpoint, data, timeout) -end - -function comms_chotox.read(endpoint, len, timeout) -end - - -function comms_chotox.init(baseboards) - --parameters sanity check - assert(type(baseboards)=="table") - - local n_boards=1 - --local bb = bobot_baseboard.BaseBoard:new({idBoard=iSerial, comms=comms_usb}) - local bb = {idBoard=1, comms=comms_chotox} - local devices={} - local is_hotplug= {button=true, led=true, grey=true, distanc=true} - for i, name in ipairs({"button", "grey", "distanc","butia"}) do - local dd={name=name, module=name, baseboard=bb, handler=i} - dd.open = function() return true end - dd.close = function() end - dd.read = function() return "" end - dd.send = function() return true end - if is_hotplug[name] then dd.hotplug=true end - - local d = bobot_device:new(dd) -- in_endpoint=0x01, out_endpoint=0x01}) - - devices[name]=true - devices[#devices+1]=d - end - bb.devices=devices - baseboards[1]=bb - return n_boards -end - -return comms_chotox diff --git a/lib/support/lib/comms_serial.lua b/lib/support/lib/comms_serial.lua deleted file mode 100644 index 4bd3bb0..0000000 --- a/lib/support/lib/comms_serial.lua +++ /dev/null @@ -1,94 +0,0 @@ ---module(..., package.seeall); - ---local socket=require("socket") - -local bobot_baseboard = require("bobot_baseboard") -local bobot = require("bobot") - -local my_path = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] -assert(package.loadlib(my_path .. "lua_serialcomm.so","luaopen_serialcomm"))() -local serialcomm=_G.serialcomm; _G.serialcomm=nil - -local serial_handler - ---executes s on the console and returns the output -local function run_shell (s) - local f = io.popen(s) -- runs command - local l = f:read("*a") -- read output of command - f:close() - return l -end - -local function split_words(s) - local words={} - for p in string.gmatch(s, "%S+") do - words[#words+1]=p - end - return words -end - -local comms_serial = {} - -function comms_serial.send(endpoint, data, timeout) - --parameters sanity check - assert(type(serial_handler)=="number") - --assert(type(endpoint)=="number") - assert(type(data)=="string") - assert(type(timeout)=="number") - - --local tini=socket.gettime() - local ret = serialcomm.send_msg(serial_handler, data) - --bobot.debugprint ('%%%%%%%%%%%%%%%% comms serial send',socket.gettime()-tini) - return ret -end - -function comms_serial.read(endpoint, len, timeout) - --parameters sanity check - assert(type(serial_handler)=="number") - --assert(type(endpoint)=="number") - --assert(type(len)=="number") - --assert(type(timeout)=="number") - - return serialcomm.read_msg(serial_handler, len, timeout) -end - - -function comms_serial.init(baseboards) - --parameters sanity check - assert(type(baseboards)=="table") - - --FIXME leer ttyusbs... - --local tty_s=run_shell("ls /dev/ttyUSB* ") - local tty_s=run_shell("sh -c 'ls /dev/ttyUSB* 2> /dev/null'") --supress errors - local tty_t=split_words(tty_s) - local tty - local err - if (#tty_t == 0) then - return 0,"no ttyUSB found" - end - - -- tty="/dev/ttyUSB0" - --for i=1, #tty_t do - for _, ttyI in ipairs(tty_t) do - bobot.debugprint ("Trying to connect to", ttyI) - serial_handler, err = serialcomm.init(ttyI, 115200) - if serial_handler then - tty=ttyI - break - else - bobot.debugprint("Error connecting:", err) - end - end - if not serial_handler then - bobot.debugprint("cs:", "no ttyUSB could be open") - return 0, err - end - bobot.debugprint ("cs:", tty) - local bb = bobot_baseboard:new({idBoard=tty, comms=comms_serial}) - - baseboards[#baseboards+1]=bb - - return 1 -end - -return comms_serial diff --git a/lib/support/lib/comms_usb.lua b/lib/support/lib/comms_usb.lua deleted file mode 100644 index 91d64b5..0000000 --- a/lib/support/lib/comms_usb.lua +++ /dev/null @@ -1,99 +0,0 @@ ---module(..., package.seeall); - -local bobot_baseboard = require("bobot_baseboard") -local bobot = require("bobot") - -local my_path = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] -assert(package.loadlib(my_path .. "libluausb.so","luaopen_libusb"))() -local libusb=_G.libusb; _G.libusb=nil - -local usb_bulk_write = libusb.bulk_write -local usb_bulk_read = libusb.bulk_read - -local USB4ALL_VENDOR = 0x04d8 -local USB4ALL_PRODUCT = 0x000c -local USB4ALL_CONFIGURATION = 1 -local USB4ALL_INTERFACE = 0 - -local READ_HEADER_SIZE = 3 - -local libusb_handler - - -local comms_usb = {} - -function comms_usb.send(endpoint, data, timeout) - --parameters sanity check - assert(type(libusb_handler)=="userdata") - assert(type(endpoint)=="number") - assert(type(data)=="string") - assert(type(timeout)=="number") - - return usb_bulk_write(libusb_handler, endpoint, data, timeout) -end - -function comms_usb.read(endpoint, len, timeout) - --parameters sanity check - assert(type(libusb_handler)=="userdata") - assert(type(endpoint)=="number") - assert(type(len)=="number") - assert(type(timeout)=="number") - - return usb_bulk_read(libusb_handler, endpoint, len+READ_HEADER_SIZE, timeout) -end - - -function comms_usb.init(baseboards) - --parameters sanity check - assert(type(baseboards)=="table") - - - --refresh devices and buses - libusb.find_busses() - libusb.find_devices() - local n_boards = 0 - - local buses=libusb.get_busses() - for dirname, bus in pairs(buses) do --iterate buses - local devices=libusb.get_devices(bus) - for filename, device in pairs(devices) do --iterate devices - local descriptor = libusb.device_descriptor(device) - - --if device is baseboard... - if ((descriptor.idVendor == USB4ALL_VENDOR) and (descriptor.idProduct == USB4ALL_PRODUCT)) then - --try to intialize baseboard - bobot.debugprint("Initializing Baseboard:", descriptor.idVendor, descriptor.idProduct) - libusb_handler = libusb.open(device) - - if not libusb_handler then - bobot.debugprint("Error opening device") - break - end - if not libusb.set_configuration(libusb_handler, USB4ALL_CONFIGURATION) then - bobot.debugprint("Error configuring device, retrying after a reset") - libusb.reset(libusb_handler) - if not libusb.set_configuration(libusb_handler, USB4ALL_CONFIGURATION) then - bobot.debugprint("Error configuring device.") - break - end - end - if not libusb.claim_interface(libusb_handler, USB4ALL_INTERFACE) then - bobot.debugprint("Error seting device interface") - break - end - - --success initializing, instantiate BaseBoard object and register - local iSerial=descriptor.iSerialNumber - local bb = bobot_baseboard:new({idBoard=iSerial, comms=comms_usb}) - --bb:force_close_all() - --bobot.debugprint("Baseboard:", iSerial) - - baseboards[#baseboards+1]=bb - n_boards = n_boards + 1 - end - end - end - return n_boards -end - -return comms_usb diff --git a/lib/support/lib/libluausb.so b/lib/support/lib/libluausb.so Binary files differdeleted file mode 100755 index a7c9406..0000000 --- a/lib/support/lib/libluausb.so +++ /dev/null diff --git a/lib/support/lib/lua_serialcomm.so b/lib/support/lib/lua_serialcomm.so Binary files differdeleted file mode 100755 index cb79295..0000000 --- a/lib/support/lib/lua_serialcomm.so +++ /dev/null diff --git a/lib/support/lib/mime/core.so b/lib/support/lib/mime/core.so Binary files differdeleted file mode 100755 index 696b7d9..0000000 --- a/lib/support/lib/mime/core.so +++ /dev/null diff --git a/lib/support/lib/socket/core.so b/lib/support/lib/socket/core.so Binary files differdeleted file mode 100755 index ddfc8c3..0000000 --- a/lib/support/lib/socket/core.so +++ /dev/null |