From: <ean...@us...> - 2012-08-19 22:33:06
|
Revision: 10887 http://octave.svn.sourceforge.net/octave/?rev=10887&view=rev Author: eandrius Date: 2012-08-19 22:32:59 +0000 (Sun, 19 Aug 2012) Log Message: ----------- i2c: initial commit \nserial: small changes to error reporting Modified Paths: -------------- trunk/octave-forge/main/serial/DESCRIPTION trunk/octave-forge/main/serial/src/serial.h trunk/octave-forge/main/serial/src/srl_baudrate.cc trunk/octave-forge/main/serial/src/srl_read.cc trunk/octave-forge/main/serial/src/srl_write.cc Added Paths: ----------- trunk/octave-forge/main/i2c/ trunk/octave-forge/main/i2c/COPYING trunk/octave-forge/main/i2c/DESCRIPTION trunk/octave-forge/main/i2c/INDEX trunk/octave-forge/main/i2c/NEWS trunk/octave-forge/main/i2c/src/ trunk/octave-forge/main/i2c/src/Makefile trunk/octave-forge/main/i2c/src/i2c.cc trunk/octave-forge/main/i2c/src/i2c.h trunk/octave-forge/main/i2c/src/i2c_addr.cc trunk/octave-forge/main/i2c/src/i2c_close.cc trunk/octave-forge/main/i2c/src/i2c_read.cc trunk/octave-forge/main/i2c/src/i2c_write.cc Added: trunk/octave-forge/main/i2c/COPYING =================================================================== --- trunk/octave-forge/main/i2c/COPYING (rev 0) +++ trunk/octave-forge/main/i2c/COPYING 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Added: trunk/octave-forge/main/i2c/DESCRIPTION =================================================================== --- trunk/octave-forge/main/i2c/DESCRIPTION (rev 0) +++ trunk/octave-forge/main/i2c/DESCRIPTION 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,11 @@ +Name: i2c +Version: 0.1.0 +Date: 2012-08-19 +Author: Andrius Sutas <and...@gm...> +Maintainer: Andrius Sutas <and...@gm...> +Title: i2c +Description: i2c functions for communicating from within octave. +Categories: i2c +Depends: octave (>= 3.4.0) +Autoload: no +License: LGPLv3+ Added: trunk/octave-forge/main/i2c/INDEX =================================================================== --- trunk/octave-forge/main/i2c/INDEX (rev 0) +++ trunk/octave-forge/main/i2c/INDEX 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,8 @@ +i2c >> i2c +i2c + i2c + i2c_addr + i2c_read + i2c_write + i2c_close + Added: trunk/octave-forge/main/i2c/NEWS =================================================================== --- trunk/octave-forge/main/i2c/NEWS (rev 0) +++ trunk/octave-forge/main/i2c/NEWS 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,12 @@ +Summary of important user-visible changes for i2c 0.1.0: +------------------------------------------------------------------- + + ** Initial release + + ** The following functions are new: + i2c + i2c_addr + i2c_read + i2c_write + i2c_close + Added: trunk/octave-forge/main/i2c/src/Makefile =================================================================== --- trunk/octave-forge/main/i2c/src/Makefile (rev 0) +++ trunk/octave-forge/main/i2c/src/Makefile 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,19 @@ +OCT = i2c.oct +OBJ := i2c.o i2c_close.o i2c_addr.o i2c_write.o i2c_read.o + + +MKOCTFILE ?= mkoctfile + +all: $(OCT) + +%.oct: $(OBJ) + $(MKOCTFILE) $^ + +%.o: %.cc + $(MKOCTFILE) -c -s $< + +clean: + rm -f *.oct *.o + + +.PHONY: all clean Added: trunk/octave-forge/main/i2c/src/i2c.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,109 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +DEFINE_OCTAVE_ALLOCATOR (octave_i2c); +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_i2c, "octave_i2c", "octave_i2c"); + +static bool type_loaded = false; + +octave_i2c::octave_i2c() +{ + this->fd = -1; +} + +octave_i2c::octave_i2c(string path, int flags) +{ + this->fd = open(path.c_str(), flags, 0); +} + +octave_i2c::~octave_i2c() +{ + this->i2c_close(); +} + +int octave_i2c::i2c_get_fd() +{ + return this->fd; +} + +void octave_i2c::print (std::ostream& os, bool pr_as_read_syntax ) const +{ + print_raw(os, pr_as_read_syntax); + newline(os); +} + +void octave_i2c::print_raw (std::ostream& os, bool pr_as_read_syntax) const +{ + os << this->fd; +} + +// PKG_ADD: autoload ("i2c", "i2c.oct"); +DEFUN_DLD (i2c, args, nargout, "i2c() function has one mandatory output argument") +{ +#ifdef __WIN32__ + error("i2c: Windows platform support is not yet implemented, go away..."); + return octave_value(); +#endif + + int nargin = args.length(); + + // Default values + int oflags = O_RDWR; + string path("/dev/i2c-0"); + + // Do not open interface if return value is not assigned + if (nargout != 1) + { + print_usage(); + return octave_value(); + } + + // Open the interface + octave_i2c* retval = new octave_i2c(path, oflags); + + if (retval->i2c_get_fd() < 0) + { + error("i2c: Error opening the interface: %s\n", strerror(errno)); + return octave_value(); + } + + return octave_value(retval); +} Added: trunk/octave-forge/main/i2c/src/i2c.h =================================================================== --- trunk/octave-forge/main/i2c/src/i2c.h (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c.h 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,72 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#ifndef i2c_H +#define i2c_H + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <string> + +using std::string; + +class octave_i2c : public octave_base_value +{ +public: + octave_i2c(); + octave_i2c(string, int); + ~octave_i2c(); + + int i2c_get_fd(); + int i2c_close(); + + int i2c_set_addr(int); + int i2c_get_addr(); + + // Simple i2c commands + int i2c_write(unsigned char*, int); + int i2c_read(char*, unsigned int); + + + // Overloaded base functions + double i2c_value() const + { + return (double)this->fd; + } + + virtual double scalar_value (bool frc_str_conv = false) const + { + return (double)this->fd; + } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax) const; + + // Properties + bool is_constant (void) const { return true;} + bool is_defined (void) const { return true;} + bool print_as_scalar (void) const { return true;} + +private: + int fd; + int addr; + + DECLARE_OCTAVE_ALLOCATOR + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + + +#endif Added: trunk/octave-forge/main/i2c/src/i2c_addr.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_addr.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_addr.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,89 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_addr", "i2c.oct"); +DEFUN_DLD (i2c_addr, args, nargout, "Hello World Help String") +{ + if (args.length() > 2 || + args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + + // Setting new slave address + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + i2c->i2c_set_addr(args(1).int_value()); + + return octave_value(); + } + + // Returning current slave address + return octave_value(i2c->i2c_get_addr()); +} + +int octave_i2c::i2c_set_addr(int addr) +{ + + if (::ioctl(i2c_get_fd(), I2C_SLAVE, addr) < 0) + { + error("i2c: Error setting slave address: %s\n", strerror(errno)); + return false; + } + + return true; +} + +int octave_i2c::i2c_get_addr() +{ + return this->addr; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_close.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_close.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_close.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,66 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_close", "i2c.oct"); +DEFUN_DLD (i2c_close, args, nargout, "Hello World Help String") +{ + if (args.length() != 1 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + i2c->i2c_close(); + + return octave_value(); +} + +int octave_i2c::i2c_close() +{ + int retval = ::close(this->i2c_get_fd()); + this->fd = -1; + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_read.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_read.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_read.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,101 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_read", "i2c.oct"); +DEFUN_DLD (i2c_read, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + char *buffer = NULL; + unsigned int buffer_len = 1; + + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + buffer_len = args(1).int_value(); + } + + buffer = new char [buffer_len + 1]; + + if (buffer == NULL) + { + error("i2c_read: cannot allocate requested memory..."); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + int retval; + + retval = i2c->i2c_read(buffer, buffer_len); + + octave_value_list return_list; + uint8NDArray data(retval); + + for (int i = 0; i < retval; i++) + data(i) = buffer[i]; + + return_list(1) = retval; + return_list(0) = data; + + delete[] buffer; + + return return_list; +} + +int octave_i2c::i2c_read(char *buf, unsigned int len) +{ + int retval = ::read(i2c_get_fd(), buf, len); + + if (retval != len) + error("i2c: Failed to read from the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_write.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_write.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_write.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,90 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// 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. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_write", "i2c.oct"); +DEFUN_DLD (i2c_write, args, nargout, "Hello World Help String") +{ + if (args.length() != 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + const octave_base_value& data = args(1).get_rep(); + int retval; + + if (data.is_string()) + { + string buf = data.string_value(); + retval = i2c->i2c_write((unsigned char*)buf.c_str(), buf.length()); + } + else if (data.byte_size() == data.numel()) + { + NDArray dtmp = data.array_value(); + unsigned char* buf = new unsigned char [dtmp.length()]; + + for (int i = 0; i < dtmp.length(); i++) + buf[i] = (unsigned char)dtmp(i); + + retval = i2c->i2c_write(buf, data.byte_size()); + + delete[] buf; + } + else + { + print_usage(); + return octave_value(-1); + } + + return octave_value(retval); +} + +int octave_i2c::i2c_write(unsigned char *buf, int len) +{ + int retval = ::write(i2c_get_fd(), buf, len); + + if (retval < 0) + error("i2c: Failed to write to the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Modified: trunk/octave-forge/main/serial/DESCRIPTION =================================================================== --- trunk/octave-forge/main/serial/DESCRIPTION 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/DESCRIPTION 2012-08-19 22:32:59 UTC (rev 10887) @@ -6,6 +6,6 @@ Title: Serial Description: Serial functions for communicating from within octave. Categories: Serial -Depends: octave (>= 3.6.2) +Depends: octave (>= 3.2.0) Autoload: no License: LGPLv3+ Modified: trunk/octave-forge/main/serial/src/serial.h =================================================================== --- trunk/octave-forge/main/serial/src/serial.h 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/serial.h 2012-08-19 22:32:59 UTC (rev 10887) @@ -23,12 +23,6 @@ #include <string> -/* a=target variable, b=bit number to act upon 0-n */ -#define BIT_SET(a,b) ((a) |= (1<<(b))) -#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b))) -#define BIT_FLIP(a,b) ((a) ^= (1<<(b))) -#define BIT_CHECK(a,b) ((a) & (1<<(b))) - #define BITMASK_SET(x,y) ((x) |= (y)) #define BITMASK_CLEAR(x,y) ((x) &= (~(y))) #define BITMASK_TOGGLE(x,y) ((x) ^= (y)) Modified: trunk/octave-forge/main/serial/src/srl_baudrate.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_baudrate.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_baudrate.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -38,19 +38,13 @@ // PKG_ADD: autoload ("srl_baudrate", "serial.oct"); DEFUN_DLD (srl_baudrate, args, nargout, "Hello World Help String") { - if (args.length() < 1 || args.length() > 2) + if (args.length() < 1 || args.length() > 2 || + args(0).type_id() != octave_serial::static_type_id()) { - error("srl_baudrate: expecting one or two arguments..."); + print_usage(); return octave_value(-1); } - - if (args(0).type_id() != octave_serial::static_type_id()) - { - error("srl_baudrate: expecting first argument of type octave_serial..."); - return octave_value(-1); - } - // Setting new baudrate if (args.length() > 1) { Modified: trunk/octave-forge/main/serial/src/srl_read.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -88,9 +88,8 @@ } octave_value_list return_list; - uint8NDArray data; - data.resize(buffer_read); - + uint8NDArray data(buffer_read); + // TODO: clean this up for (int i = 0; i < buffer_read; i++) { Modified: trunk/octave-forge/main/serial/src/srl_write.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_write.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_write.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -39,24 +39,14 @@ // PKG_ADD: autoload ("srl_write", "serial.oct"); DEFUN_DLD (srl_write, args, nargout, "Hello World Help String") { - if (args.length() != 2) + if (args.length() != 2) || + args(0).type_id() != octave_serial::static_type_id() || + !args(1).is_string()) { - error("srl_write: expecting two arguments..."); + print_usage(); return octave_value(-1); } - - if (args(0).type_id() != octave_serial::static_type_id()) - { - error("srl_write: expecting first argument of type octave_serial..."); - return octave_value(-1); - } - - if (!args(1).is_string()) - { - error("srl_write: expecting second argument of type string..."); - return octave_value(-1); - } - + octave_serial* serial = NULL; const octave_base_value& rep = args(0).get_rep(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |