Skip to content

Commit e17a8ae

Browse files
nwahFozzTexx
authored andcommitted
feat(rs232): support BeckerSocket transport (#3)
1 parent 91825c2 commit e17a8ae

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

fujinet_pc.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ if(FUJINET_TARGET STREQUAL "RS232")
387387

388388
lib/bus/rs232/rs232.h lib/bus/rs232/rs232.cpp
389389
lib/bus/rs232/FujiBusPacket.h lib/bus/rs232/FujiBusPacket.cpp
390+
lib/bus/drivewire/BeckerSocket.h lib/bus/drivewire/BeckerSocket.cpp
390391

391392
lib/media/rs232/diskType.h lib/media/rs232/diskType.cpp
392393
lib/media/rs232/diskTypeImg.h lib/media/rs232/diskTypeImg.cpp

lib/bus/drivewire/BeckerSocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifdef BUILD_COCO
1+
#if defined(BUILD_COCO) || defined(BUILD_RS232)
22

33
#include "BeckerSocket.h"
44
#include "fnSystem.h"
@@ -675,4 +675,4 @@ void BeckerSocket::setHost(std::string host, int port)
675675
_port = port;
676676
}
677677

678-
#endif // BUILD_COCO
678+
#endif // BUILD_COCO || BUILD_RS232

lib/bus/rs232/rs232.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ void systemBus::_rs232_process_cmd()
185185
{
186186
_modemDev->modemActive = false;
187187
Debug_println("Modem was active - resetting RS232 baud");
188-
_port.setBaudrate(_rs232Baud);
188+
_serial.setBaudrate(_rs232Baud);
189189
}
190190

191191
// Read CMD frame
192192
std::string packet;
193193
int val, count;
194194
for (count = 0; count < 2; )
195195
{
196-
val = _port.read();
196+
val = _port->read();
197197
if (val < 0)
198198
break;
199199
packet.push_back(val);
@@ -263,7 +263,7 @@ void systemBus::service()
263263
return; // break!
264264
}
265265

266-
if (_port.available())
266+
if (_port->available())
267267
{
268268
_rs232_process_cmd();
269269
}
@@ -296,11 +296,20 @@ void systemBus::setup()
296296

297297
// Set up UART
298298
#ifndef FUJINET_OVER_USB
299-
_port.begin(ChannelConfig()
300-
.baud(Config.get_rs232_baud())
301-
.readTimeout(200)
302-
.deviceID(SERIAL_DEVICE)
303-
);
299+
if (Config.get_boip_enabled())
300+
{
301+
Debug_printf("RS232 SETUP: BOIP host: %s\n", Config.get_boip_host().c_str());
302+
_becker.begin(Config.get_boip_host(), Config.get_rs232_baud());
303+
_port = &_becker;
304+
}
305+
else {
306+
_serial.begin(ChannelConfig()
307+
.baud(Config.get_rs232_baud())
308+
.readTimeout(200)
309+
.deviceID(SERIAL_DEVICE))
310+
;
311+
_port = &_serial;
312+
}
304313

305314
#ifdef ESP_PLATFORM
306315
// // INT PIN
@@ -326,11 +335,12 @@ void systemBus::setup()
326335
fnSystem.digital_write(PIN_RS232_DSR,DIGI_LOW);
327336
#endif /* ESP_PLATFORM */
328337
#else /* FUJINET_OVER_USB */
329-
_port.begin();
338+
_serial.begin();
339+
_port = &_serial;
330340
#endif /* FUJINET_OVER_USB */
331341

332342
Debug_println("RS232 Setup Flush");
333-
_port.discardInput();
343+
_port->discardInput();
334344
}
335345

336346
// Add device to RS232 bus
@@ -445,7 +455,7 @@ void systemBus::setBaudrate(int baud)
445455

446456
Debug_printf("Changing baudrate from %d to %d\n", _rs232Baud, baud);
447457
_rs232Baud = baud;
448-
_port.setBaudrate(baud);
458+
_serial.setBaudrate(baud);
449459
}
450460

451461
#ifdef OBSOLETE
@@ -479,63 +489,63 @@ void systemBus::sendReplyPacket(fujiDeviceID_t source, bool ack, void *data, siz
479489
FujiBusPacket packet(source, ack ? FUJICMD_ACK : FUJICMD_NAK,
480490
ack ? std::string(static_cast<const char*>(data), length) : nullptr);
481491
std::string encoded = packet.serialize();
482-
_port.write(encoded.data(), encoded.size());
492+
_port->write(encoded.data(), encoded.size());
483493
return;
484494
}
485495

486496
/* Convert direct bus access into bus packets? */
487497
size_t systemBus::read(void *buffer, size_t length)
488498
{
489499
abort();
490-
return _port.read(buffer, length);
500+
return _port->read(buffer, length);
491501
}
492502

493503
size_t systemBus::read()
494504
{
495505
abort();
496-
return _port.read();
506+
return _port->read();
497507
}
498508

499509
size_t systemBus::write(const void *buffer, size_t length)
500510
{
501511
abort();
502-
return _port.write(buffer, length);
512+
return _port->write(buffer, length);
503513
}
504514

505515
size_t systemBus::write(int n)
506516
{
507517
abort();
508-
return _port.write(n);
518+
return _port->write(n);
509519
}
510520

511521
size_t systemBus::available()
512522
{
513523
abort();
514-
return _port.available();
524+
return _port->available();
515525
}
516526

517527
void systemBus::flushOutput()
518528
{
519529
abort();
520-
_port.flushOutput();
530+
_port->flushOutput();
521531
}
522532

523533
size_t systemBus::print(int n, int base)
524534
{
525535
abort();
526-
return _port.print(n, base);
536+
return _port->print(n, base);
527537
}
528538

529539
size_t systemBus::print(const char *str)
530540
{
531541
abort();
532-
return _port.print(str);
542+
return _port->print(str);
533543
}
534544

535545
size_t systemBus::print(const std::string &str)
536546
{
537547
abort();
538-
return _port.print(str);
548+
return _port->print(str);
539549
}
540550

541551
#endif /* BUILD_RS232 */

lib/bus/rs232/rs232.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "UARTChannel.h"
55
#include "FujiBusPacket.h"
6+
#include "../drivewire/BeckerSocket.h"
67

78
#ifdef ESP_PLATFORM
89
#include <freertos/FreeRTOS.h>
@@ -216,11 +217,9 @@ class systemBus
216217

217218
bool useUltraHigh = false; // Use fujinet derived clock.
218219

219-
#if FUJINET_OVER_USB
220-
ACMChannel _port;
221-
#else /* ! FUJINET_OVER_USB */
222-
UARTChannel _port;
223-
#endif /* FUJINET_OVER_USB */
220+
IOChannel *_port;
221+
UARTChannel _serial;
222+
BeckerSocket _becker;
224223

225224
void _rs232_process_cmd();
226225
/* void _rs232_process_queue(); */

0 commit comments

Comments
 (0)