Problem with class ofSerial

Hello!

I started to port Guino ( https://github.com/madshobye/guino ) to android, and get the following errors:

Compiling GUINO for Release
make[1]: Entering directory `/c/Development/of_v0.8.1_android_release/examples/android/GUINO'
Compiling src/EasyTransfer.cpp
C:/Development/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/arm-linux-androideabi-g++ -c -Os -Wall -nostdlib --sysroot=C:/Development/android-ndk-r9d/platforms/android-17/arch-arm/ -fno-short-enums -DANDROID -I./libs/armeabi -I./libs/armeabi-v7a -I./libs/x86 -I./src -I../../../addons/ofxAndroid/src -I../../../addons/ofxAccelerometer/src -I../../../addons/ofxUI/src -I"C:/Development/android-ndk-r9d/platforms/android-17/arch-arm//usr/include/" -I"C:/Development/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/include" -I"C:/Development/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/include" -I"C:/Development/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include" -I"C:/Development/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi/include" -I"C:/Development/android-ndk-r9d/sources/crystax/include/" -I"../../../libs/glu/include_android" -I"../../../addons/ofxAndroid/src" -I../../../libs/FreeImage/include -I../../../libs/freetype/include -I../../../libs/freetype/include/freetype2 -I../../../libs/freetype/include/freetype2/freetype -I../../../libs/freetype/include/freetype2/freetype/config -I../../../libs/freetype/include/freetype2/freetype/internal -I../../../libs/freetype/include/freetype2/freetype/internal/services -I../../../libs/glfw/include -I../../../libs/glfw/include/GLFW -I../../../libs/openssl/include -I../../../libs/openssl/include/openssl -I../../../libs/poco/include -I../../../libs/tess2/include -I../../../libs/openFrameworks -I../../../libs/openFrameworks/3d -I../../../libs/openFrameworks/app -I../../../libs/openFrameworks/communication -I../../../libs/openFrameworks/events -I../../../libs/openFrameworks/gl -I../../../libs/openFrameworks/graphics -I../../../libs/openFrameworks/math -I../../../libs/openFrameworks/sound -I../../../libs/openFrameworks/types -I../../../libs/openFrameworks/utils -I../../../libs/openFrameworks/video  -MMD -MP -MF obj/android/armv5/Release/src/EasyTransfer.d -MT obj/android/armv5/Release/src/EasyTransfer.o -o obj/android/armv5/Release/src/EasyTransfer.o -c src/EasyTransfer.cpp
src/EasyTransfer.cpp: In member function 'void EasyTransfer::sendData()':
src/EasyTransfer.cpp:22:10: error: invalid use of incomplete type 'class ofSerial'
   _serial->writeByte(0x06);
          ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:23:10: error: invalid use of incomplete type 'class ofSerial'
   _serial->writeByte(0x85);
          ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:24:10: error: invalid use of incomplete type 'class ofSerial'
   _serial->writeByte(size);
          ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:27:12: error: invalid use of incomplete type 'class ofSerial'
     _serial->writeByte(*(address+i));
            ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:29:10: error: invalid use of incomplete type 'class ofSerial'
   _serial->writeByte(CS);
          ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp: In member function 'bool EasyTransfer::receiveData()':
src/EasyTransfer.cpp:38:15: error: invalid use of incomplete type 'class ofSerial'
     if(_serial->available() >= 3){
               ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:42:21: error: invalid use of incomplete type 'class ofSerial'
       while( _serial->readByte() != 0x06) {
                     ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:47:13: error: invalid use of incomplete type 'class ofSerial'
   if(_serial->available() < 3)
             ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:51:18: error: invalid use of incomplete type 'class ofSerial'
       if (_serial->readByte() == 0x85){
                  ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:52:25: error: invalid use of incomplete type 'class ofSerial'
         rx_len = _serial->readByte();
                         ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:66:18: error: invalid use of incomplete type 'class ofSerial'
     while(_serial->available() && rx_array_inx <= rx_len){
                  ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
src/EasyTransfer.cpp:67:42: error: invalid use of incomplete type 'class ofSerial'
       rx_buffer[rx_array_inx++] = _serial->readByte();
                                          ^
In file included from ../../../libs/openFrameworks/utils/ofLog.h:5:0,
                 from ../../../libs/openFrameworks/ofMain.h:7,
                 from src/EasyTransfer.h:31,
                 from src/EasyTransfer.cpp:1:
../../../libs/openFrameworks/types/ofTypes.h:27:7: error: forward declaration of 'class ofSerial'
 class ofSerial;
       ^
make[1]: *** [obj/android/armv5/Release/src/EasyTransfer.o] Error 1
make[1]: Leaving directory `/c/Development/of_v0.8.1_android_release/examples/android/GUINO'
make: *** [Release] Error 2

18:57:42 Build Finished (took 1m:933ms)

Already found this thread: MVC Pattern in oF, circular dependency problem but that does not hel for me.

Is somebody se the error?

Source files:
EasyTransfer.cpp:

#include "EasyTransfer.h"




//Captures address and size of struct
void EasyTransfer::begin(uint8_t * ptr, uint8_t length, ofSerial *theSerial){
    address = ptr;
    size = length;
    cout << "size";
    cout << size;
    _serial = theSerial;
    
    //dynamic creation of rx parsing buffer in RAM
    rx_buffer = (uint8_t*) malloc(size);
}

//Sends out struct in binary, with header, length info and checksum
void EasyTransfer::sendData(){
  uint8_t CS = size;
  
  _serial->writeByte(0x06);
  _serial->writeByte(0x85);
  _serial->writeByte(size);
  for(int i = 0; i<size; i++){
    CS^=*(address+i);
    _serial->writeByte(*(address+i));
  }
  _serial->writeByte(CS);

}

bool EasyTransfer::receiveData(){
  
  //start off by looking for the header bytes. If they were already found in a previous call, skip it.
  if(rx_len == 0){
  //this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
    if(_serial->available() >= 3){
        
    //this will block until a 0x06 is found or buffer size becomes less then 3.
        
      while( _serial->readByte() != 0x06) {
         
        //This will trash any preamble junk in the serial buffer
        //but we need to make sure there is enough in the buffer to process while we trash the rest
        //if the buffer becomes too empty, we will escape and try again on the next call
        if(_serial->available() < 3)
            return false;
          
        }
      if (_serial->readByte() == 0x85){
        rx_len = _serial->readByte();
        //make sure the binary structs on both Arduinos are the same size.
        if(rx_len != size){
          rx_len = 0;
          return false;
          
        }
      }
    }
  }
   
  
  //we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
  if(rx_len != 0){
    while(_serial->available() && rx_array_inx <= rx_len){
      rx_buffer[rx_array_inx++] = _serial->readByte();
    }
    
    if(rx_len == (rx_array_inx-1)){
      //seem to have got whole message
      //last uint8_t is CS
      calc_CS = rx_len;
      for (int i = 0; i<rx_len; i++){
        calc_CS^=rx_buffer[i];
      } 
      
      if(calc_CS == rx_buffer[rx_array_inx-1]){//CS good
        memcpy(address,rx_buffer,size);
        rx_len = 0;
        rx_array_inx = 0;
         
        return true;
        }
        
      else{
      //failed checksum, need to clear this out anyway
        rx_len = 0;
        rx_array_inx = 0;
        return false;
         
      }
        
    }
  }

  
  return false;
}

EasyTransfer.h:

/******************************************************************
*  EasyTransfer Arduino Library 
*        details and example sketch: 
*            http://www.billporter.info/easytransfer-arduino-library/
*
*        Brought to you by:
*              Bill Porter
*              www.billporter.info
*
*        See Readme for other info and version history
*    
*  
*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
<http://www.gnu.org/licenses/>
*
*This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 
*To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or
*send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
******************************************************************/
#ifndef EasyTransfer_h
#define EasyTransfer_h


//make it a little prettier on the front end. 
#define details(name) (byte*)&name,sizeof(name)

#include "ofMain.h"

class EasyTransfer {
public:
void begin(uint8_t *, uint8_t, ofSerial *theSerial);
//void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial);
void sendData();
bool receiveData();
private:
ofSerial *_serial;
//NewSoftSerial *_serial;
uint8_t * address;  //address of struct
uint8_t size;       //size of struct
uint8_t * rx_buffer; //address for temporary storage and parsing buffer
uint8_t rx_array_inx;  //index for RX parsing buffer
uint8_t rx_len;        //RX packet length according to the packet
uint8_t calc_CS;       //calculated Chacksum
};



#endif

The code can be compiled for OSX and Windows target.

Still not find any soulution. Is it a problemwith the class EasyTransfer or with ofSerial?

Maybe EasyTransfer should have

#include "ofSerial.h"
1 Like