LibDriver BA234
Loading...
Searching...
No Matches
driver_ba234_register_test.c
Go to the documentation of this file.
1
36
38
39static ba234_handle_t gs_handle;
40
49{
50 uint8_t res;
51 uint16_t reg;
52 ba234_info_t info;
53 ba234_status_t status;
54
55 /* link interface function */
64
65 /* get ba234 information */
66 res = ba234_info(&info);
67 if (res != 0)
68 {
69 ba234_interface_debug_print("ba234: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print chip information */
76 ba234_interface_debug_print("ba234: chip is %s.\n", info.chip_name);
77 ba234_interface_debug_print("ba234: manufacturer is %s.\n", info.manufacturer_name);
78 ba234_interface_debug_print("ba234: interface is %s.\n", info.interface);
79 ba234_interface_debug_print("ba234: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 ba234_interface_debug_print("ba234: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 ba234_interface_debug_print("ba234: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 ba234_interface_debug_print("ba234: max current is %0.2fmA.\n", info.max_current_ma);
83 ba234_interface_debug_print("ba234: max temperature is %0.1fC.\n", info.temperature_max);
84 ba234_interface_debug_print("ba234: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start register test */
88 ba234_interface_debug_print("ba234: start register test.\n");
89
90 /* ba234 init */
91 res = ba234_init(&gs_handle);
92 if (res != 0)
93 {
94 ba234_interface_debug_print("ba234: init failed.\n");
95
96 return 1;
97 }
98
99 /* ba234_baseline_calibration test */
100 ba234_interface_debug_print("ba234: ba234_baseline_calibration test.\n");
101
102 /* baseline calibration */
103 res = ba234_baseline_calibration(&gs_handle);
104 if (res != 0)
105 {
106 ba234_interface_debug_print("ba234: baseline calibration failed.\n");
107 (void)ba234_deinit(&gs_handle);
108
109 return 1;
110 }
111 ba234_interface_debug_print("ba234: check baseline calibration %s.\n", (res == 0) ? "ok" : "error");
112
113 /* ba234_salinity_calibration test */
114 ba234_interface_debug_print("ba234: ba234_salinity_calibration test.\n");
115
116 /* 1.0 */
117 res = ba234_salinity_convert_to_register(&gs_handle, 1.0f, &reg);
118 if (res != 0)
119 {
120 ba234_interface_debug_print("ba234: salinity convert to register failed.\n");
121 (void)ba234_deinit(&gs_handle);
122
123 return 1;
124 }
125
126 /* salinity calibration */
127 res = ba234_salinity_calibration(&gs_handle, reg);
128 if (res != 0)
129 {
130 ba234_interface_debug_print("ba234: salinity calibration failed.\n");
131 (void)ba234_get_last_status(&gs_handle, &status);
132 ba234_interface_debug_print("ba234: last status is 0x%02X.\n", status);
133 (void)ba234_deinit(&gs_handle);
134
135 return 1;
136 }
137 ba234_interface_debug_print("ba234: check salinity calibration %s.\n", (res == 0) ? "ok" : "error");
138
139 /* ba234_get_last_status test */
140 ba234_interface_debug_print("ba234: ba234_get_last_status test.\n");
141
142 /* get last status */
143 res = ba234_get_last_status(&gs_handle, &status);
144 if (res != 0)
145 {
146 ba234_interface_debug_print("ba234: get last status failed.\n");
147 (void)ba234_deinit(&gs_handle);
148
149 return 1;
150 }
151 ba234_interface_debug_print("ba234: last status is 0x%02X.\n", status);
152
153 /* finish register test */
154 ba234_interface_debug_print("ba234: finish register test.\n");
155 (void)ba234_deinit(&gs_handle);
156
157 return 0;
158}
driver ba234 register test header file
struct ba234_info_s ba234_info_t
ba234 information structure definition
uint8_t ba234_info(ba234_info_t *info)
get chip's information
uint8_t ba234_get_last_status(ba234_handle_t *handle, ba234_status_t *status)
get last status
uint8_t ba234_init(ba234_handle_t *handle)
initialize the chip
uint8_t ba234_deinit(ba234_handle_t *handle)
close the chip
struct ba234_handle_s ba234_handle_t
ba234 handle structure definition
uint8_t ba234_salinity_calibration(ba234_handle_t *handle, uint16_t value)
salinity calibration
uint8_t ba234_baseline_calibration(ba234_handle_t *handle)
baseline calibration
uint8_t ba234_salinity_convert_to_register(ba234_handle_t *handle, float percentage, uint16_t *reg)
convert the salinity to the register raw data
ba234_status_t
ba234 status enumeration definition
uint8_t ba234_interface_uart_flush(void)
interface uart flush
uint16_t ba234_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
void ba234_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ba234_interface_uart_init(void)
interface uart init
void ba234_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ba234_interface_uart_deinit(void)
interface uart deinit
uint8_t ba234_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t ba234_register_test(void)
register test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]