-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_array_masking.c
53 lines (44 loc) · 1.13 KB
/
temp_array_masking.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
u_int32_t data[32] = { 0, 0, 0, 0, 0, 0, 1, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 0, 1, 0
};
u_int32_t buffer[4] = {0, 0, 0, 0};
u_int32_t hum_temp = 0x27300e4;
u_int32_t ParseAM2301Data (u_int32_t* data);
void main(void)
{
int temp_hum = 0;
char str[100];
temp_hum = ParseAM2301Data(data);
/*u_int32_t humidity = temp_hum >> 16;
u_int32_t temperature = temp_hum & 0xFFFF;
sprintf ((char*) str, "Temperature: %lu, humidity: %lu\r\n", temperature, humidity);
printf("%s", str);*/
test1();
}
u_int32_t ParseAM2301Data (u_int32_t* data)
{
int i = 0;
u_int32_t hum_temp = 0;
for (i=0; i<32; i++)
{
hum_temp <<=1;
hum_temp |= data[i];
}
return hum_temp;
}
void test1()
{
char str[100];
buffer[3] |= hum_temp>>24;
buffer[2] |= hum_temp>>16;
buffer[1] |= hum_temp>>8;
buffer[0] |= hum_temp;
sprintf ((char*) str, "Temperature: %d.%d, Humidity: %d.%d\r\n",
buffer[3], buffer[4], buffer[2], buffer[1]);
printf(str);
}