Skip to content

Commit ef249c9

Browse files
committed
ArduinoAPI v1.5.2
1 parent 6786160 commit ef249c9

File tree

137 files changed

+3395
-18389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+3395
-18389
lines changed

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@v2
2828

29-
- name: Create link to String.h
30-
run: echo '#include "WString.h"' > ArduinoCore-API/api/String.h
31-
32-
- name: Create link to String.cpp
33-
run: echo '#include "WString.cpp"' > ArduinoCore-API/api/String.cpp
34-
35-
- name: Fix catch lib issues
36-
run: echo 'add_compile_definitions(CATCH_CONFIG_NO_POSIX_SIGNALS)' >> ArduinoCore-API/test/CMakeLists.txt
37-
3829
- name: Relax some warings
3930
# run: echo 'add_compile_options(-Wno-unused-function)' >> ArduinoCore-API/test/CMakeLists.txt
4031
# run: echo 'add_compile_options(-Wno-error=all)' >> ArduinoCore-API/test/CMakeLists.txt

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/build
1+
build/
22
.vscode
33

ArduinoCore-API/api/ArduinoAPI.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
This library is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313
Lesser General Public License for more details.
1414
1515
You should have received a copy of the GNU Lesser General Public
@@ -20,8 +20,8 @@
2020
#ifndef ARDUINO_API_H
2121
#define ARDUINO_API_H
2222

23-
// version 1.2.0
24-
#define ARDUINO_API_VERSION 10200
23+
// version 1.5.2
24+
#define ARDUINO_API_VERSION 10502
2525

2626
#include "Binary.h"
2727

@@ -32,7 +32,7 @@
3232
#include "Printable.h"
3333
#include "PluggableUSB.h"
3434
#include "Server.h"
35-
#include "WString.h"
35+
#include "String.h"
3636
#include "Stream.h"
3737
#include "Udp.h"
3838
#include "USBAPI.h"
@@ -46,9 +46,10 @@
4646
#include <string.h>
4747
#include <math.h>
4848

49-
#ifdef __cplusplus
5049
// Misc Arduino core functions
5150
#include "Common.h"
51+
52+
#ifdef __cplusplus
5253
// Compatibility layer for older code
5354
#include "Compat.h"
5455
#endif

ArduinoCore-API/api/CanMsg.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
CanMsg.cpp - Library for CAN message handling
3+
Copyright (c) 2023 Arduino. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/**************************************************************************************
21+
* INCLUDE
22+
**************************************************************************************/
23+
24+
#include "CanMsg.h"
25+
26+
/**************************************************************************************
27+
* NAMESPACE
28+
**************************************************************************************/
29+
30+
namespace arduino
31+
{
32+
33+
/**************************************************************************************
34+
* STATIC CONST DEFINITION
35+
**************************************************************************************/
36+
37+
uint8_t const CanMsg::MAX_DATA_LENGTH;
38+
uint32_t const CanMsg::CAN_EFF_FLAG;
39+
uint32_t const CanMsg::CAN_SFF_MASK;
40+
uint32_t const CanMsg::CAN_EFF_MASK;
41+
42+
/**************************************************************************************
43+
* NAMESPACE
44+
**************************************************************************************/
45+
46+
} /* arduino */

