gpt4 book ai didi

c++ - 烦人的错误 : expected class name before '{' token

转载 作者:行者123 更新时间:2023-11-30 04:21:20 31 4
gpt4 key购买 nike

<分区>

我一直在尝试使用 arduino 库编译一个基本程序,并且在“{”标记错误之前一直得到这个预期的类名。我是 C++ 的新手,非常感谢详细的解释/插入式解决方案。

代码如下:

SerialGSM.h

#ifndef _SerialGSM_H
#define _SerialGSM_H
#include "Arduino.h"
#include <SoftwareSerial.h>

#define SERIALTIMEOUT 2000
#define PHONESIZE 13
#define MAXMSGLEN 160

class SerialGSM : public SoftwareSerial {
public:
SerialGSM(int rxpin,int txpin);
void FwdSMS2Serial();
void SendSMS();
void SendSMS(char * cellnumber,char * outmsg);
void DeleteAllSMS();
void Reset();
void EndSMS();
void StartSMS();
int ReadLine();
int ReceiveSMS();
void Verbose(boolean var1);
boolean Verbose();
void Sender(char * var1);
char * Sender();
void Rcpt(char * var1);
char * Rcpt();
void Message(char * var1);
char * Message();
void Boot();

boolean verbose;
char sendernumber[PHONESIZE + 1];
char rcpt[PHONESIZE + 1];
char outmessage[160];
char inmessage[160];

protected:
unsigned long lastrec;

};

#endif /* not defined _SerialGSM_H */

SerialGSM.cpp

// SerialGSM version 1.1
// by Meir Michanie
// meirm@riunx.com





// error codes
// http://www.developershome.com/sms/resultCodes2.asp
#include <SerialGSM.h>

SerialGSM::SerialGSM(int rxpin,int txpin):
SoftwareSerial(rxpin,txpin)
{
verbose=false;
}

void SerialGSM::FwdSMS2Serial(){
Serial.println("AT+CMGF=1"); // set SMS mode to text
this->println("AT+CMGF=1"); // set SMS mode to text
delay(200);
this->ReadLine();
Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
this->println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
delay(200);
this->ReadLine();
}

void SerialGSM::SendSMS(char * cellnumber,char * outmsg){
this->Rcpt(cellnumber);
if (verbose) Serial.println(rcpt);
this->StartSMS();
this->Message(outmsg);
Serial.print(outmessage);
this->print(outmessage);
this->EndSMS();
delay(500);
this->ReadLine();
}

void SerialGSM::SendSMS(){
if (verbose) Serial.println(rcpt);
if (verbose) Serial.println(outmessage);
this->StartSMS();
Serial.print(outmessage);
this->print(outmessage);
this->EndSMS();
delay(500);
this->ReadLine();
}

void SerialGSM::DeleteAllSMS(){
Serial.println("AT+CMGD=1,4"); // delete all SMS
this->println("AT+CMGD=1,4"); // delete all SMS
delay(200);
this->ReadLine();
}

void SerialGSM::Reset(){
Serial.println("AT+CFUN=1,1"); // Reset Modem
this->println("AT+CFUN=1,1"); // Reset Modem
delay(200);
this->ReadLine();
}


void SerialGSM::EndSMS(){
this->print(char(26)); // ASCII equivalent of Ctrl-Z
Serial.println();

//delay(5 * 1000); // the SMS module needs time to return to OK status
}

void SerialGSM::StartSMS(){

Serial.println("AT+CMGF=1"); // set SMS mode to text
this->println("AT+CMGF=1"); // set SMS mode to text
delay(200);
this->ReadLine();

Serial.print("AT+CMGS=");
this->print("AT+CMGS=");

this->print(char(34)); // ASCII equivalent of "

Serial.print(rcpt);
this->print(rcpt);

this->println(char(34)); // ASCII equivalent of "

delay(500); // give the module some thinking time
this->ReadLine();

}

int SerialGSM::ReadLine(){
static int pos=0;
char nc;
while (this->available()){
nc=this->read();
if (nc == '\n' or (pos > MAXMSGLEN) or ((millis()> lastrec + SERIALTIMEOUT)and (pos > 0)) ){
nc='\0';
lastrec=millis();
inmessage[pos]=nc;
pos=0;
if (verbose) Serial.println(inmessage);
return 1;
}
else if (nc=='\r') {
}
else{
inmessage[pos++]=nc;
lastrec=millis();
}
}
return 0;
}


int SerialGSM::ReceiveSMS(){
static boolean insms=0;
if (this->ReadLine()){
// Get the number of the sms sender in order to be able to reply
if ( strstr(inmessage, "CMT: ") != NULL ){
insms=1;
int sf=6;
if(strstr(inmessage, "+CMT:")) sf++;
for (int i=0;i < PHONESIZE;i++){
sendernumber[i]=inmessage[sf+i];
}
sendernumber[PHONESIZE]='\0';
return 0;
}else{
if(insms) {
insms=0;
return 1;
}
}
}
return 0;
}


boolean SerialGSM::Verbose(){
return verbose;
}

void SerialGSM::Verbose(boolean var1){
verbose=var1;
}

char * SerialGSM::Sender(){
return sendernumber;
}


char * SerialGSM::Rcpt(){
return rcpt;
}

char * SerialGSM::Message(){
return inmessage;
}


void SerialGSM::Sender(char * var1){
sprintf(sendernumber,"%s",var1);
}


void SerialGSM::Rcpt(char * var1){
sprintf(rcpt,"%s",var1);
}

void SerialGSM::Message(char * var1){
sprintf(outmessage,"%s",var1);
}

void SerialGSM::Boot(){
int counter=0;
while(counter++ < 15){
if (verbose) Serial.print(".");
delay(1000);
}
if (verbose) Serial.println();

}

Arduino 草图

#include <SerialGSM.h>
SerialGSM cell(2,3);

boolean sendonce=true;
void setup(){
Serial.begin(9600);
// cell.begin(9600);
cell.Verbose(true);
cell.Boot();
cell.DeleteAllSMS();
cell.FwdSMS2Serial();
}


void loop(){
if (cell.ReceiveSMS()){
Serial.print("Sender: ");
Serial.println(cell.Sender());
Serial.print("message: ");
Serial.println(cell.Message());
cell.DeleteAllSMS();
}
}

编辑:

完整的错误信息如下:/home/agt/arduino/libraries/SerialGSM.h:10: 错误:'{' 标记前的预期类名谢谢

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com