X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fhardware%2Fkern-scale%2Fprotocol.c;h=722e06256ee3a177464e404409205f2d3be359f8;hb=060df80fb354246cc309ef80927d38e37e922eb2;hp=01838e3d55da75bbe230a9e20dfe733a729e0ac2;hpb=563ba4a5c22475357604bffd1e391a4c53c55e50;p=libsigrok.git
diff --git a/src/hardware/kern-scale/protocol.c b/src/hardware/kern-scale/protocol.c
index 01838e3d..722e0625 100644
--- a/src/hardware/kern-scale/protocol.c
+++ b/src/hardware/kern-scale/protocol.c
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include
@@ -43,6 +42,7 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
devc = sdi->priv;
+ /* Note: digits/spec_digits will be overridden later. */
sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
analog.meaning->channels = sdi->channels;
@@ -65,7 +65,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
{
struct scale_info *scale;
struct dev_context *devc;
- int len, i, offset = 0;
+ int len, offset;
struct sr_serial_dev_inst *serial;
scale = (struct scale_info *)sdi->driver;
@@ -85,6 +85,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
devc->buflen += len;
/* Now look for packets in that data. */
+ offset = 0;
while ((devc->buflen - offset) >= scale->packet_size) {
if (scale->packet_valid(devc->buf + offset)) {
handle_packet(devc->buf + offset, sdi, info);
@@ -95,8 +96,8 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
}
/* If we have any data left, move it to the beginning of our buffer. */
- for (i = 0; i < devc->buflen - offset; i++)
- devc->buf[i] = devc->buf[offset + i];
+ if (offset < devc->buflen)
+ memmove(devc->buf, devc->buf + offset, devc->buflen - offset);
devc->buflen -= offset;
}
@@ -125,7 +126,7 @@ SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data)
}
if (sr_sw_limits_check(&devc->limits))
- sdi->driver->dev_acquisition_stop(sdi);
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}