ArduinoCore-API/api/CanMsg.h

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
CanMsg.h - Library for CAN message handling
3+
Copyright (c) 2023 Arduino. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef ARDUINOCORE_API_CAN_MSG_H_
21+
#define ARDUINOCORE_API_CAN_MSG_H_
22+
23+
/**************************************************************************************
24+
* INCLUDE
25+
**************************************************************************************/
26+
27+
#include <inttypes.h>
28+
#include <string.h>
29+
30+
#include "Print.h"
31+
#include "Printable.h"
32+
#include "Common.h"
33+
34+
/**************************************************************************************
35+
* NAMESPACE
36+
**************************************************************************************/
37+
38+
namespace arduino
39+
{
40+
41+
/**************************************************************************************
42+
* CLASS DECLARATION
43+
**************************************************************************************/
44+
45+
class CanMsg : public Printable
46+
{
47+
public:
48+
static uint8_t constexpr MAX_DATA_LENGTH = 8;
49+
50+
static uint32_t constexpr CAN_EFF_FLAG = 0x80000000U;
51+
static uint32_t constexpr CAN_SFF_MASK = 0x000007FFU; /* standard frame format (SFF) */
52+
static uint32_t constexpr CAN_EFF_MASK = 0x1FFFFFFFU; /* extended frame format (EFF) */
53+
54+
55+
CanMsg(uint32_t const can_id, uint8_t const can_data_len, uint8_t const * can_data_ptr)
56+
: id{can_id}
57+
, data_length{min(can_data_len, MAX_DATA_LENGTH)}
58+
, data{0}
59+
{
60+
if (data_length && can_data_ptr)
61+
memcpy(data, can_data_ptr, data_length);
62+
}
63+
64+
CanMsg() : CanMsg(0, 0, nullptr) { }
65+
66+
CanMsg(CanMsg const & other)
67+
{
68+
id = other.id;
69+
data_length = other.data_length;
70+
if (data_length > 0)
71+
memcpy(data, other.data, data_length);
72+
}
73+
74+
virtual ~CanMsg() { }
75+
76+
CanMsg & operator = (CanMsg const & other)
77+
{
78+
if (this != &other)
79+
{
80+
id = other.id;
81+
data_length = other.data_length;
82+
if (data_length > 0)
83+
memcpy(data, other.data, data_length);
84+
}
85+
return (*this);
86+
}
87+
88+
virtual size_t printTo(Print & p) const override
89+
{
90+
char buf[20] = {0};
91+
size_t len = 0;
92+
93+
/* Print the header. */
94+
if (isStandardId())
95+
len = snprintf(buf, sizeof(buf), "[%03" PRIX32 "] (%d) : ", getStandardId(), data_length);
96+
else
97+
len = snprintf(buf, sizeof(buf), "[%08" PRIX32 "] (%d) : ", getExtendedId(), data_length);
98+
size_t n = p.write(buf, len);
99+
100+
/* Print the data. */
101+
for (size_t d = 0; d < data_length; d++)
102+
{
103+
len = snprintf(buf, sizeof(buf), "%02X", data[d]);
104+
n += p.write(buf, len);
105+
}
106+
107+
/* Wrap up. */
108+
return n;
109+
}
110+
111+
112+
uint32_t getStandardId() const {
113+
return (id & CAN_SFF_MASK);
114+
}
115+
uint32_t getExtendedId() const {
116+
return (id & CAN_EFF_MASK);
117+
}
118+
bool isStandardId() const {
119+
return ((id & CAN_EFF_FLAG) == 0);
120+
}
121+
bool isExtendedId() const {
122+
return ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG);
123+
}
124+
125+
126+
/*
127+
* CAN ID semantics (mirroring definition by linux/can.h):
128+
* |- Bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
129+
* |- Bit 30 : reserved (future remote transmission request flag)
130+
* |- Bit 29 : reserved (future error frame flag)
131+
* |- Bit 0-28 : CAN identifier (11/29 bit)
132+
*/
133+
uint32_t id;
134+
uint8_t data_length;
135+
uint8_t data[MAX_DATA_LENGTH];
136+
};
137+
138+
/**************************************************************************************
139+
* FREE FUNCTIONS
140+
**************************************************************************************/
141+
142+
inline uint32_t CanStandardId(uint32_t const id) {
143+
return (id & CanMsg::CAN_SFF_MASK);
144+
}
145+
146+
inline uint32_t CanExtendedId(uint32_t const id) {
147+
return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK));
148+
}
149+
150+
/**************************************************************************************
151+
* NAMESPACE
152+
**************************************************************************************/
153+
154+
} /* arduino */
155+
156+
#endif /* ARDUINOCORE_API_CAN_MSG_H_ */
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
CanMsgRingbuffer.cpp - Library for CAN message handling
3+
Copyright (c) 2023 Arduino. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/**************************************************************************************
21+
* INCLUDE
22+
**************************************************************************************/
23+
24+
#include "CanMsgRingbuffer.h"
25+
26+
/**************************************************************************************
27+
* NAMESPACE
28+
**************************************************************************************/
29+
30+
namespace arduino
31+
{
32+
33+
/**************************************************************************************
34+
* CTOR/DTOR
35+
**************************************************************************************/
36+
37+
CanMsgRingbuffer::CanMsgRingbuffer()
38+
: _head{0}
39+
, _tail{0}
40+
, _num_elems{0}
41+
{
42+
}
43+
44+
/**************************************************************************************
45+
* PUBLIC MEMBER FUNCTIONS
46+
**************************************************************************************/
47+
48+
void CanMsgRingbuffer::enqueue(CanMsg const & msg)
49+
{
50+
if (isFull())
51+
return;
52+
53+
_buf[_head] = msg;
54+
_head = next(_head);
55+
_num_elems = _num_elems + 1;
56+
}
57+
58+
CanMsg CanMsgRingbuffer::dequeue()
59+
{
60+
if (isEmpty())
61+
return CanMsg();
62+
63+
CanMsg const msg = _buf[_tail];
64+
_tail = next(_tail);
65+
_num_elems = _num_elems - 1;
66+
67+
return msg;
68+
}
69+
70+
/**************************************************************************************
71+
* NAMESPACE
72+
**************************************************************************************/
73+
74+
} /* arduino */

0 commit comments

Comments
 (0)