1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
## Copyright (C) 2018-2022 John Donoghue <john.donoghue@ieee.org>
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details. see
## <https://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {} {@var{retval} =} __sendCommand__ (@var{obj}, @var{cmd}, @var{data}, @var{timeout})
## Private function
## @end deftypefn
## Author: jdonoghue <jdonoghue@JYRW4S1>
## Created: 2018-05-15
function [dataOut, errcode] = __sendCommand__ (obj, libid, cmd, data, timeout)
if nargin < 3
error ("@arduino.__sendCommand__: expected command");
endif
% send command and get back reponse
if !isa(obj.connected, "octave_serialport") && !isa(obj.connected, "octave_tcp")
error ("@arduino.__sendCommand__: not connected to a arduino");
endif
% connected yet ?
% simple procol here, each field is a byte
% sends A5 EXT CMD datasize [data,,,]
% currently ext is 0 - may use later to identify module to send to ?
% A5 00 00 00 = reset
% A5 00 01 00 = req board info
dataOut = [];
errcode = 0;
if (nargin < 4)
data = [];
endif
if (nargin < 5)
timeout = 0.5;
endif
if iscell(data)
data = cell2mat(data);
endif
hdr = uint8([ hex2dec("A5") libid cmd numel(data)]);
set(obj.connected, "timeout", timeout);
len = fwrite(obj.connected, [hdr data]);
if (obj.debug)
printf(">> "); printf("%d ", [hdr data]); printf("\n");
endif
[dataOut, errcode] = __recvResponse__ (obj.connected, libid, cmd, timeout, obj.debug);
endfunction
|