Low level LwMesh Questions

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Warning: I am reading through each line of the LwMesh source code, to get a good understanding of what it is doing. I am going to have a number of questions (that may expose my ignorance more of the C programming language than anything else...). Please be patient with what may seem like dumb questions.

The first two:

1. In nwkPrivate.h, in the definition of the NwkIb_t struct, the final variable is:

bool		(*endpoint[NWK_MAX_ENDPOINTS_AMOUNT])(NWK_DataInd_t *ind);

What is this doing? I tried tracing through the WinAVR rabbit hole (starting from stdbool.h), but got lost several layers down. It's been a long time since I have programmed in C++, but I would think that avrgcc uses uint8_t vars for bools (rather than some one bit variable). Is this right? If so, it looks like this definition is casting a pointer to a struct as an address (dereferenced pointer to the beginning of an array)? I know this is not correct. Could someone explain it better?

Edit: a similar line appears in sysTimer.h (last var in the struct):

typedef struct SYS_TIMER_t {
	//Internal Data
	struct SYS_Timer_t	*next
	uint32_t			timeout;

	//Timer Parameters
	uint32_t			interval;
	SYS_TimerMode_t		mode;
	void				(*handler)(struct SYS_Timer_t *timer);
} SYS_TIMER_t;

2. In nwk.h, in the definition of the NWK_DATAReq_t struct, there is the following line:

void (*confirm)(struct NWK_DataReq_t *req);

What does this mean? It is casting a struct declaration as (*confirm)? I get a warning about this line when I compile: 'struct NWK_DataReq_t' is declared inside paramter list. Its scope is only this definition or declaration, which is probably not what you want" Again, any explanation would be appreciated.

I am sure there will be more as I read through the code....

Science is not consensus. Science is numbers.

Last Edited: Fri. Oct 16, 2015 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
bool      (*endpoint[NWK_MAX_ENDPOINTS_AMOUNT])(NWK_DataInd_t *ind);

Defines an array of function pointers. Number of elements in array is NWK_MAX_ENDPOINTS_AMOUNT. Each function ponited to take a NWK_DataInd_t * as the only parameter, and returns a bool. Name of array is "endpoint".

That piece of code would have been clearer if it was cut into several pieces, first a typedef of the function pointer type and then the definition of the array of such function pointers. sketchy, not tested:

typedef bool (*endpoint_t)(NWK_DataInd_t *ind);

endpoint_t endpoints[NWK_MAX_ENDPOINTS_AMOUNT];

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan,

Thanks for your answer. I have always struggled with function pointers, but I think I get at least this particular example now...

Science is not consensus. Science is numbers.