* 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>
#include <stdlib.h>
#include <math.h>
#include <string.h>
float floatval;
struct sr_datafeed_packet packet;
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));
+ /* 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;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
- devc->num_samples++;
+ sr_session_send(sdi, &packet);
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
}
{
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;
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);
}
/* 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;
}
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct scale_info *scale;
- int64_t time;
void *info;
(void)fd;
g_free(info);
}
- if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
- sr_info("Requested number of samples reached.");
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- return TRUE;
- }
-
- if (devc->limit_msec) {
- time = (g_get_monotonic_time() - devc->starttime) / 1000;
- if (time > (int64_t)devc->limit_msec) {
- sr_info("Requested time limit reached.");
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- return TRUE;
- }
- }
+ if (sr_sw_limits_check(&devc->limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}