Controlling EIB/KNX Devices from Linux using USB. Heinz W. Werntges. University of Applied Sciences Wiesbaden. Jens Neumann and Vladimir Vinarski



Similar documents
Controlling EIB/KNX devices from Linux using USB

AN249 HUMAN INTERFACE DEVICE TUTORIAL. Relevant Devices This application note applies to all Silicon Labs USB MCUs. 1.

Exploiting USB Devices with Arduino. Greg Ose Black Hat USA 2011

AN1164. USB CDC Class on an Embedded Device INTRODUCTION ASSUMPTIONS FEATURES LIMITATIONS

AN295 USB AUDIO CLASS TUTORIAL. 1. Introduction. 2. USB, Isochronous Transfers, and the Audio Class Overview USB Operational Overview

Linux Driver Devices. Why, When, Which, How?

Simplified Description of USB Device Enumeration

Learning USB by Doing.

Freescale MQX USB Device User Guide

Ways to Use USB in Embedded Systems

Virtual KNX/EIB devices in IP networks

Open-source foundations for PC based KNX/EIB access and management

Do More With Less. On Driver-less Interfacing with Embedded Devices. Peter Korsgaard

A Design of Video Acquisition and Transmission Based on ARM. Ziqiang Hao a, Hongzuo Li b

Freescale MQX RTOS USB Host User s Guide

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Remote Access Server - Dial-Out User s Guide

WIZnet S2E (Serial-to-Ethernet) Device s Configuration Tool Programming Guide

USB Overview. This course serves as an introduction to USB.

IBM Tivoli Composite Application Manager for Microsoft Applications: Microsoft Hyper-V Server Agent Version Fix Pack 2.

Freescale Semiconductor, I

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Useful USB Gadgets on Linux

Sensors and the Zaurus S Hardware

Caml Virtual Machine File & data formats Document version: 1.4

Software User Guide UG-461

Bypassing Endpoint Security for $20 or Less. Philip A. Polstra, ppolstra.blogspot.com

User Manual (DA-70155)

KNX IP only A New Class of KNX Devices. WEINZIERL ENGINEERING GmbH. Dr.-Ing. Th. Weinzierl D Tyrlaching

LSN 10 Linux Overview

Operating Systems: Basic Concepts and History

AVR32807: Getting Started with the AVR UC3 Software Framework USB Classes. 32-bit Microcontrollers. Application Note. Features.

USB TO SERIAL CONVERTER

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

i.mx USB loader A white paper by Tristan Lelong

Installing Java (Windows) and Writing your First Program

Windows Host Utilities Installation and Setup Guide

Next Generation ETS Software A preview of the upcoming new ETS5 system & user enhancements. KNX Association, Brussels André Hänel

DEVICE DRIVERS AND TERRUPTS SERVICE MECHANISM Lesson-14: Device types, Physical and Virtual device functions

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Industrial Networks & Databases

M.Sc. IT Semester III VIRTUALIZATION QUESTION BANK Unit 1 1. What is virtualization? Explain the five stage virtualization process. 2.

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

Super Pro Net TM Network Key Installation and Operation

VIA Fedora Linux Core 8 (x86&x86_64) VT8237R/VT8237A/VT8237S/VT8251/CX700/VX800 V-RAID V3.10 Driver Installation Guide

evm Virtualization Platform for Windows

CANnes PC CAN Interface Manual

Chapter 02: Computer Organization. Lesson 04: Functional units and components in a computer organization Part 3 Bus Structures

PL-2303HX Edition (Chip Rev A) USB to Serial Bridge Controller Product Datasheet

Accessing I2C devices with Digi Embedded Linux 5.2 example on Digi Connect ME 9210

Local Interconnect Network Training. Local Interconnect Network Training. Overview

A guide to CLARiSUITE TM network solutions

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Application Note: AN00121 Using XMOS TCP/IP Library for UDP-based Networking

An Overview of Embedded Computing

