Skip to content

Commit d7fd2d2

Browse files
Lynx compile (#1068)
* lynx disk changes - partial blocks accounted for - checksum, ack/nack receive in disk block send media type changes - basically removed media type detection, treat all files the same misc cleanup * Use MEDIA_BLOCK_SIZE in all disk routines, general cleanup * Getting lynx to compile again after refactoring work by Fozztexx
1 parent 6a2f5ea commit d7fd2d2

File tree

6 files changed

+107
-103
lines changed

6 files changed

+107
-103
lines changed

lib/bus/comlynx/comlynx.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ void virtualDevice::comlynx_send(uint8_t b)
8787
SYSTEM_BUS.wait_for_idle();
8888

8989
// Write the byte
90-
fnUartBUS.write(b);
91-
fnUartBUS.flush();
92-
fnUartBUS.read();
90+
SYSTEM_BUS.write(b);
91+
SYSTEM_BUS.flush();
92+
SYSTEM_BUS.read();
9393
}
9494

9595
void virtualDevice::comlynx_send_buffer(uint8_t *buf, unsigned short len)
@@ -105,20 +105,20 @@ void virtualDevice::comlynx_send_buffer(uint8_t *buf, unsigned short len)
105105
if (SYSTEM_BUS._udpDev->udpstreamActive)
106106
SYSTEM_BUS.wait_for_idle();
107107

108-
fnUartBUS.write(buf, len);
109-
fnUartBUS.readBytes(buf, len);
108+
SYSTEM_BUS.write(buf, len);
109+
SYSTEM_BUS.read(buf, len);
110110
}
111111

