Skip to content

Commit 89c36f3

Browse files
Merge pull request #8 from Vrekrer/master
Fork Sync
2 parents cc70e05 + 79d04c5 commit 89c36f3

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Vrekrer_scpi_arrays_code.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// ## SCPI_String_Array member functions ##
66

77
///Add indexing capability.
8-
char* SCPI_String_Array::operator[](const uint8_t index) {
8+
char* SCPI_String_Array::operator[](const uint8_t index) const {
99
if (index >= size_) return NULL; //Invalid index
1010
return values_[index];
1111
}
@@ -26,19 +26,19 @@ char* SCPI_String_Array::Pop() {
2626
}
2727

2828
///Returns the first element of the array
29-
char* SCPI_String_Array::First() {
29+
char* SCPI_String_Array::First() const {
3030
if (size_ == 0) return NULL; //Empty array
3131
return values_[0];
3232
}
3333

3434
///Returns the last element of the array
35-
char* SCPI_String_Array::Last() {
35+
char* SCPI_String_Array::Last() const {
3636
if (size_ == 0) return NULL; //Empty array
3737
return values_[size_ - 1];
3838
}
3939

4040
///Array size
41-
uint8_t SCPI_String_Array::Size() {
41+
uint8_t SCPI_String_Array::Size() const {
4242
return size_;
4343
}
4444

@@ -98,4 +98,4 @@ SCPI_Parameters::SCPI_Parameters(char* message) {
9898
parameter = strtok(NULL, ",");
9999
}
100100
//TODO add support for strings parameters (do not split parameters inside "")
101-
}
101+
}

src/Vrekrer_scpi_parser.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ Header file.
5656
*/
5757
class SCPI_String_Array {
5858
public:
59-
char* operator[](const byte index); //Add indexing capability
59+
char* operator[](const byte index) const; //Add indexing capability
6060
void Append(char* value); //Append new string (LIFO stack Push)
6161
char* Pop(); //LIFO stack Pop
62-
char* First(); //Returns the first element of the array
63-
char* Last(); //Returns the last element of the array
64-
uint8_t Size(); //Array size
62+
char* First() const; //Returns the first element of the array
63+
char* Last() const; //Returns the last element of the array
64+
uint8_t Size() const; //Array size
6565
bool overflow_error = false; //Storage overflow error
6666
const uint8_t storage_size = SCPI_ARRAY_SYZE; //Max size of the array
6767
protected:
@@ -104,7 +104,7 @@ using SCPI_C = SCPI_Commands;
104104
using SCPI_P = SCPI_Parameters;
105105

106106
///Void template used with SCPI_Parser::RegisterCommand.
107-
using SCPI_caller_t = void(*)(SCPI_Commands, SCPI_Parameters, Stream&);
107+
using SCPI_caller_t = void(*)(SCPI_Commands, SCPI_Parameters, Stream&);
108108
///Void template used with SCPI_Parser::RegisterSpecialCommand.
109109
using SCPI_special_caller_t = void(*)(SCPI_Commands, Stream&);
110110

@@ -234,8 +234,21 @@ class SCPI_Parser {
234234

235235
// Include the implementation code here
236236
// This allows Arduino IDE users to configure options with #define directives
237+
//
238+
// Important!!! Implement the library only once in the main.ino file. If you are
239+
// including the same file in other *.cpp files, write this instead:
240+
//
241+
// #define VREKRER_SCPI_PARSER_NO_IMPL
242+
// #include "Vrekrer_scpi_parser.h"
243+
//
244+
// Otherwise, the Arduino linker script will return this error:
245+
//
246+
// (.text+0x0): multiple definition of `SCPI_Parser::ProcessInput(Stream&, char const*)'
247+
248+
#ifdef VREKRER_SCPI_PARSER_NO_IMPL
237249
#include "Vrekrer_scpi_arrays_code.h"
238250
#include "Vrekrer_scpi_parser_code.h"
239251
#include "Vrekrer_scpi_parser_special_code.h"
252+
#endif
240253

241254
#endif //VREKRER_SCPI_PARSER_H_

0 commit comments

Comments
 (0)