MVMFirmwareCpp v0.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SensorSFM3019 Class Reference

#include <driver_SFM3019.h>

Collaboration diagram for SensorSFM3019:
Collaboration graph
[legend]

Public Member Functions

bool Init (t_i2cdevices device, void *hw_handle)
 
bool doMeasure (float *Flow, float *T)
 
float GetIntegral ()
 
void ResetIntegral ()
 

Private Member Functions

const char * sfm_common_get_driver_version (void)
 
int16_t sfm_common_probe (uint8_t i2c_address)
 
int16_t sfm_common_read_product_identifier (uint8_t i2c_address, uint32_t *product_number, uint8_t(*serial_number)[8])
 
int16_t sfm_common_read_scale_factor_offset_and_unit (const SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd, int16_t *flow_scale, int16_t *flow_offset, uint16_t *unit)
 
int16_t sfm_common_convert_flow_float (const SfmConfig *sfm_config, int16_t flow_raw, float *flow)
 
float sfm_common_convert_temperature_float (int16_t temperature_raw)
 
int16_t sfm_common_start_continuous_measurement (SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd)
 
int16_t sfm_common_read_measurement_raw (const SfmConfig *sfm_config, int16_t *flow_raw, int16_t *temperature_raw, uint16_t *status)
 
int16_t sfm_common_stop_continuous_measurement (SfmConfig *sfm_config)
 
uint8_t sensirion_common_generate_crc (uint8_t *data, uint16_t count)
 
int8_t sensirion_common_check_crc (uint8_t *data, uint16_t count, uint8_t checksum)
 
int16_t sensirion_i2c_general_call_reset (void)
 
uint16_t sensirion_fill_cmd_send_buf (uint8_t *buf, uint16_t cmd, const uint16_t *args, uint8_t num_args)
 
int16_t sensirion_i2c_read_words (uint8_t address, uint16_t *data_words, uint16_t num_words)
 
int16_t sensirion_i2c_read_words_as_bytes (uint8_t address, uint8_t *data, uint16_t num_words)
 
int16_t sensirion_i2c_write_cmd (uint8_t address, uint16_t command)
 
int16_t sensirion_i2c_write_cmd_with_args (uint8_t address, uint16_t command, const uint16_t *data_words, uint16_t num_words)
 
int16_t sensirion_i2c_delayed_read_cmd (uint8_t address, uint16_t cmd, uint32_t delay_us, uint16_t *data_words, uint16_t num_words)
 
int16_t sensirion_i2c_read_cmd (uint8_t address, uint16_t cmd, uint16_t *data_words, uint16_t num_words)
 
int16_t sfm3019_probe (void)
 
SfmConfig sfm3019_create (void)
 
int16_t sensirion_i2c_select_bus (uint8_t bus_idx)
 
void sensirion_i2c_init (void)
 
void sensirion_i2c_release (void)
 
int8_t sensirion_i2c_read (uint8_t address, uint8_t *data, uint16_t count)
 
int8_t sensirion_i2c_write (uint8_t address, const uint8_t *data, uint16_t count)
 
void sensirion_sleep_usec (uint32_t useconds)
 

Private Attributes

uint8_t i2c_address
 
t_i2cdevices i2c_device
 
HWhwi
 
DebugIfaceClassdbg
 
float Integral
 
bool _initialized = false
 
SfmConfig sfm3019
 

Detailed Description

Definition at line 32 of file driver_SFM3019.h.

Member Function Documentation

◆ doMeasure()

bool SensorSFM3019::doMeasure ( float *  Flow,
float *  T 
)

Definition at line 461 of file driver_SFM3019.cpp.

462 {
463  int16_t flow_raw;
464  int16_t temperature_raw;
465  uint16_t status;
466  int16_t error;
467  if (!_initialized) return false;
468 
469  error = sfm_common_read_measurement_raw(&sfm3019, &flow_raw,
470  &temperature_raw, &status);
471  if (error) {
472  //Serial.println("Error while reading measurement");
473  return false;
474  }
475  else {
476  float flow;
477  float temperature;
478  error = sfm_common_convert_flow_float(&sfm3019, flow_raw, &flow);
479  if (error) {
480  //Serial.println("Error while converting flow");
481  return false;
482  }
483  *T = sfm_common_convert_temperature_float(temperature_raw);
484  *Flow = flow;
485  Integral += flow;
486  //Serial.println("Flow: " + String(flow) + " flow_raw: " + String(flow_raw) + " T: " +String(temperature) + " Traw: " +String(temperature_raw) + " status: " + String(status));
487  }
488 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetIntegral()

float SensorSFM3019::GetIntegral ( )

Definition at line 490 of file driver_SFM3019.cpp.

491 {
492  return Integral;
493 }
Here is the caller graph for this function:

◆ Init()

bool SensorSFM3019::Init ( t_i2cdevices  device,
void *  hw_handle 
)

Definition at line 389 of file driver_SFM3019.cpp.

390 {
391 
392  DriverContext* dc;
393  dc = (DriverContext*)hw_handle;
394  hwi = (HW*)dc->hwi;
395  dbg = (DebugIfaceClass*)dc->dbg;
396  i2c_address = 0x2e;
397  i2c_device = device;
398 
399  _initialized = false;
400  const char* driver_version = sfm_common_get_driver_version();
401  if (driver_version) {
402  dbg->DbgPrint(DBG_KERNEL, DBG_INFO, "SFM driver version " + String(driver_version));
403  }
404  else {
405  dbg->DbgPrint(DBG_KERNEL, DBG_ERROR, "SFM fatal: Getting driver version failed");
406  return false;
407  }
408 
409  int16_t error;
410 
411  /* Reset all I2C devices */
413  if (error) {
414  dbg->DbgPrint(DBG_KERNEL, DBG_ERROR, "General call reset failed");
415  return false;
416  }
417  /* Wait for the SFM3019 to initialize */
419 
420  uint32_t timeout = millis();
421  while (sfm3019_probe()) {
422  dbg->DbgPrint(DBG_KERNEL, DBG_ERROR, "SFM sensor probing failed");
423  if (millis() - timeout > 1000)
424  return false;
425  hwi->__delay_blocking_ms(10);
426  }
427 
428  uint32_t product_number = 0;
429  uint8_t serial_number[8] = {};
431  &product_number, &serial_number);
432  if (error) {
433  dbg->DbgPrint(DBG_KERNEL, DBG_ERROR, "Failed to read product identifier");
434  return false;
435  }
436  else {
437  dbg->DbgPrint(DBG_KERNEL, DBG_WARNING, "Product: " + String(product_number));
438  for (size_t i = 0; i < 8; ++i) {
439  dbg->DbgPrint(DBG_KERNEL, DBG_WARNING, String(serial_number[i]));
440  }
441  }
442 
443  hwi->__delay_blocking_ms(1000);
445 
448  if (error) {
449  dbg->DbgPrint(DBG_KERNEL, DBG_ERROR, "Failed to start measurement");
450  }
451 
452  /* Wait for the first measurement to be available. Wait for
453  * SFM3019_MEASUREMENT_WARM_UP_TIME_US instead for more reliable results */
454  hwi->__delay_blocking_ms(100);
455 
456  _initialized = true;
457  return true;
458 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetIntegral()

void SensorSFM3019::ResetIntegral ( )

Definition at line 494 of file driver_SFM3019.cpp.

495 {
496  Integral = 0;
497 }
Here is the caller graph for this function:

◆ sensirion_common_check_crc()

int8_t SensorSFM3019::sensirion_common_check_crc ( uint8_t *  data,
uint16_t  count,
uint8_t  checksum 
)
private

Definition at line 97 of file driver_SFM3019.cpp.

98  {
99  if (sensirion_common_generate_crc(data, count) != checksum)
100  return STATUS_FAIL;
101  return STATUS_OK;
102 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_common_generate_crc()

uint8_t SensorSFM3019::sensirion_common_generate_crc ( uint8_t *  data,
uint16_t  count 
)
private

Definition at line 79 of file driver_SFM3019.cpp.

79  {
80  uint16_t current_byte;
81  uint8_t crc = CRC8_INIT;
82  uint8_t crc_bit;
83 
84  /* calculates 8-Bit checksum with given polynomial */
85  for (current_byte = 0; current_byte < count; ++current_byte) {
86  crc ^= (data[current_byte]);
87  for (crc_bit = 8; crc_bit > 0; --crc_bit) {
88  if (crc & 0x80)
89  crc = (crc << 1) ^ CRC8_POLYNOMIAL;
90  else
91  crc = (crc << 1);
92  }
93  }
94  return crc;
95 }
Here is the caller graph for this function:

◆ sensirion_fill_cmd_send_buf()

uint16_t SensorSFM3019::sensirion_fill_cmd_send_buf ( uint8_t *  buf,
uint16_t  cmd,
const uint16_t *  args,
uint8_t  num_args 
)
private

sensirion_fill_cmd_send_buf() - create the i2c send buffer for a command and a set of argument words. The output buffer interleaves argument words with their checksums. @buf: The generated buffer to send over i2c. Then buffer length must be at least SENSIRION_COMMAND_LEN + num_args * (SENSIRION_WORD_SIZE + CRC8_LEN). @cmd: The i2c command to send. It already includes a checksum. @args: The arguments to the command. Can be NULL if none. @num_args: The number of word arguments in args.

Returns
The number of bytes written to buf

Definition at line 110 of file driver_SFM3019.cpp.

111  {
112  uint8_t crc;
113  uint8_t i;
114  uint16_t idx = 0;
115 
116  buf[idx++] = (uint8_t)((cmd & 0xFF00) >> 8);
117  buf[idx++] = (uint8_t)((cmd & 0x00FF) >> 0);
118 
119  for (i = 0; i < num_args; ++i) {
120  buf[idx++] = (uint8_t)((args[i] & 0xFF00) >> 8);
121  buf[idx++] = (uint8_t)((args[i] & 0x00FF) >> 0);
122 
123  crc = sensirion_common_generate_crc((uint8_t*)&buf[idx - 2],
125  buf[idx++] = crc;
126  }
127  return idx;
128 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_delayed_read_cmd()

int16_t SensorSFM3019::sensirion_i2c_delayed_read_cmd ( uint8_t  address,
uint16_t  cmd,
uint32_t  delay_us,
uint16_t *  data_words,
uint16_t  num_words 
)
private

sensirion_i2c_delayed_read_cmd() - send a command, wait for the sensor to process and read data back @address: Sensor i2c address @cmd: Command @delay: Time in microseconds to delay sending the read request @data_words: Allocated buffer to store the read data @num_words: Data words to read (without CRC bytes)

Returns
STATUS_OK on success, an error code otherwise

Definition at line 190 of file driver_SFM3019.cpp.

192  {
193  int16_t ret;
194  uint8_t buf[SENSIRION_COMMAND_SIZE];
195 
196  sensirion_fill_cmd_send_buf(buf, cmd, NULL, 0);
197  ret = sensirion_i2c_write(address, buf, SENSIRION_COMMAND_SIZE);
198  if (ret != STATUS_OK)
199  return ret;
200 
201  if (delay_us)
202  sensirion_sleep_usec(delay_us);
203 
204  return sensirion_i2c_read_words(address, data_words, num_words);
205 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_general_call_reset()

int16_t SensorSFM3019::sensirion_i2c_general_call_reset ( void  )
private

Send a general call reset.

Warning
This will reset all attached I2C devices on the bus which support general call reset.
Returns
STATUS_OK on success, an error code otherwise

Definition at line 104 of file driver_SFM3019.cpp.

104  {
105  const uint8_t data = 0x06;
106  hwi->I2CWrite(IIC_GENERAL_CALL_SENSIRION, (uint8_t *)&data, (uint16_t)sizeof(data), true);
107  return 0;
108 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_init()

void SensorSFM3019::sensirion_i2c_init ( void  )
private

Initialize all hard- and software components that are needed for the I2C communication.

◆ sensirion_i2c_read()

int8_t SensorSFM3019::sensirion_i2c_read ( uint8_t  address,
uint8_t *  data,
uint16_t  count 
)
private

Execute one read transaction on the I2C bus, reading a given number of bytes. If the device does not acknowledge the read command, an error shall be returned.

Parameters
address7-bit I2C address to read from
datapointer to the buffer where the data is to be stored
countnumber of bytes to read from I2C and store in the buffer
Returns
0 on success, error code otherwise

Definition at line 216 of file driver_SFM3019.cpp.

216  {
217  uint8_t readData[32];
218  uint8_t rxByteCount = 0;
219 
220 
221  hwi->I2CRead(i2c_device, readData, count,true);
222 
223  memcpy(data, readData, count);
224 
225  return 0;
226 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_read_cmd()

int16_t SensorSFM3019::sensirion_i2c_read_cmd ( uint8_t  address,
uint16_t  cmd,
uint16_t *  data_words,
uint16_t  num_words 
)
private

sensirion_i2c_read_cmd() - reads data words from the sensor after a command is issued @address: Sensor i2c address @cmd: Command @data_words: Allocated buffer to store the read data @num_words: Data words to read (without CRC bytes)

Returns
STATUS_OK on success, an error code otherwise

Definition at line 207 of file driver_SFM3019.cpp.

208  {
209  return sensirion_i2c_delayed_read_cmd(address, cmd, 0, data_words,
210  num_words);
211 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_read_words()

int16_t SensorSFM3019::sensirion_i2c_read_words ( uint8_t  address,
uint16_t *  data_words,
uint16_t  num_words 
)
private

sensirion_i2c_read_words() - read data words from sensor

@address: Sensor i2c address @data_words: Allocated buffer to store the read words. The buffer may also have been modified on STATUS_FAIL return. @num_words: Number of data words to read (without CRC bytes)

Returns
STATUS_OK on success, an error code otherwise

Definition at line 157 of file driver_SFM3019.cpp.

158  {
159  int16_t ret;
160  uint8_t i;
161 
162  ret = sensirion_i2c_read_words_as_bytes(address, (uint8_t*)data_words,
163  num_words);
164  if (ret != STATUS_OK)
165  return ret;
166 
167  for (i = 0; i < num_words; ++i)
168  data_words[i] = be16_to_cpu(data_words[i]);
169 
170  return STATUS_OK;
171 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_read_words_as_bytes()

int16_t SensorSFM3019::sensirion_i2c_read_words_as_bytes ( uint8_t  address,
uint8_t *  data,
uint16_t  num_words 
)
private

sensirion_i2c_read_words_as_bytes() - read data words as byte-stream from sensor

Read bytes without adjusting values to the uP's word-order.

@address: Sensor i2c address @data: Allocated buffer to store the read bytes. The buffer may also have been modified on STATUS_FAIL return. @num_words: Number of data words(!) to read (without CRC bytes) Since only word-chunks can be read from the sensor the size is still specified in sensor-words (num_words = num_bytes * SENSIRION_WORD_SIZE)

Returns
STATUS_OK on success, an error code otherwise

Definition at line 130 of file driver_SFM3019.cpp.

131  {
132  int16_t ret;
133  uint16_t i, j;
134  uint16_t size = num_words * (SENSIRION_WORD_SIZE + CRC8_LEN);
135  uint16_t word_buf[SENSIRION_MAX_BUFFER_WORDS];
136  uint8_t* const buf8 = (uint8_t*)word_buf;
137 
138  ret = sensirion_i2c_read(address, buf8, size);
139  if (ret != STATUS_OK)
140  return ret;
141 
142  /* check the CRC for each word */
143  for (i = 0, j = 0; i < size; i += SENSIRION_WORD_SIZE + CRC8_LEN) {
144 
146  buf8[i + SENSIRION_WORD_SIZE]);
147  if (ret != STATUS_OK)
148  return ret;
149 
150  data[j++] = buf8[i];
151  data[j++] = buf8[i + 1];
152  }
153 
154  return STATUS_OK;
155 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_release()

void SensorSFM3019::sensirion_i2c_release ( void  )
private

Release all resources initialized by sensirion_i2c_init().

◆ sensirion_i2c_select_bus()

int16_t SensorSFM3019::sensirion_i2c_select_bus ( uint8_t  bus_idx)
private

Select the current i2c bus by index. All following i2c operations will be directed at that bus.

THE IMPLEMENTATION IS OPTIONAL ON SINGLE-BUS SETUPS (all sensors on the same bus)

Parameters
bus_idxBus index to select
Returns
0 on success, an error code otherwise

◆ sensirion_i2c_write()

int8_t SensorSFM3019::sensirion_i2c_write ( uint8_t  address,
const uint8_t *  data,
uint16_t  count 
)
private

Execute one write transaction on the I2C bus, sending a given number of bytes. The bytes in the supplied buffer must be sent to the given address. If the slave device does not acknowledge any of the bytes, an error shall be returned.

Parameters
address7-bit I2C address to write to
datapointer to the buffer containing the data to write
countnumber of bytes to read from the buffer and send over I2C
Returns
0 on success, error code otherwise

Definition at line 228 of file driver_SFM3019.cpp.

229  {
230 
231 
232  hwi->I2CWrite(i2c_device, (uint8_t*)data, count, true);
233 
234 
235  return 0;
236 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_write_cmd()

int16_t SensorSFM3019::sensirion_i2c_write_cmd ( uint8_t  address,
uint16_t  command 
)
private

sensirion_i2c_write_cmd() - writes a command to the sensor @address: Sensor i2c address @command: Sensor command

Returns
STATUS_OK on success, an error code otherwise

Definition at line 173 of file driver_SFM3019.cpp.

173  {
174  uint8_t buf[SENSIRION_COMMAND_SIZE];
175 
176  sensirion_fill_cmd_send_buf(buf, command, NULL, 0);
177  return sensirion_i2c_write(address, buf, SENSIRION_COMMAND_SIZE);
178 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_i2c_write_cmd_with_args()

int16_t SensorSFM3019::sensirion_i2c_write_cmd_with_args ( uint8_t  address,
uint16_t  command,
const uint16_t *  data_words,
uint16_t  num_words 
)
private

sensirion_i2c_write_cmd_with_args() - writes a command with arguments to the sensor @address: Sensor i2c address @command: Sensor command @data: Argument buffer with words to send @num_words: Number of data words to send (without CRC bytes)

Returns
STATUS_OK on success, an error code otherwise

Definition at line 180 of file driver_SFM3019.cpp.

182  {
183  uint8_t buf[SENSIRION_MAX_BUFFER_WORDS];
184  uint16_t buf_size;
185 
186  buf_size = sensirion_fill_cmd_send_buf(buf, command, data_words, num_words);
187  return sensirion_i2c_write(address, buf, buf_size);
188 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensirion_sleep_usec()

void SensorSFM3019::sensirion_sleep_usec ( uint32_t  useconds)
private

Sleep for a given number of microseconds. The function should delay the execution approximately, but no less than, the given time.

When using hardware i2c: Despite the unit, a <10 millisecond precision is sufficient.

When using software i2c: The precision needed depends on the desired i2c frequency, i.e. should be exact to about half a clock cycle (defined in SENSIRION_I2C_CLOCK_PERIOD_USEC in sensirion_arch_config.h).

Example with 400kHz requires a precision of 1 / (2 * 400kHz) == 1.25usec.

Parameters
usecondsthe sleep time in microseconds

Sleep for a given number of microseconds. The function should delay the execution for at least the given time, but may also sleep longer.

Parameters
usecondsthe sleep time in microseconds

Definition at line 244 of file driver_SFM3019.cpp.

244  {
245  hwi->__delay_blocking_ms((useconds / 1000) + 1);
246 }
Here is the caller graph for this function:

◆ sfm3019_create()

SfmConfig SensorSFM3019::sfm3019_create ( void  )
private

Create a new SFM3019 instance

Definition at line 378 of file driver_SFM3019.cpp.

378  {
379  SfmConfig sfm_config = {
380  i2c_address,
381  0,
382  0,
383  };
384  return sfm_config;
385 }
Here is the caller graph for this function:

◆ sfm3019_probe()

int16_t SensorSFM3019::sfm3019_probe ( void  )
private

Detects if a sensor is connected by reading out the ID register. If the sensor does not answer or if the answer is not the expected value, the test fails.

Returns
0 if a sensor was detected

Definition at line 374 of file driver_SFM3019.cpp.

374  {
376 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_convert_flow_float()

int16_t SensorSFM3019::sfm_common_convert_flow_float ( const SfmConfig sfm_config,
int16_t  flow_raw,
float *  flow 
)
private

Convert the raw flow ticks to slm.

Parameters
sfm_configPointer to the SFM object
flow_rawFlow value as read by sfm_common_read_measurement_raw
flowOut parameter to store the converted flow
Returns
0 on success, an error code otherwise

Definition at line 316 of file driver_SFM3019.cpp.

317  {
318  if (sfm_config->flow_scale == 0) {
319  return -1;
320  }
321 
322  *flow =
323  (flow_raw - sfm_config->flow_offset) / (float)(sfm_config->flow_scale);
324 
325  return 0;
326 }
Here is the caller graph for this function:

◆ sfm_common_convert_temperature_float()

float SensorSFM3019::sfm_common_convert_temperature_float ( int16_t  temperature_raw)
private

Convert the raw temperature ticks to degree Celsius.

Parameters
temperature_rawTemperature value as read by sfm_common_read_measurement_raw
Returns
The temperature in degree Celsius

Definition at line 328 of file driver_SFM3019.cpp.

328  {
329  return temperature_raw / 200.0f;
330 }
Here is the caller graph for this function:

◆ sfm_common_get_driver_version()

const char * SensorSFM3019::sfm_common_get_driver_version ( void  )
private

Return the driver version

Returns
Driver version string

Definition at line 249 of file driver_SFM3019.cpp.

249  {
250  return SFM_DRV_VERSION_STR;
251 }
Here is the caller graph for this function:

◆ sfm_common_probe()

int16_t SensorSFM3019::sfm_common_probe ( uint8_t  i2c_address)
private

Detects if a sensor is connected by reading out the ID register. If the sensor does not answer or if the answer is not the expected value, the test fails.

Parameters
i2c_addressI2C address to probe
Returns
0 if a sensor was detected

Definition at line 253 of file driver_SFM3019.cpp.

253  {
254  uint16_t buf[6];
256  buf, 6);
257 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_read_measurement_raw()

int16_t SensorSFM3019::sfm_common_read_measurement_raw ( const SfmConfig sfm_config,
int16_t *  flow_raw,
int16_t *  temperature_raw,
uint16_t *  status 
)
private

Read results of a continuous measurement

Parameters
sfm_configPointer to the SFM object
flow_rawOut parameter for the raw flow value
temperature_rawOut parameter for the raw temperature value
statusOut parameter for the status word
Returns
0 on success, an error code otherwise

Definition at line 345 of file driver_SFM3019.cpp.

348  {
349  uint16_t buf[3] = {};
350  int16_t error = sensirion_i2c_read_words(sfm_config->i2c_address, buf, 3);
351  if (error) {
352  return error;
353  }
354  if (flow_raw) {
355  *flow_raw = (int16_t)buf[0];
356  }
357  if (temperature_raw) {
358  *temperature_raw = (int16_t)buf[1];
359  }
360  if (status) {
361  *status = buf[2];
362  }
363  return 0;
364 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_read_product_identifier()

int16_t SensorSFM3019::sfm_common_read_product_identifier ( uint8_t  i2c_address,
uint32_t *  product_number,
uint8_t(*)  serial_number[8] 
)
private

Read the product identifier, consisting of a product number and a serial number.

Parameters
i2c_addressI2C address to read the product identifier from
product_numberOut parameter to store the product number
serial_numberOut parameter to store the serial number in raw byte format
Returns
0 on success, an error code otherwise

Definition at line 259 of file driver_SFM3019.cpp.

261  {
262  uint8_t buf[6 * 2];
263  int16_t error =
265  if (error) {
266  return error;
267  }
269  if (error) {
270  return error;
271  }
272  if (product_number) {
273  *product_number = ((uint32_t)buf[0] << 24) + ((uint32_t)buf[1] << 16) +
274  ((uint32_t)buf[2] << 8) + (uint32_t)buf[3];
275  }
276  if (serial_number) {
277  for (size_t i = 0; i < 8; ++i) {
278  (*serial_number)[i] = buf[i + 4];
279  }
280  }
281  return 0;
282 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_read_scale_factor_offset_and_unit()

int16_t SensorSFM3019::sfm_common_read_scale_factor_offset_and_unit ( const SfmConfig sfm_config,
SfmCmdStartContinuousMeasurement  measurement_cmd,
int16_t *  flow_scale,
int16_t *  flow_offset,
uint16_t *  unit 
)
private

Read the scale factor, offset and unit for the given measurement type.

Parameters
sfm_configPointer to the SFM object
measurement_cmdMeasurement type to get the scale, offset and unit
flow_scaleOut parameter to store the flow scale
flow_offsetOut parameter to store the flow offset
unitOut parameter to store the unit
Returns
0 on success, an error code otherwise

Definition at line 284 of file driver_SFM3019.cpp.

287  {
288 
289  uint16_t measurement_cmd_word = (uint16_t)measurement_cmd;
290 
291  uint16_t buf[3];
292  int16_t error = sensirion_i2c_write_cmd_with_args(
294  &measurement_cmd_word, 1);
295  if (error) {
296  return error;
297  }
298  error =
299  sensirion_i2c_read_words(sfm_config->i2c_address, buf, ARRAY_SIZE(buf));
300 
301  if (error) {
302  return error;
303  }
304  if (flow_scale) {
305  *flow_scale = (int16_t)buf[0];
306  }
307  if (flow_offset) {
308  *flow_offset = (int16_t)buf[1];
309  }
310  if (unit) {
311  *unit = buf[2];
312  }
313  return 0;
314 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_start_continuous_measurement()

int16_t SensorSFM3019::sfm_common_start_continuous_measurement ( SfmConfig sfm_config,
SfmCmdStartContinuousMeasurement  measurement_cmd 
)
private

Starts a continuous measurement with the given gas configuration.

Parameters
sfm_configPointer to the SFM object
measurement_cmdSelect which gas or gas mix should be measured
Returns
0 on success, an error code otherwise

Definition at line 332 of file driver_SFM3019.cpp.

333  {
334 
336  sfm_config, measurement_cmd, &sfm_config->flow_scale,
337  &sfm_config->flow_offset, NULL);
338  if (error) {
339  return error;
340  }
341 
342  return sensirion_i2c_write_cmd(sfm_config->i2c_address, measurement_cmd);
343 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfm_common_stop_continuous_measurement()

int16_t SensorSFM3019::sfm_common_stop_continuous_measurement ( SfmConfig sfm_config)
private

Stops a continuous measurement.

Parameters
sfm_configPointer to the SFM object
Returns
0 on success, an error code otherwise

Definition at line 366 of file driver_SFM3019.cpp.

366  {
367  sfm_config->flow_scale = 0;
368  sfm_config->flow_offset = 0;
369  return sensirion_i2c_write_cmd(sfm_config->i2c_address,
371 }
Here is the call graph for this function:

Member Data Documentation

◆ _initialized

bool SensorSFM3019::_initialized = false
private

Definition at line 52 of file driver_SFM3019.h.

◆ dbg

DebugIfaceClass* SensorSFM3019::dbg
private

Definition at line 49 of file driver_SFM3019.h.

◆ hwi

HW* SensorSFM3019::hwi
private

Definition at line 48 of file driver_SFM3019.h.

◆ i2c_address

uint8_t SensorSFM3019::i2c_address
private

Definition at line 44 of file driver_SFM3019.h.

◆ i2c_device

t_i2cdevices SensorSFM3019::i2c_device
private

Definition at line 45 of file driver_SFM3019.h.

◆ Integral

float SensorSFM3019::Integral
private

Definition at line 51 of file driver_SFM3019.h.

◆ sfm3019

SfmConfig SensorSFM3019::sfm3019
private

Definition at line 361 of file driver_SFM3019.h.


The documentation for this class was generated from the following files:
SFM3019_CMD_START_CONTINUOUS_MEASUREMENT_AIR
#define SFM3019_CMD_START_CONTINUOUS_MEASUREMENT_AIR
Definition: driver_SFM3019.cpp:15
DriverContext::dbg
DebugIfaceClass * dbg
Definition: DriverContext.h:7
SensorSFM3019::sensirion_i2c_write
int8_t sensirion_i2c_write(uint8_t address, const uint8_t *data, uint16_t count)
Definition: driver_SFM3019.cpp:228
DBG_INFO
@ DBG_INFO
Definition: DebugIface.h:21
HW_V4::I2CRead
bool I2CRead(t_i2cdevices device, uint8_t *wbuffer, int wlength, uint8_t *rbuffer, int rlength, bool stop)
Write buffer to I2C bus and read data.
Definition: fw_board_ni_v4.cpp:182
SensorSFM3019::i2c_address
uint8_t i2c_address
Definition: driver_SFM3019.h:44
SensorSFM3019::sfm_common_get_driver_version
const char * sfm_common_get_driver_version(void)
Definition: driver_SFM3019.cpp:249
SFM_DRV_VERSION_STR
const char * SFM_DRV_VERSION_STR
Definition: driver_SFM3019.cpp:76
SensorSFM3019::sensirion_common_check_crc
int8_t sensirion_common_check_crc(uint8_t *data, uint16_t count, uint8_t checksum)
Definition: driver_SFM3019.cpp:97
SensorSFM3019::i2c_device
t_i2cdevices i2c_device
Definition: driver_SFM3019.h:45
DriverContext
Definition: DriverContext.h:5
SensorSFM3019::sfm_common_convert_temperature_float
float sfm_common_convert_temperature_float(int16_t temperature_raw)
Definition: driver_SFM3019.cpp:328
CRC8_LEN
#define CRC8_LEN
Definition: driver_SFM3019.cpp:60
SensorSFM3019::_initialized
bool _initialized
Definition: driver_SFM3019.h:52
SensorSFM3019::sfm_common_convert_flow_float
int16_t sfm_common_convert_flow_float(const SfmConfig *sfm_config, int16_t flow_raw, float *flow)
Definition: driver_SFM3019.cpp:316
SensorSFM3019::sensirion_i2c_read_words_as_bytes
int16_t sensirion_i2c_read_words_as_bytes(uint8_t address, uint8_t *data, uint16_t num_words)
Definition: driver_SFM3019.cpp:130
SensorSFM3019::Integral
float Integral
Definition: driver_SFM3019.h:51
HW_V4::I2CWrite
bool I2CWrite(t_i2cdevices device, uint8_t *wbuffer, int wlength, bool stop)
Write buffer to I2C bus.
Definition: fw_board_ni_v4.cpp:145
SensorSFM3019::sensirion_common_generate_crc
uint8_t sensirion_common_generate_crc(uint8_t *data, uint16_t count)
Definition: driver_SFM3019.cpp:79
SFM_CMD_READ_PRODUCT_IDENTIFIER
#define SFM_CMD_READ_PRODUCT_IDENTIFIER
Definition: driver_SFM3019.cpp:68
STATUS_FAIL
#define STATUS_FAIL
Definition: driver_SFM3019.cpp:25
SFM_CMD_STOP_CONTINUOUS_MEASUREMENT
#define SFM_CMD_STOP_CONTINUOUS_MEASUREMENT
Definition: driver_SFM3019.cpp:72
DBG_ERROR
@ DBG_ERROR
Definition: DebugIface.h:19
SensorSFM3019::sfm_common_start_continuous_measurement
int16_t sfm_common_start_continuous_measurement(SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd)
Definition: driver_SFM3019.cpp:332
SensorSFM3019::sensirion_i2c_write_cmd
int16_t sensirion_i2c_write_cmd(uint8_t address, uint16_t command)
Definition: driver_SFM3019.cpp:173
CRC8_INIT
#define CRC8_INIT
Definition: driver_SFM3019.cpp:59
SensorSFM3019::sensirion_i2c_general_call_reset
int16_t sensirion_i2c_general_call_reset(void)
Definition: driver_SFM3019.cpp:104
SfmConfig::flow_offset
int16_t flow_offset
Definition: driver_SFM3019.h:15
SENSIRION_WORD_SIZE
#define SENSIRION_WORD_SIZE
Definition: driver_SFM3019.cpp:63
SfmConfig::i2c_address
uint8_t i2c_address
Definition: driver_SFM3019.h:13
SensorSFM3019::sensirion_i2c_write_cmd_with_args
int16_t sensirion_i2c_write_cmd_with_args(uint8_t address, uint16_t command, const uint16_t *data_words, uint16_t num_words)
Definition: driver_SFM3019.cpp:180
SensorSFM3019::sensirion_i2c_read
int8_t sensirion_i2c_read(uint8_t address, uint8_t *data, uint16_t count)
Definition: driver_SFM3019.cpp:216
SensorSFM3019::sfm_common_read_product_identifier
int16_t sfm_common_read_product_identifier(uint8_t i2c_address, uint32_t *product_number, uint8_t(*serial_number)[8])
Definition: driver_SFM3019.cpp:259
SensorSFM3019::sfm_common_probe
int16_t sfm_common_probe(uint8_t i2c_address)
Definition: driver_SFM3019.cpp:253
SensorSFM3019::sensirion_fill_cmd_send_buf
uint16_t sensirion_fill_cmd_send_buf(uint8_t *buf, uint16_t cmd, const uint16_t *args, uint8_t num_args)
Definition: driver_SFM3019.cpp:110
SENSIRION_MAX_BUFFER_WORDS
#define SENSIRION_MAX_BUFFER_WORDS
Definition: driver_SFM3019.cpp:65
SensorSFM3019::sfm_common_read_scale_factor_offset_and_unit
int16_t sfm_common_read_scale_factor_offset_and_unit(const SfmConfig *sfm_config, SfmCmdStartContinuousMeasurement measurement_cmd, int16_t *flow_scale, int16_t *flow_offset, uint16_t *unit)
Definition: driver_SFM3019.cpp:284
DriverContext::hwi
HW * hwi
Definition: DriverContext.h:6
SENSIRION_COMMAND_SIZE
#define SENSIRION_COMMAND_SIZE
Definition: driver_SFM3019.cpp:62
SensorSFM3019::sfm3019_probe
int16_t sfm3019_probe(void)
Definition: driver_SFM3019.cpp:374
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition: driver_SFM3019.cpp:55
HW_V4
Driver for the Nuclear Instruments V4 Hardware Board.
Definition: fw_board_ni_v4.h:23
SFM3019_SOFT_RESET_TIME_US
#define SFM3019_SOFT_RESET_TIME_US
Definition: driver_SFM3019.cpp:20
SfmConfig
Definition: driver_SFM3019.h:12
SensorSFM3019::hwi
HW * hwi
Definition: driver_SFM3019.h:48
SensorSFM3019::sfm3019_create
SfmConfig sfm3019_create(void)
Definition: driver_SFM3019.cpp:378
SensorSFM3019::sensirion_i2c_read_words
int16_t sensirion_i2c_read_words(uint8_t address, uint16_t *data_words, uint16_t num_words)
Definition: driver_SFM3019.cpp:157
CRC8_POLYNOMIAL
#define CRC8_POLYNOMIAL
Definition: driver_SFM3019.cpp:58
DBG_KERNEL
@ DBG_KERNEL
Definition: DebugIface.h:25
DebugIfaceClass::DbgPrint
void DbgPrint(dbg_source source, verbose_level vl, String s)
Print a message on the debug console.
Definition: DebugIface.cpp:40
SensorSFM3019::dbg
DebugIfaceClass * dbg
Definition: driver_SFM3019.h:49
SfmConfig::flow_scale
int16_t flow_scale
Definition: driver_SFM3019.h:14
SensorSFM3019::sensirion_i2c_read_cmd
int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd, uint16_t *data_words, uint16_t num_words)
Definition: driver_SFM3019.cpp:207
DebugIfaceClass
Debug class: this class print debug message.
Definition: DebugIface.h:38
DBG_WARNING
@ DBG_WARNING
Definition: DebugIface.h:20
SensorSFM3019::sensirion_sleep_usec
void sensirion_sleep_usec(uint32_t useconds)
Definition: driver_SFM3019.cpp:244
SFM_CMD_READ_SCALE_FACTOR_OFFSET_AND_FLOW_UNIT
#define SFM_CMD_READ_SCALE_FACTOR_OFFSET_AND_FLOW_UNIT
Definition: driver_SFM3019.cpp:70
be16_to_cpu
#define be16_to_cpu(s)
Definition: driver_SFM3019.cpp:35
SensorSFM3019::sfm3019
SfmConfig sfm3019
Definition: driver_SFM3019.h:361
STATUS_OK
#define STATUS_OK
Definition: driver_SFM3019.cpp:24
IIC_GENERAL_CALL_SENSIRION
@ IIC_GENERAL_CALL_SENSIRION
Definition: generic_definitions.h:49
SensorSFM3019::sensirion_i2c_delayed_read_cmd
int16_t sensirion_i2c_delayed_read_cmd(uint8_t address, uint16_t cmd, uint32_t delay_us, uint16_t *data_words, uint16_t num_words)
Definition: driver_SFM3019.cpp:190
SensorSFM3019::sfm_common_read_measurement_raw
int16_t sfm_common_read_measurement_raw(const SfmConfig *sfm_config, int16_t *flow_raw, int16_t *temperature_raw, uint16_t *status)
Definition: driver_SFM3019.cpp:345