Java Software and Embedded Systems [1 ed.] 9781611225099, 9781607416616

Wireless communications technologies are the platform to develop user-centric systems in a multi-device platform that al

195 79 21MB

English Pages 248 Year 2010

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Java Software and Embedded Systems [1 ed.]
 9781611225099, 9781607416616

Citation preview

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved. Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest Ebook

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved. Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest Ebook

COMPUTER SCIENCE, TECHNOLOGY AND APPLICATIONS SERIES

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

JAVA SOFTWARE AND EMBEDDED SYSTEMS

No part of this digital document may be reproduced, stored in a retrieval system or transmitted in any form or by any means. The publisher has taken reasonable care in the preparation of this digital document, but makes no expressed or implied warranty of any kind and assumes no responsibility for any errors or omissions. No liability is assumed incidental consequential damages connection with or2010. arising out of information Java Software and Embedded Systems, edited by for Mattis Hayes, andor Isaiah Johansen, Nova Sciencein Publishers, Incorporated, ProQuest

COMPUTER SCIENCE, TECHNOLOGY AND APPLICATIONS SERIES Problem Solving with Delphi - CD included Stephen John Sugden 2009 ISBN 978-1-60741-249-6 Mobile Computing Research and Applications Kevin Y. Chen and H.K. Lee (Editors) 2009. ISBN 978-1-60741-101-7 Large Scale Computations, Embedded Systems and Computer Security Fedor Komarov and Maksim Bestuzhev (Editors) 2010. ISBN: 978-1-60741-307-3

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Java Software and Embedded Systems Mattis Hayes and Isaiah Johansen (Editors) 2010. ISBN: 978-1-60741-661-6

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

COMPUTER SCIENCE, TECHNOLOGY AND APPLICATIONS SERIES

JAVA SOFTWARE AND EMBEDDED SYSTEMS

MATTIS HAYES AND

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

ISAIAH JOHANSEN EDITORS

Nova Science Publishers, Inc. New York

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010 by Nova Science Publishers, Inc.

All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means: electronic, electrostatic, magnetic, tape, mechanical photocopying, recording or otherwise without the written permission of the Publisher. For permission to use material from this book please contact us: Telephone 631-231-7269; Fax 631-231-8175 Web Site: http://www.novapublishers.com NOTICE TO THE READER The Publisher has taken reasonable care in the preparation of this book, but makes no expressed or implied warranty of any kind and assumes no responsibility for any errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of information contained in this book. The Publisher shall not be liable for any special, consequential, or exemplary damages resulting, in whole or in part, from the readers’ use of, or reliance upon, this material. Any parts of this book based on government reports are so indicated and copyright is claimed for those parts to the extent applicable to compilations of such works.

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Independent verification should be sought for any data, advice or recommendations contained in this book. In addition, no responsibility is assumed by the publisher for any injury and/or damage to persons or property arising from any methods, products, instructions, ideas or otherwise contained in this publication. This publication is designed to provide accurate and authoritative information with regard to the subject matter covered herein. It is sold with the clear understanding that the Publisher is not engaged in rendering legal or any other professional services. If legal or any other expert assistance is required, the services of a competent person should be sought. FROM A DECLARATION OF PARTICIPANTS JOINTLY ADOPTED BY A COMMITTEE OF THE AMERICAN BAR ASSOCIATION AND A COMMITTEE OF PUBLISHERS. LIBRARY OF CONGRESS CATALOGING-IN-PUBLICATION DATA Available upon request.

ISBN  H%RRN

Published by Nova Science Publishers, Inc.

New York

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

CONTENTS

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Preface

vii

Chapter 1

Java in Ambient Intelligence Applications J.A. Tejedor, Jose J. Durán, Miguel A. Patricio, J. García, A. Berlanga and José M. Molina

1

Chapter 2

The Power of Reflection: Combining Semantics in Service Oriented Architectures for Dynamic Intelligent Invocation P. Cabezas, S. Arrizabalaga, A. Salterain and J. Legarda

45

Chapter 3

Architecture of Embedded Tunable Circular Microstrip Antenna Tapas Chakravarty, Salil K. Sanyal and Asok De

69

Chapter 4

A New Development Environment for Embedded Control Systems Design and Interactive Optimization Methodologies for Robust Calibration of Automotive Engines Alessandro Casavola, Ferdinando De Cristofaro and Iolanda Montalto

89

Chapter 5

Java Software for HCI in Ubiquitous Space Takuya Yamauchi

117

Chapter 6

A Java Approach to Robotics and Artificial Intelligence Christopher M. Gifford, Jerome E. Mitchell and Arvin Agah

123

Chapter 7

Security for Java Platforms Pierre Parrend

143

Chapter 8

Reducing Code Replication in Delegation-based Java Programs Martin Kuhlemann, Christian Kästner and Sven Apel

171

Chapter 9

Script Computing for Embedded Systems Stephen S. Nestinger and Harry H. Cheng

185

Chapter 10

A Free Software Platform for Embedded Real-Time Robotics and Industrial Automation Gabriele Bruzzone, Marco Bibuli and Massimo Caccia

211

Index Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

227

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved. Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

