0

For an IOT project that I'm currently working on, I'm trying to use and rfid sensor with a particle photon in order to read rfid tags. In my doe, I get an error from the compiler that reads:

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]

}

To be more specific, I'm using the c++/java particle build ide to develop this code for my particle photon chip. and this combines 3 files (.ino, .cpp, and .h). I denoted what lines of code are cause ing an error with the comment "//This is where I seem to be getting part of the error" My files look like this:

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__

I'm not quite sure if it's a deceleration issue that's happening, but if anyone can help my, that would be great. Thanks in advance!

Follow up:

After adding void as a valid function type in init, and adding an extra pair of parenthesis in my checkBitValidationUART() function, I get a new error that looks like this:

 ../../../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

I don't know why this error comes up, If anyone can help me debug this, that would be great!

1 Answers1

2

The error message is telling you that the function init does not have a return type, and it's right.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
  • So then the compiler tries to add `int` as the return type and fails since there is no return statement, if I understand the errors correctly? – René Blanken Dec 05 '15 at 03:35
  • Thanks for your response. With what you mentioned in mind, how do you think I should change my function? – Marshall Brown Dec 05 '15 at 03:38
  • Adding `void` as a return type to your init function in both SeeedRFID.cpp and SeeedRFID.h should do the trick, if I get the error messages correctly. – René Blanken Dec 05 '15 at 03:48
  • I added void as a return type, but I got a completely new compilation error. Notice the follow up above please. – Marshall Brown Dec 05 '15 at 04:05
  • 2
    @Marshall Brown: You shoul write a sepsrate Question for this. Als try to only post the relevant parts of the code (ideally provide an [mcve](http://stackoverflow.com/help/mcve) – MikeMB Dec 05 '15 at 09:16
  • @MikeMBThanks for the feedback. The thing is, I don't know where in my code this error is pointing to. But you're right, I'll try to make another question for this. – Marshall Brown Dec 05 '15 at 14:28