Skip to content

Commit

Permalink
port of SkyWatch sketch onto ESP8266 platform: build is fine.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jun 2, 2020
1 parent e9f8933 commit f0993ea
Show file tree
Hide file tree
Showing 21 changed files with 382 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ script:
- if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then
arduino --verify --verbose-build --board $BOARD $PWD/software/firmware/source/SkyView/SkyView.ino ;
fi ;
- if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then
arduino --verify --board $BOARD $PWD/software/firmware/source/SkyWatch/SkyWatch.ino ;
fi ;
- if [[ "$BOARD" =~ "esp32:esp32:" ]]; then
arduino --verify --board $BOARD $PWD/software/firmware/source/SoftRF/SoftRF.ino ;
fi ;
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SkyWatch/BaroHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "SoCHelper.h"
#include "BaroHelper.h"

#include "SkyWatch.h"

barochip_ops_t *baro_chip = NULL;

Adafruit_BMP085 bmp180;
Expand Down
5 changes: 0 additions & 5 deletions software/firmware/source/SkyWatch/BatteryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/

#if defined(ARDUINO)
#include <Arduino.h>
#endif /* ARDUINO */

#include "SoCHelper.h"
#include "BatteryHelper.h"
#include "SkyWatch.h"

unsigned long Battery_TimeMarker = 0;
static int Battery_cutoff_count = 0;
Expand Down
8 changes: 5 additions & 3 deletions software/firmware/source/SkyWatch/EEPROMHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <protocol.h>
#include <freqplan.h>

#include "SkyWatch.h"

// start reading from the first byte (address 0) of the EEPROM

eeprom_t eeprom_block;
Expand Down Expand Up @@ -95,7 +93,11 @@ void EEPROM_defaults()
eeprom_block.field.settings.m.adapter = ADAPTER_NONE;

eeprom_block.field.settings.m.connection = CON_SERIAL;
eeprom_block.field.settings.m.baudrate = B115200; /* S76G AN3155 BR */
if (hw_info.model == SOFTRF_MODEL_SKYWATCH) {
eeprom_block.field.settings.m.baudrate = B115200; /* S76G AN3155 BR */
} else {
eeprom_block.field.settings.m.baudrate = B38400;
}
eeprom_block.field.settings.m.protocol = PROTOCOL_NMEA;
eeprom_block.field.settings.m.orientation = DIRECTION_NORTH_UP;

Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SkyWatch/GDL90Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "TrafficHelper.h"
#include "WiFiHelper.h"

#include "SkyWatch.h"

extern "C" {
#include <gdl90.h>
}
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/source/SkyWatch/NMEAHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "EEPROMHelper.h"
#include "WiFiHelper.h"

#include "SkyWatch.h"

TinyGPSPlus nmea;

TinyGPSCustom T_AlarmLevel (nmea, "PFLAA", 1);
Expand Down Expand Up @@ -406,6 +404,7 @@ void NMEA_loop()
PGRMZ_TimeMarker = millis();
}

#if !defined(EXCLUDE_RTC)
if (!RTC_sync) {
if (rtc &&
nmea.date.isValid() &&
Expand All @@ -418,6 +417,7 @@ void NMEA_loop()
RTC_sync = true;
}
}
#endif /* EXCLUDE_RTC */

#if defined(NMEA_TCP_SERVICE)
uint8_t i;
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SkyWatch/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "BluetoothHelper.h"
#include "BatteryHelper.h"

#include "SkyWatch.h"

#include <battery.h>
#include <sqlite3.h>
#include <SD.h>
Expand Down
282 changes: 282 additions & 0 deletions software/firmware/source/SkyWatch/Platform_ESP8266.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
/*
* Platform_ESP8266.cpp
* Copyright (C) 2020 Linar Yusupov
*
* 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:https://www.gnu.org/licenses/>.
*/
#if defined(ESP8266)

#include "SoCHelper.h"
#include "EEPROMHelper.h"
#include "WiFiHelper.h"

ESP8266WebServer server ( 80 );

static void ESP8266_setup()
{
hw_info.model = SOFTRF_MODEL_WEBTOP;
hw_info.revision = HW_REV_DEVKIT;
}

static void ESP8266_loop()
{

}

static void ESP8266_fini()
{

}

static void ESP8266_reset()
{
ESP.restart();
}

static void ESP8266_sleep_ms(int ms)
{
/* TODO */
}

static uint32_t ESP8266_getChipId()
{
return ESP.getChipId();
}

static bool ESP8266_EEPROM_begin(size_t size)
{
EEPROM.begin(size);
return true;
}

static void ESP8266_WiFi_setOutputPower(int dB)
{
WiFi.setOutputPower(dB);
}

