Skip to content

Commit 57f264c

Browse files
committed
Coding style defined more precisely. Issue CANopenNode#117.
1 parent ce2ac80 commit 57f264c

File tree

3 files changed

+74
-39
lines changed

3 files changed

+74
-39
lines changed

Diff for: .clang-format

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
BasedOnStyle: LLVM
3+
4+
# indent 4 spaces
5+
IndentWidth: 4
6+
7+
# break before function
8+
BreakBeforeBraces: Linux
9+
10+
# arguments and parameters in same line or one line for each
11+
BinPackArguments: false
12+
BinPackParameters: false
13+
14+
# keep up to two empty lines
15+
MaxEmptyLinesToKeep: 2

Diff for: README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,26 @@ in a project with specific hardware and specific application.
4848

4949

5050
Documentation, support and contributions
51-
-------------------------
52-
Code is documented in header files. Running
53-
[doxygen](http://www.stack.nl/~dimitri/doxygen/index.html) in project
54-
base folder will produce complete html documentation. Just open
55-
CANopenNode/doc/html/index.html in browser.
51+
----------------------------------------
52+
Code is documented in header files. Running [doxygen](http://www.doxygen.nl/)
53+
or `make doc` in project base folder will produce complete html documentation.
54+
Just open CANopenNode/doc/html/index.html in browser.
5655

5756
Report issues on https://github.com/CANopenNode/CANopenNode/issues
5857

5958
Older and still active discussion group is on Sourceforge
6059
http://sourceforge.net/p/canopennode/discussion/387151/
6160

62-
For some implementations of CANopenNode on real hardware see table below.
61+
For some implementations of CANopenNode on real hardware see
62+
[Device support](#device-support) section.
6363
[CANopenSocket](https://github.com/CANopenNode/CANopenSocket) is nice
6464
implementation for Linux devices. It includes command line interface for
6565
master access of the CANopen network. There is also some Getting started.
6666

6767
Contributions are welcome. Best way to contribute your code is to fork
68-
a project, modify it and then send a pull request.
68+
a project, modify it and then send a pull request. Some basic formatting
69+
rules should be followed: Linux style with indentation of 4 spaces. There
70+
is also a configuration file for `clang-format` tool.
6971

7072

7173
Flowchart of a typical CANopenNode implementation

Diff for: codingStyle

+50-32
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
*
44
* @file codingStyle
55
* @ingroup codingStyle
6-
* @author Janez Paternoster
7-
* @copyright 2015 Janez Paternoster
8-
*
9-
* License.
6+
* @author name
7+
* @copyright 2020 name
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
1020
*/
1121

12-
1322
#ifndef XYZ_H
1423
#define XYZ_H
1524

25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
1628

1729
/**
1830
* @defgroup codingStyle Description of coding style
@@ -22,20 +34,23 @@
2234
* Contents of this file should be the base for .h source file, except function
2335
* body at the end.
2436
*
25-
* ###Indentation
26-
* Indent size is 4.
27-
* Spaces are used, not tabs.
37+
* ###Style
38+
* - Style is based on Linux style
39+
* - Indent size is 4.
40+
* - Spaces are used, not tabs.
41+
* - More datails are defined in .clang-format file
42+
* - Some (old) code is still not corectly formatted. (To not break git history.)
2843
*
2944
* ###Doxygen
30-
* Documentation is generated by <http://doxygen.org>.
45+
* Documentation is generated by doxygen.
3146
* Doxygen comment starts with /**. /**< is used after member.
3247
* Documentation is usually in header.
3348
* Doxygen settings:
3449
* - JAVADOC_AUTOBRIEF = YES.
3550
* - See doxyfile for other settings.
3651
*
37-
* Doxygen specifics: If description of the structure member is one sentence only,
38-
* don't use period after the sentence.
52+
* Doxygen specifics: If description of the structure member is one sentence
53+
* only, don't use period after the sentence.
3954
*
4055
* ###Misra C
4156
* Code shall follow MISRA-C:2012 standard.
@@ -47,10 +62,10 @@
4762
* here.
4863
*/
4964
typedef struct {
50-
int8_t member1; /**< Short description of the member 1 */
51-
uint16_t member2; /**< Note the '/**<' sequence after the member 2 */
65+
int8_t member1; /**< Short description of the member 1 */
66+
uint16_t member2; /**< Note the '/**<' sequence after the member 2 */
5267
/** Long description of the variable stringMember. More description. */
53-
char_t stringMember[5];
68+
char_t stringMember[5];
5469
} object1_t;
5570

5671

@@ -62,37 +77,40 @@ typedef struct {
6277
*
6378
* @param obj Pointer to object. Function operates on this object (not on global
6479
* variables).
65-
* @param arg2 Description of the argument.
66-
* @param arg3 Description of the argument.
67-
* @param arg4 Description of the argument.
80+
* @param argument_2 Description of the argument.
81+
* @param argument_2 Description of the argument.
82+
* @param argument_4 Description of the argument.
6883
*
6984
* @return Some value.
7085
*/
71-
int32_t foo1(
72-
object1_t *obj,
73-
int32_t arg2,
74-
uint16_t arg3,
75-
float32_t arg4)
86+
int32_t foo1(object1_t *obj,
87+
int32_t argument_2,
88+
uint16_t argument_3,
89+
float32_t argument_4)
7690
{
7791
/* Comment */
7892

7993
/* Multiline
8094
* comment.
8195
*/
8296

83-
if(xy == yz) { /* Comment. '//' comments are not allowed */
84-
...
85-
}
86-
else {
87-
...
97+
if (xy == yz) { /* Comment. '//' comments are not allowed */
98+
a = b;
99+
} else {
100+
a = c;
88101
}
89102

90-
switch(zx) {
91-
case 1: {
92-
...
93-
}
103+
switch (zx) {
104+
case 1:
105+
a = b;
106+
break;
94107
}
95108
}
96109

97110
/** @} */
98-
#endif
111+
112+
#ifdef __cplusplus
113+
}
114+
#endif /*__cplusplus */
115+
116+
#endif /* XYZ_H */

0 commit comments

Comments
 (0)