* 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 "protocol.h"
static int mic_send(struct sr_serial_dev_inst *serial, const char *cmd)
{
int ret;
- if ((ret = serial_write(serial, cmd, strlen(cmd))) < 0) {
+ if ((ret = serial_write_blocking(serial, cmd, strlen(cmd),
+ serial_timeout(serial, strlen(cmd)))) < 0) {
sr_err("Error sending '%s' command: %d.", cmd, ret);
return SR_ERR;
}
float temperature, humidity;
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;
GSList *l;
int ret;
return SR_ERR;
}
- /* Clear 'analog', otherwise it'll contain random garbage. */
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 1);
/* Common values for both channels. */
packet.type = SR_DF_ANALOG;
/* Temperature. */
l = g_slist_copy(sdi->channels);
l = g_slist_remove_link(l, g_slist_nth(l, 1));
- analog.channels = l;
- analog.mq = SR_MQ_TEMPERATURE;
- analog.unit = SR_UNIT_CELSIUS; /* TODO: Use C/F correctly. */
+ meaning.channels = l;
+ meaning.mq = SR_MQ_TEMPERATURE;
+ meaning.unit = SR_UNIT_CELSIUS; /* TODO: Use C/F correctly. */
analog.data = &temperature;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
g_slist_free(l);
/* Humidity. */
if (mic_devs[idx].has_humidity) {
l = g_slist_copy(sdi->channels);
l = g_slist_remove_link(l, g_slist_nth(l, 0));
- analog.channels = l;
- analog.mq = SR_MQ_RELATIVE_HUMIDITY;
- analog.unit = SR_UNIT_PERCENTAGE;
+ meaning.channels = l;
+ meaning.mq = SR_MQ_RELATIVE_HUMIDITY;
+ meaning.unit = SR_UNIT_PERCENTAGE;
analog.data = &humidity;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
g_slist_free(l);
}
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
return SR_OK;
}
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
- int64_t t;
static gboolean first_time = TRUE;
struct sr_serial_dev_inst *serial;
}
}
- 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) {
- t = (g_get_monotonic_time() - devc->starttime) / 1000;
- if (t > (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))
+ sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}