Openvario / sensord

Daemon to poll air data from Openvario sensorboard
6 stars 11 forks source link

Sensorcal not working #45

Open iglesiasmarianod opened 2 years ago

iglesiasmarianod commented 2 years ago

I've built the latest image and found sensorcal is not working. It finds sensorboard as virgin and asks to initialize (even when the sensorboard is been calibrated before). I clicked on "yes" to initialize the board again, but keeps seeing the board as virgin. I ran sensorcal -c. The output is "EEPROM content not valid, run sensorcal -i" I ran sensorcal -i and seems to run OK. I suspect it has something to do with Checksum calculation or verification. Running sensorcal -d The output is "EEPROM content not valid, run sensorcal -i" twice From sensorcal:


        case 'd':
                // read actual EEPROM values
                printf("Reading EEPROM values ...\n\n");
                if( eeprom_read_data(&eeprom, &data) == 0)
                {
                  memcpy(sn,data.serial,6);
                    printf("Actual EEPROM values:\n");
                    printf("---------------------\n");
                    printf("Serial: \t\t\t%s\n", sn);
                    printf("Differential pressure offset:\t%f\n",data.zero_offset);
                }
                else
                {
                    printf("EEPROM content not valid !!\n");
                    printf("Please use -i to initialize EEPROM !!\n");
                    exit_code=2;
                    break;
                }

from 24c16.cpp

int eeprom_read_data(t_24c16 *eeprom, t_eeprom_data *data)
{
    // read eeprom data to struct
    if (eeprom_read(eeprom, (char*)data, 0x00, sizeof(*data))==1)
        return 1;                       // Failed to read the EEPROM

    // verify checksum
    if (!verify_checksum(data))
    {
        printf("EEPROM content not valid !!\n");
        printf("Please use -i to initialize EEPROM !!\n");
        return 2;
    }
    else
    {
        return 0;
    }
}

It seems to be returning 2 and printing error message twice as eeprom_read() is not printing error messages.

iglesiasmarianod commented 2 years ago

Going back from

int update_checksum(t_eeprom_data* data)
{
    char* p_data;
    char checksum=0x00;

    p_data = (char*)data;

    for (size_t i=0; i<sizeof(*data); i++)
    {
        checksum += *p_data;
        p_data++;
    }

    //printf("Checksum: %x\n", checksum);
    data->checksum = checksum;
    return (0);
}

to

int update_checksum(t_eeprom_data* data)
{
    char* p_data;
    int i;
    char checksum=0x00;

    p_data = (char*)data;

    for (i=0; i<sizeof(data); i++)
    {
        checksum += *p_data;
        p_data++;
    }

    //printf("Checksum: %x\n", checksum);
    data->checksum = checksum;
    return (0);
}

in update_checksum and verify_checksum fixes the issue.