I'm trying to implement a java wrapper for RCSwitch in a Raspberry Pi. It works fine until the grabbing method reaches the 80th iteration. Then it slows down and I can't figure out why. It needs more than 5 minutes to return with a value.
I tried to figure out the problem, but I'm not out of memory, the raspberry still has more then 300mega. In spite ot this, I tried to run the JVM with the following parameter:-Xms5m -Xmx5m
but the program still slowed down at the 80th iteration so I think its not a memory problem. My sender still sends the value, because if I restart the program it's working again until the 80th iteration, so it's not the lack of input data.
Here is the java part of the code:
public class RCSwitchWrapper {
public native int recievedValue(int PIN);
static{System.loadLibrary("RCSwitchWrapper");}
public static void main(String[] args){
RCSwitchWrapper wrapper = new RCSwitchWrapper();
int counter=0;
while(true){
counter++;
int grabbedData = wrapper.recievedValue(2);
System.out.println(counter+" grabbed data: "+grabbedData);
}
}
}
The C++ part of the code:
#include "RCSwitch.h"
#include "RCSwitchWrapper.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
RCSwitch mySwitch;
JNIEXPORT jint JNICALL Java_RCSwitchWrapper_recieveValue(JNIEnv *env, jobject obj,jint PIN){
if(wiringPiSetup()==-1){
printf("wiringpi error \n");
return 0;
}
mySwitch = RCSwitch();
mySwitch.enableReceive(PIN);
while(1){
if(mySwitch.available()){
int value = mySwitch.getReceivedValue();
return value;
}
mySwitch.resetAvailable();
return(-1);
}
}
Now I'm confused and can't think a solution.
Thanks in advance.