diff --git a/fujinet_pc.cmake b/fujinet_pc.cmake index b972fff8b..1d34c494b 100644 --- a/fujinet_pc.cmake +++ b/fujinet_pc.cmake @@ -69,23 +69,23 @@ set(INCLUDE_DIRS include set(SOURCES # set(SOURCES src/main.cpp -# lib/config/fnConfig.h lib/config/fnConfig.cpp -# lib/config/fnc_bt.cpp -# lib/config/fnc_cassette.cpp -# lib/config/fnc_cpm.cpp -# lib/config/fnc_enable.cpp -# lib/config/fnc_general.cpp -# lib/config/fnc_hosts.cpp -# lib/config/fnc_load.cpp -# lib/config/fnc_modem.cpp -# lib/config/fnc_mounts.cpp -# lib/config/fnc_network.cpp -# lib/config/fnc_phonebook.cpp -# lib/config/fnc_printer.cpp -# lib/config/fnc_save.cpp -# lib/config/fnc_serial.cpp -# lib/config/fnc_util.cpp -# lib/config/fnc_wifi.cpp + lib/config/fnConfig.h lib/config/fnConfig.cpp + lib/config/fnc_bt.cpp + lib/config/fnc_cassette.cpp + lib/config/fnc_cpm.cpp + lib/config/fnc_enable.cpp + lib/config/fnc_general.cpp + lib/config/fnc_hosts.cpp + lib/config/fnc_load.cpp + lib/config/fnc_modem.cpp + lib/config/fnc_mounts.cpp + lib/config/fnc_network.cpp + lib/config/fnc_phonebook.cpp + lib/config/fnc_printer.cpp + lib/config/fnc_save.cpp + lib/config/fnc_serial.cpp + lib/config/fnc_util.cpp + lib/config/fnc_wifi.cpp include/debug.h lib/utils/utils.h lib/utils/utils.cpp lib/utils/cbuf.h lib/utils/cbuf.cpp @@ -208,7 +208,7 @@ set(SOURCES # lib/base64/base64.h lib/base64/base64.c # lib/encrypt/crypt.h lib/encrypt/crypt.cpp # lib/compat/compat_inet.c -# lib/compat/compat_gettimeofday.c + lib/compat/compat_gettimeofday.h lib/compat/compat_gettimeofday.c ) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/lib/FileSystem/fnFS.h b/lib/FileSystem/fnFS.h index 414f50470..0eb2d2f38 100644 --- a/lib/FileSystem/fnFS.h +++ b/lib/FileSystem/fnFS.h @@ -4,15 +4,28 @@ #include #include +#include +#ifndef ESP_PLATFORM +#include "compat_dirent.h" +#include "fnFile.h" +#endif + #ifndef FILE_READ -#define FILE_READ "r" -#define FILE_WRITE "w" -#define FILE_APPEND "a" +#define FILE_READ "rb" +#define FILE_WRITE "wb" +#define FILE_APPEND "ab" +#define FILE_READ_TEXT "rt" +#define FILE_WRITE_TEXT "wt" +#define FILE_APPEND_TEXT "at" #endif +#ifdef ESP_PLATFORM #define MAX_PATHLEN 256 +#else +#define MAX_PATHLEN 1024 +#endif #define FNFS_INVALID_DIRPOS 0xFFFF @@ -22,6 +35,10 @@ enum fsType FSTYPE_LITTLEFS, FSTYPE_SDFAT, FSTYPE_TNFS, +#ifndef ESP_PLATFORM + FSTYPE_SMB, + FSTYPE_FTP, +#endif FSTYPE_COUNT }; @@ -40,7 +57,11 @@ typedef struct fsdir_entry fsdir_entry_t; class FileSystem { protected: +#ifdef ESP_PLATFORM char _basepath[20] = { '\0' }; +#else + char _basepath[MAX_PATHLEN] = { '\0' }; +#endif bool _started = false; fsdir_entry _direntry; @@ -61,6 +82,9 @@ class FileSystem static const char *type_to_string(fsType type); static long filesize(FILE *); +#ifndef ESP_PLATFORM + static long filesize(FileHandler *); +#endif static long filesize(const char *filepath); // Different FS implemenations may require different startup parameters, @@ -68,6 +92,9 @@ class FileSystem //virtual bool start()=0; virtual FILE * file_open(const char* path, const char* mode = FILE_READ) = 0; +#ifndef ESP_PLATFORM + virtual FileHandler * filehandler_open(const char* path, const char* mode = FILE_READ) = 0; +#endif virtual bool exists(const char* path) = 0; diff --git a/lib/FileSystem/fnFsSD.h b/lib/FileSystem/fnFsSD.h index b8686dd42..7ea453554 100644 --- a/lib/FileSystem/fnFsSD.h +++ b/lib/FileSystem/fnFsSD.h @@ -1,7 +1,9 @@ #ifndef _FN_FSSD_ #define _FN_FSSD_ -#include +#ifdef ESP_PLATFORM +#include "esp_vfs_fat.h" +#endif #include @@ -10,16 +12,27 @@ class FileSystemSDFAT : public FileSystem { private: +#ifdef ESP_PLATFORM FF_DIR _dir; +#else + DIR * _dir; +#endif uint64_t _card_capacity = 0; public: +#ifdef ESP_PLATFORM bool start(); +#else + bool start(const char *sd_path = nullptr); +#endif virtual bool is_global() override { return true; }; fsType type() override { return FSTYPE_SDFAT; }; const char * typestring() override { return type_to_string(FSTYPE_SDFAT); }; FILE * file_open(const char* path, const char* mode = FILE_READ) override; +#ifndef ESP_PLATFORM + FileHandler * filehandler_open(const char* path, const char* mode = FILE_READ) override; +#endif bool exists(const char* path) override; diff --git a/lib/bus/sio/sio.h b/lib/bus/sio/sio.h index 90d291a48..2f0faa85d 100755 --- a/lib/bus/sio/sio.h +++ b/lib/bus/sio/sio.h @@ -1,11 +1,14 @@ #ifndef SIO_H #define SIO_H -#include -#include - #include +#ifdef ESP_PLATFORM +#include +#include +#else +#include "sio/siocom/fnSioCom.h" +#endif #define DELAY_T4 850 #define DELAY_T5 250 @@ -47,6 +50,7 @@ FN_HISPEED_INDEX=40 // 18,806 (18,806) baud #define SIO_STANDARD_BAUDRATE 19200 #define SIO_HISPEED_LOWEST_INDEX 0x0A // Lowest HSIO index we'll accept +#define SIO_HISPEED_x2_INDEX 0x10 // this index is accepted too (by FujiNet-PC) #define COMMAND_FRAME_SPEED_CHANGE_THRESHOLD 2 #define SERIAL_TIMEOUT 300 @@ -146,7 +150,9 @@ class virtualDevice * Atari that we are now processing the command. */ void sio_ack(); - +#ifndef ESP_PLATFORM + void sio_late_ack(); // for NetSIO, ACK is delayed until we now how much data will be read from Atari +#endif /** * @brief Send a non-acknowledgement (NAK) to the Atari 'N' * This should be used if the command received by the SIO device is invalid, in the first place. It is not @@ -263,6 +269,10 @@ class systemBus bool useUltraHigh = false; // Use fujinet derived clock. +#ifndef ESP_PLATFORM + bool _command_processed = false; +#endif + void _sio_process_cmd(); void _sio_process_queue(); @@ -293,6 +303,11 @@ class systemBus bool shuttingDown = false; // TRUE if we are in shutdown process bool getShuttingDown() { return shuttingDown; }; +#ifndef ESP_PLATFORM + void set_command_processed(bool processed); + void sio_empty_ack(); // for NetSIO, notify hub we are not interested to handle the command +#endif + sioCassette *getCassette() { return _cassetteDev; } sioPrinter *getPrinter() { return _printerdev; } sioCPM *getCPM() { return _cpmDev; } @@ -300,7 +315,9 @@ class systemBus // I wish this codebase would make up its mind to use camel or snake casing. modem *get_modem() { return _modemDev; } +#ifdef ESP_PLATFORM QueueHandle_t qSioMessages = nullptr; +#endif }; extern systemBus SIO; diff --git a/lib/config/fnConfig.cpp b/lib/config/fnConfig.cpp index c91b8f1bc..fc247810a 100644 --- a/lib/config/fnConfig.cpp +++ b/lib/config/fnConfig.cpp @@ -1,5 +1,5 @@ #include "fnConfig.h" -#include +#include "compat_string.h" fnConfig Config; diff --git a/lib/config/fnConfig.h b/lib/config/fnConfig.h index 92527c84b..83ebfc4ae 100755 --- a/lib/config/fnConfig.h +++ b/lib/config/fnConfig.h @@ -1,6 +1,8 @@ #ifndef _FN_CONFIG_H #define _FN_CONFIG_H +#include + #include "printer.h" #include "../encrypt/crypt.h" #include "../../include/debug.h" @@ -16,9 +18,26 @@ #define HOST_SLOT_INVALID -1 +#ifdef ESP_PLATFORM + #define HSIO_INVALID_INDEX -1 #define CONFIG_FILENAME "/fnconfig.ini" + +#else + +#define HSIO_DISABLED_INDEX -1 // HSIO disabled, use standard speed only + +#define CONFIG_FILENAME "fnconfig.ini" + +#define SD_CARD_DIR "SD" + +#define WEB_SERVER_LISTEN_URL "http://0.0.0.0:8000" + +#define CONFIG_DEFAULT_NETSIO_PORT 9997 + +#endif + #define CONFIG_FILEBUFFSIZE 2048 #define CONFIG_DEFAULT_SNTPSERVER "pool.ntp.org" @@ -45,6 +64,7 @@ class fnConfig MOUNTMODE_INVALID }; typedef mount_modes mount_mode_t; + mount_mode_t mount_mode_from_string(const char *str); enum mount_types { @@ -53,7 +73,26 @@ class fnConfig }; typedef mount_types mount_type_t; - mount_mode_t mount_mode_from_string(const char *str); +#ifndef ESP_PLATFORM + enum serial_command_pin + { + SERIAL_COMMAND_NONE = 0, + SERIAL_COMMAND_DSR, + SERIAL_COMMAND_CTS, + SERIAL_COMMAND_RI, + SERIAL_COMMAND_INVALID + }; + serial_command_pin serial_command_from_string(const char *str); + + enum serial_proceed_pin + { + SERIAL_PROCEED_NONE = 0, + SERIAL_PROCEED_DTR, + SERIAL_PROCEED_RTS, + SERIAL_PROCEED_INVALID + }; + serial_proceed_pin serial_proceed_from_string(const char *str); +#endif // GENERAL std::string get_general_devicename() { return _general.devicename; }; @@ -81,6 +120,24 @@ class fnConfig const char * get_network_sntpserver() { return _network.sntpserver; }; +#ifndef ESP_PLATFORM + std::string get_general_interface_url() { return _general.interface_url; }; + void store_general_interface_url(const char *url); + std::string get_general_config_path() { return _general.config_file_path; }; + void store_general_config_path(const char *file_path); + std::string get_general_SD_path() { return _general.SD_dir_path; }; + void store_general_SD_path(const char *dir_path); + + + // SERIAL PORT + std::string get_serial_port() { return _serial.port; }; + serial_command_pin get_serial_command() { return _serial.command; }; + serial_proceed_pin get_serial_proceed() { return _serial.proceed; }; + void store_serial_port(const char *port); + void store_serial_command(serial_command_pin command_pin); + void store_serial_proceed(serial_proceed_pin proceed_pin); +#endif + // WIFI bool have_wifi_info() { return _wifi.ssid.empty() == false; }; std::string get_wifi_ssid() { return _wifi.ssid; }; @@ -188,6 +245,16 @@ class fnConfig bool get_apetime_enabled(); void store_apetime_enabled(bool enabled); +#ifndef ESP_PLATFORM + // NETSIO (Connection to Atari emulator) + bool get_netsio_enabled() { return _netsio.netsio_enabled; } + std::string get_netsio_host() { return _netsio.host; }; + int get_netsio_port() { return _netsio.port; }; + void store_netsio_enabled(bool enabled); + void store_netsio_host(const char *host); + void store_netsio_port(int port); +#endif + void load(); void save(); @@ -214,6 +281,10 @@ class fnConfig void _read_section_phonebook(std::stringstream &ss, int index); void _read_section_cpm(std::stringstream &ss); void _read_section_device_enable(std::stringstream &ss); +#ifndef ESP_PLATFORM + void _read_section_serial(std::stringstream &ss); + void _read_section_netsio(std::stringstream &ss); +#endif enum section_match { @@ -231,6 +302,10 @@ class fnConfig SECTION_PHONEBOOK, SECTION_CPM, SECTION_DEVICE_ENABLE, +#ifndef ESP_PLATFORM + SECTION_SERIAL, + SECTION_NETSIO, +#endif SECTION_UNKNOWN }; section_match _find_section_in_line(std::string &line, int &index); @@ -245,6 +320,21 @@ class fnConfig "w" }; +#ifndef ESP_PLATFORM + const char * _serial_command_pin_names[SERIAL_COMMAND_INVALID] = { + "none", + "DSR", + "CTS", + "RI" + }; + + const char * _serial_proceed_pin_names[SERIAL_PROCEED_INVALID] = { + "none", + "DTR", + "RTS" + }; +#endif + struct host_info { host_type_t type = HOSTTYPE_INVALID; @@ -303,8 +393,12 @@ class fnConfig struct general_info { - std::string devicename = "fujinet"; + std::string devicename = "FujiNet"; +#ifdef ESP_PLATFORM int hsio_index = HSIO_INVALID_INDEX; +#else + int hsio_index = HSIO_DISABLED_INDEX; +#endif std::string timezone; bool rotation_sounds = true; bool config_enabled = true; @@ -312,13 +406,34 @@ class fnConfig bool fnconfig_spifs = true; bool status_wait_enabled = true; bool encrypt_passphrase = false; - #ifdef BUILD_ADAM +#ifdef BUILD_ADAM bool printer_enabled = false; // Not by default. - #else +#else bool printer_enabled = true; - #endif +#endif +#ifndef ESP_PLATFORM + std::string interface_url = WEB_SERVER_LISTEN_URL; // default URL to serve web interface + std::string config_file_path = CONFIG_FILENAME; // default path to load/save config file (program CWD) + std::string SD_dir_path = SD_CARD_DIR; // default path to load/save config file +#endif + }; + +#ifndef ESP_PLATFORM + struct serial_info + { + std::string port; + serial_command_pin command = SERIAL_COMMAND_DSR; + serial_proceed_pin proceed = SERIAL_PROCEED_DTR; }; + struct netsio_info + { + bool netsio_enabled = false; + std::string host = ""; + int port = CONFIG_DEFAULT_NETSIO_PORT; + }; +#endif + struct modem_info { bool modem_enabled = true; @@ -370,6 +485,10 @@ class fnConfig general_info _general; modem_info _modem; cassette_info _cassette; +#ifndef ESP_PLATFORM + serial_info _serial; + netsio_info _netsio; +#endif cpm_info _cpm; device_enable_info _denable; phbook_info _phonebook_slots[MAX_PB_SLOTS]; diff --git a/lib/config/fnc_general.cpp b/lib/config/fnc_general.cpp index 1f8d4a99c..1e4907066 100644 --- a/lib/config/fnc_general.cpp +++ b/lib/config/fnc_general.cpp @@ -46,6 +46,7 @@ void fnConfig::store_general_status_wait_enabled(bool status_wait_enabled) _general.status_wait_enabled = status_wait_enabled; _dirty = true; } + void fnConfig::store_general_encrypt_passphrase(bool encrypt_passphrase) { if (_general.encrypt_passphrase == encrypt_passphrase) @@ -67,10 +68,12 @@ void fnConfig::store_general_encrypt_passphrase(bool encrypt_passphrase) _dirty = true; } + bool fnConfig::get_general_encrypt_passphrase() { return _general.encrypt_passphrase; } + void fnConfig::store_general_boot_mode(uint8_t boot_mode) { if (_general.boot_mode == boot_mode) @@ -98,6 +101,38 @@ void fnConfig::store_general_fnconfig_spifs(bool fnconfig_spifs) _dirty = true; } +#ifndef ESP_PLATFORM +void fnConfig::store_general_interface_url(const char *url) +{ + if (_general.interface_url.compare(url) == 0) + return; + + _general.interface_url = url; + // this option is not stored in config file + // _dirty = true; +} + +void fnConfig::store_general_config_path(const char *file_path) +{ + if (_general.config_file_path.compare(file_path) == 0) + return; + + _general.config_file_path = file_path; + // this option is not stored in config file + // _dirty = true; +} + +void fnConfig::store_general_SD_path(const char *dir_path) +{ + if (_general.SD_dir_path.compare(dir_path) == 0) + return; + + _general.SD_dir_path = dir_path; + // this option is not stored in config file + // _dirty = true; +} +#endif + // Saves ENABLE or DISABLE printer void fnConfig::store_printer_enabled(bool printer_enabled) { @@ -125,7 +160,11 @@ void fnConfig::_read_section_general(std::stringstream &ss) else if (strcasecmp(name.c_str(), "hsioindex") == 0) { int index = atoi(value.c_str()); +#ifdef ESP_PLATFORM if (index >= 0 && index < 10) +#else + if (index >= -1 && index <= 10 || index == 16) // accepted values: -1(HSIO disabled),0..10,16 +#endif _general.hsio_index = index; } else if (strcasecmp(name.c_str(), "timezone") == 0) diff --git a/lib/config/fnc_load.cpp b/lib/config/fnc_load.cpp index c793a7f74..3858d4487 100644 --- a/lib/config/fnc_load.cpp +++ b/lib/config/fnc_load.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "keys.h" #include "utils.h" @@ -17,6 +18,7 @@ */ void fnConfig::load() { +#ifdef ESP_PLATFORM Debug_println("fnConfig::load"); #if defined(NO_BUTTONS) || defined(BUILD_LYNX) || defined(BUILD_APPLE) || defined(BUILD_RS232) || defined(BUILD_RC2014) @@ -89,6 +91,28 @@ New behavior: copy from SD first if available, then read FLASH. Debug_println("Load fnconfig.ini from flash"); fin = fsFlash.file_open(CONFIG_FILENAME); } +// ESP_PLATFORM + #else +// !ESP_PLATFORM + Debug_printf("fnConfig::load \"%s\"\n", _general.config_file_path.c_str()); + + struct stat st; + if (stat(_general.config_file_path.c_str(), &st) < 0) + { + _dirty = true; // We have a new (blank) config, so we treat it as needing to be saved + Debug_println("No config found - starting fresh!"); + return; // No local copy - ABORT + } + FILE *fin = fopen(_general.config_file_path.c_str(), FILE_READ_TEXT); +// !ESP_PLATFORM + #endif + + if (fin == nullptr) + { + Debug_printf("Failed to open config file\n"); + return; + } + // Read INI file into buffer (for speed) // Then look for sections and handle each char *inibuffer = (char *)malloc(CONFIG_FILEBUFFSIZE); @@ -162,6 +186,14 @@ New behavior: copy from SD first if available, then read FLASH. case SECTION_DEVICE_ENABLE: // Thom put this here to handle explicit device enables in adam _read_section_device_enable(ss); break; +#ifndef ESP_PLATFORM + case SECTION_SERIAL: + _read_section_serial(ss); + break; + case SECTION_NETSIO: + _read_section_netsio(ss); + break; +#endif case SECTION_UNKNOWN: break; } @@ -169,6 +201,7 @@ New behavior: copy from SD first if available, then read FLASH. _dirty = false; +#ifdef ESP_PLATFORM if (fnConfig::get_general_fnconfig_spifs() == true) // Only if flash is enabled { if (true == fsFlash.exists(CONFIG_FILENAME)) @@ -215,4 +248,5 @@ New behavior: copy from SD first if available, then read FLASH. } } } +#endif // ESP_PLATFORM } diff --git a/lib/config/fnc_network.cpp b/lib/config/fnc_network.cpp index 78953d5af..3a667c16f 100644 --- a/lib/config/fnc_network.cpp +++ b/lib/config/fnc_network.cpp @@ -1,5 +1,6 @@ #include "fnConfig.h" #include +#include "compat_string.h" void fnConfig::store_udpstream_host(const char host_ip[64]) { diff --git a/lib/config/fnc_phonebook.cpp b/lib/config/fnc_phonebook.cpp index c4b6a29bd..326f7d3ed 100644 --- a/lib/config/fnc_phonebook.cpp +++ b/lib/config/fnc_phonebook.cpp @@ -14,6 +14,7 @@ std::string fnConfig::get_pb_host_name(const char *pbnum) //Return empty (not found) return std::string(); } + std::string fnConfig::get_pb_host_port(const char *pbnum) { int i=0; @@ -27,6 +28,7 @@ std::string fnConfig::get_pb_host_port(const char *pbnum) //Return empty (not found) return std::string(); } + bool fnConfig::add_pb_number(const char *pbnum, const char *pbhost, const char *pbport) { //Check maximum lenght of phone number @@ -50,6 +52,7 @@ bool fnConfig::add_pb_number(const char *pbnum, const char *pbhost, const char * return false; } + bool fnConfig::del_pb_number(const char *pbnum) { int i=0; @@ -69,6 +72,7 @@ bool fnConfig::del_pb_number(const char *pbnum) //Not found return false; } + void fnConfig::clear_pb(void) { for (int i=0; i +#include +#ifdef ESP_PLATFORM #include +#endif #include "fnFS.h" +// from sysexits.h +// #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +// exit code should be monitored by parent process and FN restarted if ended with 75 +#define EXIT_AND_RESTART 75 #define FILE_COPY_BUFFERSIZE 2048 @@ -21,13 +28,19 @@ class SystemManager { private: - char _uptime_string[18]; + char _uptime_string[24]; char _currenttime_string[40]; int _hardware_version = 0; // unknown bool a2spifix = false; bool a2no3state = false; bool ledstrip_found = false; +#ifdef ESP_PLATFORM gpio_num_t safe_reset_gpio = GPIO_NUM_14; // Default 14 for most boards, can be changed in fnSystem during hardware checks +#else + char _uname_string[128]; + uint64_t _reboot_at = 0; + int _reboot_code = EXIT_AND_RESTART; +#endif public: SystemManager(); @@ -86,21 +99,34 @@ class SystemManager #define DIGI_LOW 0x00 #define DIGI_HIGH 0x01 +#ifdef ESP_PLATFORM void set_pin_mode(uint8_t pin, gpio_mode_t mode, pull_updown_t pull_mode = PULL_NONE, gpio_int_type_t intr_type = GPIO_INTR_DISABLE); +#endif int digital_read(uint8_t pin); void digital_write(uint8_t pin, uint8_t val); +#ifdef ESP_PLATFORM void reboot(); +#else + void reboot(uint32_t delay_ms = 0, bool reboot=true); + bool check_deferred_reboot(); +#endif uint32_t get_cpu_frequency(); uint32_t get_free_heap_size(); uint32_t get_psram_size(); const char *get_sdk_version(); chipmodels get_cpu_model(); int get_cpu_rev(); +#ifdef ESP_PLATFORM int64_t get_uptime(); unsigned long millis(); unsigned long micros(); +#else + uint64_t get_uptime(); + uint64_t millis(); + uint64_t micros(); +#endif void delay_microseconds(uint32_t us); void delay(uint32_t ms); @@ -111,6 +137,10 @@ class SystemManager const char *get_fujinet_version(bool shortVersionOnly = false); +#ifndef ESP_PLATFORM + const char *get_uname(); +#endif + int get_sio_voltage(); void yield(); @@ -130,7 +160,9 @@ class SystemManager bool spifix() { return a2spifix; }; bool no3state() { return a2no3state; }; bool ledstrip() { return ledstrip_found; }; +#ifdef ESP_PLATFORM gpio_num_t get_safe_reset_gpio() { return safe_reset_gpio; }; +#endif }; extern SystemManager fnSystem; diff --git a/lib/hardware/fnUART.h b/lib/hardware/fnUART.h index 547c18c19..84a02eafa 100644 --- a/lib/hardware/fnUART.h +++ b/lib/hardware/fnUART.h @@ -3,21 +3,48 @@ #ifndef FNUART_H #define FNUART_H +#ifdef ESP_PLATFORM #include +#endif + +#if defined (_WIN32) +#include +#endif #include +#include class UARTManager { private: +#ifdef ESP_PLATFORM uart_port_t _uart_num; QueueHandle_t _uart_q; +#else + char _device[64]; // device name or path + uint32_t _baud; + int _command_pin; + int _proceed_pin; + +#if defined (_WIN32) + int _command_status; + int _proceed_set; + int _proceed_clear; + HANDLE _fd; +#else + int _command_tiocm; + int _proceed_tiocm; + int _fd; +#endif +#endif // !ESP_PLATFORM + bool _initialized = false; // is UART ready? size_t _print_number(unsigned long n, uint8_t base); public: +#ifdef ESP_PLATFORM UARTManager(uart_port_t uart_num=0); void begin(int baud); @@ -58,9 +85,67 @@ class UARTManager size_t print(unsigned int n, int base = 10); size_t print(long n, int base = 10); size_t print(unsigned long n, int base = 10); +#else + UARTManager(); + + void begin(int baud); + void end(); + bool poll(int ms); + + void suspend(int sec=5); + bool initialized() { return _initialized; } + + void set_port(const char *device, int command_pin, int proceed_pin); + const char* get_port(int &command_pin, int &proceed_pin); + + void set_baudrate(uint32_t baud); + uint32_t get_baudrate() { return _baud; } + + bool command_asserted(); + bool motor_asserted() { return false; } // not pin available + void set_proceed(bool level); + void set_interrupt(bool level) {} // not pin available + + int available(); + void flush(); + void flush_input(); + + bool waitReadable(uint32_t timeout_ms); + + int read(); + size_t readBytes(uint8_t *buffer, size_t length, bool command_mode=false); + size_t readBytes(char *buffer, size_t length) { return readBytes((uint8_t *)buffer, length); } + + size_t write(uint8_t); + size_t write(const uint8_t *buffer, size_t size); + size_t write(const char *s); + + size_t write(unsigned long n) { return write((uint8_t)n); } + size_t write(long n) { return write((uint8_t)n); } + size_t write(unsigned int n) { return write((uint8_t)n); } + size_t write(int n) { return write((uint8_t)n); } + + // size_t printf(const char *format, ...); + + // //size_t println(const char *format, ...); + // size_t println(const char *str); + // size_t println() { return print("\n"); }; + // size_t println(std::string str); + // size_t println(int num, int base = 10); + + // //size_t print(const char *format, ...); + size_t print(const char *str); + size_t print(const std::string &str); + size_t print(int n, int base = 10); + size_t print(unsigned int n, int base = 10); + size_t print(long n, int base = 10); + size_t print(unsigned long n, int base = 10); +#endif // ESP_PLATFORM }; +#ifdef ESP_PLATFORM extern UARTManager fnUartDebug; extern UARTManager fnUartBUS; +#endif #endif //FNUART_H diff --git a/lib/hardware/fnWiFi.h b/lib/hardware/fnWiFi.h index c4b1a5a3f..abf8f6d2e 100644 --- a/lib/hardware/fnWiFi.h +++ b/lib/hardware/fnWiFi.h @@ -1,6 +1,12 @@ #ifndef FNWIFI_H #define FNWIFI_H +#ifndef ESP_PLATFORM +// dummy wifi module +#include "fnDummyWiFi.h" +#endif // !ESP_PLATFORM + +#ifdef ESP_PLATFORM #include #include #include @@ -98,4 +104,5 @@ class WiFiManager extern WiFiManager fnWiFi; +#endif // ESP_PLATFORM #endif // FNWIFI_H diff --git a/lib/tcpip/fnDNS.h b/lib/tcpip/fnDNS.h index 1853484f9..3111ed020 100644 --- a/lib/tcpip/fnDNS.h +++ b/lib/tcpip/fnDNS.h @@ -1,7 +1,22 @@ #ifndef _FN_DNS_ #define _FN_DNS_ -#include + +#include "compat_inet.h" + +#ifndef ESP_PLATFORM + +/* borrowed from lwip/ip4_addr.h */ +/** 255.255.255.255 */ +#define IPADDR_NONE ((uint32_t)0xffffffffUL) +/** 127.0.0.1 */ +#define IPADDR_LOOPBACK ((uint32_t)0x7f000001UL) +/** 0.0.0.0 */ +#define IPADDR_ANY ((uint32_t)0x00000000UL) +/** 255.255.255.255 */ +#define IPADDR_BROADCAST ((uint32_t)0xffffffffUL) + +#endif // !ESP_PLATFORM in_addr_t get_ip4_addr_by_name(const char *hostname); -#endif // _FN_DNS_ \ No newline at end of file +#endif // _FN_DNS_ diff --git a/pc_merge_notes.md b/pc_merge_notes.md index 548c6426f..5bda5b2e1 100644 --- a/pc_merge_notes.md +++ b/pc_merge_notes.md @@ -2,63 +2,75 @@ - TODO: src/main.cpp -- TODO: lib/config/fnConfig.h lib/config/fnConfig.cpp +- **DONE** / merge: lib/config/fnConfig.h lib/config/fnConfig.cpp -- TODO: lib/config/fnc_bt.cpp + removed get_general_label(), use get_general_devicename() instead -- TODO: lib/config/fnc_cassette.cpp +- **DONE** / identical: lib/config/fnc_bt.cpp -- TODO: lib/config/fnc_cpm.cpp +- **DONE** / identical: lib/config/fnc_cassette.cpp -- TODO: lib/config/fnc_enable.cpp +- **DONE** / identical: lib/config/fnc_cpm.cpp -- TODO: lib/config/fnc_general.cpp +- **DONE** / identical: lib/config/fnc_enable.cpp -- TODO: lib/config/fnc_hosts.cpp +- **DONE**: lib/config/fnc_general.cpp -- TODO: lib/config/fnc_load.cpp +- **DONE** / identical: lib/config/fnc_hosts.cpp -- TODO: lib/config/fnc_modem.cpp +- **DONE**: lib/config/fnc_load.cpp -- TODO: lib/config/fnc_mounts.cpp +- **DONE** / identical: lib/config/fnc_modem.cpp -- TODO: lib/config/fnc_network.cpp +- **DONE** / identical: lib/config/fnc_mounts.cpp -- TODO: lib/config/fnc_phonebook.cpp +- **DONE** / merge: lib/config/fnc_network.cpp -- TODO: lib/config/fnc_printer.cpp +- **DONE** / identical: lib/config/fnc_phonebook.cpp -- TODO: lib/config/fnc_save.cpp +- **DONE** / identical: lib/config/fnc_printer.cpp -- TODO: lib/config/fnc_serial.cpp +- **DONE** / merge: lib/config/fnc_save.cpp -- TODO: lib/config/fnc_util.cpp +- **DONE** / merge: lib/config/fnc_serial.cpp -- TODO: lib/config/fnc_wifi.cpp +- **DONE** / merge: lib/config/fnc_util.cpp -- **DONE** / merged: include/debug.h +- **DONE** / identical: lib/config/fnc_wifi.cpp -- **DONE** / merged: lib/utils/utils.h lib/utils/utils.cpp +- **DONE** / merge: include/debug.h -- **DONE** / no change: lib/utils/cbuf.h lib/utils/cbuf.cpp +- **DONE** / merge: lib/utils/utils.h lib/utils/utils.cpp -- **WIP**: lib/utils/string_utils.h lib/utils/string_utils.cpp +- **DONE** / identical: lib/utils/cbuf.h lib/utils/cbuf.cpp -- TODO: lib/hardware/fnWiFi.h lib/hardware/fnDummyWiFi.h lib/hardware/fnDummyWiFi.cpp +- **DONE**: lib/utils/string_utils.h lib/utils/string_utils.cpp + +- **WIP**: lib/hardware/fnWiFi.h lib/hardware/fnDummyWiFi.h lib/hardware/fnDummyWiFi.cpp + + fnWiFi.h - TODO: lib/hardware/led.h lib/hardware/led.cpp -- TODO: lib/hardware/fnUART.h lib/hardware/fnUART.cpp +- **WIP**: lib/hardware/fnUART.h lib/hardware/fnUART.cpp + + fnUART.h + +- **WIP**: lib/hardware/fnSystem.h lib/hardware/fnSystem.cpp lib/hardware/fnSystemNet.cpp -- TODO: lib/hardware/fnSystem.h lib/hardware/fnSystem.cpp lib/hardware/fnSystemNet.cpp + fnSystem.h - TODO: lib/FileSystem/fnDirCache.h lib/FileSystem/fnDirCache.cpp -- TODO: lib/FileSystem/fnFS.h lib/FileSystem/fnFS.cpp +- **WIO**: lib/FileSystem/fnFS.h lib/FileSystem/fnFS.cpp + + fnFS.h - TODO: lib/FileSystem/fnFsSPIFFS.h lib/FileSystem/fnFsSPIFFS.cpp -- TODO: lib/FileSystem/fnFsSD.h lib/FileSystem/fnFsSD.cpp +- **WIP**: lib/FileSystem/fnFsSD.h lib/FileSystem/fnFsSD.cpp + + fnFsSD.h - TODO: lib/FileSystem/fnFsTNFS.h lib/FileSystem/fnFsTNFS.cpp @@ -83,7 +95,9 @@ (std::string std::vectort etc.) to fix "ambiguous byte" compilation errors - FN-PC files with "ambiguous byte" fix: EdUrlParser.[h,cpp] fnjson.cpp fnFTP.h -- TODO: lib/tcpip/fnDNS.h lib/tcpip/fnDNS.cpp +- **WIP**: lib/tcpip/fnDNS.h lib/tcpip/fnDNS.cpp + + fnDNS.h - TODO: lib/tcpip/fnUDP.h lib/tcpip/fnUDP.cpp @@ -193,7 +207,9 @@ - TODO: lib/bus/iwm/iwm_slip.h lib/bus/iwm/iwm_slip.cpp -- TODO: lib/bus/sio/sio.h lib/bus/sio/sio.cpp +- **WIP**: lib/bus/sio/sio.h lib/bus/sio/sio.cpp + + sio.h - TODO: lib/bus/sio/siocom/sioport.h lib/bus/sio/siocom/sioport.cpp @@ -285,6 +301,6 @@ - TODO: lib/compat/compat_inet.c -- TODO: lib/compat/compat_gettimeofday.c +- **DONE** / merged: lib/compat/compat_gettimeofday.h lib/compat/compat_gettimeofday.c - TODO: