Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7b6a39

Browse files
authored
Merge branch 'arduino:master' into Feat/more-string-functions
2 parentsb7564a0 +0ecb1aa commitc7b6a39

18 files changed

+487
-24
lines changed

‎.github/workflows/unit-tests.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ jobs:
3838
coverage-data-path:${{ env.COVERAGE_DATA_PATH }}
3939

4040
# See: https://github.com/codecov/codecov-action/blob/master/README.md
41-
-name:Upload coverage report to Codecov
42-
uses:codecov/codecov-action@v1
41+
-name:Code coverage
42+
uses:codecov/codecov-action@v3
4343
with:
44-
file:${{ env.COVERAGE_DATA_PATH }}
44+
token:${{ secrets.CODECOV_TOKEN }}
45+
files:${{ env.COVERAGE_DATA_PATH }}
4546
fail_ci_if_error:true

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
.idea/

‎api/ArduinoAPI.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#ifndefARDUINO_API_H
2121
#defineARDUINO_API_H
2222

23-
// version 1.4.1
24-
#defineARDUINO_API_VERSION10401
23+
// version 1.4.2
24+
#defineARDUINO_API_VERSION10402
2525

2626
#include"Binary.h"
2727

‎api/CanMsg.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is free software; you can redistribute it and/or modify
3+
* it under the terms of either the GNU General Public License version 2
4+
* or the GNU Lesser General Public License version 2.1, both as
5+
* published by the Free Software Foundation.
6+
*/
7+
8+
/**************************************************************************************
9+
* INCLUDE
10+
**************************************************************************************/
11+
12+
#include"CanMsg.h"
13+
14+
/**************************************************************************************
15+
* NAMESPACE
16+
**************************************************************************************/
17+
18+
namespacearduino
19+
{
20+
21+
/**************************************************************************************
22+
* STATIC CONST DEFINITION
23+
**************************************************************************************/
24+
25+
uint8_tconst CanMsg::MAX_DATA_LENGTH;
26+
uint32_tconst CanMsg::CAN_EFF_FLAG;
27+
uint32_tconst CanMsg::CAN_SFF_MASK;
28+
uint32_tconst CanMsg::CAN_EFF_MASK;
29+
30+
/**************************************************************************************
31+
* NAMESPACE
32+
**************************************************************************************/
33+
34+
}/* arduino*/

‎api/CanMsg.h‎

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
* INCLUDE
1313
**************************************************************************************/
1414

15-
#include<stdint.h>
15+
#include<inttypes.h>
1616
#include<string.h>
1717

18-
#include<Arduino.h>
18+
#include"Print.h"
19+
#include"Printable.h"
20+
#include"Common.h"
1921

2022
/**************************************************************************************
2123
* NAMESPACE
@@ -31,14 +33,19 @@ namespace arduino
3133
classCanMsg :publicPrintable
3234
{
3335
public:
34-
staticsize_tconstexpr MAX_DATA_LENGTH =8;
36+
staticuint8_tconstexpr MAX_DATA_LENGTH =8;
37+
38+
staticuint32_tconstexpr CAN_EFF_FLAG =0x80000000U;
39+
staticuint32_tconstexpr CAN_SFF_MASK =0x000007FFU;/* standard frame format (SFF)*/
40+
staticuint32_tconstexpr CAN_EFF_MASK =0x1FFFFFFFU;/* extended frame format (EFF)*/
41+
3542

3643
CanMsg(uint32_tconst can_id,uint8_tconst can_data_len,uint8_tconst * can_data_ptr)
3744
: id{can_id}
38-
, data_length{can_data_len}
45+
, data_length{min(can_data_len, MAX_DATA_LENGTH)}
3946
, data{0}
4047
{
41-
memcpy(data, can_data_ptr,min(can_data_len, MAX_DATA_LENGTH));
48+
memcpy(data, can_data_ptr,data_length);
4249
}
4350

4451
CanMsg() : CanMsg(0,0,nullptr) { }
@@ -52,14 +59,15 @@ class CanMsg : public Printable
5259

5360
virtual~CanMsg() { }
5461