Product Manual. ABB i-bus KNX IP Interface IPS/S 2.1. Intelligent Installation Systems ABB

AKD EtherNet/IP Communication

Matrix 510/520 User Guide

WinDriver 5.22 User s Guide. Jungo Ltd

Red Hat Linux Internals

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

python-escpos Documentation

MeshBee Open Source ZigBee RF Module CookBook

Jorix kernel: real-time scheduling

73S1215F, 73S1217F Device Firmware Upgrade Host Driver/Application Development User s Guide April 27, 2009 Rev UG_12xxF_029

Development of complex KNX Devices

ETS5 Overview of new functionality

Visualisation Systems. KNX Association

BLUETOOTH SERIAL PORT PROFILE. iwrap APPLICATION NOTE

Computer Systems Structure Input/Output

Computer Automation Techniques. Arthur Carroll

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

µtasker Document FTP Client

Chapter 5 Busses, Ports and Connecting Peripherals

Linux Kernel Architecture

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

System Calls and Standard I/O

Fondamenti su strumenti di sviluppo per microcontrollori PIC

"Charting the Course...

Embedded Component Based Programming with DAVE 3

Internal LVDS Dynamic Backlight Brightness Control

TivaWare USB Library USER S GUIDE SW-TM4C-USBL-UG Copyright Texas Instruments Incorporated

Version 1.0. File System. Network Settings

Application Program Description

Tutorial for MPLAB Starter Kit for PIC18F

Inwall Room Temperature Unit

Windows Host Utilities 6.0 Installation and Setup Guide

Gigabit Ethernet Packet Capture. User s Guide

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Fall Lecture 1. Operating Systems: Configuration & Use CIS345. Introduction to Operating Systems. Mostafa Z. Ali. mzali@just.edu.

Special FEATURE. By Heinrich Munz

User's Guide - Beta 1 Draft

Chapter 6, The Operating System Machine Level

Bluetooth HID Profile

Installing the Operating System with Express Setup

Technical Support Bulletin Nr.18 Modbus Tips

Future Technology Devices International Ltd. Mac OS X Installation Guide

USB Flash Drive User s Manual

Utilizing MBARI s Software Infrastructure and Application for MOOS (SIAM) for NOAA s Real-time Environmental Coastal Observing Network (RECON)

Transcription:

Fachhochschule Wiesbaden - Controlling EIB/KNX Devices from Linux using USB Heinz W. Werntges University of Applied Sciences Wiesbaden Jens Neumann and Vladimir Vinarski Loewe Opta GmbH, Kompetenzzentrum Hannover 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 1 Fachhochschule Wiesbaden - Introduction Why USB? Why Linux? About the authors 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 2

Introduction About the authors Jens Neumann & Vladimir Vinarski Authors of the Open Source tool Linux EIB Home Server See http://sourceforge.net/projects/eibcontrol Participation in EMBASSI project Affiliation: Loewe Opta Competence Center Hannover Heinz Werntges Teaches computer science at FH Wiesbaden since 2003 Background: Physics + commercial IT New to EIB/KNX: First contact about 1 year ago Motivation: Make EIB/KNX more popular and accessible, especially for the Linux community 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 3 Introduction KNX access via Windows Linux RS.232 Available Available IP Available Available Task: Fill this gap! USB Available Missing 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 4

Introduction Why USB instead of RS.232? PC view: RS.232 is legacy hardware, gets replaced Notebook PCs: Rarely equipped with RS.232 anymore EIB/KNX view: RS.232 transmissions are slower than USB and are sometimes riddled with timing issues Special FT1.2 protocol required USB downside: USB adds complexity Why not skip USB and go right for IP? Cost issues 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 5 Introduction Why use Linux instead of Windows? It is Open Source Adapt it to your particular project s / product s needs Well-established for (not-too-small) embedded systems Royalty-free! It is powerful Suffices for most practical purposes Real-time options available, strong on networks (IP!), Very reliable, good success record on servers Because it s there Don t miss the Linux community and its many technology addicts Well-established in academia, and it is always good to have an alternative. 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 6

