forked from Digilent/openscope-mz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
176 lines (147 loc) · 6.2 KB
/
main.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/************************************************************************/
/* */
/* main.cpp */
/* */
/* Main function for the OpenScope Application */
/* */
/************************************************************************/
/* Author: Keith Vogel */
/* Copyright 2016, Digilent Inc. */
/************************************************************************/
/* Revision History: */
/* */
/* 2/17/2016 (KeithV): Created */
/************************************************************************/
#include <OpenScope.h>
#include <math.h>
//#define DC1VOLTAGE (1200)
//#define DC2VOLTAGE (-DC1VOLTAGE)
STATE MState = MSysInit;
int main(__attribute__((unused)) int argc, __attribute__((unused)) char** argv) {
STATE retState = Idle;
static uint32_t tStart = 0;
InitInstruments();
// We need to wait for the Arduino IDE to open the COM port
// if the Serial Monitor is open after the reset
tStart = SYSGetMilliSecond();
while(SYSGetMilliSecond() - tStart < 500);
Serial.begin(SERIALBAUDRATE);
Serial.print("OpenScope v");
Serial.println(szProgVersion);
Serial.println("Written by: Keith Vogel, Digilent Inc.");
Serial.println("Copyright 2016 Digilent Inc.");
Serial.println();
while (1) {
switch (MState) {
// inits the MCU
case MSysInit:
if (CFGSysInit() == Idle) {
tStart = SYSGetMilliSecond();
MState = MSysVoltages;
}
break;
// read the power supply and reference voltages
case MSysVoltages:
if (InitSystemVoltages() == Idle) {
MState = MHeaders;
}
break;
case MHeaders:
Serial.print("MRF24 Info -- ");
Serial.print("DeviceType: 0x");
Serial.print((int) myMRFDeviceInfo.deviceType, 16);
Serial.print(" Rom Version: 0x");
Serial.print((int) myMRFDeviceInfo.romVersion, 16);
Serial.print(" Patch Version: 0x");
Serial.println((int) myMRFDeviceInfo.patchVersion, 16);
Serial.println();
Serial.print("USB+: ");
Serial.print(uVUSB);
Serial.println("uV");
Serial.print("VCC 3.3: ");
Serial.print(uV3V3);
Serial.println("uV");
Serial.print("VRef 3.0: ");
Serial.print(uVRef3V0);
Serial.println("uV");
Serial.print("VRef 1.5: ");
Serial.print(uVRef1V5);
Serial.println("uV");
Serial.print("USB-: -");
Serial.print(uVNUSB);
Serial.println("uV");
Serial.println();
MState = MWaitSDDetTime;
break;
case MWaitSDDetTime:
if(SYSGetMilliSecond() - tStart >= SDWAITTIME)
{
MState = MReadCalibrationInfo;
}
break;
case MReadCalibrationInfo:
// This should not fail
// if nothing is found, default values are loaded
if(CFGGetCalibrationInfo(instrGrp) == Idle)
{
Serial.print("Using calibration from: ");
Serial.println(rgCFGNames[((IDHDR *) rgInstr[DCVOLT1_ID])->cfg]);
MState = MLookUpWiFi;
}
break;
case MLookUpWiFi:
if ((retState = WiFiLookupConnInfo(dWiFiFile, pjcmd.iWiFi.wifiWConn)) == Idle) {
Serial.print("Found parameter for AP: ");
Serial.println(pjcmd.iWiFi.wifiWConn.ssid);
MState = MConnectWiFi;
}
else if(IsStateAnError(retState))
{
Serial.print("Unable to connect to WiFi AP. Error 0x");
Serial.println(retState, 16);
MState = MLoop;
}
break;
case MConnectWiFi:
if((retState = WiFiConnect(pjcmd.iWiFi.wifiWConn, false)) == Idle)
{
Serial.print("Connected to AP: ");
Serial.println(pjcmd.iWiFi.wifiAConn.ssid);
Serial.println("Starting Web Server");
MState = MLoop;
// fBlockIOBus = true;
// MState = Calibrating;
}
else if(IsStateAnError(retState))
{
Serial.print("Error Connecting to WiFi, Error: 0x");
Serial.println(retState, 16);
MState = MLoop;
// fBlockIOBus = true;
// MState = Calibrating;
}
break;
case Calibrating:
// if(OSCCalibrate(rgInstr[OSC1_ID], rgInstr[OSC1_DC_ID]) == Idle)
if(AWGCalibrate(rgInstr[AWG1_ID]) == Idle)
{
fBlockIOBus = false;
MState = MLoop;
}
break;
case MLoop:
UIMainPage(dWiFiFile, VOLWFPARM, pjcmd.iWiFi.wifiAConn);
break;
default:
break;
}
// loop services
HTTPTask(); // Keep the HTTP Server alive
DEIPcK::periodicTasks(); // Keep Stack alive
LEDTask();
CFGSdHotSwapTask();
JSONCmdTask(); // Process the JSON queued commands
LoopStatsTask();
}
return 0;
}