CAPS Code Examples¶
This page provides examples for using the CAPS (Capabilities-based Architecture Platform for Smart-devices) modeling language for IoT system design.
Download: CAPS Code Examples (ZIP)
Example Categories¶
Hardware Modeling with CAPSHWML¶
These examples demonstrate how to model hardware components using CAPSHWML:
Overview of CAPS¶
CAPS is a model-based approach for designing IoT systems. It uses XML-based model files to define:
- Hardware components and their capabilities
- Software architectures and service interfaces
- Network configurations and protocols
- System behaviors and interactions
The primary benefit of using CAPS is the ability to model an IoT system at a high level of abstraction before implementation.
Note: You dont have to write these files, this will be generated automatically using the diagram panel from the eclipse as shown in the tutorial.
Hardware Modeling with CAPSHWML¶
CAPSHWML (CAPS Hardware Modeling Language) is used to define the hardware components of an IoT system. These models specify sensors, actuators, processors, memory, and energy sources.
Motion-Based Lighting System Hardware Model¶
The following example defines a hardware model for a motion-based lighting system.
MotionLight.capshwml¶
This file defines the hardware specification for an occupancy sensor node.
<!-- Gist of MotionLight.capshwml -->
<NodeSpecification>
<nodes name="Occupancy Sensor" OS="TinyOS" macProtocol="ZIGBEE" routingProtocol="GEAR">
<energySources type="ContinuousEnergySource" name="Electricity"/>
<OccupancySensors name="OccupancySensor"/>
<microcontroller>
<processors name="Atmel Atmega328" frequency="120" cpi="1.0"/>
<memory name="RAM" size="2"/>
</microcontroller>
</nodes>
</NodeSpecification>
Key Components¶
- Node Specification: Defines an "Occupancy Sensor" node with TinyOS operating system and ZIGBEE communication protocol
- Energy Source: Uses a continuous energy source (mains electricity)
- Sensors: Includes an occupancy sensor for motion detection
- Microcontroller: Specifies an Atmel Atmega328 processor with 120 MHz frequency and 2MB RAM
Software Architecture with CAPSSAML¶
CAPSSAML (CAPS Software Architecture Modeling Language) defines the software architecture of an IoT system, including components, interfaces, and interactions.
Motion-Based Lighting System Software Model¶
Note: This is not the complete file it just shows the syntax and the structure of the file.
<!-- Gist of MotionLight.capssaml -->
<SoftwareArchitecture>
<components name="Motion Detection">
<provides interface="SensorReading" type="boolean"/>
</components>
<components name="Light Controller">
<requires interface="SensorReading" type="boolean"/>
<provides interface="LightControl" type="command"/>
</components>
<components name="Light Actuator">
<requires interface="LightControl" type="command"/>
</components>
<connections source="Motion Detection" target="Light Controller" interface="SensorReading"/>
<connections source="Light Controller" target="Light Actuator" interface="LightControl"/>
</SoftwareArchitecture>
Key Components¶
- Motion Detection: Component that provides sensor readings
- Light Controller: Component that consumes sensor readings and provides light control commands
- Light Actuator: Component that consumes light control commands to operate the lights
- Connections: Defines how components interact through interfaces
Deployment Modeling with CAPSDEPLOY¶
CAPSDEPLOY models define how software components are deployed onto hardware nodes.
<!-- Gist of MotionLight.capsdeploy -->
<Deployment>
<mapping component="Motion Detection" node="Occupancy Sensor"/>
<mapping component="Light Controller" node="Gateway Node"/>
<mapping component="Light Actuator" node="Light Node"/>
</Deployment>
Key Concepts¶
- Mapping: Specifies which software components run on which hardware nodes
- The Motion Detection component is deployed on the Occupancy Sensor node
- The Light Controller runs on a gateway device
- The Light Actuator is deployed on a dedicated light control node
Network Configuration with CAPSNETWORK¶
CAPSNETWORK models define the network configuration for the IoT system.
<!-- Gist of MotionLight.capsnetwork -->
<Network>
<topology type="Star">
<centralNode name="Gateway Node"/>
<edgeNodes name="Occupancy Sensor"/>
<edgeNodes name="Light Node"/>
</topology>
<protocol name="ZIGBEE">
<properties securityLevel="Medium" dataRate="250kbps"/>
</protocol>
</Network>
Key Features¶
- Topology: Defines a star network with a central gateway node
- Protocol: Specifies ZIGBEE communication with medium security level and 250kbps data rate
- Nodes: Lists all nodes participating in the network
How to Use CAPS Models¶
- Design Phase:
- Create hardware models (.capshwml) to define physical devices
- Develop software architecture models (.capssaml) to define components
- Create deployment models (.capsdeploy) to map software to hardware
-
Define network configurations (.capsnetwork) for communication
-
Analysis Phase:
- Validate models for consistency and completeness
- Analyze power consumption based on hardware specifications
- Verify network coverage and communication patterns
-
Check memory and processing requirements against hardware capabilities
-
Implementation Phase:
- Generate code stubs based on the models
- Implement component functionality according to interface specifications
- Deploy software following the deployment model
- Configure network according to network specifications
Benefits of Model-Based Design with CAPS¶
- Abstraction: Focus on system design without getting lost in implementation details
- Validation: Check system properties before implementation
- Reusability: Reuse models for similar IoT applications
- Documentation: Models serve as living documentation of the system
- Traceability: Maintain clear relationships between requirements and implementation
These CAPS models provide a foundation for designing IoT systems in a structured and systematic way, ensuring that hardware capabilities, software functions, and network requirements are properly aligned.