Personal tools
The Open Lighting Project has moved!

We've launched our new site at www.openlighting.org. This wiki will remain and be updated with more technical information.

Difference between revisions of "IPad ArtNet Node"

From wiki.openlighting.org

Jump to: navigation, search
(Initial draft)
 
(Preparing libartnet from Git)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
Written by Tobi Schäfer, September 2010.
 
Written by Tobi Schäfer, September 2010.
 +
Updated by Tobi Schäfer, July 2011.
  
Prerequisites: libarnet 1.1.0, Mac OS X 10.6.4, Xcode 3.2.3, iPad w/ iOS 3.2
+
Prerequisites: libartnet 1.1.0, Mac OS X 10.6.8, Xcode 4.0.2, iPad w/ iOS 4.3
  
== Using libartnet in the Xcode Simulator ==
+
== Using libartnet in Xcode ==
  
=== Installing libartnet ===
+
This is documentation of my first steps using libartnet and Xcode. I am still a complete newbie with all these things. However, I suceeded in running a simple program on the iPad sending and receiving Art-Net data – not without help from the excellent people of the open-ligthing ML<ref>http://groups.google.com/group/open-lighting/browse_thread/thread/e3f322613b710d9d/661d7e4babba4bf1</ref>. I tried to sum up here my experiences so far, although I am sure there are better ways to achieve the same result.
  
curl -O http://code.google.com/p/linux-lighting/downloads/detail?name=libartnet-1.1.0.tar.gz
+
First, we download the libartnet sources and prepare them for inclusion in Xcode. We need to generate a file called <code>config.h</code> to make things work. This can be done either by downloading a tarball or checking out the sources with Git.
tar xzf libartnet-1.1.0.tar.gz
 
cd libartnet-1.1.0
 
./configure CC="gcc -arch i386"
 
make
 
sudo make install
 
  
=== Adding libartnet.dylib to XCode ===
+
=== Preparing libartnet from Tarball ===
  
Simply drag&drop the file <code>libartnet.1.dylib</code> from the <code>/usr/local/lib</code> directory to the Frameworks group in Xcode.
+
Copy the URL from http://code.google.com/p/open-lighting/downloads/list
 +
$ curl -O http://code.google.com/....
 +
$ tar -xzf libartnet-1.1.0.tar.gz
 +
$ cd libartnet-1.1.0/
 +
$ ./configure
 +
$ cp config.h artnet/
  
''Hint:'' you can easily open hidden directories in a new window from within Terminal.app:
+
=== Preparing libartnet from Git ===
  
  open /usr/local/lib
+
  $ git clone https://github.com/OpenLightingProject/libartnet.git
 +
$ cd libartnet/
 +
$ autoreconf -i
 +
$ ./configure
 +
$ cp config.h artnet/
  
Add the path <code>/usr/local/include</code> to the Header Search Paths in the Search Paths section of your project or target and tick the recursive checkbox.<ref>http://iphone.olipion.com/cross-compilation/include-library-in-xcode-project</ref>
+
=== Adding libartnet to Xcode ===
  
[[File:Screen shot 2010-09-16 at 11.59.40.png]]
+
Create a directory called <code>Vendor/artnet</code> in the Xcode project directory – in the file system or Finder, not in the Xcode application; the latter will be done in the next step – and copy the source files from the <code>artnet</code> directory of the previous step into the new <code>Vendor/artnet</code> directory.
  
== Using libartnet On The iPad ==
+
$ mkdir -p ~/test/Vendor/artnet
 +