Fachhochschule Wiesbaden - Background on Linux and USB 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 7 Background Linux: Kernel, device drivers, and modules Application User space Kernel Boot image Kernel space Device driver Device driver Hardware Application System calls Loadable module Loadable module E.g., the Linux EIB Home Server Q: How do we talk to KNX devices? Q: New module needed? E.g., the KNX USB Interface 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 8

Background Linux: The USB module family USB devices Broad variety, both block and character devices Kernel 2.6.12.1: 70 USB modules available Families : atm, class, core, host, image, input, media, misc, mon, net, serial, storage Plug-and-play option requires dynamic driver and device management Layered approach: usbcore usbserial usbhid ehci_hcd uhci_hcd visor 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 9 Fachhochschule Wiesbaden - The KNX USB Interface 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 10

The KNX USB Interface Specifications AN037: KNX on USB Protocol Specification & KNX USB Interface Device Requirements (2003.07.07) AN070: USB adaptations (2005.03.17) Key features HID class (HID = human interface device) Interrupt transfer mode for data exchange, both in & out Max. 64 octets of data per transfer Reserved usage page ID: Non-standard control page The multitude of KNX controls is not modelled with USB means; instead, KNX frames are tunneled through HID reports New protocol for tunneling, different from FT1.2 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 11 The KNX USB Interface USB HID support by Linux Based on usbcore module Part of input module family Specialized modules (e.g. for keyboard, mouse) available for popular usage page IDs Generic module hiddev available for other page IDs Result 1: hiddev is the appropriate driver for KNX USB interfaces Modern Linux kernels already support KNX USB devices KNX USB programming may be restricted to user space (no new KNX/USB kernel module needed!) Well so far for the theory 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 12

Fachhochschule Wiesbaden - Device discovery 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 13 Device discovery What happens when you plug in a KNX USB device? The USB core system exchanges control information It adds the device to the list of connected USB devices It assigns the appropriate driver (major device number) It loads the required module(s) into the kernel It issues an available minor device number Device path determined! 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 14

Device discovery Example for KNX USB interfaces usbcore detects a generic HID hiddev needed Major device no = 180, minor device no = 96+x x=0 if this is the first generic HID (x=1 if second, ) Resulting device path is /dev/usb/hiddev0 Alternative approach: usbdevfs Ex: Second device on bus of first USB controller: /proc/bus/usb/001/002 (Not used here) 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 15 Device discovery Information about USB devices Selection by vendor ID and product ID All devices on the USB bus can also be searched automatically Device selection can be based on vendor & product ID when those are known a priori. Tools lsusb usbview lsmod Lists device descriptors + bus topology X front-end, similar Lists loaded modules, incl. USB modules 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 16

Device discovery lsusb output for a KNX USB device: First 16 of 106 lines Bus 003 Device 002: ID 145c:1330 Device Descriptor: blength 18 bdescriptortype 1 bcdusb 1.01 bdeviceclass 0 (Defined at Interface level) bdevicesubclass 0 bdeviceprotocol 0 bmaxpacketsize0 8 idvendor 0x145c idproduct 0x1330 bcddevice 1.01 imanufacturer 1 Busch-Jaeger Elektro GmbH iproduct 2 KNX-USB Interface (Flush mounted) iserial 0 bnumconfigurations 1 Use these parameters for device selection 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 17 Fachhochschule Wiesbaden - Test setup 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 18

Test setup Test equipment and procedure IBM Thinkpad T42p SuSE Linux 9.2 Kernels 2.6.8.14-24 & 2.6.12.1 Test sequences / reports: Actuator: 8 x binary BJE 6195/81 BCU / USB BJE 6123 USB-82 1) Device feature get frame (Query supported EMI types) 2) Device feature response frame 3) Device feature set frame (Set active EMI type to EMI1) 4) PC_SET_VAL.req, tunnelled (Activate Link Layer) 5) L_DATA.req, tunnelled (Switch light on, group addr.=1/0/0) 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 19 Fachhochschule Wiesbaden - Writing reports Now that we know which device to open: How do we write data to it? Three approaches: 1) Windows (for comparison) 2) Linux, libhid 3) Linux, standard (system calls) 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 20

