Aiko parameter issue

Hi,

As part of a school project I want to run a function that pulls in GPS data at regular intervals then returns the values to the main loop using pointers.

using the syntax

Events.addHandler(GetGPSCoords(&data), 10000);

I get

invaild use of void expression

I think this may be that Aiko may not handle pointers been passed to it, any help would be most welcome.

cheers

: -(

You need to tell us a little more about the project. What is the Events object you are using? It would appear that the addHandler function takes the name of a function and an interval. It will then call the function at regular intervals.

If that's the case, there is a very specific signature for the function that it can call. Your function must match that signature.

It would appear that yours does not. You can always make your function place data in a global variable.

Hi there

Sorry being new I am still learning concepts of C and electronics but here goes,

essentialy this system sends a GPS Coords on a serial RF transmitter to track a high altitude balloon taking pictures of the Earths curvature.

The full code is below, you can now see the function I am calling. The idea is the signal is only sent every few minutes as power (or lack of it) is a real issue so I have to conserve how much juce the RF uses as possible.(its very powerful)

The function works fine until I try passing it through the Event Handler function.

Please excuse the bad codeing, I am new in my defence

#include <AikoEvents.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
//#include <gpsdata.h>
#define MIN_HEIGHT 1000
using namespace Aiko;
struct gpsdata {
int altitudeInt;
int longitudeInt;
int latitudeInt;
int sectorNUM;
char altitude[14];
char longitude[14];
char latitude[14];
};
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int runGPS = 0; // Defines if GPS Coords are to be pulled in
int intialALT = 0;
int RunOnce = 0;
int x;
void setup() {
gpsdata data;
Events.addHandler(GetGPSCoords(&data), 10000);
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
}
static void GetGPSCoords(struct gpsdata *a);
static void SectorDetermine(struct gpsdata *a);
static void test();
void loop(){

gpsdata data;
// Ouput GPS Coord on Serial port
//if (runGPS = 0){
// for (x=0;x<10;x++){
// GetGPSCoords(&data);
// }
//}
if (RunOnce = 0){
intialALT = (data.altitudeInt);
RunOnce++;
}
SectorDetermine(&data);
Events.loop();
}
static void GetGPSCoords(struct gpsdata *a){
int i;
int fieldLength = 12;
// int idxStartLong= 14;
// int idxStartLat = 26;
// int idxStartAlt = 38;
int byteGPS=0;
char linea[300] ="";
char comandoGPR[7] = "$GPGGA";
char ptr;
int cont=0;
int conta=0;
int contb=0;
int bien=0;
int indices[14];
char delims[] = ",";
char result = NULL;
for (i=0;i<300;i++){
linea
=' ';

  • }*
    for (i=0;i<300;i++){
  • byteGPS=Serial.read();*
  • if (byteGPS == -1) {*
  • delay(100);*
  • }*
  • else {*
  • linea[conta]=byteGPS;*
  • conta++;*
    Serial.print(byteGPS, BYTE);
  • if (byteGPS==13){ // If the received byte is = to 13, end of transmission*
  • digitalWrite(ledPin, LOW);*
  • cont=0;*
  • bien=0;*
  • for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR*
    _ if (linea*==comandoGPR[i-1]){_
    _
    bien++;_
    _
    }_
    _
    }_
    _
    if(bien==6){ // If yes, continue and process the data*_
    * for (int i=0;i<300;i++){*
    _ if (linea*==','){ // check for the position of the "," separator*
    * indices[cont]=i;
    cont++;
    }
    if (linea==''){ // ... and the ""
    indices[14]=i;
    cont++;
    }
    }
    Serial.println(""); // ... and write to the serial port*

    * Serial.println("");
    Serial.println("---------------");
    for (int i=0;i<9;i++){
    switch(i){
    case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
    case 1 :Serial.print("Latitude: ");break;
    case 2 :Serial.print("Direction (N/S): ");break;
    case 3 :Serial.print("Longitude: ");break;
    case 4 :Serial.print("Longitude (E/W): ");break;
    case 5 :Serial.print("FIX Valid (0/1): ");break;
    case 6 :Serial.print("Number of Satellites: ");break;
    case 7 :Serial.print("HDOP: ");break;
    case 8 :Serial.print("Altitude Meters: ");break;
    }
    for (int j=indices;j<(indices[i+1]-1);j++){
    Serial.print(linea[j+1]);
    }
    Serial.println("");
    }
    Serial.println("---------------");
    }*_

* strncpy(a->longitude,&linea[(indices[1])],(fieldLength-1));*
* strncpy(a->latitude,&linea[(indices[3])],fieldLength);*
* strncpy(a->altitude,&linea[(indices[8])],(indices[8]-indices[9]));*
* a->altitudeInt = atoi(a->altitude);*
* conta=0; // Reset the buffer*
* for (int i=0;i<300;i++){ // *
_ linea*=' ';
}
}
}
}
}
static void SectorDetermine(struct gpsdata *a){
if ((a->altitudeInt) < 300){
(a->sectorNUM) == 10;
}
if ((a->altitudeInt) < 1500){
(a->sectorNUM) == 20;
}
}
static void test(){
Serial.print("Hello");
}*_

From AikoEvents.h:

      void addHandler(void (*handler)(), unsigned int interval, unsigned int delay = 0);

So, it is as I expected. The handler must take no arguments, and must return nothing.

Your function will need to make use of a global variable

Ok would you mind expounding on that a bit? I thought pointers where global?

A pointer may have global or local scope, depending on where it is defined:

char *globalPtr;

void loop()
{
   char *localPtr;
}

The pointer may point to local memory or global memory:

char *global = "GlobalMemoryUsed";
char *globalPtrToGlobalMemory;
char *globalPtrToLocalMemory;

void loop()
{
   char *local = "LocalMemoryUsed";

   char *localPtrToLocalMemory = local;
   char *localPtrToGlobalMemory = global;

   globalPtrToGlobalMemory = global;
   globalPtrToLocalMemory = local;   // NOT A GOOD IDEA
}

So, the scope of the pointer and the scope of the memory do not need to match, although a global pointer to local memory is not a good idea. The local memory can go out of scope, resulting in a dangling pointer, which is a recipe for disaster.

In your case, though, you don't need pointers at all. Just move:

gpsdata data;

so that it is global in scope, and quit passing pointers or references to data.