$ cp artnet/*.[ch] ~/test/Vendor/artnet
  
Getting libartnet to work on the iPad is a little bit trickier and involves cross-compiling the library for the iPad’s processor architecture.
+
$ ls -l ~/test
 +
total 0
 +
drwxr-xr-x  10 tobi  tobi  340 Jul  1 17:20 ArtNetTest
 +
drwxr-xr-x  5 tobi  tobi  170 Jul  1 21:17 ArtNetTest.xcodeproj
 +
drwxr-xr-x  7 tobi  tobi  238 Jul  1 15:05 ArtNetTestTests
 +
drwxr-xr-x  4 tobi  tobi  136 Jul  1 21:08 Vendor
  
Fortunately, there is help on the Intertubes.
+
$ ls -l ~/test/Vendor/artnet
 +
total 352
 +
-rw-r--r--  1 tobi  tobi  44082 Jul  1 20:52 artnet.c
 +
-rw-r--r--  1 tobi  tobi  11580 Jul  1 20:52 artnet.h
 +
-rw-r--r--  1 tobi  tobi  1987 Jul  1 20:52 common.h
 +
-rw-r--r--  1 tobi  tobi  4831 Jul  1 20:52 config.h
 +
-rw-r--r--  1 tobi  tobi  1754 Jul  1 20:52 misc.c
 +
-rw-r--r--  1 tobi  tobi  1610 Jul  1 20:52 misc.h
 +
-rw-r--r--  1 tobi  tobi  18941 Jul  1 20:52 network.c
 +
-rw-r--r--  1 tobi  tobi  8495 Jul  1 20:52 packets.h
 +
-rw-r--r--  1 tobi  tobi  13397 Jul  1 20:52 private.h
 +
-rw-r--r--  1 tobi  tobi  27731 Jul  1 20:52 receive.c
 +
-rw-r--r--  1 tobi  tobi  2806 Jul  1 20:52 tod.c
 +
-rw-r--r--  1 tobi  tobi  1307 Jul  1 20:52 tod.h
 +
-rw-r--r--  1 tobi  tobi  12364 Jul  1 20:52 transmit.c
  
=== Cross-compiling libartnet For The iPad ===
+
Now drag&drop the Vendor folder to the top level of the Xcode project and choose the following options for adding files.
  
First of all, it is safer to remove already installed libartnet files if you should have built the dynamic library in a previous step. Otherwise you could follow the steps in [http://developer.apple.com/library/mac/#qa/qa2006/qa1393.html Apple’s Technical QA1393 document].
+
[[File:Screen_shot_2011-07-01_at_20.45.17.png‎]]
  
rm -rf /usr/local/lib/libartnet.*
+
The structure of your project should look similar to this:
  
Then clean your libartnet build directory:
+
[[File:Screen_shot_2011-07-01_at_20.57.03.png‎]]
  
make distclean
+
Add the path to the <code>Vendor</code> directory to the Header Search Paths in the Search Paths section of your build target and tick the recursive checkbox.<ref>http://iphone.olipion.com/cross-compilation/include-library-in-xcode-project</ref>
  
I found a [http://stackoverflow.com/questions/1602182/cross-compile-autotools-based-libraries-for-official-iphone-sdk helper script] which sets all necessary cross-compiling flag
+
[[File:Screen_shot_2011-07-01_at_21.10.22.png‎]]
  
Copy it to your Mac as <code>build.sh</code>. You probably need to modify the SDK version to your needs:
+
Finally. add the <code>HAVE_CONFIG_H</code> macro to the Preprocessor Macros section of your project’s build settings.
  
export SDKVER="3.2"
+
[[File:Screen_shot_2011-07-01_at_21.17.40.png]]
  
Furthermore, you should add the following line before the <code>./configure ...</code> command to prevent another error from happening:<ref>http://groups.google.com/group/open-lighting/msg/28e002886ba95ced</ref>
+
At this point your project should build and run without error – the libartnet source code will be compiled and linked automatically.
 
 
export ac_cv_func_malloc_0_nonnull=yes
 
 
 
Make the file executable and then run the script:
 
 
 
chmod a+x build.sh
 
./build.sh
 
 
 
If it compiles it should install the file <code>libartnet.a</code> into the directory <code>/opt/iphone-3.2/lib</code> as well as the header files into </code>/opt/iphone/include</code>.
 
 
 
=== Adding libartnet.a To Xcode ===
 
 
 
As with <code>libartnet.dylib</code> drag&drop the <code>libartnet.a</code> file to the Frameworks group in Xcode.
 
 
 
Similarly, add the path <code>/usr/iphone-3.2/include</code> to the Header Search Paths in the Search Paths section of your project or target and tick the recursive checkbox.
 
  
 
== Example Code ==
 
== Example Code ==
Line 71: Line 81:
 
[[File:Screen shot 2010-09-16 at 12.12.59.png]]
 
[[File:Screen shot 2010-09-16 at 12.12.59.png]]
  
The code is just a proof of concept and not ready for production. It creates and sets up an Art-Net node, defines a handler method for incoming data and then creates an infinite loop sending Art-Net polls and checking for Art-Net input.  
+
The code is just a proof of concept and not ready for production – actually it is pretty bad because it abuses the <code>main</code> method instead of creating its own controller. However, it reduces complexity and simply shows the basic approach to using libartnet from within Objective-C code.
 +
 
 +
The code creates and sets up an Art-Net node, defines a handler method for incoming data and then creates an infinite loop sending Art-Net polls and checking for Art-Net input.  
  
 
  #import "artnet.h"
 
  #import "artnet.h"
Line 115: Line 127:
 
         artnet_set_handler(artnetNode, ARTNET_RECV_HANDLER, artnetReceiver, NULL);  
 
         artnet_set_handler(artnetNode, ARTNET_RECV_HANDLER, artnetReceiver, NULL);  
 
   
 
   
        if (artnet_set_dmx_handler(artnetNode, dmxHandler, NULL) != 0) {
 
                printf("Error: %s\n", artnet_strerror());
 
                exit(-1);
 
        }     
 
       
 
 
         if (artnet_start(artnetNode) != 0) {
 
         if (artnet_start(artnetNode) != 0) {
 
                 printf("Error: %s\n", artnet_strerror());
 
                 printf("Error: %s\n", artnet_strerror());
Line 135: Line 142:
 
         //artnet_destroy(artnetNode);
 
         //artnet_destroy(artnetNode);
 
      
 
      
     return retVal;
+
     return 0;
 
  }
 
  }
  
Line 142: Line 149:
 
If your program builds and runs without errors you now can test whether Art-Net data is sent and received. Wireshark<ref>http://www.wireshark.org</ref> is a handy tool for monitoring your network.
 
If your program builds and runs without errors you now can test whether Art-Net data is sent and received. Wireshark<ref>http://www.wireshark.org</ref> is a handy tool for monitoring your network.
  
However, for sending Art-Net data you will need a more appropriate tool. I am using the [[OLA_Command_Line_Tools|OLA Command Line Tools]], running them from another machine running GNU/Linux.
+
However, for sending Art-Net data you will need a more appropriate tool. I am using the [[OLA_Command_Line_Tools|OLA Command Line Tools]], running them from another machine with GNU/Linux (Ubuntu 10.04) as operating system.
 
 
Although I did not test it, you probably can also install OLA on another Mac or even the same machine you are running XCode on, using the available [http://code.google.com/p/linux-lighting/downloads/detail?name=OLA%200.8.1.dmg Installer Disk Image] and/or following the steps of the [[OLA_on_OS_X|OLA On Mac OS X]] page.
 
  
=== Installing OLA On Ubuntu ===
+
Although I did not test it, you probably can also install OLA on the same machine you are running Xcode on.
  
Please refer to the [[OLA_on_Linux|OLA On Linux]] page.
+
=== Installing OLA on Mac OS X ===
  
If you should get the following error try to fix it with one of [http://groups.google.com/group/open-lighting/msg/72060f6327d30df6 two available solutions]:
+
Please refer to the [[OLA_on_OS_X|OLA On Mac OS X]] page.
  
Rpc.pb.cc: In copy constructor 'ola::rpc::RpcMessage::RpcMessage(const ola::rpc::RpcMessage&)':
+
=== Installing OLA on Ubuntu ===
Rpc.pb.cc:143: error: base class 'class google::protobuf::Message' should be explicitly initialized in the copy constructor
 
  
A similar error can occur when building the ola-examples package:
+
Please refer to the [[OLA_on_Linux|OLA On Linux]] page.
 
 
g++ -DHAVE_CONFIG_H -I. -I..    -Wall -Werror -I/usr/local/include/
 
libola  -g -O2 -MT ola-dmxconsole.o -MD -MP -MF .deps/ola-
 
dmxconsole.Tpo -c -o ola-dmxconsole.o ola-dmxconsole.cpp
 
cc1plus: warnings being treated as errors
 
ola-dmxconsole.cpp: In function ‘void mask()’:
 
ola-dmxconsole.cpp:150: error: value computed is not used
 
ola-dmxconsole.cpp:156: error: value computed is not used
 
ola-dmxconsole.cpp: In function ‘void values()’:
 
ola-dmxconsole.cpp:184: error: value computed is not used
 
ola-dmxconsole.cpp:188: error: value computed is not used
 
ola-dmxconsole.cpp:190: error: value computed is not used
 
ola-dmxconsole.cpp:194: error: value computed is not used
 
ola-dmxconsole.cpp:197: error: value computed is not used
 
ola-dmxconsole.cpp:202: error: value computed is not used
 
ola-dmxconsole.cpp:205: error: value computed is not used
 
ola-dmxconsole.cpp:208: error: value computed is not used
 
ola-dmxconsole.cpp:215: error: value computed is not used
 
ola-dmxconsole.cpp:225: error: value computed is not used
 
ola-dmxconsole.cpp:226: error: value computed is not used
 
ola-dmxconsole.cpp:227: error: value computed is not used
 
make[2]: *** [ola-dmxconsole.o] Error 1
 
 
 
You should be able to prevent this by editing <code>./src/Makefile.am</code>, removing <code>-Werror</code> and then running <code>autoreconfig && ./configure</code> again.<ref>http://groups.google.com/group/open-lighting/msg/c6d86d03dd74ed5b</ref>
 
  
=== Patching An Art-Net Node ===
+
=== Patching an Art-Net Node ===
  
 
To make the Ubuntu machine act as an Art-Net node first start the OLA daemon with a debug level of 3:
 
To make the Ubuntu machine act as an Art-Net node first start the OLA daemon with a debug level of 3:
Line 187: Line 167:
 
  olad -l 3
 
  olad -l 3
  
Then we are patching the machine for Art-Net output in universe 1 on port 0:
+
Then patch the machine for Art-Net output in universe 1 on port 0:
  
 
  ola_patch -d 1 -p 0 -u 1
 
  ola_patch -d 1 -p 0 -u 1
Line 201: Line 181:
 
[[File:Screenshot-tobi@acker- ~.png]]
 
[[File:Screenshot-tobi@acker- ~.png]]
  
== Sources ==
+
== References ==
  
 
<references/>
 
<references/>

Latest revision as of 20:24, 19 January 2014

Written by Tobi Schäfer, September 2010. Updated by Tobi Schäfer, July 2011.

Prerequisites: libartnet 1.1.0, Mac OS X 10.6.8, Xcode 4.0.2, iPad w/ iOS 4.3

Using libartnet in Xcode

This is documentation of my first steps using libartnet and Xcode. I am still a complete newbie with all these things. However, I suceeded in running a simple program on the iPad sending and receiving Art-Net data – not without help from the excellent people of the open-ligthing ML<ref>http://groups.google.com/group/open-lighting/browse_thread/thread/e3f322613b710d9d/661d7e4babba4bf1</ref>. I tried to sum up here my experiences so far, although I am sure there are better ways to achieve the same result.

First, we download the libartnet sources and prepare them for inclusion in Xcode. We need to generate a file called config.h to make things work. This can be done either by downloading a tarball or checking out the sources with Git.

Preparing libartnet from Tarball

Copy the URL from http://code.google.com/p/open-lighting/downloads/list

$ curl -O http://code.google.com/....
$ tar -xzf libartnet-1.1.0.tar.gz
$ cd libartnet-1.1.0/
$ ./configure
$ cp config.h artnet/

Preparing libartnet from Git

$ git clone https://github.com/OpenLightingProject/libartnet.git
$ cd libartnet/
$ autoreconf -i
$ ./configure
$ cp config.h artnet/

Adding libartnet to Xcode

Create a directory called Vendor/artnet in the Xcode project directory – in the file system or Finder, not in the Xcode application; the latter will be done in the next step – and copy the source files from the artnet directory of the previous step into the new Vendor/artnet directory.

$ mkdir -p ~/test/Vendor/artnet
$ cp artnet/*.[ch] ~/test/Vendor/artnet
$ ls -l ~/test
total 0
drwxr-xr-x  10 tobi  tobi  340 Jul  1 17:20 ArtNetTest
drwxr-xr-x   5 tobi  tobi  170 Jul  1 21:17 ArtNetTest.xcodeproj
drwxr-xr-x   7 tobi  tobi  238 Jul  1 15:05 ArtNetTestTests
drwxr-xr-x   4 tobi  tobi  136 Jul  1 21:08 Vendor
$ ls -l ~/test/Vendor/artnet
total 352
-rw-r--r--  1 tobi  tobi  44082 Jul  1 20:52 artnet.c
-rw-r--r--  1 tobi  tobi  11580 Jul  1 20:52 artnet.h
-rw-r--r--  1 tobi  tobi   1987 Jul  1 20:52 common.h
-rw-r--r--  1 tobi  tobi   4831 Jul  1 20:52 config.h
-rw-r--r--  1 tobi  tobi   1754 Jul  1 20:52 misc.c
-rw-r--r--  1 tobi  tobi   1610 Jul  1 20:52 misc.h
-rw-r--r--  1 tobi  tobi  18941 Jul  1 20:52 network.c
-rw-r--r--  1 tobi  tobi   8495 Jul  1 20:52 packets.h
-rw-r--r--  1 tobi  tobi  13397 Jul  1 20:52 private.h
-rw-r--r--  1 tobi  tobi  27731 Jul  1 20:52 receive.c
-rw-r--r--  1 tobi  tobi   2806 Jul  1 20:52 tod.c
-rw-r--r--  1 tobi  tobi   1307 Jul  1 20:52 tod.h
-rw-r--r--  1 tobi  tobi  12364 Jul  1 20:52 transmit.c

Now drag&drop the Vendor folder to the top level of the Xcode project and choose the following options for adding files.

Screen shot 2011-07-01 at 20.45.17.png

The structure of your project should look similar to this:

Screen shot 2011-07-01 at 20.57.03.png

Add the path to the Vendor directory to the Header Search Paths in the Search Paths section of your build target and tick the recursive checkbox.<ref>http://iphone.olipion.com/cross-compilation/include-library-in-xcode-project</ref>

Screen shot 2011-07-01 at 21.10.22.png

Finally. add the HAVE_CONFIG_H macro to the Preprocessor Macros section of your project’s build settings.

Screen shot 2011-07-01 at 21.17.40.png

At this point your project should build and run without error – the libartnet source code will be compiled and linked automatically.

Example Code

You now should be ready to build and run the following code in the Simulator as well as on the iPad. Thus, do not forget to select the corresponding setting from the Overview drop-down menu.

Screen shot 2010-09-16 at 12.12.59.png

The code is just a proof of concept and not ready for production – actually it is pretty bad because it abuses the main method instead of creating its own controller. However, it reduces complexity and simply shows the basic approach to using libartnet from within Objective-C code.

The code creates and sets up an Art-Net node, defines a handler method for incoming data and then creates an infinite loop sending Art-Net polls and checking for Art-Net input.

#import "artnet.h"
#import "packets.h"

int artnetReceiver(artnet_node node, void *pp, void *d) {
       NSLog(@"Receiving Art-Net data!");
       artnet_packet pack = (artnet_packet) pp;
       printf("Received packet sequence %d\n", pack->data.admx.sequence);
       printf("Received packet type %d\n", pack->type);
       printf("Received packet data %s\n", pack->data.admx.data);
       return 0;
 }

int main(int argc, char *argv[]) {
       
       char *ip_addr = NULL;
       
       uint8_t subnet_addr = 0; 
       uint8_t port_addr = 1;
       
       artnet_node *artnetNode = artnet_new(ip_addr, 1);
       
       if (!artnetNode) {
               printf("Error: %s\n", artnet_strerror());
               exit(-1);
       }
       
       artnet_set_long_name(artnetNode, "Art-Net Test");
       artnet_set_short_name(artnetNode, "ANT");
       
       // set the upper 4 bits of the universe address 
       artnet_set_subnet_addr(artnetNode, subnet_addr) ;
       
       // enable port 0        
       artnet_set_port_type(artnetNode, 0, ARTNET_ENABLE_OUTPUT, ARTNET_PORT_DMX) ; 

       // bind port 0 to universe 1 
       artnet_set_port_addr(artnetNode, 0, ARTNET_OUTPUT_PORT, port_addr); 
       
       artnet_dump_config(artnetNode);

       artnet_set_handler(artnetNode, ARTNET_RECV_HANDLER, artnetReceiver, NULL); 

       if (artnet_start(artnetNode) != 0) {
               printf("Error: %s\n", artnet_strerror());
               exit(-1);
       }       
       
       while (YES) {
               artnet_send_poll(artnetNode, NULL, ARTNET_TTM_DEFAULT);
               //printf("arnet_get_sd() => %i\n", artnet_get_sd(artnetNode));
               printf("artnet_read() => %i\n", artnet_read(artnetNode, 1));
       }
   
       // Use this to deallocate memory
       //artnet_stop(artnetNode);
       //artnet_destroy(artnetNode);
   
   return 0;
}

Testing Data Transmission

If your program builds and runs without errors you now can test whether Art-Net data is sent and received. Wireshark<ref>http://www.wireshark.org</ref> is a handy tool for monitoring your network.

However, for sending Art-Net data you will need a more appropriate tool. I am using the OLA Command Line Tools, running them from another machine with GNU/Linux (Ubuntu 10.04) as operating system.

Although I did not test it, you probably can also install OLA on the same machine you are running Xcode on.

Installing OLA on Mac OS X

Please refer to the OLA On Mac OS X page.

Installing OLA on Ubuntu

Please refer to the OLA On Linux page.

Patching an Art-Net Node

To make the Ubuntu machine act as an Art-Net node first start the OLA daemon with a debug level of 3:

olad -l 3

Then patch the machine for Art-Net output in universe 1 on port 0:

ola_patch -d 1 -p 0 -u 1

Now start ola_dmxconsole for sending some Art-Net data in universe 1:

ola_dmxconsole -u 1

If you run the Art-Net project in Xcode (either with the Simulator or on the iPad) and open the Xcode console window you should see log messages according to your actions in the DMX console.

E.g. try to navigate to a channel with the left and right cursor keys and then increase or decrease the value with the scroll up/down keys.

Screenshot-tobi@acker- ~.png

References

<references/>