-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOCS.ino
178 lines (148 loc) · 5.03 KB
/
OCS.ino
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
/*
* Title Observatory-Control-System
* by Howard Dutton
*
* Copyright (C) 2012 to 2024 Howard Dutton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* Revision History, see GitHub
*
*
* Author: Howard Dutton
* http://www.stellarjourney.com
*
* Description
*
* General Purpose Observatory Control
* with LX200 derived command set.
*
*/
// Use tabs "Config..." to configure the OCS to your requirements
// Firmware version ----------------------------------------------------------------------------------------------------------------
#define FirmwareName "OCS"
#define FirmwareVersionMajor 3
#define FirmwareVersionMinor 10 // minor version 00 to 99
#define FirmwareVersionPatch "c" // for example major.minor patch: 10.03c
#define FirmwareVersionConfig 2 // internal, for tracking configuration file changes
#include "src/Common.h"
#include "src/lib/tasks/OnTask.h"
#include "src/lib/watchdog/Watchdog.h"
#include "src/lib/nv/Nv.h"
#include "src/lib/sense/Sense.h"
#include "src/Validate.h"
#include "src/observatory/Observatory.h"
#include "src/pages/chartJS/ChartJS.h"
char ocsVersion[10];
#if DEBUG == PROFILER
extern void profiler();
#endif
void systemServices() {
nv.poll();
}
void sensesPoll() {
sense.poll();
}
bool hasFileSystem = false;
void setup() {
sprintf(ocsVersion, "%d.%02d%s", FirmwareVersionMajor, FirmwareVersionMinor, FirmwareVersionPatch);
#if DEBUG != OFF
SERIAL_DEBUG.begin(SERIAL_DEBUG_BAUD);
delay(2000);
#endif
VF("MSG: OCS "); VL(ocsVersion);
VF("MSG: MCU "); VLF(MCU_STR);
// start low level hardware
VLF("MSG: Setup, HAL initalize");
HAL_INIT();
nv.init();
delay(2000);
// start any file system
#ifdef BUILTIN_SDCARD
#if defined(SDCARD_CS_PIN) && SDCARD_CS_PIN == OFF
#undef SDCARD_CS_PIN
#endif
#define SDCARD_CS_PIN BUILTIN_SDCARD
#endif
#if WEATHER_CHARTS == ON
#ifdef ESP32
hasFileSystem = FS.begin(true);
if (hasFileSystem) {
VF("MSG: Setup, FatFS ");
File dataFile = FS.open(FS_PREFIX "Chart.js", FILE_READ);
if (!dataFile) {
VLF("didn't find Chart.js");
File dataFile = FS.open(FS_PREFIX "Chart.js", FILE_WRITE);
if (dataFile) {
VLF("MSG: Setup, writing FatFS Chart.js data");
dataFile.print(ChartJS);
dataFile.close();
} else { DLF("ERR: Setup, error opening FatFS Chart.js file for write"); }
} else {
VLF("found Chart.js");
dataFile.close();
}
FS.end();
} else { DLF("ERR: Setup, error opening FatFS"); }
hasFileSystem = FS.begin();
#else
#if defined(SDCARD_CS_PIN) && SDCARD_CS_PIN != OFF
#if SD_CARD == ON
hasFileSystem = FS.begin(SDCARD_CS_PIN);
#else
pinMode(SDCARD_CS_PIN, OUTPUT);
digitalWrite(SDCARD_CS_PIN, HIGH);
#endif
#endif
#endif
if (hasFileSystem) {
VLF("MSG: Setup, start FatFS success");
} else {
DLF("ERR: Setup, error opening FatFS");
}
#endif
// start system service task
VF("MSG: Setup, start system service task (rate 10ms priority 7)... ");
// add task for system services, runs at 10ms intervals so commiting 1KB of NV takes about 10 seconds
// the cache is scanned (for writing) at 2000 bytes/second but can be slower while reading data into the cache at startup
if (tasks.add(10, 0, true, 7, systemServices, "SysSvcs")) { VLF("success"); } else { VLF("FAILED!"); }
// start input sense monitor task
VF("MSG: Setup, start input sense monitor task (rate 1ms priority 7)... ");
if (tasks.add(10, 0, true, 7, sensesPoll, "Sensors")) { VLF("success"); } else { VLF("FAILED!"); }
// start observatory instance
observatory.init(FirmwareName, FirmwareVersionMajor, FirmwareVersionMinor, FirmwareVersionPatch, FirmwareVersionConfig);
// start the IP command channels
#if OPERATIONAL_MODE != OFF
#if SERIAL_SERVER == STANDARD || SERIAL_SERVER == BOTH
SERIAL_SIP.begin(9999, 2L*1000L);
#endif
#if SERIAL_SERVER == PERSISTANT || SERIAL_SERVER == BOTH
SERIAL_PIP1.begin(9998, 120L*1000L, true);
#endif
#endif
// start command channel tasks
commandChannelInit();
tasks.yield(2000);
// start task manager debug events
#if DEBUG == PROFILER
tasks.add(142, 0, true, 7, profiler, "Profilr");
#endif
}
void loop() {
tasks.yield();
watchdog.reset();
}