The FlexiPanel Bluetooth Protocol is a remote UI service for computers, electrical appliances, and other devices.
September 01, 2004
URL:http://www.drdobbs.com/mobile/bluetooth-remote-device-user-interfaces/184405820
Richard is a development engineer at FlexiPanel Ltd and coauthor of Data Mining and Business Intelligence: A Guide to Productivity. He may be contacted at rhoptroffflexipanel.com.
I originally developed the FlexiPanel protocol in 2002 as an IrDA infrared protocol for engine tuning in hobbyist racing cars. The engine was controlled by a microcontroller that needed to be fine-tuned with a number of preset values. Incorporating an onboard user interface (such as an LCD display and keyboard) to enter the tuning parameters was impracticalit would be too expensive, heavy, bulky, and fragile. At the time, PDAs with infrared capability were becoming popular, so it seemed logical to use one for the user interface. The FlexiPanel protocol was thus conceived as a way to let embedded systems create UIs on any suitable device that users might have at hand.
However, the protocol's limitations, and its wider potential, soon became apparent. IrDA might be wireless but, in practice, the communicating devices must be held steady within a one-foot (30 cm) range of each other and within line of sight. On the other hand, emerging radio technologies, such as Wi-Fi, Bluetooth, and ZigBee (a low-power protocol), offered 330-foot (100 m) range. Nor did they need exterior real estatea tremendous product design advantage in terms of cost, aesthetics, and reliability in hostile environments.
Consequently, we decided to migrate the technology to Bluetooth, on the grounds that it was widely implemented on remote devices and suited the ad hoc nature of the connection between appliances and remote handhelds. In addition, Intel had just committed incorporating Bluetooth into its Centrino 2 chipset. While Wi-Fi and ZigBee remain viable transport layers, they currently are not implemented widely enough on handheld devices.
At the same time, it became clear that the FlexiPanel protocol's potential went far beyond engine tuning. It provides a Human Machine Interface for smart dust (intelligent devices comprised of a microcontroller and a few external components), thus far extending their range of application. It offers a UI for "headless" (no screen or keyboard) single-board computers. This promises cost reductions for point-of-sale systems, computer-operated machine tools, and the like, while freeing operators from control panels. In traditional Windows applications, the protocol offers the possibility of a supplementary, roaming UI. Though rarely vital to Windows applications, roaming capability is a liberating addition to any application that might have anything to say to users while away from their desk.
In short, the FlexiPanel Bluetooth Protocol is a remote user-interface service for computers, electrical appliances, and other machinery. A FlexiPanel server resides on the application and holds a UI database that reflects the appliance's human-machine interface needs. A FlexiPanel client can connect at any time, read the database, and display the UI. Users may then control the application from the client device. Using Bluetooth, clients can be up to 330 feet away without need for line-of-sight communication. FlexiPanel clients have been implemented on a range of PDAs and cellphones and are freely available (http://www.flexipanel.com/DownloadsIndex.htm).
Like many higher level protocols such as OBEX file exchange, FlexiPanel sits on top of the RFCOMM serial port emulation layer of the Bluetooth protocol stack (Figure 1). It is not part of the official Bluetooth Standard. However, the Standard is relatively open in that anyone is free to create FlexiPanel clients, and FlexiPanel server licenses are royalty free (http://www.flexipanel.com/RemoteControlsAPI/index.htm).
As with all emerging technologies, early Bluetooth devices suffered from clunky operation and compatibility problems. This was particularly true of service discoveryfinding out what Bluetooth devices are in range and the services they provide. Many 2002-era devices were limited to preconnection over a virtual serial port, rather than providing service discovery APIs. In the last year, Microsoft's support for Bluetooth in Windows Sockets has made service discovery a one-click process that even Amazon boss Jeff Bezos would be proud of.
From the application's perspective, FlexiPanel is a GUI service just like any other. It can create controls and subsequently change the properties of those controls. If users modify a control, the application is sent a notification message. The application doesn't need to know that the UI is displayed remotely. Conversely, just like a web browser, the FlexiPanel client is generic and does not need to know anything about the server it is providing a UI for. (Client software is generally free, too.) Table 1 lists the types of control that may be created. Under the hood, the FlexiPanel protocol is based on just 12 basic types of message passed between client and server (Table 2).
The main differences between the FlexiPanel protocol and regular UI services are:
In the following example, I use the FlexiPanel server C library to create a remote control panel for a data-logging embedded system. The library is intended to work with the lowest level embedded controllers possible. Therefore, I make no assumptions within the library about serial port buffering or multithreading support.
The data logger records the value of a proximity sensor. It has no UI of its own and relies on FlexiPanel to communicate with the outside world. The distance measured is displayed as a digital readout on a number control and as a historical log in a matrix control.
The data logger (Figure 5) is based on an 80186-based FlashCore embedded controller from Tern (http://www.tern.com/). A GP2D12 analog proximity sensor (Sharp Electronics) is connected to an A/D input and serves as the data source. A BlueWAVE Bluetooth serial module from Wireless Futures (http://www.wirelessfutures.co.uk/products/) is connected to a serial port to enable connection to FlexiPanel remote clients. The data logger's job is simple and few lines of code are required to implement it (Listing One). All calls to the FlexiPanel server library begin with the prefix FBVS. Like most FlexiPanel applications written for embedded controllers, it consists of fixed sections: initialization, user interface definition, main program loop, client message processing, and an ungraceful disconnect handler.
The OrderMaster console application uses the FlexiPanel .NET library to create a remote control panel for a restaurant order-taking system. A Windows server computer with a printer is located near the kitchen and prints out the orders for the kitchen and the checks for the customers. It needs to be Bluetooth equipped and, therefore, will require a USB Bluetooth adapter (ideally a class 1 adapter with a 330-foot range).
The wait-staff carry remote devices for taking orders. The application is targeted specifically for PocketPC clients. The UI has been designed using a fat thumbs approach, where the controls are large enough that no stylus is required. In keeping with the FlexiPanel philosophy, however, any FlexiPanel client would be able to connect. A waiter who lost his PocketPC could always use his cellphone to take orders. Indeed, it would be possible for customers to place orders and print out their checks themselves if they had an appropriate device.
Figure 6 is the OrderMaster main screen. At the top is a text control for displaying a summary of the current order. Below it are section controls that drill down to specific sections of the menu. At the bottom is a list control to select the table being served and buttons to order the check, clear the order, and confirm the order.
Figure 7 is an Appetizer subscreen. At the top is the section control that returns to the main screen. Below it are number controls for setting order quantities for individual items on the menu. The code required to implement OrderMaster is available electronically; see "Resource Center," page 5. Since much of the code is repetitive and would in practice be replaced with loops working from a menu database, code for subscreens other than the appetizers has not been implemented.
The FlexiPanel .NET namespace is called RCapiM. It consists of static function calls for management of the user interface service and classes for each of the 12 control types. Like the data logger, this application consists of the same five sections: initialization, UI definition, main program loop, client message processing, and ungraceful disconnect handler.
Born almost by accident while trying to optimize engine performance, the FlexiPanel Protocol has evolved into a patented user-interface service for a range of devices from tiny microcontrollers to .NET applications. Future development plans include:
DDJ
// Bluetooth module is connected to serial port SER1 extern COM ser1_com; #define BTH_BAUD 12 // 115,200 baud for SER1 #define BTH_INBUFF 1024 // SER1 Input buffer size #define BTH_OUTBUFF 1024 // SER1 Output buffer size unsigned char ser1_in_buf[BTH_INBUFF]; // SER1 Input buffer unsigned char ser1_out_buf[BTH_OUTBUFF]; // SER1 Output buffer // UI constants #define CID_ATOD 1 #define CID_CHART_TY 2 #define NUM_CTRL 2 #define NUM_OPTION 2 // function prototypes void ProcessFlexiPanelMessages(void); void HaltProcesses(void); void main(void) { int16 loopcount; // initialize serial port (calls serial I/O library) s1_init( BTH_BAUD, ser1_in_buf, BTH_INBUFF, ser1_out_buf, BTH_OUTBUFF, &ser1_com ); // initialize FlexiPanel library and give the UI a name FBVSInit( NULL, NULL, 1, &ser1_com, NUM_OPTION ); FBVSSetDevNameAndCharSet( "Tern Demo" ); // initiate control panel description FBVSStartControlList( NUM_CTRL ); // numeric display of distance FBVSAddNumber( CID_ATOD, CTL_NUM_FIXEDPOINT, "Range", 0, 0, 0, 2, -2, "%% m", NULL); // graphical display of distance log FBVSAddMatrix(CID_CHART_TY, CTL_MTX_DATA_TY | CTL_MTX_Y_FIXEDPOINT | CTL_MTX_Y_2BYTE, "Data Log", 30, 0, NULL, 1, NULL, "Range", "Time", "%% m", "%HH%:%mm%:%ss%", 2, -2, 0, 0, NULL); // suggest how chart might be displayed FBVSSetOption( PPC_DEV_ID, CID_CHART_TY, PPC_ATT_STYLE, PPC_CST_MATRIX_POINTS ); FBVSSetOption( WIN_DEV_ID, CID_CHART_TY, WIN_ATT_STYLE, WIN_CST_MATRIX_POINTS ); // complete control panel description FBVSPostControls( ); // start control panel service FBVSConnect(); // main program loop loopcount = 0; while (1) { // ensure each loop takes around 10ms delay_ms(10); // discover whether client has sent any messages ProcessFlexiPanelMessages(); // every 3 seconds, ping loopcount ++; if (loopcount == 300) { loopcount = 0; // ping if ( FBVSIsClientConnected() && FBVSIsPingSupported() && FBVSPing() ) { // lost contact with remote device; continue cautiously HaltProcesses(); } } // every second, log proximity sensor if (loopcount%100==0) { int16 range; DateTimeU dt; // read A/D (calls A/D library) range = fb_ad16( 0xc6 ); // update numeric display FBVSSetNumberControlData( CID_ATOD, range ); // update chart SetToCurrentTime( &dt ); FBVSAddMatrixControlData( CID_CHART_TY, &range, &dt ); // send updated time to client FBVSUpdateControlsOnClient( ); } } } void ProcessFlexiPanelMessages(void) { // check for message switch (FBVSGetNotifyCode()) { // nothing has happened case FBVSN_NoNotify: break; // Client has connected; clear the contents of the matrix control case FBVSN_ClientConnected: FBVSSetMatrixControlData( CID_CHART_TY, 0, NULL, NULL ); break; // Client has modified a control. in this app, no controls are // modifiable by the client, so nothing to do case FBVSN_ClientData: break; // Client has disconnected case FBVSN_ClientDisconnected: break; // following messages are informational only and will be ignored case FBVSN_GotProfileRequest: case FBVSN_GotPinged: case FBVSN_GotPingReply: case FBVSN_GotAck: case FBVSN_IncompatibleVersion: break; case FBVSN_Abandon: // Error; generally only gets here during development HaltProcesses(); Reset(); break; } } void HaltProcesses(void) { // In this function, anything controlled by the embedded // controller is put in a fail-safe state. // nothing being controlled in this app, so nothing to do }Back to article
Logical Control | Example Depiction on a Remote Client | Function/Value |
Button | Button | Single-press event. |
Latch | Check Box, Radio Button | Binary value. |
Text | Static Text, Edit text | Character string. |
Number | Progress Bar, Slider | Integer or fixed-point value. |
Matrix | Table, Column Chart, Line chart | 2D array of numeric values. |
Date Time | Date Time Picker | Seconds to years plus day of week |
List | List Box | One of n selection. |
Section | Popup Menu | Arranges controls in a hierarchy. |
Password | Client-Specific Dialogs | Controls access UI. |
Message | Message Box | Alerts users. |
Blob* | Client-Specific Dialogs | Exchanges binary data. |
Files* | Client-Specific Dialogs | Exchanges files. |
Message | Originator (Client/Server) | Purpose |
Greetings | Either | Establishes a connection. |
Goodbye | Either | Closes a connection. |
New Control Panel | Server | Sends control descriptions to client. |
Control Modified | Either | Modifies a control's value. |
Ping | Either | Presence check request. |
Ping Reply | Either | Presence check confirmation. |
Ack | Either | Acknowledge receipt of message. |
New Server | Server | Server initializing. |
Props Update | Server | Modifies a control's properties. |
Files | Server | Downloads requested files. |
Profile Request | Client | Requests device-specific layout advice. |
Profile Reply | Server | Downloads device-specific layout advice. |
Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.