Home Database Mysql Tutorial 第2篇 入门

第2篇 入门

Jun 07, 2016 pm 03:26 PM
getting Started based on program illustrate

除非特别说明,所有的程序都是基于 tinyos-1.3 的,并在 VM 模拟 Win xp 32 位下用 cygwin 调试运行。 思想: Tinyos 使用的是一种特殊的,面向组件的编程思想,这种思想和用惯了面向对象的编程思想的我来说,非常不习惯。 Tinyos 和 nesC 为什么难学? 因为

除非特别说明,所有的程序都是基于tinyos-1.3的,并在VM 模拟Win xp 32位下用cygwin调试运行。

 

思想:

Tinyos使用的是一种特殊的,面向组件的编程思想,这种思想和用惯了面向对象的编程思想的我来说,非常不习惯。TinyosnesC为什么难学?因为他没有正常的教科书,不像C C++Java 一样有专门的书或者资料,告诉你需要实现什么功能,要去用到什么类(这里是组件),要去用什么接口,要去用什么函数。 Tinyos完全没有这些东西,什么都是让你自己去摸索和实践。

 

所以你有太多的不习惯:

1.       你不习惯NesC程序的基本组成是Component,每个Component是一个*.nc文件。这里不像Java,大家都知道java当中的类是有继承关系,有子类超类等等。你只需要知道一些简单的类,就可以自己扩展学习,即使有没见过的类,也可以找到很详细的介绍和使用方法。NesC中没有类的概念,自然也就没有子类超类,没有继承,也就是说,如果你知道有这么一个Component,你就可以用这个Component 可以完成一定的工作。但是如果你不知道这个Component呢,尤其是某些底层的Component 那么嘿嘿~~!!  要么你像我一样,去逼自己看懂系统提供那些的Component,要么自己写一个。可问题你现在连最简单的blink程序都看不懂,更何况自己写了。所以每个用NesC的初学者都和瞎子差不多,说白了,你就是什么都不会的。你的C还有java经验都根本没用。当然,你会if 还有for语句,这是你在学习tinyos中唯一比买菜大妈强的地方。

 

2.       你不习惯NesC程序的中Component的使用方法。

NesC程序中采用了一种所谓的wiring的机制来指明componentcomponent之间的关系。

 

3.       你不习惯NesC程序的中组件的层次结构,也就是接口,方法,属性,函数的关系。

一个Component调用其他的Component的方式是使用 “interface”,使用方用关键字“uses”interface连接到提供方 “provides”interface。那么使用方就可以在自己的实现中去使用来自提供方“interface”当中的方法。在这里必须强调:

A.一个组件如果use某个interface,就必须实现这个interface当中的event

B.一个组件如果provide某个interface,就必须实现这个interface当中所有的command

 

Interface我个人把他看成是系统可以识别的方法或者说函数的集合,或者可以说系统的API,通常interface的内容是几个command / event的声明。单看interface文件而言,commandevent里面的内容是空着的,这点和java很像。

 

command event是逻辑代码具体实现的地方,他们的具体内容由provide他们的component来实现。我们所熟悉的内容在这里出现,iffor都可以在这里出现了。我的理解,commandevent就是我们熟悉的c语言当中的函数,或者java当中的方法。因为command出现了标志性的括号,比如init()。注意,在被调用的时候,Command“call”event“signal”

TinyOS提供了一些系统interface,用来完成基本的程序功能。这里很神奇,因为知道某个interface就可以直接完成你的工作,但是作为学习者的我们就非常的累,你必须去熟悉和了解这些interface对应的功能和用法。比如stdcontrol接口就是用来控制程序流程,有3command,分别是init(),start(),stop()。再比如Leds接口是用来控制传感器上的灯的,有很多command,比如redon(),redoff()就是控制红灯亮暗。

componentinterfacecommand/event当中是有层次关系的。

一般来说,component是最高级的,可以理解为Interface Component的下层,command/eventinterface的下层。Component. Interface. Command()

 

4.       你不习惯NesC程序的中组件的分类和定义。

常见的Component分为两类,“configuration”和“module

