Skip to content

Commit 0a8be99

Browse files
committed
Temporary hack to make rs232bus read() work until devices learn to do packets
1 parent 9754c72 commit 0a8be99

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/bus/rs232/rs232.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void virtualDevice::bus_to_computer(uint8_t *buf, uint16_t len, bool err)
9797
len = length
9898
Returns checksum
9999
*/
100+
#ifdef OBSOLETE
100101
uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
101102
{
102103
// Retrieve data frame from computer
@@ -130,6 +131,16 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
130131

131132
return ck_rcv;
132133
}
134+
#else
135+
uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
136+
{
137+
// FIXME - This is a terrible hack to allow devices to continue
138+
// directly read/write the bus instead of upgrading them to work
139+
// with packets.
140+
size_t rlen = SYSTEM_BUS.read(buf, len);
141+
return rs232_checksum(buf, rlen);
142+
}
143+
#endif /* OBSOLETE */
133144

134145
// RS232 NAK
135146
void virtualDevice::rs232_nak()
@@ -219,6 +230,12 @@ void systemBus::_rs232_process_cmd()
219230
tempFrame->device(), tempFrame->command(),
220231
tempFrame->data() ? tempFrame->data()->size() : -1);
221232

233+
// FIXME - This is a terrible hack to allow devices to continue
234+
// directly read/write the bus instead of upgrading them to work
235+
// with packets.
236+
_lastPacketReceived = tempFrame.get();
237+
_lastReadPosition = 0;
238+
222239
if (tempFrame->device() == FUJI_DEVICEID_DISK && _fujiDev != nullptr
223240
&& _fujiDev->boot_config)
224241
{
@@ -500,8 +517,20 @@ void systemBus::sendReplyPacket(fujiDeviceID_t source, bool ack, void *data, siz
500517
/* Convert direct bus access into bus packets? */
501518
size_t systemBus::read(void *buffer, size_t length)
502519
{
503-
abort();
504-
return _port->read(buffer, length);
520+
// FIXME - This is a terrible hack to allow devices to continue
521+
// directly read/write the bus instead of upgrading them to work
522+
// with packets.
523+
// Assuming 'data()' returns the optional:
524+
auto optional_data = _lastPacketReceived->data();
525+
526+
if (!optional_data.has_value())
527+
return 0;
528+
529+
size_t avail = optional_data.value().size() - _lastReadPosition;
530+
avail = std::min(avail, (size_t) length);
531+
memcpy(buffer, optional_data.value().data() + _lastReadPosition, avail);
532+
_lastReadPosition += avail;
533+
return avail;
505534
}
506535

507536
size_t systemBus::read()

lib/bus/rs232/rs232.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ struct rs232_message_t
199199
class systemBus
200200
{
201201
private:
202+
// FIXME - DO NOT DO CACHE THE LAST PACKET RECEIVED. This is a
203+
// terrible hack to allow devices to continue directly read/write
204+
// the bus instead of upgrading them to work with packets.
205+
FujiBusPacket *_lastPacketReceived;
206+
size_t _lastReadPosition;
207+
202208
std::forward_list<virtualDevice *> _daisyChain;
203209

204210
int _command_frame_counter = 0;

0 commit comments

Comments
 (0)