static bool ESP8266_WiFi_hostname(String aHostname)
{
return WiFi.hostname(aHostname);
}

static void ESP8266_WiFiUDP_stopAll()
{
WiFiUDP::stopAll();
}

static IPAddress ESP8266_WiFi_get_broadcast()
{
struct ip_info ipinfo;
IPAddress broadcastIp;

if (WiFi.getMode() == WIFI_STA) {
wifi_get_ip_info(STATION_IF, &ipinfo);
} else {
wifi_get_ip_info(SOFTAP_IF, &ipinfo);
}
broadcastIp = ~ipinfo.netmask.addr | ipinfo.ip.addr;

return broadcastIp;
}

static void ESP8266_WiFi_transmit_UDP(int port, byte *buf, size_t size)
{
IPAddress ClientIP;
struct station_info *stat_info;
WiFiMode_t mode = WiFi.getMode();

switch (mode)
{
case WIFI_STA:
ClientIP = ESP8266_WiFi_get_broadcast();

SoC->swSer_enableRx(false);

Uni_Udp.beginPacket(ClientIP, port);
Uni_Udp.write(buf, size);
Uni_Udp.endPacket();

SoC->swSer_enableRx(true);

break;
case WIFI_AP:
stat_info = wifi_softap_get_station_info();

while (stat_info != NULL) {
ClientIP = stat_info->ip.addr;

SoC->swSer_enableRx(false);

Uni_Udp.beginPacket(ClientIP, port);
Uni_Udp.write(buf, size);
Uni_Udp.endPacket();

SoC->swSer_enableRx(true);

stat_info = STAILQ_NEXT(stat_info, next);
}
wifi_softap_free_station_info();
break;
case WIFI_OFF:
default:
break;
}
}

static size_t ESP8266_WiFi_Receive_UDP(uint8_t *buf, size_t max_size)
{
return 0; // WiFi_Receive_UDP(buf, max_size);
}

static int ESP8266_WiFi_clients_count()
{
struct station_info *stat_info;
int clients = 0;
WiFiMode_t mode = WiFi.getMode();

switch (mode)
{
case WIFI_AP:
stat_info = wifi_softap_get_station_info();

while (stat_info != NULL) {
clients++;

stat_info = STAILQ_NEXT(stat_info, next);
}
wifi_softap_free_station_info();

return clients;
case WIFI_STA:
default:
return -1; /* error */
}
}

static void ESP8266_swSer_begin(unsigned long baud)
{
SerialInput.begin(baud, SERIAL_8N1);
}

static void ESP8266_swSer_enableRx(boolean arg)
{

}

static uint32_t ESP8266_maxSketchSpace()
{
return (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
}

static void ESP8266_Battery_setup()
{

}

static float ESP8266_Battery_voltage()
{
return analogRead (SOC_GPIO_PIN_BATTERY) / SOC_A0_VOLTAGE_DIVIDER ;
}

static bool ESP8266_DB_init()
{
return false;
}

static bool ESP8266_DB_query(uint8_t type, uint32_t id, char *buf, size_t size)
{
return false;
}

static void ESP8266_DB_fini()
{

}

static void ESP8266_TTS(char *message)
{

}

static void ESP8266_Button_setup()
{

}

static void ESP8266_Button_loop()
{

}

static void ESP8266_Button_fini()
{

}

static bool ESP8266_Baro_setup()
{
return false;
}

static void ESP8266_WDT_setup()
{

}

static void ESP8266_WDT_fini()
{

}

static void ESP8266_Service_Mode(boolean arg)
{

}

const SoC_ops_t ESP8266_ops = {
SOC_ESP8266,
"ESP8266",
ESP8266_setup,
ESP8266_loop,
ESP8266_fini,
ESP8266_reset,
ESP8266_sleep_ms,
ESP8266_getChipId,
ESP8266_EEPROM_begin,
ESP8266_WiFi_setOutputPower,
ESP8266_WiFi_hostname,
ESP8266_WiFiUDP_stopAll,
ESP8266_WiFi_transmit_UDP,
ESP8266_WiFi_Receive_UDP,
ESP8266_WiFi_clients_count,
ESP8266_swSer_begin,
ESP8266_swSer_enableRx,
ESP8266_maxSketchSpace,
ESP8266_Battery_setup,
ESP8266_Battery_voltage,
ESP8266_DB_init,
ESP8266_DB_query,
ESP8266_DB_fini,
ESP8266_TTS,
ESP8266_Button_setup,
ESP8266_Button_loop,
ESP8266_Button_fini,
ESP8266_Baro_setup,
ESP8266_WDT_setup,
ESP8266_WDT_fini,
ESP8266_Service_Mode,
NULL
};

#endif /* ESP8266 */
Loading

0 comments on commit f0993ea

Please sign in to comment.