Parsing CTi Sensor Data with an Arduino Due

I have been using a slightly modified version of code sent to me from CTi (Tilt-33A). It is found below. I'm having problems getting the data in the serial buffer, it just shows up as "f". There is a picture of the serial buffer displaying what I'm getting now. It could be something with "unsigned char checkCRC(unsigned char * msg)", since I changed it so the code would compile.

/*
Modifying C program from CTi to Arduino Compatible
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


unsigned char checkCRC(char * msg)
{

    unsigned int i;
    char crc = 0;
    /* Calculate the CRC */
    for (i = 0; i < strlen((char *)msg); i++)
        crc ^= msg[i];

    /*return crc;*/
}

int parse_tilt_30(char *data, char rv[][64])
{
    int i = 0;
    char *token, *crc;
    
    token = strtok(data, "*");
    crc = strtok(NULL, "*");
    /* Check if CRC equal to the CRC in message */
    if (strtol(crc, NULL, 16) != checkCRC(token+1))
        /*return -1;*/
    token = strtok(token, ",");
    /* Parsing the msg */
    while (token != NULL)
    {
        token = strtok(NULL, ",");
        if (token != NULL)
            strcpy(rv[i++], token);
    }
    /*return 1;*/
}


void setup() {
 Serial.begin(115200);   
}


void loop(){
    int  ret = 0;
    char data[64] = "$CSTLT,+0997.6,-0009.2,+0003.0,+087.09,+002.58,+000,22.40*42\n\r";
    char rv[7][64] = {{0}};
    float Ax, Ay, Az;
    float Pitch, Roll, Rotation;
    float Temperature;
    
    if (parse_tilt_30(data, rv) < 0)
    {
        printf("Checksum Error!\n");
    }

    Ax          = strtof(rv[0], NULL);
    printf("Ax: %+5.1f, ", Ax);
    Ay          = strtof(rv[1], NULL);
    printf("Ay: %+5.1f, ", Ay);
    Az          = strtof(rv[2], NULL);
    printf("Az: %+5.1f\n", Az);
    Pitch       = strtof(rv[3], NULL);
    printf("Pitch: %+5.2f, ", Pitch);
    Roll        = strtof(rv[4], NULL);
    printf("Roll: %+5.2f, ", Roll);
    Rotation    = strtof(rv[5], NULL);
    printf("Rotation: %+5.2f\n", Rotation);
    Temperature = strtof(rv[6], NULL);
    printf("Temperature: %+4.1f\n", Temperature);
    
    delay(5000);
}

There is at least an issue with your printf() usage, it should be, e.g. :

printf("My var = %+4.2f \n", var); // Note the \n before " !!

See the C++ reference for printf() usage:

http://www.cplusplus.com/reference/cstdio/printf/

I figured it out! This is probably not the most elegant way to do it, but it works for me. Hopefully, someone can find this to be a useful reference.

/*

*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
  
    float Ax;
    float Ay, Az;
    float Pitch, Roll, Rotation;
    float Temperature;
    
    
    char buffer[70];
    byte inByte;

void setup () {
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  
if(Serial1.available() >0) {
    //read the incoming byte:
    inByte = Serial1.read();
    
   if (inByte == '

){
        Serial.print(" I received:");
        Serial.write(inByte);
        Serial.println(" ");
      if(Serial1.available() > 68) {
      //Serial1.readBytes(buffer, 69);
      //Serial.println(buffer);
     
      String data = Serial1.readStringUntil('*');
      Serial.print("data: ");
      Serial.println(data);
     
     
      //"CSTLT,%+6.2f,%+6.2f,%+6.2f,%+6.3f,%+6.3f,%+6.3f,%+4.1f"
        sscanf(data.c_str(), "CSTLT,%f,%f,%f,%f,%f,%f,%f ", &Ax, &Ay, &Az, &Pitch, &Roll, &Rotation, &Temperature);

Serial.println("----new-----");
        Serial.print("Ax: ");
        Serial.println(Ax);
        Serial.print("Ay: ");
        Serial.println(Ay);
        Serial.print("Az: ");
        Serial.println(Az);
        Serial.print("Pitch: ");
        Serial.println(Pitch);
        Serial.print("Roll: ");
        Serial.println(Roll);
        Serial.print("Rotation: ");
        Serial.println(Rotation);
        Serial.print("Temperature: ");
        Serial.println(Temperature);
      }
    }else{while(Serial1.available()){
    Serial1.read();}
  }
 
}
  delay(1000);
}