Coding style defined more precisely. Issue #117.

This commit is contained in:
Janez 2020-01-14 15:35:53 +01:00
parent ce2ac80a97
commit 57f264c2c4
3 changed files with 74 additions and 39 deletions

15
.clang-format Normal file
View File

@ -0,0 +1,15 @@
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: LLVM
# indent 4 spaces
IndentWidth: 4
# break before function
BreakBeforeBraces: Linux
# arguments and parameters in same line or one line for each
BinPackArguments: false
BinPackParameters: false
# keep up to two empty lines
MaxEmptyLinesToKeep: 2

View File

@ -48,24 +48,26 @@ in a project with specific hardware and specific application.
Documentation, support and contributions Documentation, support and contributions
------------------------- ----------------------------------------
Code is documented in header files. Running Code is documented in header files. Running [doxygen](http://www.doxygen.nl/)
[doxygen](http://www.stack.nl/~dimitri/doxygen/index.html) in project or `make doc` in project base folder will produce complete html documentation.
base folder will produce complete html documentation. Just open Just open CANopenNode/doc/html/index.html in browser.
CANopenNode/doc/html/index.html in browser.
Report issues on https://github.com/CANopenNode/CANopenNode/issues Report issues on https://github.com/CANopenNode/CANopenNode/issues
Older and still active discussion group is on Sourceforge Older and still active discussion group is on Sourceforge
http://sourceforge.net/p/canopennode/discussion/387151/ http://sourceforge.net/p/canopennode/discussion/387151/
For some implementations of CANopenNode on real hardware see table below. For some implementations of CANopenNode on real hardware see
[Device support](#device-support) section.
[CANopenSocket](https://github.com/CANopenNode/CANopenSocket) is nice [CANopenSocket](https://github.com/CANopenNode/CANopenSocket) is nice
implementation for Linux devices. It includes command line interface for implementation for Linux devices. It includes command line interface for
master access of the CANopen network. There is also some Getting started. master access of the CANopen network. There is also some Getting started.
Contributions are welcome. Best way to contribute your code is to fork Contributions are welcome. Best way to contribute your code is to fork
a project, modify it and then send a pull request. a project, modify it and then send a pull request. Some basic formatting
rules should be followed: Linux style with indentation of 4 spaces. There
is also a configuration file for `clang-format` tool.
Flowchart of a typical CANopenNode implementation Flowchart of a typical CANopenNode implementation

View File

@ -3,16 +3,28 @@
* *
* @file codingStyle * @file codingStyle
* @ingroup codingStyle * @ingroup codingStyle
* @author Janez Paternoster * @author name
* @copyright 2015 Janez Paternoster * @copyright 2020 name
* *
* License. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
#ifndef XYZ_H #ifndef XYZ_H
#define XYZ_H #define XYZ_H
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @defgroup codingStyle Description of coding style * @defgroup codingStyle Description of coding style
@ -22,20 +34,23 @@
* Contents of this file should be the base for .h source file, except function * Contents of this file should be the base for .h source file, except function
* body at the end. * body at the end.
* *
* ###Indentation * ###Style
* Indent size is 4. * - Style is based on Linux style
* Spaces are used, not tabs. * - Indent size is 4.
* - Spaces are used, not tabs.
* - More datails are defined in .clang-format file
* - Some (old) code is still not corectly formatted. (To not break git history.)
* *
* ###Doxygen * ###Doxygen
* Documentation is generated by <http://doxygen.org>. * Documentation is generated by doxygen.
* Doxygen comment starts with /**. /**< is used after member. * Doxygen comment starts with /**. /**< is used after member.
* Documentation is usually in header. * Documentation is usually in header.
* Doxygen settings: * Doxygen settings:
* - JAVADOC_AUTOBRIEF = YES. * - JAVADOC_AUTOBRIEF = YES.
* - See doxyfile for other settings. * - See doxyfile for other settings.
* *
* Doxygen specifics: If description of the structure member is one sentence only, * Doxygen specifics: If description of the structure member is one sentence
* don't use period after the sentence. * only, don't use period after the sentence.
* *
* ###Misra C * ###Misra C
* Code shall follow MISRA-C:2012 standard. * Code shall follow MISRA-C:2012 standard.
@ -47,10 +62,10 @@
* here. * here.
*/ */
typedef struct { typedef struct {
int8_t member1; /**< Short description of the member 1 */ int8_t member1; /**< Short description of the member 1 */
uint16_t member2; /**< Note the '/**<' sequence after the member 2 */ uint16_t member2; /**< Note the '/**<' sequence after the member 2 */
/** Long description of the variable stringMember. More description. */ /** Long description of the variable stringMember. More description. */
char_t stringMember[5]; char_t stringMember[5];
} object1_t; } object1_t;
@ -62,17 +77,16 @@ typedef struct {
* *
* @param obj Pointer to object. Function operates on this object (not on global * @param obj Pointer to object. Function operates on this object (not on global
* variables). * variables).
* @param arg2 Description of the argument. * @param argument_2 Description of the argument.
* @param arg3 Description of the argument. * @param argument_2 Description of the argument.
* @param arg4 Description of the argument. * @param argument_4 Description of the argument.
* *
* @return Some value. * @return Some value.
*/ */
int32_t foo1( int32_t foo1(object1_t *obj,
object1_t *obj, int32_t argument_2,
int32_t arg2, uint16_t argument_3,
uint16_t arg3, float32_t argument_4)
float32_t arg4)
{ {
/* Comment */ /* Comment */
@ -80,19 +94,23 @@ int32_t foo1(
* comment. * comment.
*/ */
if(xy == yz) { /* Comment. '//' comments are not allowed */ if (xy == yz) { /* Comment. '//' comments are not allowed */
... a = b;
} } else {
else { a = c;
...
} }
switch(zx) { switch (zx) {
case 1: { case 1:
... a = b;
} break;
} }
} }
/** @} */ /** @} */
#endif
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* XYZ_H */