Embedded Java 개발 자를 향한달콤한딸기의유혹 최승호 (seungho.choi@oracle.com)
Internet of Things Meets Big Data Personal Devices Med-Large Embedded / Multi-function Devices VoIP Communications Sensors / Microcontrollers Industrial controls / Network Appliances Cloud for Embedded Devices Meters Smart Appliances & electronics Connected Vehicles Management / Monitoring / Operations Enterprise Data & Applications
Industry Trends & Challenges TRENDS More Devices, Connected with Increased Capabilities Infrastructure extending to include Edge Devices Enormous amount of net new data New value-added services based on this data/connectivity CHALLENGES Custom Proprietary Solutions Lack of Platform Standards Hardware Fragmentation Multiple OS support Limited Developer and ISV ecosystems Insufficient Network Bandwidth
Java Delivers Technical Value Standards based Vast developer base of over 9M Free development tools and Mature, robust and secure run-time environment Cross platform compatibility Supported on small to large devices Seamless integration with backend services Provides a complete end to end platform to develop standards based services
Servers Desktop Embedded TV Mobile Card BD-J Key APIs Java EE JavaFX Java TV MSA Platform Java SE Java ME Java Card Language Java Language Java Platform
Java Embedded Product Family Embedded Mobile Card Java TV MSA Java SE Java ME Java Card Java Language
Java Embedded : Broadest Device Coverage
Java Embedded : Today Platform Footprint 10MB-100MB Java ME/CDC + Java SE 1MB-10MB 50KB-1MB Java Card Java ME/CLDC Small Embedded (feature phones, meters, Diagnostics, M2M Telco ) ARM 7 Cortex M ARM9/11 CortexA/PPC Mid Embedded (ereaders, VOIP, Network Eqmt, Printers, Imaging, Industrial M2M, Connected TV, Set-top boxes) MIPS32/Intel Atom/ARM High Embedded (Smartphones, Netbooks, Medical Instruments, Industrial Equipment, Embedded Servers) Device CPU/ GPU/I-O
Java ME Embedded 3.2 Stack Embedded Application(s) Logging API XML JSR 280 Security & Trust JSR 177 subset Java ME SDK Test, Emulate OEM Extension APIs * AMS API AccessPoint API Device Access API Location JSR 179 Messaging JSR 120 Web Services JSR 172 File I/O JSR 75 NetBeans IDE Develop, Deploy, Debug IMP-NG (JSR 228) Eclipse Plug-in CLDC Virtual Machine (JSR 139) Multi-tasking On-device debugging VM configurator Porting Layer * Porting Win32 Emulation port * Reference Board port * Device Operating System Additional platform port(s) Integration Network File GPS Serial I 2 C SPI GPIO...... Specialization Legend: Standardized Components Hardware Oracle Unique Features 3 rd Party Components (*) : Modifiable Components
Java Embedded is an Ideal Platform for Embedded Applications Secure, flexible execution environment: sandbox model Inherent cross-platform application compatibility Extensive developer, community, and industry support Based on open standards driven through the Java Community Process
Java Embedded UI Lightweight for smaller devices Full rich graphics for larger higher-end devices Take advantage of hardware acceleration where available Tools and ease of development
JavaFX for Embedded Powerful set of 100% Java APIs FXML for UI markup & Visual Editor Rich graphics and animation Swing integration Integrated Web content Available on Windows, MAC OSX, Linux/x86 /ARM
The Raspberry Pi is a credit-card-sized single -board computer developed in the UK by th e Raspberry Pi Foundation
Specification Model A Model B SoC CPU Broadcom BCM2835 (CPU, GPU, DSP, SDRAM, and single USB port) 700 MHz ARM1176JZF-S core (ARM11 family) Memory(SDRAM) 256MB (Shared with GPU) 512MB (Shared with GPU USB 2.0 Ports Video Output Audio Output Onboard Storage 1 (direct from BCM2835 chip) 2 (via the built in integrated 3-port USB hu b) HDMI, Composite HDMI, Stereo SD/MMC/SDIO card slot Onboard Network None 10/100 Ethernet Power 5V Micro USB Price US $25 US $35
ARM Features 32-bit RISC Architecture ARM accounts for 75% of embedded 32-bit CPUs today 8 billion chips sold last year, more than 30 billion in total Zero manufactured by ARM Abstract architecture and microprocessor core designs Raspberry Pi uses an ARM11 with ARMv6 instruction set Low power consumption Good for mobile devices Raspberry Pi can be powered from 700mA 5V only PSU Raspberry Pi does not require heatsink of fan
Office HTPC Robot Remote Control Sound Digital Photo Frame Home Gateway 3D Graphic Quadcopter Media Streaming Cloud Storage Multimedia Game Printer Server Sensor Device Animation Programming M2 M Blackbox CCTV Control Web Server
Performing the Essential Linux Setup Download the Raspbian "Wheezy" Linux distribution for the Raspberry Pi Copy the Raspbian Wheezy image to SD card Resize the SD card partitions Perform the first boot
Performing the Essential Linux Setup
Performing the Essential Linux Setup
Performing the Java SE for Embedded Devices Setup Acquire the Java SE for Embedded Devices evaluation software Unpack the Java download Launch Java Performing Optional Linux Tuning and Tweaking
Optional Linux Tuning and Tweaking Set up a static IP address Enable swapping and optimize file system access Automatically start the graphical user interface Set up time zone and locale Set up a time server Set up an internet proxy Update the Linux package Remap the keyboard Enable sound
JavaFX on Raspberry Pi 제 13 회한국자바개발자컨퍼런스
Apache Tomcat on Raspberry Pi 제 13 회한국자바개발자컨퍼런스
How to Develop Java Application on Raspberry Pi 제 13 회한국자바개발자컨퍼런스
Displaying HTML in JavaFX 제 13 회한국자바개발자컨퍼런스
Displaying HTML in JavaFX public class Main extends Application { public static void main(string[] args) { Launcher.launch(Main.class, args); } @Override public void start(stage stage) { WebEngine eng = new WebEngine("http://google.com"); WebView webview = new WebView(eng); Scene scene = new Scene(webView); stage.setscene(scene); stage.settitle("web Test"); stage.setvisible(true); }}
Hello World in JavaFX public class JavaFXExample extends Application { @Override public void start(stage stage) { Scene scene = new Scene( LabelBuilder.create().text("Hello World!").layoutX(25).build()); stage.settitle("welcome to JavaFX!"); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } }
Calling JavaScript from JavaFX String script = "alert('we've got a message, Houston!'); ; eng.executescript(script);
Using Java on the Raspberry Pi
Using Java on the Raspberry Pi Sound UIs, JavaFX Serial (TTL UART) USB GPIO/SPI/I2C
Make A Noise with Java Sound drivers now included in new distros Java Sound API Remember to add audio to user s groups modprobe snd_pcm_oss (creates /dev/dsp, needed by MIDI interface) Some bits work, others not so much Playing (the right format) WAV file works MIDI seems unbelievably slow FreeTTS text-to-speech Some bits working (limited domain voice)
JavaFX on the Raspberry Pi Work involves optimal implementation of Prism graphic engine Configure with Djavafx.platform x11 (X11, software rendering) directfb (Not currently working due to need for 16/32 DirectFB) fb (Framebuffer with soft rendering) eglfb (OpenGL rendering to framebuffer)
Using The Serial Port UART provides TTL level signals (3.3V) RS-232 uses 12V signals Use MAX3232 chip to convert Use this for access to serial console Turn off serial console: Edit /etc/inittab Edit /boot/cmdline.txt Comment out /dev/ttyama0 lines
USB Peripherals Universal Serial Bus (But not as simple as serial) Easy devices are ones that appear as simple serial devices /dev/ttyusb0 More complex devices need native code and libusb apt-get install libusb-1.0-0-dev
Java and Serial Port/USB Serial Device JavaComm API Install RXTX package apt-get install librxtx-java How to solve the /dev/ttys* only problem System.setProperty ( gnu.io.rxtx.serialports, /dev/ttyusb0 );
public class TwoWaySerialComm { void connect(string portname) throws Exception { CommPortIdentifier portidentifier = CommPortIdentifier.getPortIdentifier(portName); if (portidentifier.iscurrentlyowned()) { System.out.println("Error: Port is currently in use ); } else { int timeout = 2000; CommPort commport = portidentifier.open(this.getclass().getname(), timeout); if (commport instanceof SerialPort) { SerialPort serialport = (SerialPort)commPort; serialport.setserialportparams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); InputStream in = serialport.getinputstream(); OutputStream out = serialport.getoutputstream(); (new Thread(new SerialReader(in))).start(); (new Thread(new SerialWriter(out))).start(); } else { System.out.println("Error: Only serial ports are handled by this example. ); } } }
public static class SerialReader implements Runnable { InputStream in; public SerialReader( InputStream in ) { this.in = in; } } public void run() { byte[] buffer = new byte[ 1024 ]; int len = -1; try { while( ( len = this.in.read( buffer ) )!= -1 ) { System.out.print( new String( buffer, 0, len ) ); } } catch( IOException e ) { e.printstacktrace(); } }
public static class SerialWriter implements Runnable { OutputStream out; public SerialWriter( OutputStream out ) { } this.out = out; } public void run() { try { int c = 0; while( ( c = System.in.read() )!= -1 ) { this.out.write( c ); } } catch( IOException e ) { e.printstacktrace(); } }
The OWI Robot Arm Cheap and Cheerful Comes with USB interface Use native code for control and JNI Simple control protocol 3bytes (1 = arm, 2 = base, 3 = light) Combining movements requires some bit twiddling Can only stop all motors, not individually
Robot Arm Control JNI Code Native C functions Initialization of arm using libusb and appropriate device Separate function for each control element Compile to shared library Use JNI to generate header file appropriate to Java code usage e.g. native int arm_usb_init() Compile to shared library JNI is not easy to reuse
Robot Arm Control Java Code Java code is simple Calibration required to determine time for specific movement arm_gripper_move(open); usleep(500); arm_gripper_move(stop); usleep(500); arm_gripper_move(close); usleep(500); arm_gripper_move(stop);
Gamepad Controller Manual dexterity Linux supports most of these out of the box Drivers create entries in /dev/input Java API through JInput Mature technology (not been touched since 2003) Recompile code on RasPi Needed to tweak build script for incomplete classpath Devices do not have general read/write access
Gamepad Controller Code Wrote library on top of Jinput Jinput to generic, needed code to be more specific to gamepad GamePadController gpc = new GamePadController(); gpc.addbuttonlistener(gamepadcontroller.button_1, this); gpc.addjoysticklistener(gamepadcontroller.joystick_left, this); new Thread(gpc).start();
Gamepad Controller Code public void buttonaction(buttonevent be) { if (be.getid() == GamePadController.BUTTON_1) robotarm.setgripperlight(true);... } public void joystickaction(joystickevent jse) { if (jse.getid() == GamePadController.JOYSTICK_LEFT){ if ((position & JoystickEvent.POSITION_LEFT)!= 0) robotarm.moveelbow(armcontroller.up); }... }
How to Use SPI and I2C Even more complex peripherals Drivers still experimental Devices for SPI /dev/spidev-0.0 and /dev/spidev-0.1 Devices for I2C Run i2c-dev /dev/i2c-0 Not yet tried these with Java (Screen and JavaFX project next)
Conclusions Raspberry Pi is a very cool (and cheap) computer Great for teaching Great introduction to ARM Java works well and will get better Opportunities are limitless!
Further Information http://java.oracle.com http://www.oracle.com/technetwork/java/embedded http://www.raspberrypi.org Raspberry Pi User Guide Eben Upton, Gareth Halfacree