A framework for modeling, simulation, and automatic code generation for sensor network applications

Publisher:平和梦想Latest update time:2011-09-21 Source: 中华电子网 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

When Wireless Sensor Networks (WSN) are used in the field, information sharing and collaborative processing are performed through wireless channel communication.

There are currently two types of functional analysis packages for WSN applications, namely platform-specific operating systems and tailor-made models, both of which have obvious defects in the application development stage. The first type is difficult to migrate applications to other platforms, such as migrating from TinyOS to MANTIS or migrating to ZigBee-compatible platforms, and a large amount of code must be rewritten and debugged. The second type has a lot of platform-dependent specific code that needs to be developed and debugged. If problems are found after the development and integration phase is over, the only solution is to debug based on LEDs, which is extremely time-consuming.

Reference Simulation Framework

The MathWorks company built a sensor network model based on Simulink as a base time simulator for dynamic systems. The model has two main components: a wireless channel model (hereinafter referred to as Communication Medium) and a Node block.

The Communication Medium block can be implemented in C and can be modified to reuse any existing channel and connection model.

The Node block has multiple fully parameterized motes, including hardware and software platform models. For example, it includes timers, LEDs, and parameterized Stateflow blocks for applications. Stateflow is a finite state machine language used to model and simulate control logic and flow charts. It can be used to implement algorithms (applications, middleware, or device drivers) running in each mote.

Simply modify the template algorithm (Stateflow library object), set the connection parameters of the nodes in the Communication Medium block, and start simulating. Collect statistics using animated state diagrams, observation instruments, and displays to perform functional analysis of the algorithm. If the analysis of the results indicates that improvements are needed, you can achieve them by improving the algorithm.

After completing the functional analysis of the algorithm, the algorithm's Stateflow is used to automatically generate code for any supported WSN platform. This is done using a custom feature of the RealTime Workshop Embedded Coder software that generates embeddable ANSI C code for Simulink and Stateflow blocks.

A Simple Simulation Framework for WSN

Figure 1 A simple simulation framework for WSN

WSN Application Operating System Examples: TinyOS and MANTIS

The programming model of TinyOS is component-based. Conceptual entities are represented by two types of components: modules and configurations. Interfaces are implemented to declare command and event signatures. Events are software abstractions, such as receiving a packet of information, completing a sensor sampling, etc. Commands are used to trigger actions, such as sensor reading operations or starting a radio to receive and transmit information. TinyOS applications are written using nesC, an extension of the C language.

MANTIS is a lightweight, multi-threaded operating system that can perform multitasking on energy-constrained distributed sensor networks. The scheduler uses a priority-based round-robin scheduler that supports thread pre-emption, allowing the operating system to switch freely between active threads without waiting. Due to this approach, the operating system responds to critical events faster than TinyOS. The MANTIS kernel and API are written in standard C.

A framework for modeling, simulation and code generation of WSN applications

Figure 2. WSN application modeling, simulation, and code generation framework

Implementing WSN Applications

The computational body of MANTIS threads and tasks, as well as the commands of TinyOS, are actually written in C. In MANTIS, the integration is very straight-forward, since the ANSI C output of Real-Time Workshop Embedded Coder can be used directly as user threads. TinyOS programs consist of high-level abstractions, but the body of these abstractions is written in C, so only a transcoder is needed, which takes C code as input, splits the code into different parts (including definitions, functions, etc.), and uses these parts to generate nesC code.

This article uses the Target Language Compiler (TLC) from The MathWorks to implement such a code converter. It provides a mechanism to generate platform-specific code, accepting parts from ANSI C code (such as includes, definitions, function codes, etc.), and also adding custom code for the target platform. When using Stateflow, there is no need to consider the actual implementation of common functions in TinyOS or MANTIS, because these functions are already implemented in the TLC library and can be used for any operating system. By using TLC scripts to automatically generate TinyOS or MANTIS applications, these applications can be compiled and executed for the target platform without modification. In addition, TLC can rewrite and modify source code, split the source code and make it suitable for the underlying platform. This not only achieves better optimization than the compiler, but also makes it easy to migrate applications between hardware and software platforms.

Reference address:A framework for modeling, simulation, and automatic code generation for sensor network applications

Previous article:LabVIEW Helps Optimize Software Development Practices and Source Code Control
Next article:Intelligent and networked design of traffic signal control

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号