-1

I am trying to make a c-program that will will a string, but I want it only to read a very small part of it. The NMEA-telegram that I try to read is $WIXDR, and do receive the necessary strings. Here's 2 examples of strings that I get into the CPU:

$WIXDR,C,1.9,C,0,H,83.2,P,0,P,1023.9,H,0*46
$WIXDR,V,0.01,M,0,Z,10,s,0,R,0.8,M,0,V,0.0,M,1,Z,0,s,1,R,0.0,M,1,R,89.9,M,2,R,0.0,M,3*60

If it were only 1 string (not both C and V), this would not be a problem for me. The problem here is that it's 2 seperate strings. One with the temperature, and one with rain-info.

The only thing that I'm interested in is the value "1.9" from

$WIXDR,C,1.9,C,0......

Here's what I have so far:

void ProcessXDR(char* buffPtr)
{
    char valueBuff[10];
    int result, x;
    float OutSideTemp;
    USHORT uOutSideTemp;
//  char charTemperature, charRain
    IODBerr eCode;

    //Outside Temperature
    result = ReadAsciiVariable(buffPtr, &valueBuff[0], &buffPtr, sizeof(valueBuff));
    sscanf(&valueBuff[0],"%f",&OutSideTemp);
    OutSideTemp *= 10;
    uOutSideTemp = (USHORT)OutSideTemp;
    eCode = IODBWrite(ANALOG_IN,REG_COM_XDR,1,&uOutSideTemp,NULL);
    
}


            // XDR ...
            if(!strcmp(&nmeaHeader[0],"$WIXDR"))
            {
                if(PrintoutEnable)printf("XDR\n");
                ProcessXDR(buffPtr);
                Timer[TIMER_XDR] = 1200;          // Update every minute
                ComStateXDR = 1;
                eCode = IODBWrite(DISCRETE_IN,REG_COM_STATE_XDR,1,&ComStateXDR,NULL);
            }

There's more, but this is the main part that I have.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • 1
    You haven't actually asked a specific question nor described a specific problem that occurs in your code. Why are the `C` and `V` causing you problems? If you want further help please provide complete code as a a[minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and clearly state the specific problem in he code. – kaylum Apr 23 '21 at 21:23
  • "The only thing I'm interested in" sounds like you are looking for some sort of projection, but hard to tell. – Neil Apr 24 '21 at 00:14
  • For the string containing the "C", i want it to write the value that is after the "C" to uOutsideTemp. For the string containing the "V", I dont want it to do anything.The only interesting thing for me is the value "1.9" in this case. – Pr0t0typ3 Apr 24 '21 at 06:16
  • The complete code is about 1800 lines... it's used to read different nmea-strings (not only XDR) sending values to conning, and a lot more... All other nmea-strings are working as intended, but this one is new to me. I have the string in, but not how to collect the one value of 1.9 and write it to uOutsideTemp – Pr0t0typ3 Apr 24 '21 at 06:24

1 Answers1

0

I have found the answer to my own question. The code that would do as I intented is as follows: What my little code does, is to look for the letter C, and if the C is found, it will take the value after it and put it into "OutSideTemp". The reason I had to look for C is that there is also a similar string received with the letter V (Rain). If someone have any input in a way it could be better, I don't mind, but this little piece here does what I need it to do.

Here's to example telegrams I receive (I wanted the value 3.0 to be put into "OutSideTemp"): $WIXDR,C,3.0,C,0,H,59.2,P,0,P,1026.9,H,04F $WIXDR,V,0.00,M,0,Z,0,s,0,R,0.0,M,0,V,0.0,M,1,Z,0,s,1,R,0.0,M,1,R,89.9,M,2,R,0.0,M,358

void ProcessXDR(char* buffPtr)
{
char valueBuff[10];
int result, x;
float OutSideTemp;
USHORT uOutSideTemp;
//  char charTemperature, charRain
IODBerr eCode;

//  Look for "C"
result = ReadAsciiVariable(buffPtr, &valueBuff[0], &buffPtr, sizeof(valueBuff));
//  sscanf(&valueBuff[0],"%f",&charTemperature);
if (valueBuff[0] == 'C')

//Outside Temperature
result = ReadAsciiVariable(buffPtr, &valueBuff[0], &buffPtr, sizeof(valueBuff));
sscanf(&valueBuff[0],"%f",&OutSideTemp);
OutSideTemp *= 10;
uOutSideTemp = (USHORT)OutSideTemp;
eCode = IODBWrite(ANALOG_IN,REG_COM_XDR,1,&uOutSideTemp,NULL);
}
  • Typically in such programs, you would just read a whole line and then parse it with like `if (fscanf(input_stream, " $WIXDR,C,%f,%*[^\n]", &val) == 1)` at a time. See gpsd sources. There is a maximum limit of characters in NMEA line - that format was specifically designed to be easy to work with in small devices. – KamilCuk May 01 '21 at 12:51