configuration”用来完成component间的连接。这个是tinyos特有的。至少在我学习过的语言中,是独一无二的。我不评价这种机制好或者是不好,但是既然学习了这门语言,也就好好学习这个机制。

 

这个机制可以说是tinyos的核心,所以必须明白,而且要非常清楚!它涉及到所有的nesC程序,所以可以认为这里是学明白nesC的关键。

 

有两个关键字来实现wiring,我翻译成“连接”好了。关键字à”和“ß”永远是将一个使用(uses)的接口于一个提供(provides)的接口相连接。也就是说只有使用者组件能够调用提供者组件的接口。反过来就不可以。

 

Tinyos中,组件和接口是一个多对多的关系,即一个组件可以连接到很多接口,反过来说,很多组件都可以提供一个相同的接口!(核心!最难理解的地方!)

 

前面说,不同的组件可以提供相同的接口,如果组件ComA,ComB都提供了某一个接口InterfaceC, 那么,当组件ComD需要去访问InterfaceC接口时,怎么办?它访问的到底是ComA提供的InterfaceC还是ComB提供InterfaceC的呢?要知道,虽然接口的名称是一样的,但是不同组件提供的相同接口却是实现不同的功能。

 

所以配置文件就产生了,它的目的就是声明你要访问的组件名称,并且将它所提供的接口与你真正想要使用的接口相连接。

 

“module”才是一个组件的真实实现,用来完成该Component的功能,名字常常是xxxxxM,可以和configuration文件对应起来。 Module要声明自己使用和提供的借口,所以“module”当中是实现commandevent的真正场所,当然还有特殊的内部函数和task都在这里实现。在被调用的时候,taskpostcommand“call”event“signal”

 

5.       你不习惯NesC程序的调动机制。

 

一般来说,TinyOS中的调度机制比较简单,TinyOS的调度遵循FIFS(先来先服务)规则。没有事件发生时任务列表按着FIFS进行处理,当事件发生时发生抢占,产生中断处理。它仅设置一个任务队列。关键字post将一个任务添加到任务队列中。不同的Task之间没有优先级,但task可以被interrupt handler打断。为防止全局变量等公用数据被非正常修改,nesC规定只在task中进入公共的数据部分。使用 “async”关键字可以指出某个command或者event可以在有中断时使用。为了协调任务和中断的执行,nesC使用关键字“atomic”去指出代码不可被打断。

 

 

我不知道tinyos NesC的作者是不是吃大便长大的,本来就很晦涩难懂的nesC语言也不写个清晰的文档来解释清楚。也许可能是Tinyos tutorial 的作者英文很差(PS:这个是我美国导师说的)。在这里,请本blog的看官请注意,如果你是美式教材或者tinyos官方文档的支持者,你根本就不应该来看这篇文章,因为这篇文章就写给看不懂官方文档的同学看的。你看得懂官方文档或者说喜欢美国人的思维方式来介绍新知识新技术的方法,说明你英语和计算机科学水平比我高,所以也不用看加上我自身理解的NesC程序解释和指导的博文。虽然我在美国,但是我一点也不觉得美国的教材写的好。相反,根据我多年的教学经验和我自身的学习经验,我个人是非常认同和支持国内的很多c或者java教材的写法,层次感很清楚,介绍的内容由浅入深,知识慢慢学来。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to make Google Maps the default map in iPhone How to make Google Maps the default map in iPhone Apr 17, 2024 pm 07:34 PM

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

A Diffusion Model Tutorial Worth Your Time, from Purdue University A Diffusion Model Tutorial Worth Your Time, from Purdue University Apr 07, 2024 am 09:01 AM

Diffusion can not only imitate better, but also "create". The diffusion model (DiffusionModel) is an image generation model. Compared with the well-known algorithms such as GAN and VAE in the field of AI, the diffusion model takes a different approach. Its main idea is a process of first adding noise to the image and then gradually denoising it. How to denoise and restore the original image is the core part of the algorithm. The final algorithm is able to generate an image from a random noisy image. In recent years, the phenomenal growth of generative AI has enabled many exciting applications in text-to-image generation, video generation, and more. The basic principle behind these generative tools is the concept of diffusion, a special sampling mechanism that overcomes the limitations of previous methods.

