* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#define _GNU_SOURCE
#include <config.h>
return SR_OK;
}
-//Issue a command that expects a string return, return length of string
+//Issue a command that expects a string return that is less than 30 characters.
+//returns the length of string
int send_serial_w_resp(struct sr_serial_dev_inst *serial, char *str,
char *resp, size_t cnt)
{
if (num_read > 0)
break;
}
- //sr_spew("rwprsp1 i %d nr %d",i,num_read);
//Since the serial port is usb CDC we can't calculate timeouts based on baud rate but
//even if the response is split between two USB transfers 10ms should be plenty.
num_read +=
serial_read_blocking(serial, &(resp[num_read]), cnt - num_read,
10);
- //sr_spew("rwrsp2 nr %d",num_read);
-
if ((num_read < 1) || (num_read > 30)) {
sr_err("ERROR:Serial_w_resp failed (%d).", num_read);
return -1;
char buf[2];
int num_read;
//In case we have left over transfer from the device, drain them
+ //These should not exist in normal operation
while ((num_read = serial_read_blocking(serial, buf, 2, 10))) {
- //sr_dbg("swack drops 2 previous bytes %d %d",buf[0],buf[1]);
+ sr_dbg("swack drops 2 bytes %d %d",buf[0],buf[1]);
}
send_serial_str(serial, str);
//1000ms timeout
}
//If the wrptr is non-zero due to a residual from the previous serial transfer don't double count it towards byte_cnt
devc->byte_cnt += slice_bytes - (devc->wrptr);
- sr_spew("process slice avail %d rdptr %d sb %d byte_cnt %lld",
+ sr_spew("process slice avail %d rdptr %d sb %d byte_cnt %" PRIu64 "",
devc->bytes_avail, devc->ser_rdptr, slice_bytes,
devc->byte_cnt);
//Must have a full slice or one rle byte
packet.payload = &analog;
sr_session_send(sdi, &packet);
g_slist_free(analog.meaning->channels);
- } //if enabled
- } //for channels
+ }//if enabled
+ }//for channels
return 0;
}
analog.num_samples = num_post;
analog.data =
(devc->a_pretrig_bufs[i]) + start_post;
- //sr_spew("ring buf %d starts at %p",i,(void *) devc->a_pretrig_bufs[i]);
- //sr_spew("analog data %d starts at %p",i,(void *) analog.data);
- //sr_spew("Sending A%d ring buffer oldest ",i);
for (uint32_t j = 0;
j < analog.num_samples; j++) {
fptr =
analog.data +
(j * sizeof(float));
- //sr_spew("RNGDCT%d j %d %f %p",i,j,*fptr,(void *)fptr);
}
sr_session_send(sdi, &packet);
}
}
g_slist_free(analog.meaning->channels);
sr_dbg("Sending A%d ring buffer done ", i);
- } //if enabled
- } //for channels
+ }//if enabled
+ }//for channels
return 0;
}
sr_spew
("Process_group sending %d post trig samples dsb %d",
num_samples, devc->dig_sample_bytes);
- //for(int z=0;(z<num_samples);z++){
- // sr_spew("0x%X ",devc->d_data_buf[z]);
- //}
if (devc->num_d_channels) {
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(sdi, &packet);
}
send_analog(sdi, devc, num_samples, 0);
- } //num_sample>0
+ }//num_samples >0
devc->sent_samples += num_samples;
return 0;
- } //trigger_fired
+ }//trigger_fired
else {
size_t num_ring_samples;
size_t sptr;
size_t numtail;
size_t numwrap;
size_t srcptr;
- //sr_spew("Process_group check %d pre trig samples",num_slices);
//The trigger_offset is -1 if no trigger is found, but if a trigger is found
//then trigger_offset is the offset into the data buffer sent to it.
//The pre_trigger_samples is the total number of samples before the trigger, but limited to
num_slices *
devc->dig_sample_bytes,
&pre_trigger_samples);
- //A trigger offset >=0 indicate a trigger was seen. The stl will isue the trigger to the session
+ //A trigger offset >=0 indicates a trigger was seen. The stl will isue the trigger to the session
//and will forward all pre trigger logic samples, but we must send any post trigger logic
//and all pre and post trigger analog signals
- // sr_dbg("trggr_off %d",trigger_offset);
- // sr_dbg("pre_samp %d",pre_trigger_samples);
if (trigger_offset > -1) {
devc->trigger_fired = TRUE;
devc->sent_samples += pre_trigger_samples;
srcptr = cbuf_wrptr_cpy - num_ring_samples;
sr_spew("RNG num %zu sptr %zu eptr %zu ",
num_ring_samples, sptr, eptr);
- //sr_spew("RNG srcptr %zu nt %zu nw %zu",srcptr,numtail,numwrap);
for (i = 0; i < devc->num_a_channels; i++) {
if ((devc->a_chan_mask >> i) & 1) {
//copy tail
devc->a_data_bufs
[i]
[srcptr + j];
- //sr_spew("RNGCpyT C%d src %zu dest %zu",i,srcptr+j,sptr+j);
} //for j
} //if chan_mask
} //for channels
devc->a_data_bufs
[i]
[srcptr + j];
- //sr_spew("RNGCpyW C%d src %zu dest %zu",i,srcptr+j,j);
} //for j
} //if chan_mask
} //for channels
(numwrap) ? numwrap : (eptr +
1) %
devc->pretrig_entries;
- //sr_dbg("RNG pwrptr new %u",devc->pretrig_wr_ptr);
} //if any analog channel enabled and pretrig_entries
} //else (trigger not detected)
} //trigger not set on function entry
didx=devc->cbuf_wrptr*devc->dig_sample_bytes;
for (k = 0; k < devc->dig_sample_bytes; k++) {
devc->d_data_buf[didx + k] = devc->d_last[k];
- // sr_spew("k %d j %d v 0x%X p %d didx %d",k,j,devc->d_data_buf[(devc->cbuf_wrptr)+k],(devc->cbuf_wrptr)+k,didx);
}
// cbuf_wrptr always counts slices/samples (and not the bytes in the buffer)
// regardless of mode
sr_dbg("Reached non active state in receive %d",
devc->rxstate);
//don't return - we may be waiting for a final bytecnt
- //return TRUE;
}
if (devc->rxstate == RX_IDLE) {
//This is the normal end condition where we do one more receive
devc->buffer[devc->wrptr + len] = 0;
//Add the "#" so that spaces are clearly seen
sr_dbg("rx string %s#", devc->buffer);
- //This is not guaranteed to be a dataloss condition, but definitely indicates we are
- //processing data right at the incoming rate.
- //With the addition of the byte_cnt sent at the end we will detect any dataloss conditions
- //and thus this is disabled
- //if(len>=(int)bytes_rem-8){
- // sr_err("ERROR: Serial buffer near or at max depth, data from device may have been lost");
- //}
devc->bytes_avail = (devc->wrptr + len);
sr_spew
("rx len %d bytes_avail %ul sent_samples %ul wrptr %u",
len, devc->bytes_avail, devc->sent_samples,
devc->wrptr);
- //sr_err("rx len %d ",len);
} else if (len == 0) {
return TRUE;
} else {
sr_err("ERROR:Negative serial read code %d", len);
sdi->driver->dev_acquisition_stop(sdi);
return FALSE;
- } //len>0
- //This can be used as a bit bucket to drop all samples to see how host processing time effects
- //the devices ability to send data. Obviously no data will be forwarded to the session so it will hang
- // return TRUE;
+ }// if len>0
//Process the serial read data
devc->ser_rdptr = 0;
//But they may not use all of it, and thus the residual unused bytes are shifted to the start of the buffer
//for the next call.
residual_bytes = devc->bytes_avail - devc->ser_rdptr;
- //sr_spew("Residuals resid %d avail %d rdptr %d wrptr %d\n",residual_bytes,devc->bytes_avail,devc->ser_rdptr,devc->wrptr);
if (residual_bytes) {
for (i = 0; i < residual_bytes; i++) {
devc->buffer[i] =
}
//It's possible we need one more serial transfer to get the byte_cnt, so print that here
sr_dbg("Haven't seen byte_cnt + yet");
- } //RX_STOPPED
+ } //if RX_STOPPED
//If at the sample limit, send a "+" in case we are in continuous mode and need
//to stop the device. Not that even in non continous mode there might be cases where get an extra
//sample or two...