Skip to content

Commit 2c5ecf4

Browse files
committed
Extracting debug functionality into separate module 'DebugUtils'
1 parent d0a724d commit 2c5ecf4

File tree

3 files changed

+103
-25
lines changed

3 files changed

+103
-25
lines changed

src/ConnectionManager.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818
#ifndef CONNECTION_MANAGER_H_
1919
#define CONNECTION_MANAGER_H_
2020

21-
#define ARDUINO_CLOUD_DEBUG_LEVEL 2
21+
/******************************************************************************
22+
* INCLUDES
23+
******************************************************************************/
2224

2325
#include <Client.h>
2426
#include <Udp.h>
27+
2528
#include "utility/NTPUtils.h"
29+
#include "utility/DebugUtils.h"
30+
31+
/******************************************************************************
32+
* TYPEDEFS
33+
******************************************************************************/
2634

2735
enum NetworkConnectionState {
2836
CONNECTION_STATE_INIT,
@@ -34,6 +42,10 @@ enum NetworkConnectionState {
3442
CONNECTION_STATE_ERROR
3543
};
3644

45+
/******************************************************************************
46+
* CLASS DECLARATION
47+
******************************************************************************/
48+
3749
class ConnectionManager {
3850
public:
3951
virtual void init() = 0;
@@ -50,7 +62,6 @@ class ConnectionManager {
5062

5163
};
5264

53-
5465
#ifdef ARDUINO_SAMD_MKR1000
5566
#include <WiFi101.h>
5667
#define BOARD_HAS_WIFI
@@ -77,27 +88,4 @@ class ConnectionManager {
7788
#define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY
7889
#endif
7990

80-
static int debugMessageLevel = ARDUINO_CLOUD_DEBUG_LEVEL;
81-
inline void debugMessage(char *_msg, int _debugLevel, bool _timestamp = true, bool _newline = true) {
82-
if(_debugLevel < 0){
83-
return;
84-
}
85-
if (_debugLevel <= debugMessageLevel) {
86-
char prepend[20];
87-
sprintf(prepend, "\n[ %d ] ", millis());
88-
if(_timestamp){
89-
Serial.print(prepend);
90-
}
91-
if(_newline){
92-
Serial.println(_msg);
93-
}else{
94-
Serial.print(_msg);
95-
}
96-
}
97-
}
98-
99-
inline void setDebugMessageLevel(int _debugLevel){
100-
debugMessageLevel = _debugLevel;
101-
}
102-
10391
#endif /* CONNECTION_MANAGER_H_ */

src/utility/DebugUtils.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of ArduinoIoTCloud.
3+
*
4+
* Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to [email protected].
16+
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
22+
#include "DebugUtils.h"
23+
24+
/******************************************************************************
25+
* GLOBAL VARIABLES
26+
******************************************************************************/
27+
28+
static int debugMessageLevel = ARDUINO_IOT_CLOUD_DEFAULT_DEBUG_LEVEL;
29+
30+
/******************************************************************************
31+
* PUBLIC FUNCTIONS
32+
******************************************************************************/
33+
34+
void setDebugMessageLevel(int const debugLevel) {
35+
debugMessageLevel = debugLevel;
36+
}
37+
38+
void debugMessage(char * msg, int const debugLevel, bool const timestamp, bool const newline) {
39+
if(debugLevel < 0){
40+
return;
41+
}
42+
43+
if (debugLevel <= debugMessageLevel) {
44+
if(timestamp) {
45+
char prepend[20];
46+
sprintf(prepend, "\n[ %d ] ", millis());
47+
Serial.print(prepend);
48+
}
49+
if (newline) Serial.println(msg);
50+
else Serial.print (msg);
51+
}
52+
}

src/utility/DebugUtils.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of ArduinoIoTCloud.
3+
*
4+
* Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to [email protected].
16+
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
22+
#include <Arduino.h>
23+
24+
/******************************************************************************
25+
* CONSTANTS
26+
******************************************************************************/
27+
28+
static int const ARDUINO_IOT_CLOUD_DEFAULT_DEBUG_LEVEL = 2;
29+
30+
/******************************************************************************
31+
* PROTOTYPES
32+
******************************************************************************/
33+
34+
void setDebugMessageLevel(int debugLevel);
35+
void debugMessage(char * msg, int const debugLevel, bool const timestamp = true, bool const newline = true);
36+
37+
38+

0 commit comments

Comments
 (0)