]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/kern-scale/protocol.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / kern-scale / protocol.c
index 0af2adde405bf8ea2334ae5ee12db0b71888e64d..722e06256ee3a177464e404409205f2d3be359f8 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
@@ -33,25 +32,29 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
        struct scale_info *scale;
        float floatval;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog_old analog;
+       struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
        struct dev_context *devc;
 
        scale = (struct scale_info *)sdi->driver;
 
        devc = sdi->priv;
 
-       memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
+       /* Note: digits/spec_digits will be overridden later. */
+       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
 
-       analog.channels = sdi->channels;
+       analog.meaning->channels = sdi->channels;
        analog.num_samples = 1;
-       analog.mq = -1;
+       analog.meaning->mq = 0;
 
        scale->packet_parse(buf, &floatval, &analog, info);
        analog.data = &floatval;
 
-       if (analog.mq != -1) {
+       if (analog.meaning->mq != 0) {
                /* Got a measurement. */
-               packet.type = SR_DF_ANALOG_OLD;
+               packet.type = SR_DF_ANALOG;
                packet.payload = &analog;
                sr_session_send(sdi, &packet);
                sr_sw_limits_update_samples_read(&devc->limits, 1);
@@ -62,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;
@@ -82,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);
@@ -92,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;
 }
 
@@ -122,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;
 }