I'm trying to send through radio apc220 from a C-xenomai program to and from an arduino Mega.
I have one task created for sending, and one for reading in the xenomai program. The arduino side reads and the writes to serial.
The baud-rates are both equal and tried 9600 and 19200, but the data recieved is random data, and not the values sent.
C code (This is in a task with "rt_task_set_periodic(NULL, TM_NOW, TM_INFINITE);" and priority in task creation of 99). Values of bufferMotorX are constantly changing.
strcpy(buffer,bufferMotor1);
strcat(buffer,bufferMotor2);
strcat(buffer,bufferMotor3);
strcat(buffer,bufferMotor4);
fprintf(stderr,"sending...%s\n",buffer);
write(apcFd, buffer, CONTROLLER_BUFFER_SIZE);
Arduino side:
if (Serial.available() > 0) {
// read the incoming byte:
for (int i=0; i < 12; i++)
{
inputByte=Serial.read();
inputBuffer[i]=inputByte;
}
bufferMotor1[0]=inputBuffer[0];
bufferMotor1[1]=inputBuffer[1];
bufferMotor1[2]=inputBuffer[2];
/*bufferMotor2[0]=inputBuffer[3];
bufferMotor2[1]=inputBuffer[4];
bufferMotor2[2]=inputBuffer[5];
bufferMotor3[0]=inputBuffer[6];
bufferMotor3[1]=inputBuffer[7];
bufferMotor3[2]=inputBuffer[8];
bufferMotor4[0]=inputBuffer[9];
bufferMotor4[1]=inputBuffer[10];
bufferMotor4[2]=inputBuffer[11];*/
Serial.print("I received: ");
Serial.println(bufferMotor1);
motor1=atoi(bufferMotor1);
Any ideas on what I'm doing wrong?