PREFACE Wireless communications technologies are the platform to develop user-centric systems in a multi-device platform that allows mobility and user-friendly interaction. The development of a multi-device platform requires a common language such as Java. This book discusses two different works related with Bluetooth and GPS-GSM communication, to illustrate the capacity of Java language to develop applications that need wireless communications. Java application on the distributed system is introduced by certain keywords, design pattern, software architecture, design process and architecture for ubiquitous space. Furthermore, Java is often used as an embedded programming system, which is a combination of hardware, software, mechanical and other technical components designed to perform a dedicated function, unlike a general purposes computer. This book describes a new development framework for embedded control systems and engine calibration is presented, which supports the modelling of such systems and provides tools for the design and validation activities. An analytical method to express the resonant frequency in terms of the lumped component values is outlined as well. Wireless communications technologies are the platform to develop user-centric systems in a multi-device platform that allows mobility and user-friendly interaction. The development of a multi-device platform requires a common language as Java. In Chapter 1, two different works related with Bluetooth and GPS-GSM communication has been selected to illustrate the capacity of Java language to develop applications that need wireless communications. Service Oriented Architectures offer an incomparable setting for the management and reuse of services. In the case of such big scaled architectures the ability to choose between those services often gets blurry, because of the difficulty when trying to find the one which fits better the actual needs, or even because its invocation process gets excessively complex. Therefore, the correct identification of the services becomes really important in the environment optimization process. With regard to this, the semantic technologies cover the problem of hierarchies creation and services identification, due to the use of common languages and concepts, understandable and writeable by human beings. Chapter 2 shows a solution developed with the Java programming language over the OSGi framework, allowing the storage, identification and intelligent invocation of software services. Built upon the base provided by the OSGi framework as an entity for resource junction, the information in its internal in-memory service registry has been enhanced with the

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

viii

Mattis Hayes and Isaiah Johansen

development of an additional semantic layer based on OWL. This allows new technical approaches, adding capabilities with the development of software agents that make use of this new information. These capabilities cover the search of services according to certain terms in shared common ontologies, providing concepts and values by the client that are used in the searching and invocation process, the download of services including possible dependencies, remote invocation, and so on. Thanks to the conjugation of this semantic layer with software libraries such as the Java Reflection API, the client does not need to know any detail behind the public façade in the framework. Instead, intelligent software agents manage the existing and arranged catalogue of services in an absolutely transparent way. In Chapter 3, the authors outline a method to tune a conventional (regular shaped) microstrip antenna. An analytical method to express the resonant frequency in terms of the lumped component values is elaborated. The development of embedded control systems for automotive applications is an emerging field in the technical literature. There is, consequently, a lack of methodologies and tools that support the various development phases, starting from the early architectural design and ending with the calibration and validation processes. In Chapter 4, a new development framework for embedded control systems and engine calibration (F.I.R.E.—Functional Implementation Re-usability Environment) is presented, which supports the modelling of such systems at a high abstraction level and provides tools for the design and validation activities. The F.I.R.E. tool enables control engineers and software developers to focus on control system aspects instead of platform ones. This is achieved by means of an automation procedure of some necessary transformations during the development process. Two application examples are reported to prove the tool capabilities to allow a timing analysis and to detect a bad task scheduling before the production code is generated. The tool also provides a set of support functions to the embedded system design process, calibration and validation phases which are always crucial aspects in the overall development cycle. This consideration is particularly true for engine control systems, because their complexity is continuously increasing and more stringent time-to-market deadlines are conversely required. The use of optimization tools, able to speed up the single calibration and verification phases, has been proven effective and it is now a current industrial practice. Such experiences have also suggested that their integration within the F.I.R.E environment needs to be strongly encouraged. The rationale is that the development process of Engine Management Systems consists of several phases, each one related to a single physical engine development phase. During these phases, in which there is an incremental SW development, it is necessary to estimate from the physical engine a large set of calibration parameters in a very short time and with great accuracy. The purpose of Chapter 5 is to consider software architecture on distributed system by object-oriented language for Human Computer Interaction in ubiquitous space. The distributed system consists of middleware and web application. The middleware that connects devices has sensor information server and control functionality ,the web application that gets sensor information from the middleware presents information in browser in order to represent status of the ubiquitous space. Design process for object oriented language that includes analysis such as UML and OML is required to implement the distributed system. This chapter introduces java application on the distributed system by the following keywords,

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Preface

ix

