crayzeewulf / libserial

Serial Port Programming in C++
BSD 3-Clause "New" or "Revised" License
415 stars 142 forks source link

Don't use high baudrates when not available #55

Closed tpetazzoni closed 8 years ago

tpetazzoni commented 8 years ago

On certain architectures (namely Sparc), the maximum baud rate exposed by the kernel headers is B2000000. Therefore, the current libserial code doesn't build for the Sparc and Sparc64 architectures due to this.

In order to address this problem, this patch tests the value of __MAX_BAUD. If it's higher than B2000000 then we assume we're on an architecture that supports all baud rates up to B4000000. Otherwise, we simply don't support the baud rates above B2000000.

Fixes build failures such as:

./SerialPort.h:88:24: error: 'B2500000' was not declared in this scope BAUD_2500000 = B2500000,

Signed-off-by: Thomas Petazzoni thomas.petazzoni@free-electrons.com

crayzeewulf commented 8 years ago

Thanks for the improvements. (I've accepted the other pull request from today).

Regarding this one, what happens when __MAX_BAUD is not defined on a platform? I think this patch will result in a compilation error in that case.

tpetazzoni commented 8 years ago

Hum, you're right. So maybe we should #ifdef B.... each case instead. Should I respin a different patch?

crayzeewulf commented 8 years ago

I stand corrected. If __MAX_BAUD is not defined, the preprocessor will replace it with 0 and the check will still compile. Accepting the pull request. See this for details. Here is the relevant quote:

...any identifier which is not a boolean literal, nor currently defined as a macro name, are replaced with the number 0.