<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'self'; img-src * cid: data:;"></head><body contenteditable="false"><div id="response_container_BBPPID" style="outline:none;font-size:initial;font-family:"Calibri","Slate Pro",sans-serif,"sans-serif"" dir="auto"> <div name="BB10" id="BB10_response_div_BBPPID" dir="auto" style="width:100%;"> <span style="font-family: sans-serif;">I'm trying to get the Cochran computers working with the FTDI library and serial_ftdi so I can read them on an Android biuld. I'm having two issues that I have to ask for advice about.</span><div style="user-select: auto; font-family: sans-serif;"><br style="user-select: auto;"></div><div style="user-select: auto; font-family: sans-serif;">1. In serial_ftdi_read() a failed read exponentially backs off when there's a short read. This is causing Cochran reads to timeout about 95% of the time. It's as if reading too late causes lost data. Having a fixed backoff of 10ms works. Are there any issues if I alter this backoff tactic? It could be shortened to 1ms if 10ms is too long.<br style="user-select: auto;"><br style="user-select: auto;"><div style="user-select: auto;">diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c</div><div style="user-select: auto;">index f8cba95..bc20ce1 100644</div><div style="user-select: auto;">--- a/core/serial_ftdi.c</div><div style="user-select: auto;">+++ b/core/serial_ftdi.c</div><div style="user-select: auto;">@@ -384,7 +384,7 @@ static dc_status_t serial_ftdi_read (dc_custom_io_t *io, void *data, size_t size</div><div style="user-select: auto;">        if (timeout == -1)</div><div style="user-select: auto;">                timeout = 10000;</div><div style="user-select: auto;"> </div><div style="user-select: auto;">-       int backoff = 1;</div><div style="user-select: auto;">+       int backoff = 10;</div><div style="user-select: auto;">        int slept = 0;</div><div style="user-select: auto;">        unsigned int nbytes = 0;</div><div style="user-select: auto;">        while (nbytes < size) {</div><div style="user-select: auto;">@@ -402,12 +402,11 @@ static dc_status_t serial_ftdi_read (dc_custom_io_t *io, void *data, size_t size</div><div style="user-select: auto;">                        }</div><div style="user-select: auto;">                        serial_ftdi_sleep (device, backoff);</div><div style="user-select: auto;">                        slept += backoff;</div><div style="user-select: auto;">-                       backoff *= 2;</div><div style="user-select: auto;">                        if (backoff + slept > timeout)</div><div style="user-select: auto;">                                backoff = timeout - slept;</div><div style="user-select: auto;">                } else {</div><div style="user-select: auto;">                        // Reset backoff to 1 on success.</div><div style="user-select: auto;">-                       backoff = 1;</div><div style="user-select: auto;">+                       backoff = 10;</div><div style="user-select: auto;">                }</div><div style="user-select: auto;"> </div><div style="user-select: auto;">                nbytes += n;</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">2. It doesn't make any sense to me but setting serial break on then off is the trigger to the Cochran to wake up, so I need the ability to set breaks. Currently the code doesn't support setting breaks and is explained with the comment "// Not implemented in libftdi yet. Research it further."</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">So I looked at it and it's supported with the following libftdi-1.3 function:<br style="user-select: auto;"><br style="user-select: auto;"><div style="user-select: auto;">      int ftdi_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type bits,</div><div style="user-select: auto;">                                enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity,</div><div style="user-select: auto;">                                enum ftdi_break_type break_type);</div></div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">To make this work seamlessly with libdivecomputer's serial function I need to emulate the dc_serial_set_break function. A prototype serial_ftdi_set_break function is there and I can change it to use ftdi_set_line_property2, which means I have to get the parameters bits, sbit, and parity from somewhere.<br style="user-select: auto;"><br style="user-select: auto;">There isn't a function that will read this from the device.<br style="user-select: auto;"><br style="user-select: auto;">I could create some global vars in serial_ftdi.c, initialize them with 8,1,N values, update them as needed. To support multiple devices concurrently it would have to be an array indexed by device but it's not clear what index would work best.</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">I was thinking of a global variable like:</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">   struct serial_parm {</div><div style="user-select: auto;">      struct ftdi_context *ftdi_ctx;</div><div style="user-select: auto;">      enum ftdi_bits_type bits;</div><div style="user-select: auto;">      enum ftdi_stopbits_type sbit;</div><div style="user-select: auto;">      enum ftdi_parity_type parity;</div><div style="user-select: auto;">   } *serial_parms = NULL;</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">Then realloc() to add (on serial_ftdi_open) or remove (on serial_ftdi_close). When serial_ftdi_configure is called I can search the array and update the values so I can use them in serial_ftdi_set_break.</div><div style="user-select: auto;"><br style="user-select: auto;"></div><div style="user-select: auto;">Does this work or is there a better idea?</div><div style="user-select: auto;"><br style="user-select: auto;"></div>-- <br style="user-select: auto;"><div class="gmail_signature" style="user-select: auto;"><div dir="ltr" style="user-select: auto;"><div style="user-select: auto;">John Van Ostrand<br style="user-select: auto;"></div><div style="user-select: auto;">At large on sabbatical</div></div></div></div></div></div></body></html>