design pattern, software architecture, design process and architecture for ubiquitous space. In the first section, this chapter explains simple design patterns that are used in the software architecture. The design patterns are known as efficient methods for implementation to be composed of the software architecture. Secondly, the authors describe the software architecture such as Model View Control (MVC) and Dependency Injection (DI). The architectures as framework that are pattern-oriented architecture are used in web application and the software application. In the design process section, the authors discuss methods for software construction to implement required system, and the design process is considered in order to build distributed system for ubiquitous space. Java is heavily used in a variety of research applications, due to its ease of use, maintainability, and portability. In Chapter 6, the use of Java in robotics and artificial intelligence is discussed, accompanied by examples of Java-based research in these areas. The authors have developed software architectures for research in robotics and artificial intelligence using Java, specifically for two autonomous polar robots, which were deployed in Greenland and Antarctica to support radar remote sensing missions. Such environments require both reliable and robust software to minimize possible failures during autonomous operation. Also, a team of low-cost exploration and mapping mobile robots has been built, utilizing Java Sun SPOTs as the means of wireless robot communication and coordination, and a custom inertial measurement unit (IMU) for keeping track of robot pose. As part of this development, Java was additionally used to implement a portion of the Joint Architecture for Unmanned Systems (JAUS) communication protocol. Currently, research involving collaborative multi-agent machine learning is being performed with the Java-based WEKA machine learning suite and additional Java wrapper software. These applications illustrate that Java has a wide range of research applications in the fields of robotics and artificial intelligence. The Java environment is composed of two main parts: the Java language and the Java virtual machine. It is designed with the assumption that no software entity is to be trusted and, therefore, that each needs to be checked. The first success of Java was the inception of Java Applets, which enabled fully untrusted code provided by unknown Web sites to be executed in a browser. This feature demonstrated the isolation brought by the Java Virtual Machine (JVM) between the applications and the underlying operating system. However, the evolution of Java systems from mono-application to multi-component systems induce new vulnerabilities developers are not aware of. This requires that additional security mechanisms be used to support secure Java environments. This survey presents an overview of the security issues for the Java language and Virtual Machine. The default security model is defined and explained. Its three main components are the Java language itself, the Bytecode validation at load time and modularity supports such as the class loaders and permission domains. Known vulnerabilities are presented. They originate either in the JVM or in the code of applications. Two approaches exist for describing code vulnerabilities: source code and Bytecode. This duality enables us to identify them both during development through manual code review and tools, and in an automated manner during code deployment or installation. Security extensions for the Java Execution Environment and tools for writing secure Java code are presented. They are of three types: platform extensions, static analysis approaches and behavior injection. Platform extensions consist in strengthening the isolation between components (beans, etc.) and providing support for resource consumption accounting and control. Static analysis is often performed through

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

x

Mattis Hayes and Isaiah Johansen

generic tools that improve the code quality and thus reduce the number of exploitable bugs in the Java code. Some of these tools, such as FindBugs, encompass security-specific bugs, and some, as JSLint are dedicated to security analysis. Bytecode injection enables us to introduce security checks in the core of the code. It can be performed with the developers involved, for instance through aspect-oriented programming, or transparently, through Bytecode injection or meta-programming. An overview of the existing protection mechanisms for Java systems according to the life-cycle moment they are enforced and to the development overhead they imply concludes Chapter 7. As explained in Chapter 8, interfaces and delegation are fundamental concepts in OO languages. Although both concepts have been shown to be beneficial in software development, sometimes their implementation is cumbersome. Both result in numbers of forwarding methods or numbers of empty methods for respective classes. These trivial methods distract the user from non-trivial methods the class comprises. This increases complexity and decreases maintainability. In its current form, Java does not provide sufficient mechanisms to avoid this boilerplate code. Instead, all the methods that are empty or only forward calls have to be coded manually. In this paper, the authors introduce a new lightweight mechanism, that improves the implementation of interface-based and delegationbased programs. The authors show, though this mechanism is very simple, it solves these problems that are well-known in object-oriented software development. In three open-source Java programs of up to over 25,000 lines of source code, the authors show how they use this mechanism to generate up to 5.7% of all methods per case study that were empty or only forwarding calls. The advent of high speed ubiquitous embedded systems and embedded operating systems with features normally expected in conventional operating systems provide developers with new found system flexibility and versatility. These features are keen to the advancement of mechatronic and embedded systems such as robotic systems, sensor networks, distributed embedded computing, structural health monitoring, first respond systems, supervisory control and data acquisition (SCADA), and traffic management, especially in geographically distributed and unstructured domains. To address the challenges of uncertainty and rapid prototyping, a flexible embedded system programming platform is critical to enhance prototyping capabilities and maintainability, and provide dynamic reconfiguration and in-situ processing. Chapter 9 discusses the programmability and reconfigurability of modern full featured embedded systems along with current trends in interfacing methods. This chapter also introduces tools that allow embedded systems developers to easily program for their specific embedded system hierarchy and deal with multiple levels of complexity using the C language while exposing the feature rich functionality of embedded operating systems. Embedded real-time platforms are a basic component of both robots and machines for the automation of industrial processes. Although industrial applications traditionally rely on PLCbased hardware and, in any case, proprietary software, i.e. operating systems and development tools, in recent years dramatic improvements in hardware computer power and free software quality made realistic the employment of architectures based on PC-compatible hardware and GNU/Linux software, more common in the research community. The advantages of a free infrastructure, that can become the terrain of fruitful cooperation between research institutions and companies, can be exploited mainly in fields, in which the added value is in the application, i.e. in mechanical and algorithmic solutions, and where the point

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Preface

xi

