Date post: | 10-Mar-2018 |
Category: |
Documents |
Upload: | trinhhuong |
View: | 256 times |
Download: | 6 times |
Hands-on Workshop:
Industrial HMI Using i.MX25 and QNX® Smart Energy
Reference Software for Home and Building Control
Sheridan Ethier
Manager, Application Engineering
QNX Software Systems
August 2010
2 All content copyright QNX Software Systems.
Agenda
QNX Overview
I.MX25 Family Overview
QNX Aviage HMI Architecture Overview
Adobe Flash as a next-gen embedded HMI tool
Integrating the HMI to real-time components
ActionScript extensions
Persistent Publish-Subscribe
Hands-on
Smart Metering Reference Application
Actionscript code walkthrough and interfacing to native OS services
Exploring PPS objects and behaviours
OS control of peripheral devices
3 All content copyright QNX Software Systems.
QNX Core Product Offerings
ServicesRuntime Product Portfolio
Aviage Middleware Portfolio
Development and productivity tools
QNX Neutrino RTOS (Micro Kernel)
QNX Photon microGUI
Instrumented kernel
File systems
Multicore
Adaptive partitioning
High availability
Connectivity and networking
Integrated Java
QNX Momentics IDE
Multicore visualization
Performance optimization
Memory and system analysis
Performance and footprint optimization
Photon application builder
Target information & remote debug
Libraries and GNU tools
Support
Custom engineering
Professional Services
Training
QNX Aviage multimedia solution
QNX Aviage HMI suite (including Flash Lite 3)
QNX Aviage acoustic processing
Voyager web browser
4 All content copyright QNX Software Systems.
Advanced Runtime Module
QNX Runtime Product Portfolio
Multimedia
Suite
QNX Neutrino
RTOS
QNX Neutrino
Extensions
QNX Aviage
Middleware
Instant
Device
Activation
Extended
Networking
(security)
Multi-coreAdaptive
Partitioning
Web
Browser
Java
Acoustic
Processing
HMI
Suite
QNX Neutrino RTOS Runtime
Core
File Systems
Peripheral
Hardware
Core
Networking
Core
OS
TDP/QNETHigh
Availability
2D/3D
GraphicsPhoton
QNX Microkernel: Designed for Reliability, Designed for Embedded
Graphics
Networking
Drivers
Kernel
File System
Monolithic KernelWinCE 3.9 million lines of code
Linux: 5.76 million lines of code
XP: 40 million lines of code
Microkernel
Memory Protection
Message
passing
Micro
kernel
File System
Networking
Driver
Driver
Graphics
QNX 0.1 million lines of code
Designed for reliable,
embedded devices
Freescale i.MX25 Focus Markets
Freescale Multimedia Markets
Low-PowerHigh Integration
Advanced PerformancePlatform Software
Portable Consumer
• Smartbook
• E-book
• Smartphone
• Portable Media Player
• Personal Navigation
Automotive Infotainment
• Audio
• Connectivity and Telematics
• Video and Navigation
Home Consumer
• Media Phone/Terminal
• iPod accessories
• Remote controls
• Digital Photo Frame
• Appliances
Industrial
• POS/Scanners/Printers
• Security and Surveillance
• Industrial HMI
• Medical
• Metering
i.MX25 Target Markets
i.MX25x Series
Key Features and Advantages
400MHz ARM926EJ-S™
16KB L1 I-Cache, 16KB L1 D-Cache
128KB on-chip SRAM for low power LCD refresh
External memory interface supports DDR2, mDDR, or SDRAM up to 133MHz, 16-bit data bus
Supports off-chip NAND or NOR Flash
10/100 Ethernet MAC with RMII support
USB 2.0 OTG 480Mbps with high-speed PHY
USB 2.0 Host 480Mbps with high-speed PHY
Two CAN interfaces
Two Smartcard interfaces
SDIO interface for external Wi-Fi module
WVGA LCD controller
Resistive touchscreen controller
CMOS sensor interface
P-ATA for external CD connection or HDD
CE-ATA and SD/MMC+ for external storage
Enhanced serial audio interface
3 general purpose 12-bit ADC channels
UART’s, CSPI’s, I2C, I2S
Enhanced security features, including tamper detection for voltage, frequency and temperature
High-Assurance Boot (HAB)
3.3V I/O reduces external component count
Available Parts
i.MX251, i.MX255, i.MX253, i.MX257, i.MX258
Package and Temperature
0.8mm, 400-pin MAPBGA
-20C to +70C, -40C to +85C temperature options
AEC-Q100 Grade3 Qualification
Audio
ESAI
SSI/I2S x 2
Security
SCC RNGB
HAB SRTC
RTICv3 Dry-Ice
Standard
System
Timer x 4
PWM x 4
Watch Dog
SDMA
Advanced Connectivity
10/100 Ethernet HS OTG + Phy
CAN x 2 HS Host + Phy
SDIO x 2 Smartcard x 2
Ext Memory I/F
NAND
NOR
DDR2
mDDR
SDRAM
User I/F
LCD Controller
Touchscreen
Controller
CMOS Sensor I/F
8x8 Keypad
SLCD Controller
Ext Storage
MMC+/SD x 2
P-ATA
CE-ATA x 2
Int Memory
128KB SRAM
32KB ROM
Standard
Connectivity
CSPI x 3
UART x 5
I2C x 3
GPIO x 4
12-bit ADC x 3
1-Wire
i.MX25x
ARM926EJ-S
400MHz
16K I
Cache
16K D
Cache
System Debug
ETM SJTAG
Not available
on all variants
Common IP with
i.MX35x
i.MX25 Family: 3-Digit Part Numbering
Target Markets Automotive Automotive Industrial & Consumer
Industrial & Consumer Industrial
Example Applications
• Audio Connectivity• Secure Black Box• Smart Toll Road
Systems
• Infotainment• Secure Black Box• Smart Toll Road
Systems
• HMI• Printers• Medical• Factory Automation
• “Smart Touch” HMI• Factory Automation• Barcode Scanners
• Point-of-sale• Biometrics• Smart Meters• Secure Devices
Key Differences
• No LCD Controller• No Touchscreen
Controller• No CE-ATA/P-ATA
Full-featured automotive device
with security
• No Camera Interface
• No Touchscreen Controller
• No Smartcard• No CAN
Standard Part• No Security
Full-featured device with security
10Ku Re-sale (2010) Contact Marketing Contact Marketing
Consumer – $6.26 Consumer – $7.00Industrial – $8.11
Industrial – $6.46 Industrial – $7.37
Qualification Tier Automotive AECQ100-G3
Automotive AECQ100-G3 Industrial, Consumer Industrial, Consumer Industrial
Package 17x17 MAPBGA 0.8mm
17x17 MAPBGA 0.8mm
17x17 MAPBGA 0.8mm
17x17 MAPBGA 0.8mm
12x12 MAP BGA 0.5mm
17x17 MAPBGA 0.8mm
Temperature -40C to +85C -40C to +85C -20C to +70C-40C to +85C
-20C to +70C-40C to +85C -40C to +85C
Freescale i.MX25 PDK
Software
• Linux 2.6.x BSP
• WinCE 6.0 BSP
• Flash Programming Tool (ATK)
Part Numbers
• MCIMX25LPDKJ (Linux)
• MCIMX25WPDKJ (WinCE6.0)
Availability and Price
• Available now
• Re-sale $995
• www.freescale.com/imx25pdk
i.MX25 System Cost Advantage Examples
12
Memory interface supports low cost DDR2
Multiple boot options, including boot from NAND and SPI flash
2 USB ports – no need for external hub
Ethernet 10/100 MAC, USB PHYs and ADCs are integrated – eliminates external components
Integrated display and touchscreen controller’s
3.3V I/O – direct connectivity to peripherals
0.8mm pitch package and optimized pinout reduces PCB layer count
The “iPhone Factor”
The iPhone has been accepted as an easy to use interface device for
many functions, and is driving consumer expectations in other areas,
including Home Automation
Why Design your HMI with Flash Lite?
Industry Standard Tools
Create Rich Graphics and Animations
Designed for Embedded Devices
Large Community of Flash Developers
Adobe FlashCS3/CS4
Adobe Illustrator
Adobe Photoshop
16 All content copyright QNX Software Systems.16
QNX HMI Technology
Flash
Adobe Flash
OS interfaces
QNX HMI Technology Architecture
Vertical Stacks
& Demos
Core Applications
WebKit
engine
HTML
App
storeBrowser
Media
player
Widget
Examples
Graphics Engine
OpenVG
Screen Management
Native and EGL interface
HW Accelerated Screen TransitionsHW & Virtual Layer Management
Operating SystemQNX RTOS
Video
Render
Video
OpenGL
Application
3D native
OpenVG
Application
2D native
Composition Manager
HW Acceleration
Application framework (ActionScript based)
Flash Services and widgets
Scroll List Buttons Sliders Soft keyboard NavBar ...Transitions Themes
Native OS Services
Media Browser SQL Remote ...Graphics LayersPPS
Application launcher
Loading Settings State ...Resize
Input
Touch, keyboard, mouse
QNX CARIndustrial
SMA Demo
Industrial
White Goods DemoMedical Demo
OpenGL ES 1.1 & 2.0
Docs
Core Documentation
Generic Demo
1717
QNX HMI Technology Components: Flash
Flash Lite 3
Hardware accelerated OpenVG (on supported platforms)
ActionScript2 support
Debugging capabilities
X-Ray
Flash/Native Extensions
Browser (Webkit)
Multimedia – video, audio playback
Publish Subscribe / Data distribution services
Embedded database access (SQLite)
etc
Complete HMI framework provided by QNX
Apps, widgets, services, lifecycle management
Reference Applications
Youtube, audio and video player, browser, weather
18
QNX HMI Technology Components: Webkit and Multimedia
Webkit
HTML5 support
Includes new additions to HTML language for video, audio, geolocation etc
Uses Skia standard for 2D drawing
Current Webkit version 525; updating to version 533
Improved components for user interaction
High performance panning and zooming
HTML rendering engine; browser app provided in Flash
Multimedia
Audio & Video playback
Metadata sync’ing and management
Support for hardware assisted codecs
Streaming or file-based video playback
Combine and overlay graphics from different render engines
Flash acts as a “Window Manager”
Based on standards
Action Script, OpenGL, OpenVG, OpenKode, HTML, JavaScript, POSIX
QNX HMI Technology Components: HMI Composition
Composition
Flash
HTML
OpenVG
OpenGLVideo
22 All content copyright QNX Software Systems.
Adobe Flash in Embedded
1 billion mobile devices in 2009
400+ device models
23 All content copyright QNX Software Systems.
Why Adobe Flash?
Flash is the de facto HMI standard
Flash player installed on*:
98% of US Web users
99.3% of all Internet desktop users
Over one million graphics designers worldwide
Flash realizes the Java promise of Write Once, Run Anywhere
Class library dependency problems do not exist as in Java
Content developed for web or PC can run on embedded without change
Embedded FlashLite player uses less memory and provides faster rendering
Flash is ideal for HMI creation
Graphical environment by nature
Used by industrial designers to design look & feel
Ability to create “executable specifications”
*Numbers are estimates from Adobe, and depend on demographical & statistical info
24 All content copyright QNX Software Systems.
Flash Lite in Embedded
Adobe Flash Lite 3
Highly optimized implementation of the Flash runtime
Specifically for embedded market
Requirements in line with embedded
32-bit data bus, 200MHz
380KB core player DLL size (without video codecs)
RAM requirements:
For user interface: 4–6MB
For standalone content: 2–4MB (excludes video)
For web browsing: 32MB
Advantages
Web/desktop Flash content to mobile and back again, with minimal effort
Vector graphics adjusts to different screen sizes without loss of quality
Vector graphics creates very small content files, compared to bitmaps
25 All content copyright QNX Software Systems.
From Design to Deployment, no Detours
Flash HMI Development
1) Designer creates HMI in Adobe Flash on PC
2) .swf file from design process runs directly on the target system
3) Done.
Standard HMI Development1) Designer creates HMI in Adobe Flash on PC
2) .swf file from design process run by software engineers on PC as mock-up of system
3) Engineers attempt to duplicate behavior by recreating screens and graphics
a) Design all state logic from scratch
b) Use C/C++ code or another toolkit
c) Graphical assets not directly reusable
4) Engineers debug and get C/C++ code running on target
5) Design difficulties encountered in HMI are sent back to designers for rework with real hardware constraints
6) Engineers make adjustments to software & graphics for new design
7) Pass running system by design for verification
8) Errors in HMI duplication reworked and recoded
9) Repeat steps 4 – 8 as necessary
10) Done.
Adobe CS Development Environment
Both scripted (code) and non-scripted (timeline) behavior
Many pre-scripted actions (effects, transitions, tweens, etc.)
Graphical resources are primarily vector graphics (scalable)
Can include videos (.flv)
Very well suited for Internet or connected development
remote connection, datasets
web services
wsdl, xml, urls, etc.
Programmatic
Create graphical assets in CS3/4/5
AS3 resides in separate source files
Use Flash Develop to bind “resource-only” swfs with AS3 code for final swf
Two Methods for Flash HMI Development Workflow
Graphical/Timeline
Create graphics and ActionScript mixed together in traditional “Flash” timeline
Final .swf output directly from CS3/4/5
The Problem
How do you make the Flash player extensible?
How do you interface the Flash runtime environment with native OS services?
How do you handle computationally expensive operations?
30 All content copyright QNX Software Systems.
Flash to Native Gateway
QNX Aviage HMI Suite can implement ActionScript classes in C or C++
Interface defined in ActionScript
Implementation created in native code (C/C++)
Shared object (.so) containing C/C++ extensions loaded at player startup
Calls into C/C++ execute by…
…blocking Flash VM until finished OR
…spawning threads and using notification for callbacks
/**
* ActionScript access to system level functions
*/
intrinsic class com.qnx.extensions.example.SysUtil
{
public function SysUtil(); // constructor
function getCPUUtilization():Array; // returns [ core1%, core2%, ...]
function getMemoryUsage():Object; // returns {current:<#>, total:<#>}
function getDiskUtilization():Object; // returns {reads:<%>, writes: <%>}
function getNetworkUtilization():Object; // returns {tx:<%>, rx:<%>}
}
#include <flqnx.h>
typedef struct {
const char *class_name;
int method_count;
const char **method_names;
flqnx_as_method_type_t *method_types;
flqnx_as_method_handler_t method_handler;
int flags;
FLQNX_CLASS_CONTEXT_T context_data;
} flqnx_as_class_t;
31 All content copyright QNX Software Systems.
Considerations Going from ActionScript to Native
What should move from ActionScript into native code (C/C++)?
Time consuming or computationally intensive operations
C/C++ is faster
Lengthy or blocking operations
Flash VM is single-threaded
Items requiring deterministic behavior
Flash can’t guarantee response time
Interfaces to existing native software blocks
No need to re-write code
Visible components: Reports/charts, browser, video playback, maps, 3D visualization, etc.
Libraries: cryptography, multimedia, acoustic processing, parsing, sockets, protocols
The Problem
How do you easily inform multiple applications that common data has been updated?
How do you create modular software that allows components to be easily tested independently?
How do you integrate applications written in different languages?
34 All content copyright QNX Software Systems.
Persistent Publish Subscribe (PPS)
Subscriber and Publisher
Can be unknown from each other at compile time
Can be dynamically substituted at runtime
Can have one-to-one, one-to-many, many-to-one relationships
Do not use direct calling API; available to all languages, scripts, shells
Can be in different languages, virtual machines, sandboxes
Are asynchronous from each other
Publisher
Can be configured how to persist data
Can support on-demand publishing (pull rather than push)
Persists attribute data over reboots
Subscriber
Are notified when data changes
Do not poll (block until delta update received)
Can receive notification on changes within a publishing tree
Heat sensor
pll
EtherCAN
/fs/pps/heat, ethercan, pll
Temperature
MonitorMotor
35 All content copyright QNX Software Systems.
PPS Benefits
Attribute Feature Benefit
Applications loosely coupled to services
Object-based data publication
Asynchronous data push/pull
No polling required; unblocking notification interface
POSIX file namespace
Less brittle connection
Modifications to client or server won’t break interface
Implementation isolation (client doesn’t need to know who publisher is)
Language independent interface
Multi-view publishing Multiple objects can give differing views on same data source
Can have more than one publisher update different attributes of the same object
Easier for client’s most appropriate use
Can publish derived data
Can extend system and retain logical coherence
Client can get delta updates
Persistent state save Save to media of choice (NAND flash, NOR flash, Harddisk, USB, etc.)
Save on shutdown and system controlled points
Save attributes across system reboot
Retain object state for intermittent clients
Hands-On Agenda
Use case overview
Smart energy reference design
Connecting to the i.MX25 Target
Exploring the Flash Application
HMI to Service Integration via PPS
PPS Objects
Flash Application Interfacing to PPS Objects
Handling PPS Events in Flash
Examining Device Drivers
Driver Example
Other Drivers
Smart Energy Reference Design – Menu Tree
Home Screen Weather Info
Lighting Control Video Surveillance
Smart Energy Reference Design – More Detail
Energy Usage Detailed Monthly Energy Usage
Energy Management Editing Energy Rules
Hardware Configuration
Network
Powerline Communications
InsteonServer
DimmerControllers
FreescaleIP Camera
Zigbee Gateway
Utility Simulator
Zigbee SensorsTemperature & Humidity
Smart Meter
Load Switches
Weather, Flickr, Pandora, etc.
Smart Energy – Software Architecture
Flash Lite 3 Player
Flash(Action Script)
Drivers & Services(C/C++)
PPSExtQDBExt
SQLite
ASE
energy
usage
database
power
monitor/
scheduler
insteon
manager
media
playerhvac
io-media
envsensor
motorhvac
TCP/IP
MPEG4
TCP/IP
PPS Components
Resource Managers
Insteon
server
PPS Objects at the Command-Line
# cd /fs/pps
# ls
.notify hvac mediaplayer system
doorBell_back insteon network
doorBell_front launcher power_monitor
# cd insteon
# ls
dimmer_base1 dimmer_main2 dimmer_up2 light2_main light_sun1
dimmer_base2 dimmer_main3 dimmer_up3 light_base2 light_sun2
dimmer_main1 dimmer_up1 dummy_sun1 light_main1 light_up2
# cat dimmer_main3
@dimmer_main3
ID::15
Label::dimmer_main3
Level::255
Schedule::-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
Zone::1
isdimmer::1
Temp sensor
Power Meter
Light
/fs/pps/hvac, insteon, etc
Temperature
Light Levelkwh
High Level Software View
PPSWrapper
Insteon-mgr
Insteon Device 1
2
3
5
PPSExt
4pps_extension
Flash
OS Services / Native C-code
Insteon Light Devices Uses QNX PPS Class(SmartEnergyPanel/src/com/qnx/smartenergypanel/system/insteon/InsteonDevice.as)
Light Change Event Uses Insteon Devices Class (…/smartenergypanel/system/control/commands/lights/UpdateLightCommand.as)
Restart Flash App from Telnet Window
# pidin -p flash ar
1003580 /qnx-ia/armle/bin/flash -o /qnx-ia/etc/system/config/flash.conf /qnx-ia/runtime/startup.swf
# slay flash
# flash -o /qnx-ia/etc/system/config/flash.conf /tmp/SmartEnergyPanel.swf
Change the Light Dimmer to See the Debug Output
View PPS object from 2nd telnet window
View Flash debug output from 1st telnet window
Handling Event Changes (i.e. from PPS objects)(…/smartenergypanel/system/control/commands/lights/InitializeLightsCommand.as)
Restart Flash App
# Ctrl + C (stop the Flash app)
# flash -o /qnx-ia/etc/system/config/flash.conf /tmp/SmartEnergyPanel.swf
Manually Change the PPS Object
# echo Level::20 >> dimmer_main3
#
# cat dimmer_main3
@dimmer_main3
ID::15
Label::dimmer_main3
Level::20
Schedule::-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
Zone::1
isdimmer::1
Change PPS object from 2nd telnet window
View Flash debug output from 1st telnet window
Restart Flash App and Driver
# Ctrl + C (stop the Flash app)
# flash -o /qnx-ia/etc/system/config/flash.conf /tmp/SmartEnergyPanel.swf
# /tmp/insteon-mgr-test -S -n dimmer_main3 -d -z1 -l255 -i15 &
Move the slider to see the affect on the driver
View Flash debug output from 1st telnet window
See change in PPS object from 2nd telnet window
HVAC System
hvac
DescriptionController process for each zone
InputsResMgr: EnvSensor for temp, humidity, light
PPS: Receive temp settings
OutputsResMgr: Controls motor (furnace, a/c & fan)
PPS: Publish temp & humidity data
hvac-sep-wrapper
DescriptionSingle control for access to all zones
InputsPPS: set zone temp
Output: PPS: current zone temp
motor
DescriptionMotor proxy (dummy)
InputsResMgr: Accept motor controls
EnvSensor
Description
Zigbee sensor gateway
Inputs
TCP/IP: read sensors through gateway
Outputs
ResMgr: sensor data
hvac
wrapper
envsensor
motorhvac
TCP/IP
Power Control
insteon-mgr
Description
Controls electrical on/off for lighting, water heater, pool pump
Inputs
PPS: Receive control commands
Outputs
Send on/off to devices through server
power monitor
Description
Periodic recording of power consumption
Handle scheduled power events
Receive power grid messages & pricing
Inputs
PPS: functions for open, play, stop, etc.
Outputs
SQL: Record power usage data
SQLite
power
monitorinsteon-mgr
TCP/IP
Insteon
server
Video Camera System
pps-media-player
Description: Plays video camera stream
Inputs
PPS: Turn on/off video source
Outputs
None
io-media
Description
Creates graph for streaming read and MPEG4 video decoding
Inputs
C API: functions for open, play, stop, etc.
TCP/IP: Camera stream from URL
Outputs
Video data
pps-media-
player
io-media
MPEG4
Summary
Use case overview
Smart energy reference design
Connecting to the i.MX25 Target
Exploring the Flash Application
HMI to Service Integration via PPS
PPS Objects
Flash Application Interfacing to PPS Objects
Handling PPS Events in Flash
Examining Device Drivers
Driver Example
Other Drivers
Hands On
Instructor will present demo on VMWare, students work on i.MX25 targets
Instructor and students will explore the modular software architecture and discuss the advantages this design
Instructor will walk through Flash Action Script code down to native C-code drivers
Students will be able to modify data objects at the OS level to follow the reaction at the HMI and vice-versa
93
Reference Design Software Architecture
Flash Lite 3 Player
PPS SQL
Power
Scheduler
SQL
SQLite
Energy Usage
Database
PP
S
Flash Player Extensions
Insteon
Lighting
PPS
HVAC
Controlle
r
PPS
MPG4Mediaplaye
r
PPS
Load
Switches
PPS
Smart
Meter
PPS
FlashAction Script
C/C++Drivers &
Applications
Zigbee
Sensors
PPS
1) HVACZoneData.as
com.qnx.smartenergypanel.system.hvac.HVACZoneData
public function HVACZoneData(i_id:String, listen:Boolean)
{
. . .
_pps = new PPSWrapper("/fs/pps/hvac/zone" + i_id +
"_state", PPSConstants.O_RDWR, listen);
. . .
}
public function getCurrentTemp():Number
{
_pps.open();
return Number(_pps.getData().currentTemp);
}
2 & 3) PPSWrapper.as / PPSExt.as
com.qnx.smartenergypanel.system.pps.PPSWrapper
public function getData():Object
{
return ppsext.data;
}
private function handleChange(event:Object):Void
{
// Logger.trace("PPS Change Event for:"+ppspath);
var ev:PPSEvent = new PPSEvent(PPSEvent.CHANGE, this);
dispatchEvent(ev);
}
com.qnx.extensions.pps.PPSExt
OnChange method invoked by PPSEvent sets ppsext.data
4) asextension/pps/ase-pps.so
pps_extension.c
static int _pps_read(struct pps_data *pdata) {
...
while ( ! done ) {
...
len = read(pdata->fd, info->data,
sizeof(info->data) - 1);
...
flash_as_ext_if->notify(pdata->player, _pps_notify_data, (void*)info);
...
}
...
}
5) hvac
hvac-resmgr.c
void update_pps(int updateMode) {
...
rv = snprintf(pps_ptr, size, "currentTemp::%.2f\n",
hvacattrs.state.sensor_data.temperature);
...
write(hvacattrs.pps_state_fd, pps_buffer, strlen(pps_buffer));
flushall();
}
//Polled by timer 3 times a second, but could be event driven by hardware
int pulse_handler (message_context_t *ctp, int code, unsigned flags,
void *handle)
{
. . .
status = devctl(hvacattrs.sensor_fd, DCMD_SENSOR_STATE_GET,
&sensor_state, sizeof (sensor_state), NULL);
. . .
update_pps(0);
}
6) Envsensor
sensor.c
void update_from_network()
{
server_host = gethostbyname(server_hostname); /* connection setup */
. . .
fd = socket(AF_INET, SOCK_STREAM, 0); /* create and send request */
bytes = snprintf(buf, sizeof(buf), "sample %s %s\n", sensor_type,
sensor_address);
write(fd, buf, bytes);
read(fd, buf, sizeof(buf)); /* read response */
. . . /* parse response */
}
int io_devctl(resmgr_context_t *ctp, io_devctl_t *msg, RESMGR_OCB_T *ocb)
{
. . .
case DCMD_SENSOR_TEMP_GET:
*(unsigned*)dptr = ocb->attr->data.temperature;
nbytes = sizeof(ocb->attr->data.temperature);
break;
. . .
msg -> o.ret_val = 0;
msg -> o.nbytes = nbytes;
return (_RESMGR_PTR (ctp, &msg -> o, sizeof (msg -> o) + nbytes));
}