-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlh_l05d.c
183 lines (157 loc) · 4.6 KB
/
dlh_l05d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* @file: dlh_l05d.c
* @brief:
* @author: shaxz
* @created: 2024-04-29 17:40:58
* Copyright 2024 , All Rights Reserved.
*/
/* includes ------------------------------------------------------------------*/
#include "dlh_l05d.h"
/* private marcos ------------------------------------------------------------*/
/* private types -------------------------------------------------------------*/
/* private variables ---------------------------------------------------------*/
/* private functions ---------------------------------------------------------*/
/***
*
* @brief get sensor address
* @return sensor address
*/
unsigned char get_dlh_addr(void)
{
return DLH_L05D_ADRESS;
}
unsigned char set_dlh_sensor_cmd(dlhCmd_e cmd)
{
unsigned char ucRetCmd;
switch(cmd){
case SINGLE :
ucRetCmd = DLH_L05D_SINGLE;
break;
case AVG_2 :
ucRetCmd = DLH_L050_AVG_2;
break;
case AVG_4 :
ucRetCmd = DLH_L050_AVG_4;
break;
case AVG_8 :
ucRetCmd = DLH_L050_AVG_8;
break;
case AVG_16 :
ucRetCmd = DLH_L050_AVG_16;
break;
default:
ucRetCmd = DLH_L05D_ERROR;
break;
}
return ucRetCmd;
}
/***
* @brief
* Status Byte Definition ****************************
* Bit Description **********************************
* Bit 7 [MSB] [Always = 0] *************************
* 6 Power : [1 = Power On] ********************
* 5 Busy: [ 1 = Processing Command, 0 = Ready] *
* 4:3 Mode: [00 = Normal Operation ] **********
* 2 Memory Error [ 1 = EEPROM Checksum Fail] ***
* 1 Sensor Configuration [ always = 0] *********
* Bit 0 [LSB] ALU Error [1 = Error] ***************
* @param sensor_data
* @return DLH_L05D State
*/
unsigned char parseStatusByte(unsigned char ucStatusByte, dlhData_s *data) {
char *cStatusMsg = NULL;
#if DEBUG_ENABLE
char temp_str[50] ={0};
#endif
data->status_s.uiPower = (ucStatusByte & 0x40) >> 6;
#if DEBUG_ENABLE
if(!data->status_s.uiPower){
sprintf(temp_str, "Power: %d\r\n", data->status_s.uiPower);
debug_print(temp_str);
}
#endif
data->status_s.uiBusy = (ucStatusByte & 0x20) >> 5;
#if DEBUG_ENABLE
if(!data->status_s.uiBusy){
sprintf(temp_str, "Busy: %d\r\n", data->status_s.uiBusy);
debug_print(temp_str);
}
#endif
data->status_s.uiMode = (ucStatusByte & 0x18) >> 3;
#if DEBUG_ENABLE
if(data->status_s.uiMode != 0){
sprintf(temp_str, "Mode: %d\r\n", data->status_s.uiMode);
debug_print(temp_str);
}
#endif
data->status_s.uiMemoryError = (ucStatusByte & 0x04) >> 2;
#if DEBUG_ENABLE
if(data->status_s.uiMemoryError != 0) {
sprintf(temp_str, "Memory Error: %d\r\n", data->status_s.uiMemoryError);
debug_print(temp_str);
}
#endif
data->status_s.uiSensorConfig = (ucStatusByte & 0x02) >> 1;
#if DEBUG_ENABLE
if(data->status_s.uiSensorConfig != 0){
sprintf(temp_str, "Sensor Configuration: %d\r\n", data->status_s.uiSensorConfig);
debug_print(temp_str);
}
#endif
data->status_s.uiAluError = ucStatusByte & 0x01;
#if DEBUG_ENABLE
if(data->status_s.uiAluError != 0) {
sprintf(temp_str, "ALU Error: %d\r\n", data->status_s.uiAluError);
debug_print(temp_str);
}
#endif
if (data->status_s.uiMode != 0) {
switch (data->status_s.uiMode) {
case 1:
cStatusMsg = "device in command mode\r\n";
break;
case 2:
cStatusMsg = "stale data\r\n";
break;
case 3:
cStatusMsg = "diagnostic condition\r\n";
break;
default:
break;
}
if (cStatusMsg != NULL) {
#if DEBUG_ENABLE > 0
debug_print(cStatusMsg);
#endif
return DLH_L05D_ERROR;
}
}
return DLH_L05D_OK;
}
/***
* @brief Calculate sensor pressure
*
* @param sensor_data
* @return ABPMANV State
*/
unsigned char calc_dlh_p(signed int siPressureOrg, float *fPressure)
{
if (fPressure == NULL)
return DLH_L05D_ERROR;
*fPressure = 1.25 * ((float)(siPressureOrg - DLH_SENSOR_OSdig) / DLH_SENSOR_MAX_24B) * DLH_SENSOR_FSS;
return DLH_L05D_OK;
}
/***
* @brief Calculate sensor temperature
*
* @param sensor_data
* @return DLH_L05D State
*/
unsigned char calc_dlh_t(signed int siTemperOrg, float *fTemper)
{
if (fTemper == NULL)
return DLH_L05D_ERROR;
*fTemper = ((float)siTemperOrg * DLH_SENSOR_TEMPER_MAX / DLH_SENSOR_MAX_24B) - DLH_SENSOR_TEMPER_MIN;
return DLH_L05D_OK;
}