So this is my sending (arduino) side
struct MyStruct_t {
double imuRoll; //MinIMU-9 data
double imuPitch;//MinIMU-9 data
double imuYaw; //MinIMU-9 data
long flAt; // GPS latitude
long flOn; // GPS Longitude
//char GPSs{300]="";
unsigned int FC_AP; //Front Center Ultrasonic Avrage Ping
unsigned int FL_AP; //Front Left Ultrasonic Avrage Ping
unsigned int FR_AP; //Front Rgith Ultrasonic Avrage Ping
unsigned int RC_AP; //Rear Center Ultrasonic Avrage Ping
int FCir; //Front Center Infrared sen
int FLir; //Front Left Infrared sen
int FRir; //Front Right Infrared sen
int RCir; //Rear Center Infrared sen
double BSTempature; //Barometric sen tempature
int BSPressure; //Barometric sen pressure
int Heading; //LM303 mag heading
}MyStruct;
void setup(){
Serial.begin(57600);
Serial3.begin(57600);
}
char sendBuff[90], tmpbuff[10];
void loop() {
fillStruct();
makeString();
sendStr();
}
void sendStr(){
// for (int i = 0; i < sizeof(sendBuff); i++){
Serial.println(sendBuff);
Serial3.println(sendBuff);
// }
// Serial.println("");
// Serial3.println("");
}
void fillStruct(){
MyStruct.imuYaw = 111.456;
MyStruct.imuPitch = -222.679;
MyStruct.imuRoll = 333.012;
MyStruct.flAt = 43.475743;
MyStruct.flOn = -76.429243;
MyStruct.FC_AP = 00; //Front Center Ultrasonic Avrage Ping
MyStruct.FL_AP = 11; //Front Left Ultrasonic Avrage Ping
MyStruct.FR_AP = 22; //Front Rgith Ultrasonic Avrage Ping
MyStruct.RC_AP = 33; //Rear Center Ultrasonic Avrage Ping
MyStruct.FCir = 1; //Front Center Infrared sen
MyStruct.FLir = 1; //Front Left Infrared sen
MyStruct.FRir = 0; //Front Right Infrared sen
MyStruct.RCir = 1; //Rear Center Infrared sen
MyStruct.BSTempature = 99.1; //Barometric sen tempature
MyStruct.BSPressure = 30000; //Barometric sen pressure
MyStruct.Heading = 292; //LM303 mag heading
}
void makeString(){
strcpy(sendBuff, "<");
dtostrf(MyStruct.imuYaw, 4,2, tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
dtostrf(MyStruct.imuPitch, 4,2, tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
dtostrf(MyStruct.imuRoll, 4,2, tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, "::");
(MyStruct.flAt,3,6,tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
dtostrf(MyStruct.flOn,3,6,tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.Heading,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, "::");
itoa(MyStruct.FC_AP,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.FL_AP,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.FR_AP,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.RC_AP,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, "::");
itoa(MyStruct.FCir,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.FLir,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.FRir,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.RCir,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, "::");
dtostrf(MyStruct.BSTempature,2,2,tmpbuff);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ",");
itoa(MyStruct.BSPressure,tmpbuff,10);
strcat(sendBuff, tmpbuff);
strcat(sendBuff, ">");
sendBuff[90] = '\0';
}
Arduino output is
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
<111.46,-222.68,333.01::333.01,-76.000000,292::0,11,22,33::1,1,0,1::99.10,30000>
dunno why lat and long are so empty after the dec but o well for now.
minicom on Pi shows the data the same at /dev/ttyAMA0 so i know it's hooked up right.
this is my PI side
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringSerial.h>
void serialRead();
void prntBuff();
float yaw, pitch, roll;
int fd, z, x, sDA;
char cChar, recBuff[90];
int main ()
{
if ((fd = serialOpen ("/dev/ttyAMA0", 57600)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
for (;;)
{
x = 0;
cChar = serialGetchar(fd);
printf("Wating for data\n");
if(cChar == '<') serialRead();
serialRead();
}
}
void serialRead(){
sDA = serialDataAvail(fd);
while (cChar != '>' ){
if (x < sizeof(recBuff)-1){
printf("Getting data!\n ");
cChar = serialGetchar(fd);
recBuff[x] = cChar;
x++;
}
else if(sDA == 0){
printf("Got no Data\n");
}
break;
}
if(cChar == '>'){
printf("End of data\n");
x++;
recBuff[x] = '0';
serialFlush(fd);
prntBuff();
}
}
void prntBuff(){
// for(z = 0;z < sizeof(recBuff);z++){
printf("%s\n",recBuff);
// }
}
Pi output is this.
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
End of data
>00
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
Wating for data
Getting data!
am i filling the array wrong or printing it wrong?