-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqain-2022-10-31
109 lines (84 loc) · 2.47 KB
/
mqain-2022-10-31
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
#include <Wire.h>
#include <math.h>
#define ADDR 0x33
int counter = 0;
int counter2 = 0;
void setup() {
Wire.begin(); //Join I2C protocol
Serial.begin(9600);
}
void decodeAnswer(unsigned int a[])
{
Serial.println("Begin Decode");
int byte[8] = {0,0,0,0,0,0,0,0};
unsigned int byte1, byte2, byte4, byte3 = 0x00;
byte1 = a[0];
byte2 = a[1];
byte3 = a[2];
byte4 = a[3];
for(int i = 0; byte1 > 0; i++)
{
byte[i] = byte1%2;
byte1 = byte1/2;
}
Serial.print("The first byte is:");
for(int i = sizeof(byte)/sizeof(int) - 1; i >= 0; i--)
Serial.print(byte[i]);
Serial.println();
for(int i =0; i < 8; i++)
byte[i] = 0;
for(int i = 0; byte2 > 0; i++)
{
byte[i] = byte2%2;
byte2 = byte2/2;
}
Serial.print("The second byte is: ");
for(int i = sizeof(byte)/sizeof(int) - 1; i >= 0; i--)
Serial.print(byte[i]);
Serial.println();
for(int i =0; i < 8; i++)
byte[i] = 0;
for(int i = 0; byte4 > 0; i++)
{
byte[i] = byte4%2;
byte4 = byte4/2;
}
Serial.print("The time elapsed for the test is: ");
Serial.print(byte3);
Serial.println(" seconds.");
Serial.print("The fourth byte is: ");
for(int i = sizeof(byte)/sizeof(int) - 1; i >= 0; i--)
Serial.print(byte[i]);
Serial.println();
Serial.println("End decode");
}
void loop() {
//Byte instructions for the tests (array)
unsigned int instructions[11] = {0x1f, 0x2f,0x11,0x21,0x12,0x22,0x14,0x24,0x18,0x28}; // Any of the two algorithms can be tested on any of the four antenna and combinations of antennas so 4!*2 possibilities.
//You can add values but refer to the manual to determine the byte to pass.
//0x1f, 0x2f,0x11,0x21,0x12,0x22,0x14,0x24,0x18,0x28
unsigned int answers[4] = {0x00, 0x00, 0x00, 0x00};
//Write
Wire.beginTransmission(ADDR); // begin on the transmission on the port with address 0x33 as per the manual and is 51 in decimal.
Wire.write(instructions[counter]);
delay(40000); // delay to allow for buffer to clear for print I believe (L)
Wire.write(0x00);
Wire.endTransmission(); //stop the transmission
Wire.requestFrom(ADDR, 4); //requestest from the slave port (the antenna at address 0x33) and pass 4 bytes
while(Wire.available())
{
answers[counter2] = Wire.read();
counter2++;
}
Serial.println();
decodeAnswer(answers);
counter2 = 0;
counter++;
Serial.println(counter);
if (counter == 11)
{
Serial.print("Program Finished");
delay(1000);
exit(0);
}
}