Skip to content

Commit 419ca6c

Browse files
Merge pull request #26 from andreagilardoni/ns-fixes
removing namespaces that may cause name clashes
2 parents 59ac3ca + 08b84e7 commit 419ca6c

File tree

8 files changed

+175
-191
lines changed

8 files changed

+175
-191
lines changed

extras/test/src/time/test_TimedAttempt.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <Arduino.h>
1515
#include <limits.h>
1616

17-
using namespace arduino::tattempt;
18-
1917
SCENARIO("Test broker connection retries") {
2018
TimedAttempt _connection_attempt(0,0);
2119

src/Arduino_HEX.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
#pragma once
1111

1212
#include "./hex/hex.h"
13+
1314
using namespace arduino;
14-
using namespace hex;

src/Arduino_SHA256.h

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
#pragma once
1111

1212
#include "./sha256/SHA256.h"
13-
using namespace arduino;
14-
using namespace sha256;

src/Arduino_TimedAttempt.h

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
#pragma once
1111

1212
#include "./time/TimedAttempt.h"
13-
14-
using namespace arduino::tattempt;

src/hex/hex.h

+13-15
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@ namespace arduino { namespace hex {
2222
String encodeUpper(const uint8_t* in, uint32_t size);
2323

2424
bool decode(const String in, uint8_t* out, uint32_t size);
25+
}} // arduino::hex
2526

26-
class THEXT {
27-
28-
public:
29-
static inline String encode(const uint8_t* in, uint32_t size) {
30-
return arduino::hex::encode(in, size);
31-
}
32-
static inline String encodeUpper(const uint8_t* in, uint32_t size) {
33-
return arduino::hex::encodeUpper(in, size);
34-
}
35-
36-
static inline bool decode(const String in, uint8_t* out, uint32_t size) {
37-
return arduino::hex::decode(in, out, size);
38-
}
27+
class THEXT {
28+
public:
29+
static inline String encode(const uint8_t* in, uint32_t size) {
30+
return arduino::hex::encode(in, size);
31+
}
32+
static inline String encodeUpper(const uint8_t* in, uint32_t size) {
33+
return arduino::hex::encodeUpper(in, size);
34+
}
3935

40-
};
36+
static inline bool decode(const String in, uint8_t* out, uint32_t size) {
37+
return arduino::hex::decode(in, out, size);
38+
}
4139

42-
}} // arduino::hex
40+
};

src/sha256/SHA256.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@ namespace arduino { namespace sha256 {
2727
::acu_sha256(input, ilen, output);
2828
}
2929

30-
class SHA256 {
31-
public:
30+
}} // arduino::sha256
3231

33-
static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;
32+
class SHA256 {
33+
public:
3434

35-
inline void begin() {
36-
return arduino::sha256::begin(&_ctx);
37-
}
38-
inline void update(uint8_t const * data, uint32_t const len) {
39-
return arduino::sha256::update(&_ctx, data, len);
40-
}
41-
inline void finalize(uint8_t * hash) {
42-
return arduino::sha256::finalize(&_ctx, hash);
43-
}
44-
static inline void sha256(uint8_t const * data, uint32_t const len, uint8_t * hash) {
45-
return arduino::sha256::sha256(data, len, hash);
46-
}
35+
static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;
4736

48-
private:
37+
inline void begin() {
38+
return arduino::sha256::begin(&_ctx);
39+
}
40+
inline void update(uint8_t const * data, uint32_t const len) {
41+
return arduino::sha256::update(&_ctx, data, len);
42+
}
43+
inline void finalize(uint8_t * hash) {
44+
return arduino::sha256::finalize(&_ctx, hash);
45+
}
46+
static inline void sha256(uint8_t const * data, uint32_t const len, uint8_t * hash) {
47+
return arduino::sha256::sha256(data, len, hash);
48+
}
4949

50-
acu_sha256_ctx _ctx;
51-
};
50+
private:
5251

53-
}} // arduino::sha256
52+
acu_sha256_ctx _ctx;
53+
};

src/time/TimedAttempt.cpp

+60-64
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,63 @@
1212
#include <Arduino.h>
1313
#include "TimedAttempt.h"
1414

15-
namespace arduino { namespace tattempt {
16-
17-
TimedAttempt::TimedAttempt(unsigned long minDelay, unsigned long maxDelay)
18-
: _minDelay(minDelay)
19-
, _maxDelay(maxDelay) {
20-
}
21-
22-
void TimedAttempt::begin(unsigned long delay) {
23-
_retryCount = 0;
24-
_retryDelay = 0;
25-
_retryTick = 0;
26-
_minDelay = delay;
27-
_maxDelay = delay;
28-
}
29-
30-
void TimedAttempt::begin(unsigned long minDelay, unsigned long maxDelay) {
31-
_retryCount = 0;
32-
_retryDelay = 0;
33-
_retryTick = 0;
34-
_minDelay = minDelay;
35-
_maxDelay = maxDelay;
36-
}
37-
38-
unsigned long TimedAttempt::reconfigure(unsigned long minDelay, unsigned long maxDelay) {
39-
_minDelay = minDelay;
40-
_maxDelay = maxDelay;
41-
return reload();
42-
}
43-
44-
unsigned long TimedAttempt::retry() {
45-
_retryCount++;
46-
return reload();
47-
}
48-
49-
unsigned long TimedAttempt::reload() {
50-
unsigned long shift = _retryCount > 31 ? 31 : _retryCount;
51-
unsigned long delay = (1UL << shift) * _minDelay;
52-
/* delay should always increase */
53-
_retryDelay = (delay > _retryDelay) ? min(delay, _maxDelay): _maxDelay;
54-
_retryTick = millis();
55-
return _retryDelay;
56-
}
57-
58-
void TimedAttempt::reset() {
59-
_retryCount = 0;
60-
}
61-
62-
bool TimedAttempt::isRetry() {
63-
return _retryCount > 0;
64-
}
65-
66-
bool TimedAttempt::isExpired() {
67-
return millis() - _retryTick > _retryDelay;
68-
}
69-
70-
unsigned int TimedAttempt::getRetryCount() {
71-
return _retryCount;
72-
}
73-
74-
unsigned int TimedAttempt::getWaitTime() {
75-
return _retryDelay;
76-
}
77-
78-
}} // arduino::tattempt
15+
TimedAttempt::TimedAttempt(unsigned long minDelay, unsigned long maxDelay)
16+
: _minDelay(minDelay)
17+
, _maxDelay(maxDelay) {
18+
}
19+
20+
void TimedAttempt::begin(unsigned long delay) {
21+
_retryCount = 0;
22+
_retryDelay = 0;
23+
_retryTick = 0;
24+
_minDelay = delay;
25+
_maxDelay = delay;
26+
}
27+
28+
void TimedAttempt::begin(unsigned long minDelay, unsigned long maxDelay) {
29+
_retryCount = 0;
30+
_retryDelay = 0;
31+
_retryTick = 0;
32+
_minDelay = minDelay;
33+
_maxDelay = maxDelay;
34+
}
35+
36+
unsigned long TimedAttempt::reconfigure(unsigned long minDelay, unsigned long maxDelay) {
37+
_minDelay = minDelay;
38+
_maxDelay = maxDelay;
39+
return reload();
40+
}
41+
42+
unsigned long TimedAttempt::retry() {
43+
_retryCount++;
44+
return reload();
45+
}
46+
47+
unsigned long TimedAttempt::reload() {
48+
unsigned long shift = _retryCount > 31 ? 31 : _retryCount;
49+
unsigned long delay = (1UL << shift) * _minDelay;
50+
/* delay should always increase */
51+
_retryDelay = (delay > _retryDelay) ? min(delay, _maxDelay): _maxDelay;
52+
_retryTick = millis();
53+
return _retryDelay;
54+
}
55+
56+
void TimedAttempt::reset() {
57+
_retryCount = 0;
58+
}
59+
60+
bool TimedAttempt::isRetry() {
61+
return _retryCount > 0;
62+
}
63+
64+
bool TimedAttempt::isExpired() {
65+
return millis() - _retryTick > _retryDelay;
66+
}
67+
68+
unsigned int TimedAttempt::getRetryCount() {
69+
return _retryCount;
70+
}
71+
72+
unsigned int TimedAttempt::getWaitTime() {
73+
return _retryDelay;
74+
}

0 commit comments

Comments
 (0)