ISO C ++禁止声明' init'没有类型[-fpermissive]

时间:2015-12-05 03:25:31

标签: java c++ arduino rfid iot

对于我目前正在进行的物联网项目,我尝试使用带有粒子光子的rfid传感器来读取rfid标签。在我的母鹿,我从编译器得到一个错误:

SeeedRFID.h:88:34: error: ISO C++ forbids declaration of 'init' with no type [-fpermissive]
     init(int rxPin, int txPin);

SeeedRFID.cpp:55:37: error: ISO C++ forbids declaration of 'init' with no type [-fpermissive]
SeeedRFID::init(int rxPin, int txPin)

SeeedRFID.cpp: In member function 'int SeeedRFID::init(int, int)':
SeeedRFID.cpp:70:1: warning: no return statement in function returning non-void [-Wreturn-type]

}

更具体地说,我使用c ++ / java粒子构建ide为我的粒子光子芯片开发此代码。这结合了3个文件(.ino,.cpp和.h)。我说明了哪些代码行导致了注释错误" //这就是我似乎正在接收错误的部分"我的文件看起来像这样:

RFID_UART.ino

#if defined (SPARK)
#include "SeeedRFID.h"
#else
#include <SoftwareSerial.h>
#include <SeeedRFID.h>
#endif

#define RFID_RX_PIN RX
#define RFID_TX_PIN TX

// #define DEBUGRFID
#define TEST

SeeedRFID RFID;
RFIDdata tag;

void setup() {
    RFID.init(RFID_RX_PIN, RFID_TX_PIN); //This is where I seem to be getting part of the error
    Serial1.begin(9600);    //Done here to prevent SeeedRFID constructor system crash
    //Serial is basically the same thing as System.out.println(); 
    Serial.begin(57600);
    Serial.println("Hello, double bk!"); //This is so I know that setup() works
}
void loop() { 
    if(RFID.isAvailable()){
        tag = RFID.data();
        Serial.print("RFID card number: ");
        Serial.println(RFID.cardNumber());
#ifdef TEST
    Serial.print("RFID raw data: ");
    for(int i=0; i<tag.dataLen; i++){
        Serial.print(tag.raw[i], HEX);
        Serial.print('\t');
        }
#endif
    }
}

SeeedRFID.cpp

#include "SeeedRFID.h"

SeeedRFID::init(int rxPin, int txPin)//This is where I seem to be getting part of the error
{
#if (PLATFORM_ID == 0) || (PLATFORM_ID == 6)    //Core or Photon (they're both the same platform essentially)
   _rfidIO = &Serial1;      // Select Serial1 or Serial2
#else
   _rfidIO = new SoftwareSerial(rxPin, txPin);
   _rfidIO->begin(9600);
#endif
   // init RFID data
   _data.dataLen = 0;
   _data.chk = 0;
   _data.valid = false;

   _isAvailable = false;
_type = RFID_UART;
}

SeeedRFID::SeeedRFID() //Empty constructor
{
}

boolean SeeedRFID::checkBitValidationUART()
{
    if( (5 == _data.dataLen) && (_data.raw[4] == _data.raw[0]^_data.raw[1]^_data.raw[2]^_data.raw[3]))
    {
    _data.valid = _isAvailable = true;
    return true;
    } else
    {
    _data.valid = _isAvailable = false;
    return false;
    }
}

boolean SeeedRFID::read()
{
    _isAvailable = false;

    if (_data.dataLen != 0)
    {
        _data.dataLen = 0;
    }

    while (_rfidIO->available())
    {
        _data.raw[_data.dataLen++] = _rfidIO->read();
#ifdef DEBUGRFID
    Serial.println("SeeedRFID:read() function, and the RFID raw data: ");
    for (int i = 0; i < _data.dataLen; ++i)
    {
        Serial.println();
        Serial.print(_data.raw[i], HEX);
        Serial.print('\t');
    }
    Serial.println();
#endif
        delay(10);
    }

    return SeeedRFID::checkBitValidationUART();
}

boolean SeeedRFID::isAvailable()
{
    switch(_type){
        case RFID_UART:
            return SeeedRFID::read();
            break;
        case RFID_WIEGAND:
            return false;
            break;
        default:
            return false;
            break;
    }
}

RFIDdata SeeedRFID::data()
{
    if (_data.valid)
    {
        return _data;
    }else{
        // empty data
        RFIDdata _tag;
        return _tag;
    }
}

unsigned long SeeedRFID::cardNumber()
{
    // unsigned long myZero = 255;

    unsigned long sum = 0;
    if(0 != _data.raw[0]){
        // _data.raw[0] =   _data.raw[0] & myZero;
        sum = sum + _data.raw[0];
        sum = sum<<24;
    }
    // _data.raw[1] =   _data.raw[1] & myZero;
    sum = sum + _data.raw[1];
    sum = sum<<16;

    unsigned long sum2 = 0;
    // _data.raw[2] =   _data.raw[2] & myZero;
    sum2 = sum2  + _data.raw[2];
    sum2 = sum2 <<8;
    // _data.raw[3] =   _data.raw[3] & myZero;
    sum2 = sum2  + _data.raw[3];

    sum = sum + sum2;

#ifdef DEBUGRFID
    Serial.print("cardNumber(HEX): ");
    Serial.println(sum, HEX);
    Serial.print("cardNumber: ");
    Serial.println(sum);
#endif

    return sum;
}

SeeedRFID.h

#ifndef SeeedRFID_H
#define SeeedRFID_H


#include "application.h"

struct RFIDdata
{
    int dataLen;
    byte chk;
    boolean valid;
    unsigned char raw[5];
};

enum RFIDType
{ 
    RFID_UART,
    RFID_WIEGAND
};

class SeeedRFID
{ 
private:
 #if (PLATFORM_ID == 0) || (PLATFORM_ID == 6)   //Core or Photon
    USARTSerial * _rfidIO; // software serial
 #else
    SoftwareSerial * _rfidIO; // software serial
 #endif
    RFIDdata _data;
    boolean _isAvailable;
    RFIDType _type;
    boolean checkBitValidationUART();
    boolean read();
public:
    SeeedRFID(int rxPin, int txPin);
    SeeedRFID();   // Empty constructor
    ~SeeedRFID();
        init(int rxPin, int txPin);//This is where I seem to be getting part of the error

    boolean isAvailable();
RFIDdata data();
unsigned long cardNumber();
};

#endif //__SeeedRFID_H__

我不太确定这是否是一个减速问题,但如果有人能帮助我,那就太好了。提前谢谢!

跟进:

在init中添加void作为有效函数类型,并在checkBitValidationUART()函数中添加一对额外的括号后,我得到一个如下所示的新错误:

 ../../../build/target/user/platform-6/libuser.a(rfid_uart.o): In function `__static_initialization_and_destruction_0':
 rfid_uart.cpp:17: undefined reference to `SeeedRFID::~SeeedRFID()'
 collect2: error: ld returned 1 exit status
 make: *** [78d90e0fa4198d16c036bc7b90f2e4ec4507eca98981faccb460440188a7.elf] Error 1

我不知道为什么会出现这个错误,如果有人可以帮我调试,那就太棒了!

1 个答案:

答案 0 :(得分:1)

错误消息告诉您函数init没有返回类型,而且它是正确的。