of view is that of aware users of an infrastructure, rather than of R&D competitors. This is the case of the project presented in the following, representing a success story in which the discussion between a research group and a small enterprise led to the identification of the requirements and the joined development of a common software infrastructure. When the project started in 2004, both partners, i.e. the Autonomous robotic systems and control group of CNR-ISSIA and Green Project Srl, had to substitute the obsolete platforms of their marine robots and marking machines for casting products in steelworks with a stable software and hardware infrastructure able of transparently integrating technological improvements while remaining compatible with the past (backward compatibility). On the basis of considerations, discussed below, about system reliability, development and maintenance costs (including human resources), foreseen compatibility and general technical soundness, the choice was to verify the possibility of using standard GNU/Linux for embedded real-time applications. The result is the main technical contribution of this chapter, i.e. the practical demonstration of the possibility of using standard GNU/Linux for implementing embedded real-time control systems working up to a sampling frequency of at most 2 Khz. Furthermore, four years later, the developed system is still demonstrating its capabilities transparently integrating technological improvements and increasing more and more its performance thanks to the new realtime properties of the Linux kernel. A first operative release of the platform was completed in 2005 and integrated with the CNR-ISSIA Charlie unmanned surface vehicle (USV) for robotics research. A second application was the porting to the platform of the software of the control system of Hammer, a steelwork industrial machine used for marking continuous casting products, developed by Greenproject s.r.l. At the moment, the platform is supporting the development of the ALANIS (Aluminium Autonomous Navigator for Intelligent Sampling) USV1 for surface and underwater coastal monitoring. Moreover, the integration with generic field buses and image acquisition systems is being carried out. After an introduction reporting a summary of related research in the field and a discussion of the platform requirements, the key points of the followed methodology for making GNU/Linux real-time will be presented. Finally, two applications, a research one and an industrial one, pointing out the basic real-time structures that the platform is required to implement, will be described in Chapter 10.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved. Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

In: Java Software and Embedded Systems Editors: M. Hayes and I. Johansen, pp. 1-43

ISBN: 978-1-60741-661-6 © 2010 Nova Science Publishers, Inc.

Chapter 1

JAVA IN AMBIENT INTELLIGENCE APPLICATIONS J.A. Tejedor, Jose J. Durán, Miguel A. Patricio, J. García, A. Berlanga and José M. Molina1 Applied Artificial Intelligence Group Universidad Carlos III de Madrid

Abstract

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Wireless communications technologies are the platform to develop user-centric systems in a multi-device platform that allows mobility and user-friendly interaction. The development of a multi-device platform requires a common language as Java. In this chapter, two different works related with Bluetooth and GPS-GSM communication has been selected to illustrate the capacity of Java language to develop applications that need wireless communications.

Introduction Computational resources are every time closer to all the people because of the development of devices such as Personal Digital Assistants and mobile phones which have gained a lot of popularity in these days and are increasingly being networked (e.g., Bluetooth, IEEE 802.11). The use of this technology gave birth to a new concept: mobile computing. Mobile computing field is having an increasing attention as many systems are designed towards this direction. Most of them are desired to be context aware with the aim of optimizing and automating the distribution of their services in the right time and in the right place. Context aware computing is a paradigm was firstly defined by (Shilit, 1995). This paradigm studies methods for modelling and utilizing contextual information. A more widely and used definition of what context is, was given by (Dey et al., 2001) where he defines context as: “any information that characterizes a situation related to the interaction between humans, applications, and the surrounding environment.” There are also some other categories described by Chen and Kotz (Chen and Kotz, 2000) which classify context in a more fine- grained categories. 1

E-mail address: [email protected].

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

2

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al.

Accordingly, there are several approaches developing mobile systems such as platforms, frameworks and applications for offering context-aware services. The Context Toolkit proposed by (Dey et al., 2001) assist for instance developers by providing them with abstractions enabling them to build context-aware applications. The Context Fusion Networks (Chen et al., 2004) was introduced by Chen and Kotz in 2004. It allows context-aware applications to select distributed data sources and compose them with customized data fusion operators into an information fusion graph. The graph represents how an application computes high level understandings of its execution context from low-level sensory data. The Context Fabric (Hong, 2002) is another toolkit which facilitates the development of privacysensitive, ubiquitous computing applications. There is another platform Gaia (Schmidt et al., 1999), which was developed by Roman et al. in 2002 and was designed to support also the development and execution of applications for ubiquitous computing spaces in which users interact with several devices and services at the same time. RCSM is another middleware proposed by (Yau and Karim, 2004) designed to provide the properties of context-awareness and ad-hoc communications to the applications. It provides an object-based framework for supporting context-sensitive applications similar to CORBA (OMG, 2000) or TAO (Gokhale and Schmidt, 1999) for fixed networks. There are previous approaches like Entree (Burke et al., 1996) which uses a knowledge base and case-based reasoning to recommend restaurant or for instance Cyberguide (Abowd et al., 1997) project which provides user with context-aware information about the projects performed at GVU center in Atlanta. With TV remote controllers throughout the building to detect users locations and provide them with a map that highlights the project demos available in the neighboring area of the user. A recent one is Appear which is a context-aware platform designed to provide contextual information to users in particular and well defined domains (Sanchez-Pi et al., 2007). The final goal of the ambient intelligence (AmI) is to construct intelligent environments that facilitate a ubiquitous access with independence of the physical location. This ubiquity need has produced the growing use of wireless devices (especially handheld devices) in recent years. Wireless networks are location independent; provide a wide range of coverage and extend traditional wired communication techniques. Protocols used to communicate in wireless technologies are mainly classified in the 802.1x.x protocol family for Bluetooth, infrared and Wi-Fi, and protocols used in mobile phones within the GPRS or UMTS technologies. Other wireless technologies that must be taken into account are GSM, GPS, RFID or ZigBee. Wireless LANs, also known as Wi-Fi (Wireless Fidelity) networks can be used to replace or as an extension of wired LANs. Many developments have been carried out over these technologies to develop usercentric systems. Many of this development need to process information in a multi-device platform that allows mobility and user-friendly interaction. Many examples of this new development appear in domotic house, ambient assist living, new surveillance paradigm, etc. The development of a multi-device platform requires a common language to facilitate the development of complex device-dependent application. From this set of technologies and device-dependant applications, we select two different works related with Bluetooth and GPS-GSM communication to facilitate user interaction and allow developing location based system, respectively. Bluetooth is a wireless technology utilises a short-range radio link and operates in the 2.4 - 2.48 GHz frequency band. Bluetooth is a technology that facilitates the interaction between near devices providing a high reliability and low-consumption. Using this technology, we

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications

3

have develop in Java a generic Bluetooth Java component to integrate mechanical user interface (an example with Wiimote2 will be explained) to manage an ambient assist living scenario. GPRS uses a packet-switched system which provides data transfer services on mobile phone networks. UMTS is a universal mobile telecommunications system that operates in the 2 GHz frequency band and emphasizes the compatibility. Location with this technology gives a great uncertainty (usual several Km), but the integration of GPS receivers could be useful to increase the accuracy up to meters. We have developed a Java component based on the Location API for Java ME (Java Platform, Micro Edition) JSR-179 and applied to deploy it in Nokia Mobile Phones to access the GPS and to obtain the location position.

Bluetooth Protocol and JSR-82 Package In this section, we explore some topics about the Bluetooth protocol and the JSR-82 package for Java implementation. First of all, we start with the Bluetooth Stack protocols and then we describe the most important classes and interfaces of the JSR-82 package. Finally, we show some sample codes of using this package.

Bluetooth Stack Protocols The Bluetooth stack has a defined number of protocols that helps developers to establish communication between different devices and to be able to offer a good range of services. Among others, these are most important protocols:

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.







L2CAP (Logical Link Control and Adaptation Protocol): is intended to offer a communication infrastructure based on a pair of sockets between devices, granting the ability to send raw data throw the connection. Based on this one protocol are defined the other ones Bluetooth protocols. SDP (Service Discovery Protocol): this protocol is in charge of offering services of a device at petition, telling which services are available and its properties. This protocol is really important, because it is intended to support the main capability of Bluetooth, the offering of services. OBEX (OBject EXchange): this other protocol is used between devices to help sending formatted messages between them, helping to offer a robust framework, where the communication limitations can be negotiated between devices, and messages can be refused before been received, but knowing about their attributes. This protocol is widely used in mobile devices, mainly to be able to exchange image and audio files between them, independently of the platform of the device, for example in a printer and a photo camera.

This list of protocols can be expanded, so new protocols can use these ones to help define the functionality, so a protocol that helps to create a chat application will use OBEX features 2

The primary controller for Nintendo's Wii console.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

4

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al.

to send messages, or a video streamer will use L2CAP to send data flow between devices, using its capabilities to send raw data asynchronously. A standard service created in top of OBEX is OBEX object push, which helps to send files, between devices, using OBEX capabilities to send messages, and saving later that file into the mobile device file system.

Inside JSR-82 Package The acronym JSR-82 comes from Java Specification Request, which is a proposed specification for Java that defines a series of classes and functions to be able to create wirelessly connections over Bluetooth to a mobile device. The first application of that technology is inside mobile phones, because that specification is only implemented by the mobile phone sector, became it’s usage in personal computer really complex, because it is necessary to use libraries from third-party companies to get access to Bluetooth from Java, that is because it is need to use some operative system exclusive functionalities, needing to use JNI when developing for a personal computer. To be able to use JSR-82, it is needed to select which kind of device the application will be oriented for, because them it will be necessary to select what is the most appropriate implementation of the specification: −

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.



Mobile phone To be able to use this library in a mobile phone, it should be inside the mobile using the implementation of JSR-82 in the J2ME virtual machine, but it depends of the device as the manufacturer, because someone creates their own implementations of the library, or creates their own one Bluetooth library to support Bluetooth access, been incompatible with JSR-82. Personal computer The use of that specification in a computer is really powerful, but, it has some inconvenient been the first one the requirement to use external libraries which normally do not offer full support of JSR-82, but permits to use the capabilities of a personal computer that offer more computational capability that a mobile device. The most appropriated library, because been open-source and totally free is Bluecove3 (Bluecove webpage).

In this chapter we will take a view of using Bluetooth in a personal computer using Bluecove. Bluecove is an implementation of the JSR-82 bluetooth stack for Java, in different operative systems, like Windows, Linux or MacOS, helping developers to use the JSR-82 in any computer that have almost one of those operative systems and a Bluetooth device. To be able to work with Bluetooth it is necessary to access to a group of functionalities, been the more basic ones and the most important searching devices and querying them about services, been able to use them later (JSR-82 webpage) to offer and using services between mobile devices. This package is divided among a collection of interfaces and classes, but we will take a review of the most important ones that are used in this chapter:

3

http://bluecove.org/.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications Interfaces DiscoveryListener L2CAPConnection ServiceRecord ClientSession HeaderSet Operation

Classes RemoteDevice DeviceClass UUID LocalDevice DiscoveryAgent DataElement

5

Exception BluetoothConnectionException BluetoothStateException

Figure 1. Elements of package JSR-82.

These elements functionalities are described as follows: Interfaces: •

o

o o

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

o



o o o •

o o o o

DiscoveryListener : Provides of the primitive methods to notify to an object about device and service queries. A more accurate view of this interface can be seen in the examples about devices and services search. void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod): This method is called whenever a new device is discovered by a discovery agent, telling about what is the remote device and his type. void inquiryCompleted(int discType): When a device query is completed, the listener is notified by this, telling about what kind of search it was. void servicesDiscovered(int transID, ServiceRecord[] servRecord): When services are found in a service query, the listener is notified with the full list, and the transaction ID. void serviceSearchCompleted(int transID, int respCode): Whenever a service query is finished, it is notified to the listener, telling about the transaction ID and the result code, telling about problems if they are. L2CAPConnection : Represents a connection using L2CAP protocol. L2CAPConection interface offers the primitives needed to interact with this protocol. This kind of connection will work totally like a socket, been able to send an undetermined amount of information in a one-way connection. This connection is used in the Wiimote example that is explained further. boolean ready(): Tells if the connection is ready to send data. int receive(byte[] inBuf): Put in the buffer the received data, and tells about how many data is received. void send(byte[] data): Send all the data in the vector. ServiceRecord : Offers access to service information, and defines some constants for standard id’s about attributes. This class is intended to help devices to negotiate each other about services and its restrictions, like authentication. int[] getAttributeIDs(): Received attributes. DataElement getAttributeValue(int attrID) : returns information about a desired attribute. String getConnectionURL(int requiredSecurity,boolean mustBeMaster): creates a connection string to the desired service, with the auntethication options implicit. RemoteDevice getHostDevice(): Get the RemoteDevice object associated with the service.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

6

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al. o o o •

o o o o o •

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

o o o o •

o o o o

boolean populateRecord(int[] attrIDs): fills the attribute list with the ones from the list, if able, so the value of the attribute can be set. boolean setAttributeValue(int attrID, DataElement attrValue): changes an attribute value. void setDeviceServiceClasses(int classes): set the device service classes, so the device will be able to be recognized as one of a list of generic devices. ClientSession: Permits to use OBEX (OBject EXchange) primitives in a session between mobile devices. As mentioned above, OBEX is a communications protocol that facilitates the exchange of binary objects between devices. This connection is similar as the one between a web client and a server, were the server sends a file to the client telling about how is the file, and the file itself. The example of service search uses this protocol as example of communication between devices, in this case to be able to retrieve an image file. HeaderSet connect(HeaderSet headers): Creates a connection between devices throw an OBEX service, with the desired information. HeaderSet createHeaderSet(): Creates a predefined HeaderSet with the information needed for the service, and the attributes that are needed. HeaderSet disconnect(HeaderSet headers): Disconnects from the other device, releasing the service. Operation get(HeaderSet headers): Creates a reception operation, to retrieve data from the other device. The parameter is fill with connection properties. Operation put(HeaderSet headers): Creates a sending operation, been able to send the announced data. HeaderSet : Contains the meta-information of the communication using OBEX, defining the object attributes and authentication. void createAuthenticationChallenge(String realm, boolean userID, boolean access): Creates a security mechanism, based in the realm pass prhase. Object getHeader(int headerID): return an attribute header. Normally it is an String, but it is recommended to use the toString() returned String. int[] getHeaderList(): List of header from the HeaderSet. void setHeader(int headerID, Object headerValue): set a header to a desired value. The value is defined by the toString() method of the object. Operation : Offers functionality to interact using data streams to exchange information using OBEX, so an HeaderSet can be sent throw a connection, negotiating transference attributes. void abort(): aborts the operation between the devices. HeaderSet getReceivedHeaders(): Returns the headers assigned to this operation. int getResponseCode(): Return a response code to be able to track errors. void sendHeaders(HeaderSet headers): sends headers to the other device.

Classes: • o

RemoteDevice : Offers access to device information, and defines some methods to obtain not broadcasted information of the device as the friendly name. String getBluetoothAddress(): Returns an unique identifier of the device, that identifies it of the rest of Bluetooth device available.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications o • o o o • o • o o o o

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

o o o o o • o o o o

o • • • •

7

