I need to write a command protocol divided in 3 layers

Hello

I need to write a command protocol divided in 3 layers. A data link layer, a network layer and an upper layer.

I'm programming this in C.

I would like some internet links that shows some examples of how to signal between the different layers.

I'm planning to have different state machines in the different layers. The state machines are called by an interrupt timer every 1ms.

They are going to send signals (reguests, indications and confirmation).

What is the best way to write the signaling?

Reply to
billy
Loading thread data ...

In message , billy writes

Is it September already ?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Reply to
Chris H

It's always September somewhere...

--
Grant Edwards                   grante             Yow! Uh-oh!!  I'm having
                                  at               TOO MUCH FUN!!
                               visi.com
Reply to
Grant Edwards

No, silly man. Did you think so? :-P

Reply to
billy

I though it was always mid-day somewhere.....

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Reply to
Chris H

That too.

--
Grant Edwards                   grante             Yow! Are we wet yet?
                                  at               
                               visi.com
Reply to
Grant Edwards

Callbacks using function pointers and object handles.

Reply to
Edwin van den Oetelaar

Thank you.

I found something about protothreads that can be used to simplify the state machines.

formatting link

This is maby something I can use. :-)

Reply to
billy

He seems to be correct in his speculation.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

Is this a homework? As the article wrote, this is weird code, don't use it. The simplest solution for a statemachine would be to use an enum with meaningful names and just a big switch-case.

I assume Edwin means something like the state pattern, as you can implement it easily in object oriented languages like C++, Java or Lisp:

formatting link

In C you'll need function pointers and object handles.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

That's a good question. Using something like protothreads for homework is probably not going to go over well with the instructor. OTOH, using it for real code may be an excellent idea.

Why not? I've used protothreads in products, and it works very nicely. You end up with code that's a lot more readable and more easily maintained than complex, explicit state machines.

Big, nested switch/case statements are difficult to design, troubleshoot and maintain. Writing code in a "loop/thread" style makes it a lot easier to read.

--
Grant
Reply to
Grant Edwards

No

Reply to
billy

It produces illegible code. Actually, it's worse than that, as it's likely to trick you into thinking that you know what the code is doing.

C macros are an abomination at the best of times, but macros which expand to partial control structures are much, much worse.

Most things are more readable than an explicit state machine. But the protothreads code has to be one of the few cases which aren't; what the code appears to be doing and what it's actually doing are very different things. At least with an explicit state machine you'll probably know that you don't understand it, rather than deceiving yourself into thinking that you do.

Reply to
Nobody

It seemed pretty obvious to me what the code was doing. But I did read the documentation...

I guess I just don't see the problem with that that set of macros.

You can say that about any high level language. Or even about assembly language with macros.

I guess it's a matter of taste. I never had any problems understanding code written with using protothreads. OTOH, I've spent a lot of hours trying to figure out the "path" that's being taken through explicitly coded state machines.

--
Grant
Reply to
Grant Edwards

I don't know what you have already done, but I recommend that you ensure that you have a good set of (initial) requirements and do an analysis to determine a good solution structure before making low-level implementation choices.

Is the command protocol function specified, including initialization, timing, and error recovery? Why implement in three layers, rather than one or five?

Can you adapt an existing protocol stack?

--
Thad
Reply to
Thad Smith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.