Writing reports 1) On Windows (for comparison) Device discovery Complicated, based on vendor & product ID, well-documented, fixed procedure) device handle Writing reports: Very simple a single line! WriteFile(handle, report_buffer, 64, &n_written, NULL); Derived from Endpoint Descriptor (out): wmaxpacketsize 0x0040 bytes 64 once 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 21 Writing reports 2) Linux, libhid approach Libhid: An Open Source library for accessing HIDs on Linux systems Bypasses usbhid module by directly calling into usbcore Device discovery By vendor ID and product ID + path into the HID usage tree Writing reports Convenient report exchange, similar to the Windows API unsigned char const PATHLEN = 3; int const PATH_OUT[] = { 0xffa00001, 0xffa00001, 0xffa10005 }; Usage page Usage data hid_set_output_report( handle, PATH_OUT, PATHLEN, report_buffer, 64); 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 22

Writing reports 3) Linux, standard approach Device discovery Currently: Determine the device path manually Obtain device handle from path: hnd = open(device_path, O_RDWR ); Expectation: Initially, some special system calls ioctl() Then, system call write() should suffice to send a report. Surprises: System call write() not available Hardly any documentation found! Instead, rather obscure ioctl() system calls to transfer all report octets into a kernel buffer before sending the report 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 23 Writing reports 3) Linux, standard approach:writing reports a) KNX USB report data structure struct HidReport{ unsigned char reportid; unsigned char packetinfo; unsigned char datalength; unsigned char protocolversion; unsigned char headerlength; unsigned char bodylengthhi; unsigned char bodylengthlo; unsigned char protocolid; unsigned char emiid; unsigned char manufacturecodehi; unsigned char manufacturecodelo; unsigned char emimessagecode; // 12 Byte header Item(Global): Report ID, data= [ 0x01 ] 1 Watch out for big-endian vs. little-endian processors! See AN037! unsigned char frame[52]; // max 52 octets remaining } attribute (( packed )); 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 24

Writing reports 3) Linux, standard approach: Writing reports b) Transmission loop int hidreportsend( HidReport *hidr, int hnd ) { signed char *report = (signed char *)hidr; struct hiddev_usage_ref uref; struct hiddev_report_info rinfo; Item(Global): Logical Minimum, data= [ 0x80 ] 128 Item(Global): Logical Maximum, data= [ 0x7f ] 127 Special treatment of initial report_id byte! uref.report_type = HID_REPORT_TYPE_OUTPUT; uref.report_id = *report++; uref.field_index = 0; uref.usage_code = 0xFFA10005; Item(Global): Usage, data= [ 0x05 ] 5 (null) } Item(Global): Usage Page, data= [ 0xa1 0xff ] 65441 (null) for( int uindex = 0; uindex < 63; uindex++ ) { uref.usage_index = uindex; uref.value = *report++; ioctl( hnd, HIDIOCSUSAGE, &uref ); } rinfo.report_type = HID_REPORT_TYPE_OUTPUT; rinfo.report_id = 0x01; rinfo.num_fields = 1; ioctl( hnd, HIDIOCSREPORT, &rinfo ); return 0; Item(Global): Report Count, data= [ 0x3f ] 63 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 25 Fachhochschule Wiesbaden - Reading reports How do we receive data from Konnex devices? 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 26