String getFriendlyName(boolean alwaysAsk): Ask to the device about its friendly name. DeviceClass : Defines information about purpose of a device, but that information is not treated in an special way by Bluetooth. int getMajorDeviceClass(): returns the major device number, as tell in the Bluetooth standard. int getMinorDeviceClass(): returns the minor device number, as tell in the Bluetooth standard. int getServiceClasses():returns a description of the most important offered services, as tell in the Bluetooth standard. UUID : Defines an object, so, programmers can manage protocols standard identifiers. UUID(long uuidValue): constructor of the class. This class is only used by the Bluetooth stack, or to define restrictions in the services query. LocalDevice : Represents the Bluetooth device of the system running, and offers to access information and manage the Bluetooth stack. String getBluetoothAddress(): Returns the current device Bluetooth address. DeviceClass getDeviceClass(): Get the device class of itself. int getDiscoverable(): Tells if the current device is discoverable by others. DiscoveryAgent getDiscoveryAgent(): Creates a singleton of a discovery agent, so queries of devices and services could be done. String getFriendlyName(): Return the friendly name of the device. static LocalDevice getLocalDevice(): Return the singleton copy of LocalDevice. static String getProperty(String property): Get the value of a Bluetooth stack property. static boolean isPowerOn(): take track of the power status of the Bluetooth device. boolean setDiscoverable(int mode): Changes discoverable status of the device. DiscoveryAgent : Manage queries and delegates discoveries to a desired DiscoveryListener. boolean cancelInquiry(DiscoveryListener listener): Cancels the current query that is been listened by the listener. boolean cancelServiceSearch(int transID): cancels the desired service search. RemoteDevice[] retrieveDevices(int option): Returns the list of devices discovered. int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener): Begins a query of present services to a defined device, and later tells the result to the listener. boolean startInquiry(int accessCode, DiscoveryListener listener): Begins a device query, and tells the results of it to the listener. DataElement : Represents a data structure to exchange information between devices defining an standard format. DataElement(int valueType, long value): Constructor of basic data type. DataElement(int valueType, Object value): Constructor for complex data type, that grants the ability to create a DataElement of any kind. Object getValue(): Returns de DataElement value.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

8

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al. Exceptions: •

BluetoothConnectionException : This exception is throw when a connection cannot be established. int getStatus(): Returns an error code used to defined what kind of error has been found. BleutoothStateException : This exception is throw when an operation cannot been performed because Bluetooth system cannot manage it in the current state.

o •

Search of a Mobile Device To be able to search devices, and services, is necessary to create a listener class of the search query, so the Bluetooth stack will be able to notify to the listener about the result of the query. The perform of the search will be done by a DiscoveryAgent, which is a static instantiation obtained from the LocalDevice, that will interact directly with the hardware of the system, so the Java developer will be able to isolate that functionality of her design. The device search is as defined in the next code section: package bluetoothdemo; import javax.bluetooth.*; import java.util.*; public class DeviceDiscoverer implements DiscoveryListener {

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Sample 1. DeviceDiscover class preamble.

First, it is needed to create a class that implements DiscoveryListener so the system will be able to notify of new discovered devices. BluetoothDiscoverer discover; Vector remoteDevices = new Vector(); DiscoveryAgent discoveryAgent; public DeviceDiscoverer(BluetoothDiscoverer discover) { this.discover = discover; try { this.discover.setSearching(true); LocalDevice localDevice = LocalDevice.getLocalDevice(); discoveryAgent = localDevice.getDiscoveryAgent(); discover.updateStatus("Searching for Bluetooth devices in the vicinity..."); discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this); } catch(Exception e) { e.printStackTrace(); } }

Sample 2. DeviceDiscover constructor.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications

9

In the constructor we pass an observer that will be observing the detected devices. Then, we will call the startInquiry method from the discoveryAgent to begin the search, telling about what object will be listening for the search. Once it has been done, the device will begin to search compatible devices. public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass cod) { try{ remoteDevices.addElement(remoteDevice); discover.updateStatus(" found: " + remoteDevice.getFriendlyName(true) ); discover.addDevice(remoteDevice); } catch(Exception e){ e.printStackTrace(); } }

Sample 3. DeviceDiscoverer notify method deviceDiscovered.

This method will inform the observer of a new detected device, after the DiscoveryAgent has notified to the listener about new devices. This functionality is intended to notify immediately about new discovered devices, so whenever a device is discovered it will be notified immediately. public void inquiryCompleted(int discType) { String inqStatus = null;

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

if (discType == DiscoveryListener.INQUIRY_COMPLETED) { inqStatus = " Inquiry completed"; } else if (discType == DiscoveryListener.INQUIRY_TERMINATED) { inqStatus = "Inquiry terminated"; } else if (discType == DiscoveryListener.INQUIRY_ERROR) { inqStatus = "Inquiry error"; } discover.updateStatus(inqStatus); discover.setSearching(false); discover.updateStatus("Click on the Search button to search for the all services available"); }

Sample 4. DeviceDiscoverer notify method inquiryComplet.

This other, will inform when the searching process has ended, enabling the user to take that info, or re-search for devices. This functionality is normally intended to bring back to the user the control of an application, and telling about when a new search can be performed. public void servicesDiscovered(int transID, ServiceRecord[] servRecord){} public void serviceSearchCompleted(int transID, int respCode) {}

Sample 5. DeviceDiscovered not implemented methods

This other methods are not necessary for this case, but are from the implemented interface. In the next example they are used.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

10

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al.

Querying Services to a Device In this code section we can see a class oriented exclusively to the petition of services, instead as the example before, where devices where searched. Results interesting to tell that the functionalities of searching devices and services ,have been divided among two classes, because the search query can be parallelized using threads for each device. Also it is possible to have this two functionalities in one class, and been used simultaneously. package bluetoothdemo; import javax.bluetooth.*; import java.io.*; import java.util.Vector; public class ServiceDiscoverer extends Thread implements DiscoveryListener {

Sample 6. ServiceDiscoverer class preamble.

First, is necessary to create a class that implements DiscoveryListener, as the class Thread, or the interface Runnable, so the query can be solve in background. That is done to improved performance of the system, and brings the user the capability to interact with other parts of it. UUID[] uuidSet = {new UUID(0x0003) }; int[] attrSet = {0x0100, 0x0003, 0x0004};

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

BluetoothDiscoverer discoverer = null; ServiceRecord ServiceRecord = null; RemoteDevice remoteDevice = null; String connectionURL = null; public ServiceDiscoverer(BluetoothDiscoverer discoverer, RemoteDevice remoteDevice) { this.discoverer = discoverer; this.remoteDevice = remoteDevice; }

Sample 7. ServiceDiscoverer constructor. public void run(){ try { LocalDevice localDevice = LocalDevice.getLocalDevice(); DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent(); discoverer.updateStatus( remoteDevice.getFriendlyName(true) ); discoveryAgent.searchServices(attrSet, uuidSet, remoteDevice, this); } catch(Exception e) { e.printStackTrace(); } }

Sample 8. ServiceDiscoverer threadable method.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications

11

In this diagram, we can see how different ServiceDiscoverer have been created, so, there can be performed different searches of services in different devices simultaneously. :DeviceDiscoverer

:DiscoveryAgent

serv1:ServiceDiscoverer

serv2:S erviceDiscoverer

Search for device searchDevice

deviceDis covered(d1) (d1) run

deviceDisco vered(d2) (d2) run searchServices(d1) s erachServices(d2)

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

Figure 2. Interaction of multiple service queries using threads.

In the constructor we pass the observer of the query, as the device that will be queried about its services, been the device the one that was taken from the device search. That is not necessary to begin a service search after a device search, because it is able to ask for services without a device search, but it is recommended, so, whenever the search is done, the device will be of course available. The run method will do the search as a background process, notifying of changes to the discoverer. The service query is claimed to the DiscoveryAgent as done before in the device query. Instead, that search is done in the DiscoveryAgent thread, so for been able to make more than one search, of devices a services, it is needed to do it background. public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { discoverer.addServices(remoteDevice, servRecord); for(int i = 0; i < servRecord.length; i++) { DataElement serviceNameElement = servRecord[i].getAttributeValue(0x0100); String temp_serviceName = (String)serviceNameElement.getValue(); String serviceName = temp_serviceName.trim(); discoverer.updateStatus(" -" + serviceName ); } }

Sample 9. ServiceDiscoverer notify method servicesDiscovered.

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

12

J.A. Tejedor, Jose J. Durán, Miguel A. Patricio et al.

This method informs to the discoverer the availability of services, as the information of these discovered services. If there are other observer, like the one used in these examples, it is recommended to notify them about the new services found. public void serviceSearchCompleted(int transID, int respCode) { String searchStatus = null; if (respCode == DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE) { discoverer.updateStatus("Device not reachable"); } else if (respCode == DiscoveryListener.SERVICE_SEARCH_NO_RECORDS) { discoverer.updateStatus("Service not available"); } else if (respCode == DiscoveryListener.SERVICE_SEARCH_COMPLETED) { //do nothing } else if (respCode == DiscoveryListener.SERVICE_SEARCH_TERMINATED) { discoverer.updateStatus("Service search terminated"); } else if (respCode == DiscoveryListener.SERVICE_SEARCH_ERROR) { discoverer.updateStatus("Service search error"); } }

Sample 10. ServiceDiscovered notify method serviceSearchCompleted.

This other, informs about the end of the services query, and also tells about any found problem in the search. public void inquiryCompleted(int discType){}

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod){} }

Sample 11. ServiceDiscoverer not implemented methods.

These two methods are not required for services search, because they are intended to be used in devices searches like we have seen in the previous example.

Connection with a Device Once the devices are detected, and their services too, it is possible to connect to the device and use the different available protocols, in this case we are using OBEX object push, which permits sending files using Bluetooth. In the next section we can see how to in a class interpret information and send data throw Bluetooth can be done:

Java Software and Embedded Systems, edited by Mattis Hayes, and Isaiah Johansen, Nova Science Publishers, Incorporated, 2010. ProQuest

Java in Ambient Intelligence Applications

13

package bluetoothdemo; import import import import

java.io.*; javax.bluetooth.*; javax.microedition.io.Connector; javax.obex.*;

public class BluetoothDiscoverer { JFrameBluetooth aThis; BluetoothDiscoverer(JFrameBluetooth aThis) { this.aThis = aThis; }

Sample 12. BluetoothDiscoverer preamble.

Copyright © 2010. Nova Science Publishers, Incorporated. All rights reserved.

This class interacts with the graphic interface, so the functionality of Bluetooth and user interaction can be divided among them. We can see it as a facade design pattern, helping dividing functionality among classes.

Figure 3. Graphic interface showing services detected. void addServices(RemoteDevice remoteDevice, ServiceRecord[] servRecord) { String[][] serv = new String[servRecord.length][2]; for(int i=0;i