55-
voidoperator = (CanMsgconst & other)
62+
CanMsg &operator = (CanMsgconst & other)
5663
{
57-
if (this == &other)
58-
return;
59-
60-
this->id = other.id;
61-
this->data_length = other.data_length;
62-
memcpy(this->data, other.data,this->data_length);
64+
if (this != &other)
65+
{
66+
this->id = other.id;
67+
this->data_length = other.data_length;
68+
memcpy(this->data, other.data,this->data_length);
69+
}
70+
return (*this);
6371
}
6472

6573
virtualsize_tprintTo(Print & p)constoverride
@@ -68,7 +76,10 @@ class CanMsg : public Printable
6876
size_t len =0;
6977

7078
/* Print the header.*/
71-
len =snprintf(buf,sizeof(buf),"[%08X] (%d) :", id, data_length);
79+
if (isStandardId())
80+
len =snprintf(buf,sizeof(buf),"[%03" PRIX32"] (%d) :",getStandardId(), data_length);
81+
else
82+
len =snprintf(buf,sizeof(buf),"[%08" PRIX32"] (%d) :",getExtendedId(), data_length);
7283
size_t n = p.write(buf, len);
7384

7485
/* Print the data.*/
@@ -82,11 +93,45 @@ class CanMsg : public Printable
8293
return n;
8394
}
8495

96+
97+
uint32_tgetStandardId()const {
98+
return (id & CAN_SFF_MASK);
99+
}
100+
uint32_tgetExtendedId()const {
101+
return (id & CAN_EFF_MASK);
102+
}
103+
boolisStandardId()const {
104+
return ((id & CAN_EFF_FLAG) ==0);
105+
}
106+
boolisExtendedId()const {
107+
return ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG);
108+
}
109+
110+
111+
/*
112+
* CAN ID semantics (mirroring definition by linux/can.h):
113+
* |- Bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
114+
* |- Bit 30 : reserved (future remote transmission request flag)
115+
* |- Bit 29 : reserved (future error frame flag)
116+
* |- Bit 0-28 : CAN identifier (11/29 bit)
117+
*/
85118
uint32_t id;
86119
uint8_t data_length;
87120
uint8_t data[MAX_DATA_LENGTH];
88121
};
89122

123+
/**************************************************************************************
124+
* FREE FUNCTIONS
125+
**************************************************************************************/
126+
127+
inlineuint32_tCanStandardId(uint32_tconst id) {
128+
return (id & CanMsg::CAN_SFF_MASK);
129+
}
130+
131+
inlineuint32_tCanExtendedId(uint32_tconst id) {
132+
return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK));
133+
}
134+
90135
/**************************************************************************************
91136
* NAMESPACE
92137
**************************************************************************************/

‎api/Print.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
287287
uint8_t i =0;
288288
uint8_t innerLoops =0;
289289

290+
// Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178
291+
if (n64 ==0) {
292+
write('0');
293+
return1;
294+
}
295+
290296
// prevent crash if called with base == 1
291297
if (base <2) base =10;
292298