Reading reports 1) Windows (for comparison) Single call ( ReadFile ), similar to sending. Convenient 2) Linux, libhid approach Convenient report exchange, similar to the Windows API Two alternatives (control transfers, interrupt transfers) 3) Linux, standard approach Control transfers: Reports received bytewise, similar to sending Interrupt transfers: Reports received through system call read() Array of data structures which contain the desired report bytes Three different data structures available, selectable through flags Use e.g. separate thread to prevent blocking I/O Note: Some work left to be done here. 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 27 Fachhochschule Wiesbaden - Results 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 28

Results 1) Windows (for comparison) Worked as expected Results Effect ok No effect Call ok ++ - Call error - - 2) Linux, libhid approach Kernel 2.6.8.14: Non-reproducible results! New: Kernel reported timeout problems Discussion with libhid authors: Device timing ok? Libhid: No outbound interrupt transfers Results Effect ok No effect Call ok + ++ Call error + ++ The libhid approach is currently NOT an option! Kernel 2.6.12.1: Calls always return ok, but without effect. Kernel: Timeouts! Results Effect ok No effect Call ok -- ++ Call error -- -- 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 29 Results 3) Linux, standard approach Status of conference proceedings, end of July 2005: Results Effect ok No effect Call ok - ++ Call error - - Kernel debugging required! Breakthrough on last Sunday: Results Effect ok No effect Call ok ++ - Call error - - A user space driver is indeed all it takes to make Linux applications talk to KNX devices through a KNX USB interface! 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 30

Fachhochschule Wiesbaden - Outlook 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 31 Outlook Upgrade of Linux/Windows EIB Homeserver Will support also USB, both on Linux and Windows Needs adaptation from FT1.2 to AN037 protocol Current hardware requires downgrade from EMI2 to EMI1 format Note: Authors expected upgrade to cemi format. Support for high-level programming languages like Ruby API to KNX USB through extension modules (.dll,.so) Foundation for efficient, high-level programming projects User interfaces Automation tasks Open Source user space driver, to be supplied on the Web Some work left to be done for the read() system calls See http://www.informatik.fh-wiesbaden.de/~werntges/proj 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 32

Outlook A personal vision Low-cost, ubiquitous USB access to KNX systems Maybe integrated into power supplies? An open source supplement to ETS3 Near-term goal: Change KNX installation parameters just with a PC and free software no electrician or high-end panel involved. Far-term goal: An Open Source, platform-independent tool for programming EIB/KNX systems in non-commercial environments Skill requirements: High Price: Low (free tool) Convenience: Low Productivity: Low Let s offer something to the technical enthusiasts with good skills but low budget. We need those early adopters as multiplies! 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 33 Fachhochschule Wiesbaden - Appendix (Optional slides) 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 34

Introduction Situation before USB Sensor Actuator BCU / RS.232 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 35 Introduction Situation with USB (only at PC end) Sensor Actuator BCU / RS.232 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 36

Introduction Situation with USB (only at KNX end) Sensor Actuator BCU / USB 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 37 Introduction Situation with USB Sensor Actuator BCU / USB 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 38

Background Linux: Drivers, modules and devices Kernel 2.6.12.1: 1270 (!) modules in total Most drivers may be either statically linked or dynamically loaded Devices: Special files Accessed as special files in the filesystem ( everything is a file ) Two types: Block devices Block is smallest access unit, random access Ex: First IDE disk /dev/hda Char. devices Octet is smallest access unit; typically serial access Ex: COM1 /dev/ttys0 Note: One driver may serve multiple devices. 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 39 Background Linux: Drivers, modules and devices Basic drivers are enumbered by the kernel See Major device no and /proc/devices Ex: 180 usb, 188 ttyusb One driver/module can control multiple devices See Minor device no and /proc/devices File system entries in /dev map filenames to device no s: sd 4: ttys 188: ttyusb fd 180: usb Driver pool 4, 0 4, 1 188, 0 180, 0 180, 96 /dev/hda /dev/fd0 /dev/ttys0 /dev/ttys1 /dev/usb/ttyusb0 /dev/usb/lp0 /dev/usb/hiddev0 19.09.2005 H. Werntges, FB Informatik, FH Wiesbaden 40