Over a million developers have joined DZone.

Build Light: Continuous Delivery Meets Reengineering a USB Driver

DZone's Guide to

Build Light: Continuous Delivery Meets Reengineering a USB Driver

· DevOps Zone ·
Free Resource

Read why times series is the fastest growing database category.

Continuous Delivery is a pattern language used in software development to automate and improve the process of software delivery. Techniques such as automated testing, continuous integration and continuous deployment allow software to be developed to a high standard, easily packaged and deployed to test environments.

Continuous delivery treats the commonplace notion of a deployment pipeline: a set of validations through which a piece of software must pass on its way to release. Code is compiled if necessary and then packaged by build servers like Jenkins or Bamboo every time a change is committed to a source control repository, then tested by a number of different techniques before it can be marked as releasable.

As a developer you have to monitor the build server after each commit, in order to see if your work has impacts on the upcomming release. The article Using a Raspberry PI to control an extreme feedback device has inspired us to buy a traffic light in the Cleware Shop. We find the idea cool to visualize the results of our commits with a traffic light and see it as addition to the cS Jenkins Bell. The traffic light is a simple USB device that has a green, a yellow and a red led.

Unfortunately, the original driver of the traffic light only support Microsoft Windows and Linux. But many people at comSysto use Apple PowerBooks.That is why we decided to reengieer the driver and put it in an Java API.  We monitored the linux driver on an Ubuntu virtual machine with the usbmon facility of the Linux kernel. Usbmon can be used to dump information on the raw packet that is sent during the USB communication of the computer and the USB device, which is in our case the Cleware traffic light.

sudo modprobe usbmon

If you do not want to watch the whole communication between a computer and USB device, a tool called Usbdump helps to view only the communication to a defined USB device. Usbdump is a simple frontend for the Linux kernel’s usbmon facility. Every USB device is identified by a vendor and product ID. In case of the Cleware traffic light, the vendor ID is 0D50 and the product ID is 0008.

usbdump -d 0D50:0008 -u 1

Once the usbdump is started, you can switch on and off the traffic light with the original driver and you will get a similar dump as result of the observation. The dump is compressed a little bit. It only shows the switch on and off sequence of the yellow led of the traffic light.

3.680370 1<-- 6: 8a00 0000 0000
3.686056 -->2 3: 0011 01
11.649153 1<-- 6: 8e00 0000 0000
11.675358 -->2 3: 0011 00
11.681172 1<-- 6: 8e00 0000 0000

As you can see, the switch-on sequence of the yellow LED is 0011 01, and the switch-off sequence is 0011 00. Now, all information is available to implement a driver. The HID-API provides a simple Java API for devices such as USB Devices on Mac, Linux and Windows. It is a very simple API. As you can see in the class diagram below, it only consists of four classes. The ClassPathLibraryLoader initializes the native driver, and with the HIDManager you can access a specific device or list all devices. The HIDDeviceInfo delivers information about the USB device and HIDDevice is responsible for the write operations. The write method of the HIDDevice  must be used to write to the USB device. In our case that means, if you want to switch on the yellow light of the traffic light, you have to create a byte array for the sequence 0011 01 using the write method. After the data is written, the yellow light will flash.

HID API Diagram

HID API Class Diagram

We are able to create a very simple Java API for the Cleware traffic light with the help of the  HID-API. As you can see in the class diagram below, there is a TrafficLightFactory that creates a TrafficLightImpl instance, which is used to perform operations like  switching on and off the LEDs of the traffic light USB device.

Class Diagram Java Driver

Class Diagram Java Driver

You can easily use this API in your own application, you only have to put the following dependency in your Maven POM.xml:


If you are using a modern build system like Gradle, you can put the following dependency in your build.gradle:

compile "com.comsysto.buildlight:cleware-driver:1.0"

Here is a code example of how to use the Cleware Traffic Light Java Driver with the above mentioned dependency:

public class TrafficLightFactoryTest {
    public static void main(String[] args) {
        TrafficLight light = TrafficLightFactory.createNewInstance();

Now, let’s come back to continous delivery. We created a small application on top of the Cleware Traffic Light Java Driver, which is called Build Light. It is a watchdog for Jenkins and Bamboo that switches the green LED on the traffic light on when a build succeeds, blinks the yellow light when a build is running and flashes the red light when a build has failed. You can see how it looks like in the following videos:

You can get the Build Light source code from comSysto’s GitHUB repository. The only thing you have to do is visit the link below and unzip the compressed file. It is available for Windows, Mac OS X, Linux and the Raspberry Pi.

Download Build Light artifacts and source

The following Shell commands show how you can install Build Light on Mac OS X:

bzuther@MacBook ~/Downloads$ tar xvf buildlight-0.1-DEV.zip
bzuther@MacBook ~/Downloads$ cd buildlight-0.1-DEV/bin
bzuther@MacBook ~/Downloads$ ./buildlight

You have to create a buildlight.properties file in the bin directory after you have unzipped Build Light. You define the build you want to watch in this file. Here is an example for Jenkins and Bamboo:

#Jenkins example:
#Bamboo example:

Learn how to get 20x more performance than Elastic by moving to a Time Series database.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}