You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.7 KiB
C++
85 lines
1.7 KiB
C++
#include "comm.h"
|
|
|
|
|
|
void CommunicationsController::initOta() {
|
|
ArduinoOTA.setHostname(WIFI_SSID);
|
|
ArduinoOTA.setPassword(WIFI_PASSWORD);
|
|
ArduinoOTA.begin();
|
|
}
|
|
|
|
void CommunicationsController::initWifi() {
|
|
WiFiSettings.hostname = WIFI_SSID;
|
|
WiFiSettings.password = WIFI_PASSWORD;
|
|
|
|
WiFiSettings.onPortalWaitLoop = []() {
|
|
ArduinoOTA.handle();
|
|
};
|
|
|
|
WiFiSettings.connect();
|
|
}
|
|
|
|
void CommunicationsController::init() {
|
|
initOta();
|
|
initWifi();
|
|
|
|
while (WiFi.status() != WL_CONNECTED);
|
|
|
|
WebMonitor.begin();
|
|
l4sServer.begin();
|
|
}
|
|
|
|
byte CommunicationsController::process(float *azimuth, float *altitude) {
|
|
ArduinoOTA.handle();
|
|
create_connection();
|
|
|
|
if (l4s) {
|
|
while (l4s.connected()) {
|
|
handle_client();
|
|
byte resp = parseLook4Sat(azimuth, altitude);
|
|
ArduinoOTA.handle();
|
|
|
|
if (resp == 1) {
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CommunicationsController::handle_client() {
|
|
l4s.flush();
|
|
received = recv();
|
|
}
|
|
|
|
byte CommunicationsController::parseLook4Sat(float* azimuth, float* altitude) {
|
|
String tmp = received.substring(9);
|
|
int spaceIndex = tmp.indexOf(' ');
|
|
|
|
if (spaceIndex != -1) {
|
|
*azimuth = tmp.substring(0, spaceIndex).toFloat();
|
|
*altitude = tmp.substring(spaceIndex+1).toFloat();
|
|
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CommunicationsController::create_connection() {
|
|
l4s = l4sServer.accept();
|
|
}
|
|
|
|
String CommunicationsController::recv() {
|
|
String rec = "";
|
|
|
|
while (l4s.available()) {
|
|
rec += (char)(l4s.read());
|
|
}
|
|
|
|
if (rec.length() == 0) {
|
|
rec = "Ç";
|
|
}
|
|
return rec;
|
|
}
|