Hi Stefan,
Let me explain, what I mean.
To add my sensor I use the generated templates from you:
https://cern-ipmc.web.cern.ch/sensors
The Config file (XML) I filled in as I know the sensor parameters etc.
The Header file I didn’t modify at all.
In the C file, there is a part where I describe the sensor reading command:
/* ------------------------------------------------------------------ */
/* This section contains functions specific to the device. */
/* ------------------------------------------------------------------ */
unsigned char initialize_sensor_dcdc(unsigned short i2c_addr, unsigned short reg){
return 0x00;
}
unsigned char read_sensor_dcdc(unsigned char *value, unsigned short i2c_addr, unsigned short reg){
*value = 0x00;
unsigned char data[2]; // 2 bytes Data Buffer as READ_VIN is 16-bit
// char i2c_dev_read_reg(unsigned short addr, unsigned char reg, unsigned char *pdata, unsigned char size)
if (i2c_dev_read_reg(i2c_addr, reg, data, 2)) return I2C_ERROR;
*value = ((data[1] << 6) + (data[0] >> 2)); // 8-bit READ_VIN mantissa [9:2]
return 0x00; //return non-zero value in case of reading error (sensor not updated)
}
Then the C file, there is a part, not specific for my sensor,
/* ------------------------------------------------------------------ */
/* This section contains Template sensor methods. */
/* ------------------------------------------------------------------ */
/* Fill the Get Sensor Reading reply */
static char sensor_dcdc_fill_rd(sensor_t *sensor, unsigned char *msg){
/* Get instance index using the pointer address */
unsigned char i, sval, error;
i = ((sensor_dcdc_t *) sensor) - sensor_dcdc;
if (sensor_dcdc_initialized[i]) {
sensor_dcdc_initialized[i] = initialize_sensor_dcdc(sensor_dcdc_ro[i].i2c_addr, sensor_dcdc_ro[i].reg);
}
error = read_sensor_dcdc(&sval, sensor_dcdc_ro[i].i2c_addr, sensor_dcdc_ro[i].reg);
/* Update sensor value */
if (error == 0){
sensor_threshold_update_s(&sensor_dcdc[i].sensor, sval, 0);
}
return sensor_threshold_fill_reading(sensor, msg);
}
My understanding that part is related to the internal IPMC functionality and I’m not supposed to modify it.
You suggest to look at the example the sensor driver code of the temperature sensor on the IPMC here:
https://gitlab.cern.ch/ep-ese-be-xtca/ipmc-project/-/blob/master/ipmc-sensors/sensor_mcp9801.c#L112
The function here is:
static void sensor_mcp9801_update_reading(unsigned char num, unsigned char flags)
is quite different from my:
static char sensor_dcdc_fill_rd(sensor_t *sensor, unsigned char *msg)
It uses the function
monly_i2c_is_ready(addr)
where
addr = PRG_RD(sensor_mcp9801_ro[num].i2c_addr);
I understand, that I have to use this function - monly_i2c_is_ready(addr) in my code, around
error = read_sensor_dcdc(&sval, sensor_dcdc_ro[i].i2c_addr, sensor_dcdc_ro[i].reg);
But I ‘m not sure how to get the (addr) for the monly_i2c_is_ready(addr) as I don’t have the “num”.
So, will be grateful if you can tell me the implementation.
Please, let me know if my question is not clear.
Thank you,
Yuri