Generate PPT with one click! Kimi: Let the 'PPT migrant workers' become popular first Generate PPT with one click! Kimi: Let the 'PPT migrant workers' become popular first Aug 01, 2024 pm 03:28 PM

Kimi: In just one sentence, in just ten seconds, a PPT will be ready. PPT is so annoying! To hold a meeting, you need to have a PPT; to write a weekly report, you need to have a PPT; to make an investment, you need to show a PPT; even when you accuse someone of cheating, you have to send a PPT. College is more like studying a PPT major. You watch PPT in class and do PPT after class. Perhaps, when Dennis Austin invented PPT 37 years ago, he did not expect that one day PPT would become so widespread. Talking about our hard experience of making PPT brings tears to our eyes. "It took three months to make a PPT of more than 20 pages, and I revised it dozens of times. I felt like vomiting when I saw the PPT." "At my peak, I did five PPTs a day, and even my breathing was PPT." If you have an impromptu meeting, you should do it

Clock app missing in iPhone: How to fix it Clock app missing in iPhone: How to fix it May 03, 2024 pm 09:19 PM

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

All CVPR 2024 awards announced! Nearly 10,000 people attended the conference offline, and a Chinese researcher from Google won the best paper award All CVPR 2024 awards announced! Nearly 10,000 people attended the conference offline, and a Chinese researcher from Google won the best paper award Jun 20, 2024 pm 05:43 PM

In the early morning of June 20th, Beijing time, CVPR2024, the top international computer vision conference held in Seattle, officially announced the best paper and other awards. This year, a total of 10 papers won awards, including 2 best papers and 2 best student papers. In addition, there were 2 best paper nominations and 4 best student paper nominations. The top conference in the field of computer vision (CV) is CVPR, which attracts a large number of research institutions and universities every year. According to statistics, a total of 11,532 papers were submitted this year, and 2,719 were accepted, with an acceptance rate of 23.6%. According to Georgia Institute of Technology’s statistical analysis of CVPR2024 data, from the perspective of research topics, the largest number of papers is image and video synthesis and generation (Imageandvideosyn

Can't allow access to camera and microphone in iPhone Can't allow access to camera and microphone in iPhone Apr 23, 2024 am 11:13 AM

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

From bare metal to a large model with 70 billion parameters, here is a tutorial and ready-to-use scripts From bare metal to a large model with 70 billion parameters, here is a tutorial and ready-to-use scripts Jul 24, 2024 pm 08:13 PM

We know that LLM is trained on large-scale computer clusters using massive data. This site has introduced many methods and technologies used to assist and improve the LLM training process. Today, what we want to share is an article that goes deep into the underlying technology and introduces how to turn a bunch of "bare metals" without even an operating system into a computer cluster for training LLM. This article comes from Imbue, an AI startup that strives to achieve general intelligence by understanding how machines think. Of course, turning a bunch of "bare metal" without an operating system into a computer cluster for training LLM is not an easy process, full of exploration and trial and error, but Imbue finally successfully trained an LLM with 70 billion parameters. and in the process accumulate

AI in use | AI created a life vlog of a girl living alone, which received tens of thousands of likes in 3 days AI in use | AI created a life vlog of a girl living alone, which received tens of thousands of likes in 3 days Aug 07, 2024 pm 10:53 PM

Editor of the Machine Power Report: Yang Wen The wave of artificial intelligence represented by large models and AIGC has been quietly changing the way we live and work, but most people still don’t know how to use it. Therefore, we have launched the "AI in Use" column to introduce in detail how to use AI through intuitive, interesting and concise artificial intelligence use cases and stimulate everyone's thinking. We also welcome readers to submit innovative, hands-on use cases. Video link: https://mp.weixin.qq.com/s/2hX_i7li3RqdE4u016yGhQ Recently, the life vlog of a girl living alone became popular on Xiaohongshu. An illustration-style animation, coupled with a few healing words, can be easily picked up in just a few days.

See all articles