Hello, I am having trouble running this library that I had downloaded from the Arduino IDE, it seems that there is something wrong with the library itself causing it to fail. Any help is appreciated!
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
In file included from c:\users\slaph\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:272:0,
from c:\users\slaph\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,
from C:\Users\slaph\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino/Arduino.h:28,
from C:\Users\slaph\Desktop\Advanced_Serial\TSM.h:4,
from C:\Users\slaph\Desktop\Advanced_Serial\TSM.cpp:1:
TSM.h:19:7: error: expected identifier before numeric constant
class TSM{
^
TSM.h:19:7: error: expected unqualified-id before numeric constant
TSM.cpp:4:1: error: expected unqualified-id before numeric constant
TSM::TSM(HardwareSerial& stream) {
^
TSM.cpp:9:5: error: expected unqualified-id before numeric constant
int TSM::begin(long baudrate) {
^
TSM.cpp:20:5: error: expected unqualified-id before numeric constant
int TSM::available() {
^
TSM.cpp:24:5: error: expected unqualified-id before numeric constant
int TSM::flush() {
^
TSM.cpp:31:10: error: expected unqualified-id before numeric constant
uint8_t* TSM::readRawData() {
^
TSM.cpp:31:10: error: expected initializer before numeric constant
TSM.cpp:39:5: error: expected unqualified-id before numeric constant
int TSM::readRawData(uint8_t* buf) {
^
TSM.cpp:47:10: error: expected unqualified-id before numeric constant
TSMData& TSM::readData() {
^
TSM.cpp:47:10: error: expected initializer before numeric constant
TSM.cpp:56:5: error: expected unqualified-id before numeric constant
int TSM::readData(TSMData& tsmData) {
^
TSM.cpp:66:9: error: expected unqualified-id before numeric constant
TSMData TSM::dataParsing(uint8_t* buf, size_t buf_len) {
^
In file included from c:\users\slaph\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:272:0,
from c:\users\slaph\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,
from C:\Users\slaph\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\cores\arduino/Arduino.h:28,
from sketch\Advanced_Serial.ino.cpp:1:
TSM.h:19:7: error: expected identifier before numeric constant
class TSM{
^
TSM.h:19:7: error: expected unqualified-id before numeric constant
Advanced_Serial:3:1: error: expected unqualified-id before numeric constant
TSM TSMini(Serial6);
^
C:\Users\slaph\Desktop\Advanced_Serial\Advanced_Serial.ino: In function 'void setup()':
Advanced_Serial:13:12: error: 'TSMini' was not declared in this scope
status = TSMini.begin(115200);
^~~~~~
C:\Users\slaph\Desktop\Advanced_Serial\Advanced_Serial.ino:13:12: note: suggested alternative: 'TSM'
status = TSMini.begin(115200);
^~~~~~
TSM
C:\Users\slaph\Desktop\Advanced_Serial\Advanced_Serial.ino: In function 'void loop()':
Advanced_Serial:24:7: error: 'TSMini' was not declared in this scope
if (TSMini.available()) {
^~~~~~
C:\Users\slaph\Desktop\Advanced_Serial\Advanced_Serial.ino:24:7: note: suggested alternative: 'TSM'
if (TSMini.available()) {
^~~~~~
TSM
exit status 1
expected identifier before numeric constant
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here is the library .ccp
#include "TSM.h"
/* TSM object, input the SPI bus and chip select pin */
TSM::TSM(HardwareSerial& stream) {
_serial = &stream; // SPI bus
}
/* starts communication with the TSM */
int TSM::begin(long baudrate) {
// begin SPI communication
_serial->begin(baudrate);
if(flush() < 0) {
return -1;
}
// successful init, return 1
return 1;
}
/* returns whether data from TSM is available*/
int TSM::available() {
return _serial->available();
}
int TSM::flush() {
_serial->flush();
memset(_buffer, 0, sizeof(_buffer));
return 1;
}
/* reads the most current raw data from TSM and stores in _buffer (member variable) */
uint8_t* TSM::readRawData() {
String str = _serial->readStringUntil('\n');
str.toCharArray((char*)_buffer, str.length());
_buffer[str.length()] = '\0';
return _buffer;
}
/* reads the most current raw data from TSM and stores in buf (argument) */
int TSM::readRawData(uint8_t* buf) {
String str = _serial->readStringUntil('\n');
str.toCharArray((char*)buf, str.length());
buf[str.length()] = '\0';
return 1;
}
/* reads the most current data from TSM and stores in _buffer (member variable) */
TSMData& TSM::readData() {
String str = _serial->readStringUntil('\n');
str.toCharArray((char*)_buffer, str.length());
_buffer[str.length()] = '\0';
_tsmData = dataParsing(_buffer, sizeof(_buffer));
return _tsmData;
}
/* reads the most current data from TSM and stores in tsmData (argument) */
int TSM::readData(TSMData& tsmData) {
String str = _serial->readStringUntil('\n');
str.toCharArray((char*)_buffer, str.length());
_buffer[str.length()] = '\0';
tsmData = dataParsing(_buffer, sizeof(_buffer));
return 1;
}
/* raw data parsing */
TSMData TSM::dataParsing(uint8_t* buf, size_t buf_len) {
TSMData tsmData = {};
char temp4[4];
char temp6[6];
char temp8[8];
char temp10[10];
unsigned int idx = 0;
while(idx < buf_len) {
switch (buf[idx]) {
case 'A':
if (buf[idx+1] == 'D') {
memcpy(temp10, &buf[idx+3], sizeof(temp10));
tsmData.airDensity = atof(temp10);
idx = idx + 12;
}
break;
case 'D':
if (buf[idx+1] == ' ') {
memcpy(temp4, &buf[idx+2], sizeof(temp4));
tsmData.windDirHor = atoi(temp4);
idx = idx + 6;
}
else if (buf[idx+1] == 'V') {
memcpy(temp4, &buf[idx+3], sizeof(temp4));
tsmData.windDirVer = atoi(temp4);
idx = idx + 6;
}
break;
case 'H':
memcpy(temp6, &buf[idx+2], sizeof(temp6));
tsmData.humidity = atof(temp6);
idx = idx + 8;
break;
case 'P':
if (buf[idx+1] == ' ') {
memcpy(temp8, &buf[idx+2], sizeof(temp8));
tsmData.pressure = atof(temp8);
idx = idx + 10;
}
else if (buf[idx+1] == 'I') {
memcpy(temp6, &buf[idx+3], sizeof(temp6));
tsmData.pitch = atof(temp6);
idx = idx + 8;
}
break;
case 'R':
if (buf[idx+1] == 'O') {
memcpy(temp6, &buf[idx+3], sizeof(temp6));
tsmData.roll = atof(temp6);
idx = idx + 8;
}
break;
case 'S':
if (buf[idx+1] == ' ') {
memcpy(temp6, &buf[idx+2], sizeof(temp6));
tsmData.windSpeed3D = atof(temp6);
idx = idx + 8;
}
else if (buf[idx+1] == '2') {
memcpy(temp6, &buf[idx+3], sizeof(temp6));
tsmData.windSpeed2D = atof(temp6);
idx = idx + 8;
}
break;
case 'T':
memcpy(temp6, &buf[idx+2], sizeof(temp6));
tsmData.sonicTemp = atof(temp6);
idx = idx + 8;
break;
default:
idx++;
break;
}
if (buf[idx] == '\0') { break; }
}
return tsmData;
}
And the header file
#ifndef TSM_H
#define TSM_H
#include "Arduino.h"
struct TSMData {
float windSpeed3D;
float windSpeed2D;
int16_t windDirHor;
int16_t windDirVer;
float sonicTemp;
float humidity;
float pressure;
float airDensity;
float pitch;
float roll;
};
class TSM{
public:
TSM(HardwareSerial& stream);
int begin(long baudrate);
int available();
int flush();
uint8_t* readRawData();
int readRawData(uint8_t* buf);
TSMData& readData();
int readData(TSMData& tsmData);
protected:
TSMData dataParsing(uint8_t* buf, size_t buf_len);
// serial(uart)
HardwareSerial* _serial = {};
// buffer for reading from sensor
TSMData _tsmData = {};
uint8_t _buffer[300];
};
#endif // TSM_H