* 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>
return SR_OK;
}
+static int send_config_update_key(const struct sr_dev_inst *sdi,
+ uint32_t key, GVariant *var)
+{
+ struct sr_config *cfg;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_meta meta;
+ int ret;
+
+ cfg = sr_config_new(key, var);
+ if (!cfg)
+ return SR_ERR;
+
+ memset(&meta, 0, sizeof(meta));
+
+ packet.type = SR_DF_META;
+ packet.payload = &meta;
+
+ meta.config = g_slist_append(meta.config, cfg);
+
+ ret = sr_session_send(sdi, &packet);
+ sr_config_free(cfg);
+
+ return ret;
+}
+
static void handle_packet(const struct sr_dev_inst *sdi)
{
float voltage, current;
if (g_str_has_prefix((const char *)devc->buf, "overtemp")) {
sr_warn("Overtemperature condition!");
devc->otp_active = TRUE;
+ send_config_update_key(sdi, SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
+ g_variant_new_boolean(TRUE));
return;
}
if (g_str_has_prefix((const char *)devc->buf, "undervolt")) {
sr_warn("Undervoltage condition!");
devc->uvc_active = TRUE;
+ send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE,
+ g_variant_new_boolean(TRUE));
+ return;
+ }
+
+ if (g_str_has_prefix((const char *)devc->buf, "err ")) {
+ sr_err("Device replied with an error: '%s'.", devc->buf);
+ return;
+ }
+
+ if (g_str_has_prefix((const char *)devc->buf, "set ")) {
+ tokens = g_strsplit((const char *)devc->buf, " ", 2);
+ current = g_ascii_strtod(tokens[1], NULL) / 1000;
+ g_strfreev(tokens);
+ send_config_update_key(sdi, SR_CONF_CURRENT_LIMIT,
+ g_variant_new_double(current));
return;
}
packet.payload = NULL;
sr_session_send(sdi, &packet);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
static void handle_new_data(const struct sr_dev_inst *sdi)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
- int64_t t;
(void)fd;
handle_new_data(sdi);
- if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) {
- sr_info("Requested number of samples reached.");
- sdi->driver->dev_acquisition_stop(sdi);
- 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);
- return TRUE;
- }
- }
+ if (sr_sw_limits_check(&devc->limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}