2nd-tinyos programming ideology (my understanding of tinyos1.x and my painstaking efforts)

Source: Internet
Author: User

Unless otherwise stated, all programs are tinyos-1.3-based and run with cygwin debugging in VM simulation Windows XP 32-bit.

 

Thoughts:

Tinyos uses a special component-oriented programming idea. I am not used to this idea or the object-oriented programming idea. Why is tinyos and NESC hard to learn? Because he does not have a normal textbook. Unlike C, C ++, and Java, he has specialized books or materials that tell you what functions to implement and what classes to use (components here ), what interface to use and what function to use. Tinyos does not have these things at all, so you can explore and practice things on your own.

 

So you have too many habits:

1. The basic component of the NESC program is component, and each component is a *. NC file. Unlike Java, we all know that classes in Java have inheritance relationships, subclasses, and so on. You only need to know some simple classes to expand and learn by yourself. Even if you have never seen any classes, you can find detailed introductions and usage methods. NESC does not have the concept of a class. Naturally, there is no subclass superclass and no inheritance. That is to say, if you know that such a component exists, you can use this component to do some work. But if you don't know this component, especially some underlying component, then hey, hey ~~!! Either you force yourself to understand the components provided by the system, or write one by yourself. But now you can't even understand the simplest blink program, let alone write it yourself. So every beginner who uses NESC is similar to the blind man. To put it bluntly, you can't do anything. Your C and Java experience are useless. Of course, you will also have the for Statement, which is the only place where you are better at tinyos than grocery shopping.

 

2.
You are not used to using component in the NESC program.

The NESC program uses a so-called wiring mechanism to specify the relationship between component and component.

 

3.
You are not used to the hierarchy of components in the NESC program, that is, the relationship between interfaces, methods, attributes, and functions.

One component calls other component by using "interface". The user uses the interface with the keyword "uses" to connect to the interface of the provider "provides. Then, the user can use methods from the "interface" of the provider in their own implementations. It must be emphasized here:

A.
If a component uses an interface, it must implement the event in the interface.

B.
If a component provide an interface, all the commands in the interface must be implemented.

 

Interface I personally think of it as a set of methods or functions that can be recognized by the system, or system APIs. Generally, the content of the interface is several declarations of command and/or event. For the interface file, the content of command and event is empty, which is similar to that of Java.

 

Command and event are the specific implementations of logic code. Their specific content is implemented by provide's component. The content we are familiar with appears here. If and for can both appear here. In my understanding, command and event are functions in C language or methods in Java. This is because the command contains symbolic parentheses, such as Init (). Note: When called, the command uses "call" and the event uses "signal ".

Tinyos provides some system interfaces for basic program functions. This is amazing because knowing an interface can directly complete your work, but as a learner, we are very tired. You must be familiar with and understand the functions and usage of these interfaces. For example, the stdcontrol interface is used to control the program flow. It has three commands: Init (), start (), and stop (). For example, the LEDs interface is used to control the lights on the sensor. There are many commands, such as redon () and redoff (), which means to control the light and darkness of the red light.

There is a hierarchical relationship among component, interface, command/event.

In general, component is the highest level. It can be understood that interface is the lower layer of component, and command/event is the lower layer of interface. Component. interface. Command ()

 

4.
You are not used to the classification and definition of components in the NESC program.

The common component is divided into two categories: "configuration" and "module"

"Configuration" is used to complete the connection between component. This is unique to tinyos. At least in the language I have learned, it is unique. I don't think this mechanism is good or not good, but since I have learned this language, I will study it well.

 

This mechanism can be said to be the core of tinyos, so it must be clear and clear! It involves all the NESC programs, so it can be considered that this is the key to understanding NESC.

 

There are two keywords to implement wiring. I have translated it into "connection. The keyword "à" and "signature" are always connected to an interface that uses (uses) and provided (provides. That is to say, only the user component can call the interface of the provider component. This is not the case.

 

In tinyos, components and interfaces are a many-to-many relationship, that is, a component can be connected to many interfaces. In other words, many components can provide the same interface! (Core! What's hard to understand !)

 

As mentioned above, different components can provide the same interface. If the coma and comb components provide an interfacec interface, what should I do when the comd component needs to access the interfacec interface? Does it access interfacec provided by coma or interfacec provided by comb? You must know that although the interface name is the same, the same interface provided by different components implements different functions.

 

The configuration file is generated. The purpose of the configuration file is to declare the name of the component you want to access and connect the interface it provides with the interface you really want to use.

 

"Module" is the real implementation of a component. It is used to complete the component function. Its name is usually xxxxxm, which can correspond to the configuration file. The module should declare its own use and provide excuses, so the "module" is the real place to implement command and event. Of course, there are also special internal functions and tasks implemented here. When the task is called, the task uses post, the command uses "call", and the event uses "signal ".

 

5.
You are not used to the transfer mechanism of the NESC program.

 

In general, the scheduling mechanism in tinyos is relatively simple. The scheduling of tinyos follows the ipvs (service first) rule. When no event occurs, the task list is processed by fifs. when the event occurs, the task is preemptible and interrupted. It only sets one task queue. Keyword Post adds a task to the task queue. Different tasks have no priority, but tasks can be interrupt.
Handler interrupt. To prevent abnormal modification of public data such as global variables, NESC stipulates that only the public data portion is entered in the task. The "async" keyword can be used to indicate that a command or event can be used when an interruption occurs. To coordinate tasks and interrupt execution, NESC uses the keyword "Atomic" to indicate that the Code cannot be interrupted.

 

 

I don't know if the authors of tinyos and NESC grew up eating stool. They didn't write a clear document to explain the obscure NESC language. Maybe the author of tinyos tutorial is very poor in English (PS: this is what my American tutor said ). Here, please read this blog. If you are a supporter of an American textbook or tinyos official document, you should not read this article, this article is intended for those who do not understand the official documentation. You can understand the official documents or the Ways Americans think to introduce new knowledge and new technologies. This shows that your English and computer science skills are higher than mine, therefore, you do not need to read the blog post that explains and guides the NESC program that I understand. Although I am in the United States, I do not think that American textbooks are well written. On the contrary, based on my many years of teaching experience and my own learning experience, I personally agree with and support the writing of many Chinese C or Java textbooks. I have a clear sense of understanding, the introduction is easy to learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.