|Re: [ecf-dev] pi4j and OSGi (remote) services|
I've done quite a lot of work with the gpio pin service (e.g. testing), and I wanted to make you and everyone aware of it.
1) the latest IGPIOPin API is available in the bundle: bundles/org.eclipse.ecf.raspberrypi.gpio in repo . This bundle will be needed on both the host and any consumer frameworks since it declares the IGPIOPin service interface.
2a) The host implementation (using pi4j) is in bundle: bundles/org.eclipse.ecf.raspberrypi.gpio.pi4j. You will probably want to look in the Activator class, since I added system properties to allow the programmer to
a) control which of the 20 pins to create services for (PINS);
b) which of the gpio pin services to export (PINS_EXPORT). I'll document this soon in a tutorial, but I haven't had a chance to write a tutorial yet.
2b) The pi4j library comes in bundle form (i.e. with an OSGi manifest, etc), and naturally this has to be available in the target platform to that the o.e.e.raspberrypi.gpio.pi4j code can use it. Note that the pi4j library itself depends upon the WiringPi native code library...see  for pi4j dependency docs and WiringPi download/install instructions. Before you can use pi4j for anything described here you have to install a recent version of WiringPi.
3) I created a simple local test application in bundle: test/bundles/org.eclipse.ecf.raspberrypi.test.gpio in . All this test application does is when the bundle is started it creates a ServiceTracker to discover registered IGPIOPin services, and when a service gets added it sets the pin state to HIGH (true). I've been using an LED with the setup described here , to test that the IGPIOPin service is working on pin 0. Short story: On my raspberry pi it is working great! I'm using a model B2, and so I had to look at the B2 pi docs to figure out which gpio pin was pin0...and of course figure out which pin was ground as well on the B2, but once I got that figured out it was working.
4) I created a test feature in test/features/org.eclipse.ecf.raspberrypi.test.gpio.feature project and also a product configuration. When exported the product configuration creates a zip named raspberrypigpiotest.zip, and I built a version of this test application and placed in the feature project build directory. I can run this on my raspberry pi (wired up to an LED on pin 0 as described above), by unzipping the raspberrypigpiotest.zip on the pi, cd into the raspberrypigpiotest/ directory, switch user to *root* (necessary because pi4j requires root access to get to the pins), change the file mode of the gpiotesthost.sh startup script to 700 (executable), and then start the gpiotesthost.sh...e.g.:
file:/home/pi/raspberrypitestgpio/.options not found
Time to load bundles: 206
"Framework is launched."
id State Bundle
0 ACTIVE org.eclipse.osgi_3.10.0.v20140407-2102
1 ACTIVE org.eclipse.ecf.raspberrypi.gpio_188.8.131.52407282024
2 ACTIVE org.eclipse.ecf.raspberrypi.gpio.pi4j_184.108.40.206407282024
3 RESOLVED org.eclipse.ecf.raspberrypi.test.gpio_220.127.116.11407282024
4 ACTIVE org.eclipse.osgi.services_3.4.0.v20140312-2051
5 ACTIVE org.eclipse.osgi.util_3.3.0.v20131023-1243
6 ACTIVE pi4j-core_1.0.0.SNAPSHOT
7 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639
8 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215
9 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036
10 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605
1) all bundles are started except bundle 3 (the test consumer of IGPIOPin services);
2) *For the moment* there are no OSGi/ECF remote services bundles present and so remote service is not being used yet.
If bundle 3 is started from the osgi console, then the IGPIOPin service (for pin 0) is discovered by the service tracker, and the pin 0 state is set to high/true (this code is in the org.eclipse.ecf.raspberrypi.test.gpio bundle). On my pi, with the LED hooked up to it, the LED lights up!
osgi> start 3
Adding GPIO Pin service. id=0
current pin state is LOW
setting state to HIGH
and if bundle 3 is stopped, the light turns off
osgi> stop 3
Removing GPIO Pin service. id=0
setting state to LOW
This testing has been working great, and so now I'm ready to do some other things over the next few days:
1) Add the ECF remote services/RSA impl to the test code, and export the IGPIOPin 0 as a remote service.
2) Install the test bundle into Eclipse as an example remote service consumer, and try manipulating pin 0 as a remote service... perhaps with some Eclipse UI (e.g. button) to do so.
Anyway, that's what's next on my list of things to do.
Feel free to ask any questions. Like I said, as soon as I can I'll document this all in the form of another tutorial.
On 7/28/2014 2:21 PM, Wim Jongman wrote: