42#define CHIP_NAME "ASAIR AOX4000"
43#define MANUFACTURER_NAME "ASAIR"
44#define SUPPLY_VOLTAGE_MIN 4.75f
45#define SUPPLY_VOLTAGE_MAX 5.25f
46#define MAX_CURRENT 32.0f
47#define TEMPERATURE_MIN -30.0f
48#define TEMPERATURE_MAX 60.0f
49#define DRIVER_VERSION 1000
54#define AOX4000_COMMAND_MODE "M"
55#define AOX4000_COMMAND_OXYGEN_PPO2 "O"
56#define AOX4000_COMMAND_OXYGEN_DENSITY "%"
57#define AOX4000_COMMAND_TEMPERATURE "T"
58#define AOX4000_COMMAND_PRESSURE "P"
59#define AOX4000_COMMAND_ALL "A"
60#define AOX4000_COMMAND_ERROR "E"
76static uint8_t a_aox4000_write_read(
aox4000_handle_t *handle,
char *input, uint16_t input_len,
char *output, uint16_t *output_len)
85 res = handle->
uart_write((uint8_t *)input, input_len);
91 *output_len = handle->
uart_read((uint8_t *)output, *output_len);
108static uint8_t a_aox4000_read(
aox4000_handle_t *handle,
char *output, uint16_t *output_len)
118 *output_len = handle->
uart_read((uint8_t *)output, *output_len);
135static uint8_t aox4000_parse_mode(
aox4000_handle_t *handle,
char *input, uint8_t *mode)
141 memset(buf, 0,
sizeof(
char) * 8);
145 *mode = (uint8_t)atoi(buf);
153 memset(buf, 0,
sizeof(
char) * 8);
178static uint8_t aox4000_parse_number(
aox4000_handle_t *handle,
const char *command,
char *input,
float *number)
180 if (strstr(input, command) != NULL)
185 memset(buf, 0,
sizeof(
char) * 16);
186 for (i = 0; i < 15; i++)
188 if (((input[2 + i] >=
'0') &&
189 (input[2 + i] <=
'9')) ||
190 (input[2 + i] ==
'.') ||
191 (input[2 + i] ==
'+') ||
192 (input[2 + i] ==
'-'))
194 buf[i] = input[2 + i];
202 *number = (float)atof(buf);
210 memset(buf, 0,
sizeof(
char) * 8);
238static uint8_t aox4000_parse_data(
aox4000_handle_t *handle,
char *input,
float *oxygen_ppo2_mbar,
239 float *oxygen_density_percentage,
float *temperature_degree,
float *pressure_mbar)
248 memset(buf, 0,
sizeof(
char) * 8);
260 p, oxygen_ppo2_mbar);
275 p, oxygen_density_percentage);
290 p, temperature_degree);
343 handle->
debug_print(
"aox4000: uart_init is null.\n");
349 handle->
debug_print(
"aox4000: uart_deinit is null.\n");
355 handle->
debug_print(
"aox4000: uart_read is null.\n");
361 handle->
debug_print(
"aox4000: uart_write is null.\n");
367 handle->
debug_print(
"aox4000: uart_flush is null.\n");
373 handle->
debug_print(
"aox4000: delay_ms is null.\n");
380 handle->
debug_print(
"aox4000: uart init failed.\n");
413 handle->
debug_print(
"aox4000: uart deinit failed.\n");
479 memset(input, 0,
sizeof(
char) * 16);
480 memset(output, 0,
sizeof(
char) * 16);
485 memset(input, 0,
sizeof(
char) * 16);
486 memset(output, 0,
sizeof(
char) * 16);
491 res = a_aox4000_write_read(handle, input, input_len, output, &output_len);
494 handle->
debug_print(
"aox4000: uart write read failed.\n");
500 handle->
debug_print(
"aox4000: response error failed..\n");
504 res = aox4000_parse_mode(handle, output, buf);
507 handle->
debug_print(
"aox4000: response error failed.\n");
511 if (buf[0] != (uint8_t)(mode))
513 handle->
debug_print(
"aox4000: response error failed.\n");
517 handle->
mode = (uint8_t)(mode);
551 memset(input, 0,
sizeof(
char) * 16);
552 memset(output, 0,
sizeof(
char) * 16);
556 res = a_aox4000_write_read(handle, input, input_len, output, &output_len);
559 handle->
debug_print(
"aox4000: uart write read failed.\n");
563 res = aox4000_parse_mode(handle, output, buf);
566 handle->
debug_print(
"aox4000: response error failed.\n");
572 handle->
debug_print(
"aox4000: response error failed..\n");
576 if ((buf[0] == 0) || (buf[0] == 1))
584 handle->
debug_print(
"aox4000: response error failed.\n");
605 float *oxygen_density_percentage,
606 float *temperature_degree,
float *pressure_mbar)
625 res = a_aox4000_read(handle, output, &output_len);
628 handle->
debug_print(
"aox4000: uart read failed.\n");
634 handle->
debug_print(
"aox4000: response error failed..\n");
638 res = aox4000_parse_data(handle, output,
639 oxygen_ppo2_mbar, oxygen_density_percentage,
640 temperature_degree, pressure_mbar);
657 memset(input, 0,
sizeof(
char) * 16);
658 memset(output, 0,
sizeof(
char) * 48);
661 res = a_aox4000_write_read(handle, input, input_len, output, &output_len);
664 handle->
debug_print(
"aox4000: uart write read failed.\n");
670 handle->
debug_print(
"aox4000: response error failed..\n");
674 res = aox4000_parse_data(handle, output,
675 oxygen_ppo2_mbar, oxygen_density_percentage,
676 temperature_degree, pressure_mbar);
716 float oxygen_density_percentage;
717 float temperature_degree;
721 res = a_aox4000_read(handle, output, &output_len);
724 handle->
debug_print(
"aox4000: uart read failed.\n");
730 handle->
debug_print(
"aox4000: response error failed..\n");
734 res = aox4000_parse_data(handle, output,
735 mbar, &oxygen_density_percentage,
736 &temperature_degree, &pressure_mbar);
753 memset(input, 0,
sizeof(
char) * 16);
754 memset(output, 0,
sizeof(
char) * 48);
755 input_len = (uint16_t)snprintf(input, 15,
"%s\r\n",
758 res = a_aox4000_write_read(handle, input, input_len,
759 output, &output_len);
762 handle->
debug_print(
"aox4000: uart write read failed.\n");
768 handle->
debug_print(
"aox4000: response error failed..\n");
813 float oxygen_ppo2_mbar;
814 float temperature_degree;
818 res = a_aox4000_read(handle, output, &output_len);
821 handle->
debug_print(
"aox4000: uart read failed.\n");
827 handle->
debug_print(
"aox4000: response error failed..\n");
831 res = aox4000_parse_data(handle, output,
832 &oxygen_ppo2_mbar, percentage,
833 &temperature_degree, &pressure_mbar);
850 memset(input, 0,
sizeof(
char) * 16);
851 memset(output, 0,
sizeof(
char) * 48);
852 input_len = (uint16_t)snprintf(input, 15,
"%s\r\n",
855 res = a_aox4000_write_read(handle, input, input_len,
856 output, &output_len);
859 handle->
debug_print(
"aox4000: uart write read failed.\n");
865 handle->
debug_print(
"aox4000: response error failed..\n");
910 float oxygen_ppo2_mbar;
911 float oxygen_density_percentage;
912 float temperature_degree;
915 res = a_aox4000_read(handle, output, &output_len);
918 handle->
debug_print(
"aox4000: uart read failed.\n");
924 handle->
debug_print(
"aox4000: response error failed..\n");
928 res = aox4000_parse_data(handle, output,
929 &oxygen_ppo2_mbar, &oxygen_density_percentage,
930 &temperature_degree, mbar);
947 memset(input, 0,
sizeof(
char) * 16);
948 memset(output, 0,
sizeof(
char) * 48);
949 input_len = (uint16_t)snprintf(input, 15,
"%s\r\n",
952 res = a_aox4000_write_read(handle, input, input_len,
953 output, &output_len);
956 handle->
debug_print(
"aox4000: uart write read failed.\n");
962 handle->
debug_print(
"aox4000: response error failed..\n");
1005 uint16_t output_len;
1006 float oxygen_ppo2_mbar;
1007 float oxygen_density_percentage;
1008 float pressure_mbar;
1011 res = a_aox4000_read(handle, output, &output_len);
1014 handle->
debug_print(
"aox4000: uart read failed.\n");
1020 handle->
debug_print(
"aox4000: response error failed..\n");
1024 res = aox4000_parse_data(handle, output,
1025 &oxygen_ppo2_mbar, &oxygen_density_percentage,
1026 degree, &pressure_mbar);
1029 handle->
debug_print(
"aox4000: response error.\n");
1041 uint16_t output_len;
1043 memset(input, 0,
sizeof(
char) * 16);
1044 memset(output, 0,
sizeof(
char) * 48);
1045 input_len = (uint16_t)snprintf(input, 15,
"%s\r\n",
1048 res = a_aox4000_write_read(handle, input, input_len,
1049 output, &output_len);
1052 handle->
debug_print(
"aox4000: uart write read failed.\n");
1058 handle->
debug_print(
"aox4000: response error failed..\n");
1066 handle->
debug_print(
"aox4000: response error.\n");
1100 l = handle->
uart_read((uint8_t *)buf, len);
1103 handle->
debug_print(
"aox4000: uart read failed.\n");
1139 handle->
debug_print(
"aox4000: uart flush failed.\n");
1143 res = handle->
uart_write((uint8_t *)buf, len);
1146 handle->
debug_print(
"aox4000: uart write failed.\n");
#define AOX4000_COMMAND_MODE
chip command definition
#define AOX4000_COMMAND_TEMPERATURE
#define AOX4000_COMMAND_ALL
#define AOX4000_COMMAND_PRESSURE
#define SUPPLY_VOLTAGE_MAX
#define AOX4000_COMMAND_OXYGEN_DENSITY
#define AOX4000_COMMAND_OXYGEN_PPO2
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define AOX4000_COMMAND_ERROR
#define CHIP_NAME
chip information definition
driver aox4000 header file
uint8_t aox4000_read(aox4000_handle_t *handle, float *oxygen_ppo2_mbar, float *oxygen_density_percentage, float *temperature_degree, float *pressure_mbar)
read data
uint8_t aox4000_read_oxygen_density(aox4000_handle_t *handle, float *percentage)
read oxygen density
uint8_t aox4000_info(aox4000_info_t *info)
get chip's information
struct aox4000_handle_s aox4000_handle_t
aox4000 handle structure definition
aox4000_status_t
aox4000 status enumeration definition
uint8_t aox4000_read_temperature(aox4000_handle_t *handle, float *degree)
read temperature
uint8_t aox4000_get_last_error(aox4000_handle_t *handle, aox4000_status_t *status)
get last error
#define AOX4000_UART_DELAY_MS
aox4000 uart delay definition
#define AOX4000_UART_POLL_DELAY_MS
aox4000 uart poll delay definition
uint8_t aox4000_deinit(aox4000_handle_t *handle)
close the chip
aox4000_mode_t
aox4000 mode enumeration definition
uint8_t aox4000_init(aox4000_handle_t *handle)
initialize the chip
struct aox4000_info_s aox4000_info_t
aox4000 information structure definition
uint8_t aox4000_read_oxygen_ppo2(aox4000_handle_t *handle, float *mbar)
read oxygen ppo2
uint8_t aox4000_read_pressure(aox4000_handle_t *handle, float *mbar)
read pressure
uint8_t aox4000_get_mode(aox4000_handle_t *handle, aox4000_mode_t *mode)
get mode
uint8_t aox4000_set_mode(aox4000_handle_t *handle, aox4000_mode_t mode)
set mode
uint8_t aox4000_command_read(aox4000_handle_t *handle, char *buf, uint16_t len)
command read
uint8_t aox4000_command_write(aox4000_handle_t *handle, char *buf, uint16_t len)
command write
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v