diff --git a/.gitignore b/.gitignore index 2b9853899..64a087cab 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ sdkconfig.fujinet-lynx-prototype sdkconfig.fujinet-lynx-devkitc sdkconfig.fujinet-adam-v1 sdkconfig.fujinet-cbm +sdkconfig.esp32s3 include/ssid.h /*.log diff --git a/include/version.h b/include/version.h index 0e5ebb136..cb9c16cc7 100644 --- a/include/version.h +++ b/include/version.h @@ -10,8 +10,8 @@ #define FN_VERSION_MAJOR 0 #define FN_VERSION_MINOR 5 -#define FN_VERSION_BUILD "41f6bdd7" +#define FN_VERSION_BUILD "111eb575" -#define FN_VERSION_DATE "2022-11-18 04:09:59" +#define FN_VERSION_DATE "2022-11-19 11:08:58" -#define FN_VERSION_FULL "0.5.41f6bdd7" +#define FN_VERSION_FULL "0.5.111eb575" diff --git a/lib/bus/sio/sio.cpp b/lib/bus/sio/sio.cpp index 94b782424..254912954 100755 --- a/lib/bus/sio/sio.cpp +++ b/lib/bus/sio/sio.cpp @@ -58,11 +58,12 @@ void virtualDevice::bus_to_computer(uint8_t *buf, uint16_t len, bool err) sio_complete(); // Write data frame - fnUartSIO.write(buf, len); + UARTManager *uart = sio_get_bus().get_modem()->get_uart(); + uart->write(buf, len); // Write checksum - fnUartSIO.write(sio_checksum(buf, len)); + uart->write(sio_checksum(buf, len)); - fnUartSIO.flush(); + uart->flush(); } /* @@ -76,14 +77,16 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len) // Retrieve data frame from computer Debug_printf("<-SIO read %hu bytes\n", len); + UARTManager *uart = sio_get_bus().get_modem()->get_uart(); + __BEGIN_IGNORE_UNUSEDVARS - size_t l = fnUartSIO.readBytes(buf, len); + size_t l = uart->readBytes(buf, len); __END_IGNORE_UNUSEDVARS // Wait for checksum - while (fnUartSIO.available() <= 0) + while (uart->available() <= 0) fnSystem.yield(); - uint8_t ck_rcv = fnUartSIO.read(); + uint8_t ck_rcv = uart->read(); uint8_t ck_tst = sio_checksum(buf, len); @@ -110,17 +113,19 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len) // SIO NAK void virtualDevice::sio_nak() { - fnUartSIO.write('N'); - fnUartSIO.flush(); + UARTManager *uart = sio_get_bus().get_modem()->get_uart(); + uart->write('N'); + uart->flush(); Debug_println("NAK!"); } // SIO ACK void virtualDevice::sio_ack() { - fnUartSIO.write('A'); + UARTManager *uart = sio_get_bus().get_modem()->get_uart(); + uart->write('A'); fnSystem.delay_microseconds(DELAY_T5); //? - fnUartSIO.flush(); + uart->flush(); Debug_println("ACK!"); } @@ -128,7 +133,7 @@ void virtualDevice::sio_ack() void virtualDevice::sio_complete() { fnSystem.delay_microseconds(DELAY_T5); - fnUartSIO.write('C'); + sio_get_bus().get_modem()->get_uart()->write('C'); Debug_println("COMPLETE!"); } @@ -136,7 +141,7 @@ void virtualDevice::sio_complete() void virtualDevice::sio_error() { fnSystem.delay_microseconds(DELAY_T5); - fnUartSIO.write('E'); + sio_get_bus().get_modem()->get_uart()->write('E'); Debug_println("ERROR!"); } @@ -148,6 +153,8 @@ void virtualDevice::sio_high_speed() bus_to_computer((uint8_t *)&hsd, 1, false); } +systemBus virtualDevice::sio_get_bus() { return SIO; } + // Read and process a command frame from SIO void systemBus::_sio_process_cmd() { @@ -155,7 +162,7 @@ void systemBus::_sio_process_cmd() { _modemDev->modemActive = false; Debug_println("Modem was active - resetting SIO baud"); - fnUartSIO.set_baudrate(_sioBaud); + _modemDev->get_uart()->set_baudrate(_sioBaud); } // Read CMD frame @@ -163,7 +170,7 @@ void systemBus::_sio_process_cmd() tempFrame.commanddata = 0; tempFrame.checksum = 0; - if (fnUartSIO.readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame)) + if (_modemDev->get_uart()->readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame)) { // Debug_println("Timeout waiting for data after CMD pin asserted"); return; @@ -341,7 +348,7 @@ void systemBus::service() else // Neither CMD nor active modem, so throw out any stray input data { - fnUartSIO.flush_input(); + _modemDev->get_uart()->flush_input(); } // Handle interrupts from network protocols @@ -358,7 +365,7 @@ void systemBus::setup() Debug_println("SIO SETUP"); // Set up UART - fnUartSIO.begin(_sioBaud); + _modemDev->get_uart()->begin(_sioBaud); // INT PIN fnSystem.set_pin_mode(PIN_INT, gpio_mode_t::GPIO_MODE_OUTPUT_OD, SystemManager::pull_updown_t::PULL_UP); @@ -390,7 +397,7 @@ void systemBus::setup() else setHighSpeedIndex(_sioHighSpeedIndex); - fnUartSIO.flush_input(); + _modemDev->get_uart()->flush_input(); } // Add device to SIO bus @@ -402,7 +409,7 @@ void systemBus::addDevice(virtualDevice *pDevice, int device_id) } else if (device_id == SIO_DEVICEID_RS232) { - _modemDev = (sioModem *)pDevice; + _modemDev = (modem *)pDevice; } else if (device_id >= SIO_DEVICEID_FN_NETWORK && device_id <= SIO_DEVICEID_FN_NETWORK_LAST) { @@ -487,7 +494,7 @@ void systemBus::toggleBaudrate() Debug_printf("Toggling baudrate from %d to %d\n", _sioBaud, baudrate); _sioBaud = baudrate; - fnUartSIO.set_baudrate(_sioBaud); + _modemDev->get_uart()->set_baudrate(_sioBaud); } int systemBus::getBaudrate() @@ -505,7 +512,7 @@ void systemBus::setBaudrate(int baud) Debug_printf("Changing baudrate from %d to %d\n", _sioBaud, baud); _sioBaud = baud; - fnUartSIO.set_baudrate(baud); + _modemDev->get_uart()->set_baudrate(baud); } // Set HSIO index. Sets high speed SIO baud and also returns that value. @@ -605,7 +612,7 @@ void systemBus::setUltraHigh(bool _enable, int _ultraHighBaud) // Enable PWM on CLOCK IN ledc_channel_config(&ledc_channel_sio_ckin); ledc_timer_config(&ledc_timer); - fnUartSIO.set_baudrate(_sioBaudUltraHigh); + _modemDev->get_uart()->set_baudrate(_sioBaudUltraHigh); } else { @@ -613,7 +620,7 @@ void systemBus::setUltraHigh(bool _enable, int _ultraHighBaud) ledc_stop(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_1, 0); _sioBaudUltraHigh = 0; - fnUartSIO.set_baudrate(SIO_STANDARD_BAUDRATE); + _modemDev->get_uart()->set_baudrate(SIO_STANDARD_BAUDRATE); } } diff --git a/lib/bus/sio/sio.h b/lib/bus/sio/sio.h index cebcc70b4..f82796422 100755 --- a/lib/bus/sio/sio.h +++ b/lib/bus/sio/sio.h @@ -104,14 +104,14 @@ union cmdFrame_t uint8_t sio_checksum(uint8_t *buf, unsigned short len); // class def'ns -class sioModem; // declare here so can reference it, but define in modem.h -class sioFuji; // declare here so can reference it, but define in fuji.h +class modem; // declare here so can reference it, but define in modem.h +class sioFuji; // declare here so can reference it, but define in fuji.h class systemBus; // declare early so can be friend -class sioNetwork; // declare here so can reference it, but define in network.h -class sioUDPStream; // declare here so can reference it, but define in udpstream.h -class sioCassette; // Cassette forward-declaration. -class sioCPM; // CPM device. -class sioPrinter; // Printer device +class sioNetwork; // declare here so can reference it, but define in network.h +class sioUDPStream; // declare here so can reference it, but define in udpstream.h +class sioCassette; // Cassette forward-declaration. +class sioCPM; // CPM device. +class sioPrinter; // Printer device class virtualDevice { @@ -248,7 +248,7 @@ class systemBus int _command_frame_counter = 0; virtualDevice *_activeDev = nullptr; - sioModem *_modemDev = nullptr; + modem *_modemDev = nullptr; sioFuji *_fujiDev = nullptr; sioNetwork *_netDev[8] = {nullptr}; sioUDPStream *_udpDev = nullptr; @@ -294,6 +294,9 @@ class systemBus sioPrinter *getPrinter() { return _printerdev; } sioCPM *getCPM() { return _cpmDev; } + // I wish this codebase would make up its mind to use camel or snake casing. + modem *get_modem() { return _modemDev; } + QueueHandle_t qSioMessages = nullptr; }; diff --git a/lib/config/fnConfig.cpp b/lib/config/fnConfig.cpp index 3a7c91517..63427ff4e 100644 --- a/lib/config/fnConfig.cpp +++ b/lib/config/fnConfig.cpp @@ -5,7 +5,7 @@ #include "../../include/debug.h" -#include "modem.h" +#include "../device/modem.h" #include "modem-sniffer.h" #include "fnSystem.h" diff --git a/lib/device/device.h b/lib/device/device.h index 14056ab0f..6a650cbe7 100644 --- a/lib/device/device.h +++ b/lib/device/device.h @@ -6,7 +6,7 @@ # include "sio/cassette.h" # include "sio/disk.h" # include "sio/udpstream.h" -# include "sio/modem.h" +# include "../lib/modem/modem.h" # include "sio/network.h" # include "sio/printer.h" # include "sio/printerlist.h" @@ -18,7 +18,7 @@ sioVoice sioV; sioUDPStream udpDev; // sioCassette sioC; // now part of sioFuji theFuji object - sioModem *sioR; + modem *sioR; sioCPM sioZ; #endif diff --git a/lib/device/modem.h b/lib/device/modem.h index d6eed4a60..98b5efe33 100644 --- a/lib/device/modem.h +++ b/lib/device/modem.h @@ -2,8 +2,8 @@ #define DEVICE_MODEM_H #ifdef BUILD_ATARI -# include "sio/modem.h" - extern sioModem *sioR; +# include "../modem/modem.h" + extern modem *sioR; #endif #ifdef BUILD_RS232 diff --git a/lib/http/httpService.cpp b/lib/http/httpService.cpp index accc6587d..aaae28f1c 100644 --- a/lib/http/httpService.cpp +++ b/lib/http/httpService.cpp @@ -10,7 +10,7 @@ #include "fnConfig.h" #include "fnWiFi.h" #include "fnFsSPIFFS.h" -#include "modem.h" +#include "../device/modem.h" #include "printer.h" #include "httpServiceConfigurator.h" #include "httpServiceParser.h" diff --git a/lib/device/sio/modem.cpp b/lib/modem/modem.cpp similarity index 93% rename from lib/device/sio/modem.cpp rename to lib/modem/modem.cpp index 5506f1275..e5370b4d2 100755 --- a/lib/device/sio/modem.cpp +++ b/lib/modem/modem.cpp @@ -1,5 +1,3 @@ -#ifdef BUILD_ATARI - #include "modem.h" #include "../../../include/debug.h" @@ -55,24 +53,24 @@ static const telnet_telopt_t telopts[] = { */ static void _telnet_event_handler(telnet_t *telnet, telnet_event_t *ev, void *user_data) { - sioModem *modem = (sioModem *)user_data; // somehow it thinks this is unused? + modem *m = (modem *)user_data; // somehow it thinks this is unused? switch (ev->type) { case TELNET_EV_DATA: - if (ev->data.size && fnUartSIO.write((uint8_t *)ev->data.buffer, ev->data.size) != ev->data.size) + if (ev->data.size && m->get_uart()->write((uint8_t *)ev->data.buffer, ev->data.size) != ev->data.size) Debug_printf("_telnet_event_handler(%d) - Could not write complete buffer to SIO.\n", ev->type); break; case TELNET_EV_SEND: - modem->get_tcp_client().write((uint8_t *)ev->data.buffer, ev->data.size); + m->get_tcp_client().write((uint8_t *)ev->data.buffer, ev->data.size); break; case TELNET_EV_WILL: if (ev->neg.telopt == TELNET_TELOPT_ECHO) - modem->set_do_echo(false); + m->set_do_echo(false); break; case TELNET_EV_WONT: if (ev->neg.telopt == TELNET_TELOPT_ECHO) - modem->set_do_echo(true); + m->set_do_echo(true); break; case TELNET_EV_DO: break; @@ -80,7 +78,7 @@ static void _telnet_event_handler(telnet_t *telnet, telnet_event_t *ev, void *us break; case TELNET_EV_TTYPE: if (ev->ttype.cmd == TELNET_TTYPE_SEND) - telnet_ttype_is(telnet, modem->get_term_type().c_str()); + telnet_ttype_is(telnet, m->get_term_type().c_str()); break; case TELNET_EV_SUBNEGOTIATION: break; @@ -93,7 +91,7 @@ static void _telnet_event_handler(telnet_t *telnet, telnet_event_t *ev, void *us } } -sioModem::sioModem(FileSystem *_fs, bool snifferEnable) +modem::modem(FileSystem *_fs, bool snifferEnable) { listen_to_type3_polls = true; activeFS = _fs; @@ -102,7 +100,7 @@ sioModem::sioModem(FileSystem *_fs, bool snifferEnable) telnet = telnet_init(telopts, _telnet_event_handler, 0, this); } -sioModem::~sioModem() +modem::~modem() { if (modemSniffer != nullptr) { @@ -116,7 +114,7 @@ sioModem::~sioModem() } // 0x40 / '@' - TYPE 3 POLL -void sioModem::sio_poll_3(uint8_t device, uint8_t aux1, uint8_t aux2) +void modem::sio_poll_3(uint8_t device, uint8_t aux1, uint8_t aux2) { bool respond = false; @@ -186,7 +184,7 @@ void sioModem::sio_poll_3(uint8_t device, uint8_t aux1, uint8_t aux2) } // 0x3F / '?' - TYPE 1 POLL -void sioModem::sio_poll_1() +void modem::sio_poll_1() { /* From Altirra sources - rs232.cpp Send back SIO command for booting. This is a 12 uint8_t + chk block that @@ -239,7 +237,7 @@ void sioModem::sio_poll_1() // 0x21 / '!' - RELOCATOR DOWNLOAD // 0x26 / '&' - HANDLER DOWNLOAD -void sioModem::sio_send_firmware(uint8_t loadcommand) +void modem::sio_send_firmware(uint8_t loadcommand) { const char *firmware; if (loadcommand == SIO_MODEMCMD_LOAD_RELOCATOR) @@ -285,7 +283,7 @@ void sioModem::sio_send_firmware(uint8_t loadcommand) } // 0x57 / 'W' - WRITE -void sioModem::sio_write() +void modem::sio_write() { uint8_t ck; @@ -335,7 +333,7 @@ void sioModem::sio_write() } // 0x53 / 'S' - STATUS -void sioModem::sio_status() +void modem::sio_status() { Debug_println("Modem cmd: STATUS"); @@ -373,13 +371,13 @@ void sioModem::sio_status() answerTimer = fnSystem.millis(); } - Debug_printf("sioModem::sio_status(%02x,%02x)\n", mdmStatus[0], mdmStatus[1]); + Debug_printf("modem::sio_status(%02x,%02x)\n", mdmStatus[0], mdmStatus[1]); bus_to_computer(mdmStatus, sizeof(mdmStatus), false); } // 0x41 / 'A' - CONTROL -void sioModem::sio_control() +void modem::sio_control() { /* AUX1: Set control state 7: Enable DTR (Data Terminal Ready) change (1=change, 0=ignore) @@ -431,7 +429,7 @@ void sioModem::sio_control() } // 0x42 / 'B' - CONFIGURE -void sioModem::sio_config() +void modem::sio_config() { Debug_println("Modem cmd: CONFIGURE"); @@ -502,14 +500,14 @@ void sioModem::sio_config() } // 0x44 / 'D' - Dump -void sioModem::sio_set_dump() +void modem::sio_set_dump() { modemSniffer->setEnable(cmdFrame.aux1); sio_complete(); } // 0x58 / 'X' - STREAM -void sioModem::sio_stream() +void modem::sio_stream() { Debug_println("Modem cmd: STREAM"); /* AUX1: I/O direction @@ -561,7 +559,7 @@ void sioModem::sio_stream() bus_to_computer((uint8_t *)response, sizeof(response), false); - fnUartSIO.set_baudrate(modemBaud); + get_uart()->set_baudrate(modemBaud); modemActive = true; Debug_printf("Modem streaming at %u baud\n", modemBaud); } @@ -569,7 +567,7 @@ void sioModem::sio_stream() /** * Set listen port */ -void sioModem::sio_listen() +void modem::sio_listen() { if (listenPort != 0) { @@ -593,7 +591,7 @@ void sioModem::sio_listen() /** * Stop listen */ -void sioModem::sio_unlisten() +void modem::sio_unlisten() { sio_ack(); tcpClient.stop(); @@ -604,7 +602,7 @@ void sioModem::sio_unlisten() /** * Lock MODEM baud rate to last configured value */ -void sioModem::sio_baudlock() +void modem::sio_baudlock() { sio_ack(); baudLock = (cmdFrame.aux1 > 0 ? true : false); @@ -618,7 +616,7 @@ void sioModem::sio_baudlock() /** * enable/disable auto-answer */ -void sioModem::sio_autoanswer() +void modem::sio_autoanswer() { sio_ack(); autoAnswer = (cmdFrame.aux1 > 0 ? true : false); @@ -628,7 +626,7 @@ void sioModem::sio_autoanswer() sio_complete(); } -void sioModem::at_connect_resultCode(int modemBaud) +void modem::at_connect_resultCode(int modemBaud) { int resultCode = 0; switch (modemBaud) @@ -655,105 +653,105 @@ void sioModem::at_connect_resultCode(int modemBaud) resultCode = 1; break; } - fnUartSIO.print(resultCode); - fnUartSIO.write(ASCII_CR); + get_uart()->print(resultCode); + get_uart()->write(ASCII_CR); } /** * Emit result code if ATV0 * No Atascii translation here, as this is intended for machine reading. */ -void sioModem::at_cmd_resultCode(int resultCode) +void modem::at_cmd_resultCode(int resultCode) { - fnUartSIO.print(resultCode); - fnUartSIO.write(ASCII_CR); - fnUartSIO.write(ASCII_LF); + get_uart()->print(resultCode); + get_uart()->write(ASCII_CR); + get_uart()->write(ASCII_LF); } /** replacement println for AT that is CR/EOL aware */ -void sioModem::at_cmd_println() +void modem::at_cmd_println() { if (cmdOutput == false) return; if (cmdAtascii == true) { - fnUartSIO.write(ATASCII_EOL); + get_uart()->write(ATASCII_EOL); } else { - fnUartSIO.write(ASCII_CR); - fnUartSIO.write(ASCII_LF); + get_uart()->write(ASCII_CR); + get_uart()->write(ASCII_LF); } - fnUartSIO.flush(); + get_uart()->flush(); } -void sioModem::at_cmd_println(const char *s, bool addEol) +void modem::at_cmd_println(const char *s, bool addEol) { if (cmdOutput == false) return; - fnUartSIO.print(s); + get_uart()->print(s); if (addEol) { if (cmdAtascii == true) { - fnUartSIO.write(ATASCII_EOL); + get_uart()->write(ATASCII_EOL); } else { - fnUartSIO.write(ASCII_CR); - fnUartSIO.write(ASCII_LF); + get_uart()->write(ASCII_CR); + get_uart()->write(ASCII_LF); } } - fnUartSIO.flush(); + get_uart()->flush(); } -void sioModem::at_cmd_println(int i, bool addEol) +void modem::at_cmd_println(int i, bool addEol) { if (cmdOutput == false) return; - fnUartSIO.print(i); + get_uart()->print(i); if (addEol) { if (cmdAtascii == true) { - fnUartSIO.write(ATASCII_EOL); + get_uart()->write(ATASCII_EOL); } else { - fnUartSIO.write(ASCII_CR); - fnUartSIO.write(ASCII_LF); + get_uart()->write(ASCII_CR); + get_uart()->write(ASCII_LF); } } - fnUartSIO.flush(); + get_uart()->flush(); } -void sioModem::at_cmd_println(std::string s, bool addEol) +void modem::at_cmd_println(std::string s, bool addEol) { if (cmdOutput == false) return; - fnUartSIO.print(s); + get_uart()->print(s); if (addEol) { if (cmdAtascii == true) { - fnUartSIO.write(ATASCII_EOL); + get_uart()->write(ATASCII_EOL); } else { - fnUartSIO.write(ASCII_CR); - fnUartSIO.write(ASCII_LF); + get_uart()->write(ASCII_CR); + get_uart()->write(ASCII_LF); } } - fnUartSIO.flush(); + get_uart()->flush(); } -void sioModem::at_handle_wificonnect() +void modem::at_handle_wificonnect() { int keyIndex = cmd.find(','); std::string ssid, key; @@ -808,7 +806,7 @@ void sioModem::at_handle_wificonnect() } } -void sioModem::at_handle_port() +void modem::at_handle_port() { //int port = cmd.substring(6).toInt(); int port = std::stoi(cmd.substr(6)); @@ -837,7 +835,7 @@ void sioModem::at_handle_port() } } -void sioModem::at_handle_get() +void modem::at_handle_get() { // From the URL, aquire required variables // (12 = "ATGEThttp://") @@ -903,7 +901,7 @@ void sioModem::at_handle_get() } } -void sioModem::at_handle_help() +void modem::at_handle_help() { at_cmd_println(HELPL01); at_cmd_println(HELPL02); @@ -953,7 +951,7 @@ void sioModem::at_handle_help() at_cmd_println("OK"); } -void sioModem::at_handle_wifilist() +void modem::at_handle_wifilist() { at_cmd_println(); at_cmd_println(HELPSCAN1); @@ -1003,7 +1001,7 @@ void sioModem::at_handle_wifilist() at_cmd_println("OK"); } -void sioModem::at_handle_answer() +void modem::at_handle_answer() { Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) @@ -1016,12 +1014,12 @@ void sioModem::at_handle_answer() CRX = true; cmdMode = false; - fnUartSIO.flush(); + get_uart()->flush(); answerHack = false; } } -void sioModem::at_handle_dial() +void modem::at_handle_dial() { int portIndex = cmd.find(':'); std::string host, port; @@ -1095,7 +1093,7 @@ void sioModem::at_handle_dial() } /*Following functions manage the phonebook*/ /*Display current Phonebook*/ -void sioModem::at_handle_pblist() +void modem::at_handle_pblist() { at_cmd_println(); at_cmd_println("Phone# Host"); @@ -1115,7 +1113,7 @@ void sioModem::at_handle_pblist() } /*Add and del entry in the phonebook*/ -void sioModem::at_handle_pb() +void modem::at_handle_pb() { // From the AT command get the info to add. Ex: atpb4321=irata.online:8002 //or delete ex: atpb4321 @@ -1188,7 +1186,7 @@ void sioModem::at_handle_pb() /* Perform a command given in AT Modem command mode */ -void sioModem::modemCommand() +void modem::modemCommand() { /* Some of these are ignored; to see their meanings, * review `modem.h`'s sioModem class's _at_cmds enums. */ @@ -1523,7 +1521,7 @@ void sioModem::modemCommand() /* Handle incoming & outgoing data for modem */ -void sioModem::sio_handle_modem() +void modem::sio_handle_modem() { /**** AT command mode ****/ if (cmdMode == true) @@ -1560,11 +1558,11 @@ void sioModem::sio_handle_modem() // In command mode - don't exchange with TCP but gather characters to a string //if (SIO_UART.available() /*|| blockWritePending == true */ ) - if (fnUartSIO.available() > 0) + if (get_uart()->available() > 0) { // get char from Atari SIO //char chr = SIO_UART.read(); - char chr = fnUartSIO.read(); + char chr = get_uart()->read(); // Return, enter, new line, carriage return.. anything goes to end the command if ((chr == ASCII_LF) || (chr == ASCII_CR) || (chr == ATASCII_EOL)) @@ -1589,9 +1587,9 @@ void sioModem::sio_handle_modem() // Clear with a space if (commandEcho == true) { - fnUartSIO.write(ASCII_BACKSPACE); - fnUartSIO.write(' '); - fnUartSIO.write(ASCII_BACKSPACE); + get_uart()->write(ASCII_BACKSPACE); + get_uart()->write(' '); + get_uart()->write(ASCII_BACKSPACE); } } } @@ -1604,7 +1602,7 @@ void sioModem::sio_handle_modem() { cmd.erase(len - 1); if (commandEcho == true) - fnUartSIO.write(ATASCII_BACKSPACE); + get_uart()->write(ATASCII_BACKSPACE); } } // Take into account arrow key movement and clear screen @@ -1612,7 +1610,7 @@ void sioModem::sio_handle_modem() ((chr >= ATASCII_CURSOR_UP) && (chr <= ATASCII_CURSOR_RIGHT))) { if (commandEcho == true) - fnUartSIO.write(chr); + get_uart()->write(chr); } else { @@ -1622,7 +1620,7 @@ void sioModem::sio_handle_modem() cmd += chr; } if (commandEcho == true) - fnUartSIO.write(chr); + get_uart()->write(chr); } } } @@ -1653,8 +1651,8 @@ void sioModem::sio_handle_modem() } } - int sioBytesAvail = fnUartSIO.available(); - //int sioBytesAvail = min(0, fnUartSIO.available()); + int sioBytesAvail = get_uart()->available(); + //int sioBytesAvail = min(0, get_uart()->available()); // send from Atari to Fujinet if (sioBytesAvail && tcpClient.connected()) @@ -1669,7 +1667,7 @@ void sioModem::sio_handle_modem() // Read from serial, the amount available up to // maximum size of the buffer - int sioBytesRead = fnUartSIO.readBytes(&txBuf[0], //SIO_UART.readBytes(&txBuf[0], + int sioBytesRead = get_uart()->readBytes(&txBuf[0], //SIO_UART.readBytes(&txBuf[0], (sioBytesAvail > TX_BUF_SIZE) ? TX_BUF_SIZE : sioBytesAvail); // Disconnect if going to AT mode with "+++" sequence @@ -1719,8 +1717,8 @@ void sioModem::sio_handle_modem() } else { - fnUartSIO.write(buf, bytesRead); - fnUartSIO.flush(); + get_uart()->write(buf, bytesRead); + get_uart()->flush(); } // And dump to sniffer, if enabled. @@ -1784,7 +1782,7 @@ void sioModem::sio_handle_modem() } } -void sioModem::shutdown() +void modem::shutdown() { if (modemSniffer != nullptr) if (modemSniffer->getEnable()) @@ -1794,16 +1792,16 @@ void sioModem::shutdown() /* Process command */ -void sioModem::sio_process(uint32_t commanddata, uint8_t checksum) +void modem::sio_process(uint32_t commanddata, uint8_t checksum) { cmdFrame.commanddata = commanddata; cmdFrame.checksum = checksum; if (!Config.get_modem_enabled()) - Debug_println("sioModem::disabled, ignoring"); + Debug_println("modem::disabled, ignoring"); else { - Debug_println("sioModem::sio_process() called"); + Debug_println("modem::sio_process() called"); switch (cmdFrame.comnd) { @@ -1871,6 +1869,4 @@ void sioModem::sio_process(uint32_t commanddata, uint8_t checksum) sio_nak(); } } -} - -#endif /* BUILD_ATARI */ \ No newline at end of file +} \ No newline at end of file diff --git a/lib/device/sio/modem.h b/lib/modem/modem.h similarity index 96% rename from lib/device/sio/modem.h rename to lib/modem/modem.h index fecaf9311..99fae50f0 100755 --- a/lib/device/sio/modem.h +++ b/lib/modem/modem.h @@ -1,16 +1,14 @@ #ifndef MODEM_H #define MODEM_H -// usually provided by esp32sshclient #include #include "bus.h" #include "fnTcpClient.h" #include "fnTcpServer.h" +#include "fnUART.h" #include "modem-sniffer.h" #include "libtelnet.h" -// #include "esp32sshclient.h" - /* Keep strings under 40 characters, for the benefit of 40-column users! */ #define HELPL01 " FujiNet Virtual Modem 850" @@ -41,7 +39,7 @@ #define HELPL26 "ATPB= | Add to Phonebook" /* Not explicitly mentioned at this time, since they are commonly known: - * (these are sioModem class's _at_cmds enums) + * (these are fujiModem class's _at_cmds enums) * - AT * - ATA (mentioned below) * - AT? (the help command itself) @@ -70,7 +68,7 @@ #define ANSWER_TIMER_MS 1000 // milliseconds to wait before issuing CONNECT command, to simulate carrier negotiation. -class sioModem : public virtualDevice +class modem : public virtualDevice { private: @@ -178,9 +176,9 @@ class sioModem : public virtualDevice bool use_telnet=false; // Use telnet mode? bool do_echo; // telnet echo toggle. string term_type; // telnet terminal type. - // ESP32SSHCLIENT ssh; // ssh instance. long answerTimer; bool answered=false; + UARTManager* uart; // UART manager to use. void sio_send_firmware(uint8_t loadcommand); // $21 and $26: Booter/Relocator download; Handler download void sio_poll_1(); // $3F, '?', Type 1 Poll @@ -230,8 +228,8 @@ class sioModem : public virtualDevice bool modemActive = false; // If we are in modem mode or not void sio_handle_modem(); // Handle incoming & outgoing data for modem - sioModem(FileSystem *_fs, bool snifferEnable); - virtual ~sioModem(); + modem(FileSystem *_fs, bool snifferEnable); + virtual ~modem(); time_t get_last_activity_time() { return _lasttime; } // timestamp of last input or output. ModemSniffer *get_modem_sniffer() { return modemSniffer; } @@ -240,6 +238,8 @@ class sioModem : public virtualDevice void set_do_echo(bool _do_echo) { do_echo = _do_echo; } string get_term_type() {return term_type; } void set_term_type(string _term_type) { term_type = _term_type; } + UARTManager* get_uart() { return uart; } + void set_uart(UARTManager *_uart) { uart = _uart; } }; diff --git a/platformio-sample.ini b/platformio-sample.ini index 0e81e7461..78352af4b 100644 --- a/platformio-sample.ini +++ b/platformio-sample.ini @@ -58,11 +58,11 @@ extra_scripts = pre:build_version.py lib_ldf_mode = deep+ upload_speed = 921600 ;upload_port = COM1 ; Windows -upload_port = /dev/ttyUSB0 ; Linux +upload_port = /dev/ttyUSB0 ; Linux/WSL ;upload_port = /dev/tty.SLAB_USBtoUART ; Mac monitor_speed = 921600 ;monitor_port = COM1 ; Windows -monitor_port = /dev/ttyUSB0 ; Linux +monitor_port = /dev/ttyUSB0 ; Linux/WSL ;monitor_port = /dev/tty.SLAB_USBtoUART ; Mac monitor_filters = time, esp32_exception_decoder ;,log2file check_skip_packages = yes ; so that check will work. diff --git a/src/main.cpp b/src/main.cpp index 487e10203..5298e03a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,7 +103,9 @@ void main_setup() SIO.addDevice(ptr, SIO_DEVICEID_PRINTER + fnPrinters.get_port(0)); // P: - sioR = new sioModem(ptrfs, Config.get_modem_sniffer_enabled()); // Config/User selected sniffer enable + sioR = new modem(ptrfs, Config.get_modem_sniffer_enabled()); // Config/User selected sniffer enable + // uart needs setting. is this right? + sioR->set_uart(&fnUartSIO); SIO.addDevice(sioR, SIO_DEVICEID_RS232); // R: