Skip to content

Commit c60f0ac

Browse files
authored
feat(rs232): support BeckerSocket transport (#3)
1 parent 7c6a23e commit c60f0ac

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

fujinet_pc.cmake

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

386386
lib/bus/rs232/rs232.h lib/bus/rs232/rs232.cpp
387387
lib/bus/rs232/FujiBusPacket.h lib/bus/rs232/FujiBusPacket.cpp
388+
lib/bus/drivewire/BeckerSocket.h lib/bus/drivewire/BeckerSocket.cpp
388389

389390
lib/media/rs232/diskType.h lib/media/rs232/diskType.cpp
390391
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: 33 additions & 23 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
}
@@ -277,7 +277,7 @@ void systemBus::service()
277277
// Neither CMD nor active modem, so throw out any stray input data
278278
{
279279
//Debug_println("RS232 Srvc Flush");
280-
_port.discardInput();
280+
_port->discardInput();
281281
}
282282
#endif /* OBSOLETE */
283283

@@ -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
@@ -426,7 +436,7 @@ void systemBus::toggleBaudrate()
426436

427437
// Debug_printf("Toggling baudrate from %d to %d\n", _rs232Baud, baudrate);
428438
_rs232Baud = baudrate;
429-
_port.setBaudrate(_rs232Baud);
439+
_serial.setBaudrate(_rs232Baud);
430440
}
431441
#endif /* OBSOLETE */
432442

@@ -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 source, bool ack, void *data, size_
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 & 1 deletion
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>
@@ -224,7 +225,9 @@ class systemBus
224225

225226
bool useUltraHigh = false; // Use fujinet derived clock.
226227

227-
UARTChannel _port;
228+
IOChannel *_port;
229+
UARTChannel _serial;
230+
BeckerSocket _becker;
228231

229232
void _rs232_process_cmd();
230233
/* void _rs232_process_queue(); */

0 commit comments

Comments
 (0)