From 0076e4f03c61fb3c33911c8f03383030e56391d3 Mon Sep 17 00:00:00 2001
From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de>
Date: Fri, 28 Apr 2017 18:07:51 +0200
Subject: [PATCH] Moar cleanup and bugfixes related to previous changes

---
 source/BrickIO.m                |  2 +-
 source/CommunicationInterface.m |  9 +---
 source/btBrickIO.m              | 77 ++++++++++++++++++---------------
 source/usbBrickIO.m             | 46 ++++++++++----------
 4 files changed, 66 insertions(+), 68 deletions(-)

diff --git a/source/BrickIO.m b/source/BrickIO.m
index ebdb054..a5ee112 100755
--- a/source/BrickIO.m
+++ b/source/BrickIO.m
@@ -11,7 +11,7 @@
 % - The read function should return a uint8 datatype
 % - The write function should be given a uint8 datatype as a parameter
 
-classdef BrickIO < handle
+classdef BrickIO < MaskedHandle
     properties (Abstract)
         % time-out period (if 0, no time-out)
         timeOut 
diff --git a/source/CommunicationInterface.m b/source/CommunicationInterface.m
index 7c222a5..1ae2fe7 100755
--- a/source/CommunicationInterface.m
+++ b/source/CommunicationInterface.m
@@ -128,13 +128,6 @@ classdef CommunicationInterface < handle
              % b = CommunicationInterface(...) is an object that represents a connection
              % interface to a Lego Mindstorms EV3 brick.
              %
-             % Options::
-             %  'debug'       Debug level, show communications packet
-             %  'ioType'      IO connection type, either usb, wifi or bt
-             %  'deviceName'   Bluetooth brick device name
-             %  'channel'  Bluetooth connection channel
-             %  'serPort'    Serial port connection
-             %
              % Notes::
              % - Can connect through: usbBrickIO, btBrickIO
              % - For USB connection:
@@ -200,7 +193,7 @@ classdef CommunicationInterface < handle
             defaultSerPort = '/dev/rfcomm0';
             defaultBTDevice = 'EV3';
             defaultBTChannel = 1;
-            if(ispc)
+            if(ispc && license('test', 'instr_control_toolbox'))
                 defaultBackend = 'instrumentControl';
             else
                 defaultBackend = 'serial';
diff --git a/source/btBrickIO.m b/source/btBrickIO.m
index 5ed51f7..0625c3f 100755
--- a/source/btBrickIO.m
+++ b/source/btBrickIO.m
@@ -1,44 +1,51 @@
-%btBrickIO Bluetooth interface between MATLAB and the brick
-%
-% Methods::
-%
-%  btBrickIO    Constructor, initialises and opens the bluetooth connection
-%  delete       Destructor, closes the bluetooth connection
-%
-%  open         Open a bluetooth connection to the brick
-%  close        Close the bluetooth connection to the brick
-%  read         Read data from the brick through bluetooth
-%  write        Write data to the brick through bluetooth
-%
-% Example::
-%           btbrick = btBrickIO(1,'/dev/rfcomm0')
-%
-% Notes::
-% - Connects to the bluetooth module on the host through a serial
-% connection. Hence be sure that a serial connection to the bluetooth
-% module can be made. Also be sure that the bluetooth module can be paired
-% to the brick before MATLAB is opened.
-% - Works under mac and potentially linux (have yet to find a suitable
-% bluetooth device that can pair with the brick under linux).
-% - Does not work under windows (will need to either virtualise the serial
-% bluetooth port or use the instrumentation and control toolbox BrickIO
-% version).
-
 classdef btBrickIO < BrickIO
+    % Bluetooth interface between MATLAB and the brick
+    %
+    % Notes:
+    %     * Connects to the bluetooth module on the host through a serial
+    %       connection. Hence be sure that a serial connection to the bluetooth
+    %       module can be made. Also be sure that the bluetooth module has been paired
+    %       to the brick before trying to connect.
+    %     * Usage is OS-dependent:
+    %       
+    %         - Windows: the deviceName- & channel-properties are needed for connection. The
+    %                    implementation is based on the Instrument Control toolbox.
+    %         - Linux (and potentially Mac): serialPort-property is needed for connection. The 
+    %                    implementation is based on MATLAB's serial port implementation.
+    %
+    % Attributes:
+    %     debug (bool): If true, each open/close/read/write-call will be noted in the console.
+    %     serialPort (string): Path to the serial-port object (default: '/dev/rfcomm0'). Only
+    %        needed when using MATLAB's serial class (i.e. on linux/mac).
+    %     deviceName (string):  Name of the BT-device = the brick (default: 'EV3'). Only
+    %        needed when using the Instrument Control toolbox (i.e. on windows).
+    %     channel (numeric > 0): BT-channel of the connected BT-device (default: 1). Only
+    %        needed when using the Instrument Control toolbox (i.e. on windows).
+    %     timeOut (numeric >= 0): seconds after which a timeout-error occurs if no packet could be
+    %        read.
+    %     backend ('serial'|'instrumentControl'): Backend this implementation is based on. Is
+    %        automatically chosend depending on the OS ('serial' for linux/mac, 
+    %        'instrumentControl' for windows).
+    %
+    
     properties
-        % debug input
+        % debug (bool): If true, each open/close/read/write-call will be noted in the console.
         debug;
-        % bluetooth serial port (used if backend == 'serial')
+        % Path to the serial-port object (default: '/dev/rfcomm0'). Only
+        %     needed when using MATLAB's serial class (i.e. on linux/mac).
         serialPort;
-        % bluetooth brick device name (used if backend == 'instrumentControl')
+        % deviceName (string):  Name of the BT-device = the brick (default: 'EV3'). Only
+        %     needed when using the Instrument Control toolbox (i.e. on windows).
         deviceName;
-        % bluetooth connection channel (used if backend == 'instrumentControl')
+        % channel (numeric > 0): BT-channel of the connected BT-device (default: 1). Only
+        %     needed when using the Instrument Control toolbox (i.e. on windows).
         channel;
-        % time-out period in seconds (if 0, no time-out)
+        % timeOut (numeric > 0): seconds after which a timeout-error occurs if no packet could be
+        %     read.
         timeOut;
-        % use implementation based on the serial-connection implementation by MATLAB (should 
-        % work on mac & linux) or based on the Instrumentation & Control Toolbox 
-        % (should work on windows) (-> 'serial'|'instrumentControl')
+        % backend ('serial'|'instrumentControl'): Backend this implementation is based on. Is
+        %     automatically chosend depending on the OS ('serial' for linux/mac, 
+        %     'instrumentControl' for windows).
         backend;
     end
     
@@ -63,7 +70,7 @@ classdef btBrickIO < BrickIO
             p.addOptional('deviceName', 'EV3');
             p.addOptional('channel', 1);
             p.addOptional('timeOut', 10);
-            if(ispc == 1)
+            if(ispc && license('test', 'instr_control_toolbox'))
                 p.addOptional('backend', 'instrumentControl');
             else
                 p.addOptional('backend', 'serial');
diff --git a/source/usbBrickIO.m b/source/usbBrickIO.m
index 6a7a7c5..d2c5fb2 100755
--- a/source/usbBrickIO.m
+++ b/source/usbBrickIO.m
@@ -1,34 +1,32 @@
-%usbBrickIO USB interface between MATLAB and the brick
-%
-% Methods::
-%
-%  usbBrickIO    Constructor, initialises and opens the usb connection
-%  delete       Destructor, closes the usb connection
-%
-%  open         Open a usb connection to the brick
-%  close        Close the usb connection to the brick
-%  read         Read data from the brick through usb
-%  write        Write data to the brick through usb
-%
-% Example::
-%           usbbrick = usbBrickIO()
-%
-% Notes::
-% - Uses the hid library implementation in hidapi.m
-
 classdef usbBrickIO < BrickIO
+    % USB interface between MATLAB and the brick
+    %
+    % Notes:
+    %     * Uses the hid library implementation in hidapi.m
+    %
+    % Attributes:
+    %     debug (bool): If true, each open/close/read/write-call will be noted in the console.
+    %     vendorID (numeric): = 0x694 for EV3 
+    %     productID (numeric): = 0x0005 for EV3
+    %     nReadBuffer (numeric): read buffer size
+    %     nWriteBuffer (numeric): write buffer size (1 Byte bigger than actual packet)
+    %     timeOut (numeric >= 0): milliseconds after which a timeout-error occurs if no packet could be
+    %        read.
+    %
+    
     properties
-        % debug input
+        % debug (bool): If true, each open/close/read/write-call will be noted in the console.
         debug = 0;
-        % vendor ID (EV3 = 0x0694)
+        % vendorID (numeric): = 0x694 for EV3 
         vendorID = 1684;
-        % product ID (EV3 = 0x0005)
+        % productID (numeric): = 0x0005 for EV3
         productID = 5;
-        % read buffer size
+        % nReadBuffer (numeric): read buffer size
         nReadBuffer = 1024;
-        % write buffer size
+        % nWriteBuffer (numeric): write buffer size (1 Byte bigger than actual packet)
         nWriteBuffer = 1025;
-        % time-out period in milliseconds (if 0, no time-out)
+        % timeOut (numeric >= 0): milliseconds after which a timeout-error occurs if no packet could be
+        %     read.
         timeOut = 10000;
     end
     
-- 
GitLab