112112
bool virtualDevice::comlynx_recv_ck()
113113
{
114114
uint8_t recv_ck, ck;
115115

116116

117-
while (fnUartBUS.available() <= 0)
117+
while (SYSTEM_BUS.available() <= 0)
118118
fnSystem.yield();
119119

120120
// get checksum
121-
recv_ck = fnUartBUS.read();
121+
recv_ck = SYSTEM_BUS.read();
122122

123123
ck = comlynx_checksum(recvbuffer, recvbuffer_len);
124124

@@ -138,10 +138,10 @@ uint8_t virtualDevice::comlynx_recv()
138138
{
139139
uint8_t b;
140140

141-
while (fnUartBUS.available() <= 0)
141+
while (SYSTEM_BUS.available() <= 0)
142142
fnSystem.yield();
143143

144-
b = fnUartBUS.read();
144+
b = SYSTEM_BUS.read();
145145

146146
// Add to receive buffer
147147
recvbuffer[recvbuffer_len] = b;
@@ -159,17 +159,17 @@ bool virtualDevice::comlynx_recv_timeout(uint8_t *b, uint64_t dur)
159159
start = current = esp_timer_get_time();
160160
elapsed = 0;
161161

162-
while (fnUartBUS.available() <= 0)
162+
while (SYSTEM_BUS.available() <= 0)
163163
{
164164
current = esp_timer_get_time();
165165
elapsed = current - start;
166166
if (elapsed > dur)
167167
break;
168168
}
169169

170-
if (fnUartBUS.available() > 0)
170+
if (SYSTEM_BUS.available() > 0)
171171
{
172-
*b = (uint8_t)fnUartBUS.read();
172+
*b = (uint8_t)SYSTEM_BUS.read();
173173
timeout = false;
174174
} // else
175175
// Debug_printf("duration: %llu\n", elapsed);
@@ -202,7 +202,7 @@ unsigned short virtualDevice::comlynx_recv_buffer(uint8_t *buf, unsigned short l
202202
{
203203
unsigned short b;
204204

205-
b = fnUartBUS.readBytes(buf, len);
205+
b = SYSTEM_BUS.read(buf, len);
206206

207207
// Add to receive buffer
208208
memcpy(&recvbuffer[recvbuffer_len], buf, len);
@@ -257,7 +257,7 @@ bool systemBus::wait_for_idle()
257257
dur = current - start;
258258

259259
// Did we get any data in the FIFO while waiting?
260-
if (fnUartBUS.available() > 0)
260+
if (SYSTEM_BUS.available() > 0)
261261
return false;
262262

263263
} while (dur < IDLE_TIME);
@@ -270,7 +270,7 @@ bool systemBus::wait_for_idle()
270270

271271
void virtualDevice::comlynx_process(uint8_t b)
272272
{
273-
fnUartDebug.printf("comlynx_process() not implemented yet for this device. Cmd received: %02x\n", b);
273+
fnDebugConsole.printf("comlynx_process() not implemented yet for this device. Cmd received: %02x\n", b);
274274
}
275275

276276
void virtualDevice::comlynx_control_status()
@@ -316,37 +316,36 @@ void virtualDevice::comlynx_idle()
316316

317317
void systemBus::_comlynx_process_cmd()
318318
{
319-
uint8_t b;
320-
321-
b = fnUartBUS.read();
322-
//start_time = esp_timer_get_time();
319+
uint8_t d, b;
323320

324-
uint8_t d = b & 0x0F;
325-
326-
#ifdef DEBUG
327-
if ((b & 0xF0) == (MN_ACK<<4))
328-
Debug_println("Lynx sent ACK");
329-
else {
330-
Debug_println("---");
331-
Debug_printf("comlynx_process_cmd: dev:%X cmd:%X\n", d, (b & 0xF0)>>4);
332-
}
333-
#endif
321+
b = SYSTEM_BUS.read();
322+
d = b & 0x0F;
334323

324+
335325
// Find device ID and pass control to it
336326
if (_daisyChain.count(d) < 1)
337327
{
338328
}
339329
else if (_daisyChain[d]->device_active == true)
340330
{
331+
#ifdef DEBUG
332+
if ((b & 0xF0) == (MN_ACK<<4))
333+
Debug_println("Lynx sent ACK");
334+
else {
335+
Debug_println("---");
336+
Debug_printf("comlynx_process_cmd: dev:%X cmd:%X\n", d, (b & 0xF0)>>4);
337+
}
338+
#endif
339+
341340
// turn on Comlynx Indicator LED
342341
fnLedManager.set(eLed::LED_BUS, true);
343342
_daisyChain[d]->comlynx_process(b);
344343
// turn off Comlynx Indicator LED
345344
fnLedManager.set(eLed::LED_BUS, false);
346345
}
347346

348-
//wait_for_idle(); // to avoid failing edge case where device is connected but disabled.
349-
fnUartBUS.flush_input();
347+
//SYSTEM_BUS.flush_input();
348+
SYSTEM_BUS.flush();
350349
}
351350

352351
void systemBus::_comlynx_process_queue()
@@ -359,7 +358,7 @@ void systemBus::service()
359358
if (_udpDev != nullptr && _udpDev->udpstreamActive)
360359
_udpDev->comlynx_handle_udpstream();
361360
// Process anything waiting
362-
else if (fnUartBUS.available() > 0)
361+
else if (SYSTEM_BUS.available() > 0)
363362
_comlynx_process_cmd();
364363
}
365364

@@ -380,7 +379,11 @@ void systemBus::setup()
380379
_udpDev = new lynxUDPStream();
381380

382381
// Set up UART
383-
fnUartBUS.begin(COMLYNX_BAUDRATE);
382+
_port.begin(ChannelConfig()
383+
.deviceID(FN_UART_BUS)
384+
.baud(COMLYNX_BAUDRATE)
385+
.parity(UART_PARITY_ODD)
386+
);
384387
}
385388

386389
void systemBus::shutdown()

lib/bus/comlynx/comlynx.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Comlynx Routines
66
*/
77

8+
#include "UARTChannel.h"
89
#include <freertos/FreeRTOS.h>
910
#include <freertos/queue.h>
1011

@@ -248,6 +249,7 @@ class systemBus
248249
lynxFuji *_fujiDev = nullptr;
249250
lynxPrinter *_printerDev = nullptr;
250251

252+
UARTChannel _port;
251253

252254
void _comlynx_process_cmd();
253255
void _comlynx_process_queue();
@@ -272,15 +274,15 @@ class systemBus
272274
//int64_t comlynx_idle_time = 1000;
273275

274276
int numDevices();
275-
void addDevice(virtualDevice *pDevice, FujiDeviceID device_id);
277+
void addDevice(virtualDevice *pDevice, fujiDeviceID_t device_id);
276278
void remDevice(virtualDevice *pDevice);
277-
void remDevice(FujiDeviceID device_id);
278-
bool deviceExists(FujiDeviceID device_id);
279-
void enableDevice(FujiDeviceID device_id);
280-
void disableDevice(FujiDeviceID device_id);
281-
virtualDevice *deviceById(FujiDeviceID device_id);
282-
void changeDeviceId(virtualDevice *pDevice, FujiDeviceID device_id);
283-
bool deviceEnabled(FujiDeviceID device_id);
279+
void remDevice(fujiDeviceID_t device_id);
280+
bool deviceExists(fujiDeviceID_t device_id);
281+
void enableDevice(fujiDeviceID_t device_id);
282+
void disableDevice(fujiDeviceID_t device_id);
283+
virtualDevice *deviceById(fujiDeviceID_t device_id);
284+
void changeDeviceId(virtualDevice *pDevice, fujiDeviceID_t device_id);
285+
bool deviceEnabled(fujiDeviceID_t device_id);
284286
QueueHandle_t qComlynxMessages = nullptr;
285287
void setUDPHost(const char *newhost, int port); // Set new host/ip & port for UDP Stream
286288

@@ -289,9 +291,20 @@ class systemBus
289291

290292
bool shuttingDown = false; // TRUE if we are in shutdown process
291293
bool getShuttingDown() { return shuttingDown; };
294+
295+
// Everybody thinks "oh I know how a serial port works, I'll just
296+
// access it directly and bypass the bus!" ಠ_ಠ
297+
size_t read(void *buffer, size_t length) { return _port.read(buffer, length); }
298+
size_t read() { return _port.read(); }
299+
size_t write(const void *buffer, size_t length) { return _port.write(buffer, length); }
300+
size_t write(int n) { return _port.write(n); }
301+
size_t available() { return _port.available(); }
302+
void flush() { _port.flushOutput(); }
303+
size_t print(int n, int base = 10) { return _port.print(n, base); }
304+
size_t print(const char *str) { return _port.print(str); }
305+
size_t print(const std::string &str) { return _port.print(str); }
292306
};
293307

294308
extern systemBus SYSTEM_BUS;
295-
//extern systemBus ComLynx;
296309

297310
#endif /* COMLYNX_H */

lib/device/comlynx/lynxFuji.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void lynxFuji::comlynx_net_scan_result()
144144
if (n < _countScannedSSIDs)
145145
fnWiFi.get_scan_result(n, detail.ssid, &detail.rssi);
146146

147-
Debug_printf("SSID: %s - RSSI: %u\n", detail.ssid, detail.rssi);
147+
Debug_printf("SSID: %s - RSSI: %d\n", detail.ssid, detail.rssi);
148148

149149
memset(response, 0, sizeof(response));
150150
memcpy(response, &detail, sizeof(detail));

0 commit comments

Comments
 (0)