-
Notifications
You must be signed in to change notification settings - Fork 0
/
transmit.cpp
152 lines (122 loc) · 3.42 KB
/
transmit.cpp
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
/* Team: Team Quasar */
/* transmit.h */
/* Program Libraries */
#include "transmit.h"
#include "util.h"
/* External Libraries */
#include <EEPROM.h>
#include <XBee.h>
/* Clear Packet */
void Clear_Packet(void)
{
//Set how much to fill packet
int i, b, c;
//Initialize packet values
G_packet.schema = 0;
G_packet.address = (EEPROM.read(3) << 8); //EEPROM address
G_packet.uptime_ms = 0;
//G_packet.n = 0;
G_packet.bmp185_press_pa = 0;
G_packet.bmp185_temp_decic = 0;
G_packet.humidity_centi_pct = 0;
//Serial.println("clear packet variable initialization");
//clear packet
for(i = 1; i < 60; i++)
{
//set index
b = i/10;
c = i/3;
//poll 10 times
G_packet.batt_mv[b] = 0;
G_packet.panel_mv[b] = 0;
//poll 3 times
G_packet.solar_irr_w_m2[c] = 0;
}
//Serial.println("clear packet bottom");
}
/* Construct Packet */
void Construct_Packet(void)
{
//Serial.println("construct packet top");
//Variable for Index and uptime
unsigned long uptime_ms;
//Put schema number in packet
G_packet.schema = 297;
//Update data
uptime_ms = millis();
//Put uptime in packet
G_packet.uptime_ms = uptime_ms;
//Poll and put battery and panel data in packet
for(int p = 0; p < 6; p++)
{ G_packet.batt_mv[p] = battery();
G_packet.panel_mv[p] = panel();
delay(400);
}
//Poll and put panel data in packet
/*for(int p = 0; p < 6; p++)
{ G_packet.panel_mv[p] = panel();
delay(400);
}*/
G_packet.bmp185_press_pa = pressure();
G_packet.bmp185_temp_decic = temp();
G_packet.humidity_centi_pct = humidity();
//Poll and put irradiance data in packet
for(int i = 0; i < 20; i++)
{ G_packet.solar_irr_w_m2[i] = irradiance();
delay(300);
}
/*//Hardcoded Test Packet
G_packet.uptime_ms = 1;
for(int p = 0; p <= 4; p++)
{ G_packet.batt_mv[p] = 1;
Serial.print("Battery");
Serial.println(G_packet.batt_mv[p]);
delay(400);
}
for(int p = 0; p <= 4; p++)
{ G_packet.panel_mv[p] = 2;
Serial.print("Panel");
Serial.println(G_packet.panel_mv[p]);
delay(400);
}
G_packet.bmp185_press_pa = 3;
Serial.print("Pressure");
Serial.println(G_packet.bmp185_press_pa);
G_packet.bmp185_temp_decic = 4;
Serial.print("Temp");
Serial.println(G_packet.bmp185_temp_decic);
G_packet.humidity_centi_pct = 5;
Serial.print("Humidity");
Serial.println(G_packet.humidity_centi_pct);
for(int i = 0; i <= 14; i++)
{ G_packet.solar_irr_w_m2[i] = 6;
Serial.print("Solar");
Serial.println(G_packet.solar_irr_w_m2[i]);
delay(1000);
}*/
}
/* Transmission Code */
void Transmit_Packet(void)
{
/* Create Xbee object */
XBee xbee = XBee();
/* Packet to be transmitted */
uint8_t payload[MAX_SIZE];
/* Obtain address of receiving end */
XBeeAddress64 addr64 = XBeeAddress64(0x0, 0x0);
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
/* Clear the payload */
memset(payload, '\0', sizeof(payload));
/* Debug Packet */
//payload[0] = '1';
//payload[1] = '5';
/* Transfer information into payload */
memcpy(payload, &G_packet, sizeof(payload));
for(int i = 0; i < MAX_SIZE; i++)
{ Serial.write(payload[i]);}
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
/* Transfer the payload */
xbee.send(zbTx); //!!Prints packet to serial monitor
/* delay */
delay(1000);
}