‎api/String.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ void String::replace(const String& find, const String& replace)
664664
}
665665
}elseif (diff <0) {
666666
unsignedint size = len;// compute size needed for result
667+
diff =0 - diff;
667668
while ((foundAt =strstr(readFrom, find.buffer)) !=NULL) {
668669
readFrom = foundAt + find.len;
669-
diff =0 - diff;
670670
size -= diff;
671671
}
672672
if (size == len)return;

‎test/CMakeLists.txt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
2525
##########################################################################
2626

2727
set(TEST_SRCS
28+
src/CanMsg/test_CanMsg.cpp
29+
src/CanMsg/test_CanMsg_CopyCtor.cpp
30+
src/CanMsg/test_CanExtendedId.cpp
31+
src/CanMsg/test_CanStandardId.cpp
32+
src/CanMsg/test_isExtendedId.cpp
33+
src/CanMsg/test_isStandardId.cpp
34+
src/CanMsg/test_operator_assignment.cpp
35+
src/CanMsg/test_printTo.cpp
2836
src/Common/test_makeWord.cpp
2937
src/Common/test_map.cpp
3038
src/Common/test_max.cpp
@@ -97,6 +105,7 @@ set(TEST_SRCS
97105
)
98106

99107
set(TEST_DUT_SRCS
108+
../api/CanMsg.cpp
100109
../api/Common.cpp
101110
../api/IPAddress.cpp
102111
../api/String.cpp
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include<catch.hpp>
10+
11+
#include<CanMsg.h>
12+
13+
/**************************************************************************************
14+
* NAMESPACE
15+
**************************************************************************************/
16+
17+
usingnamespacearduino;
18+
19+
/**************************************************************************************
20+
* TEST CODE
21+
**************************************************************************************/
22+
23+
TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for lowest valid 29-Bit CAN ID","[CanMsg-CanExtendedId-01]")
24+
{
25+
REQUIRE(CanExtendedId(0) == (CanMsg::CAN_EFF_FLAG |0U));
26+
}
27+
28+
TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for highest valid 29-Bit CAN ID","[CanMsg-CanExtendedId-02]")
29+
{
30+
REQUIRE(CanExtendedId(0x1FFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x1FFFFFFFU));
31+
}
32+
33+
TEST_CASE ("Verify capping of CAN IDs exceeding 29-Bit CAN ID range","[CanMsg-CanExtendedId-03]")
34+
{
35+
REQUIRE(CanExtendedId(0x2FFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x0FFFFFFFU));
36+
REQUIRE(CanExtendedId(0x3FFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x1FFFFFFFU));
37+
REQUIRE(CanExtendedId(0x4FFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x0FFFFFFFU));
38+
REQUIRE(CanExtendedId(0x5FFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x1FFFFFFFU));
39+
/* ...*/
40+
REQUIRE(CanExtendedId(0xFFFFFFFFU) == (CanMsg::CAN_EFF_FLAG |0x1FFFFFFFU));
41+
}

‎test/src/CanMsg/test_CanMsg.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include<catch.hpp>
10+
11+
#include<CanMsg.h>
12+
13+
/**************************************************************************************
14+
* NAMESPACE
15+
**************************************************************************************/
16+
17+
usingnamespacearduino;
18+
19+
/**************************************************************************************
20+
* TEST CODE
21+
**************************************************************************************/
22+
23+
TEST_CASE ("Test constructor with no data (data length = 0)","[CanMsg-CanMsg-01]")
24+
{
25+
CanMsgconstmsg(CanStandardId(0x20),0,nullptr);
26+
27+
REQUIRE(msg.data_length ==0);
28+
for (size_t i =0; i < CanMsg::MAX_DATA_LENGTH; i++)
29+
REQUIRE(msg.data[i] ==0);
30+
}
31+
32+
TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)","[CanMsg-CanMsg-02]")
33+
{
34+
uint8_tconst msg_data[4] = {0xDE,0xAD,0xC0,0xDE};
35+
36+
CanMsgconstmsg(CanStandardId(0x20),sizeof(msg_data), msg_data);
37+
38+
REQUIRE(msg.data_length ==4);
39+
for (size_t i =0; i < msg.data_length; i++)
40+
REQUIRE(msg.data[i] == msg_data[i]);
41+
}
42+
43+
TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)","[CanMsg-CanMsg-03]")
44+
{
45+
uint8_tconst msg_data[12] = {0,1,2,3,4,5,6,7,8,9,10,11};
46+
47+
CanMsgconstmsg(CanStandardId(0x20),sizeof(msg_data), msg_data);
48+
49+
REQUIRE(msg.data_length ==8);
50+
for (size_t i =0; i < msg.data_length; i++)
51+
REQUIRE(msg.data[i] == msg_data[i]);
52+
}
53+
54+
TEST_CASE ("Test constructor constructing a CAN frame with standard ID","[CanMsg-CanMsg-04]")
55+
{
56+
CanMsgconstmsg(CanStandardId(0x20),0,nullptr);
57+
58+
REQUIRE(msg.id ==0x20);
59+
}
60+
61+
TEST_CASE ("Test constructor constructing a CAN frame with extended ID","[CanMsg-CanMsg-05]")
62+
{
63+
CanMsgconstmsg(CanExtendedId(0x20),0,nullptr);
64+
65+
REQUIRE(msg.id == (CanMsg::CAN_EFF_FLAG |0x20));
66+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp