]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/arachnid-labs-re-load-pro/protocol.c
license: remove FSF postal address from boiler plate license text
[libsigrok.git] / src / hardware / arachnid-labs-re-load-pro / protocol.c
index 697f75a0890500dff958bbe79531df3c0dfe01ba..dd0ad409508ffc37a4376e8d3d890f49d77c028e 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>
@@ -89,6 +88,21 @@ SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
+SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on)
+{
+       int ret;
+       char buf[100];
+       const char *cmd;
+
+       cmd = (on) ? "on\n" : "off\n";
+       if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) {
+               sr_err("Error sending on/off command: %d.", ret);
+               return SR_ERR;
+       }
+
+       return SR_OK;
+}
+
 SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
                                        float *current)
 {
@@ -144,11 +158,17 @@ static void handle_packet(const struct sr_dev_inst *sdi)
        devc = sdi->priv;
 
        if (g_str_has_prefix((const char *)devc->buf, "overtemp")) {
-               sr_dbg("Overtemperature condition!");
+               sr_warn("Overtemperature condition!");
                devc->otp_active = TRUE;
                return;
        }
 
+       if (g_str_has_prefix((const char *)devc->buf, "undervolt")) {
+               sr_warn("Undervoltage condition!");
+               devc->uvc_active = TRUE;
+               return;
+       }
+
        if (!g_str_has_prefix((const char *)devc->buf, "read ")) {
                sr_dbg("Unknown packet: '%s'.", devc->buf);
                return;
@@ -197,7 +217,7 @@ static void handle_packet(const struct sr_dev_inst *sdi)
        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)
@@ -231,7 +251,6 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       int64_t t;
 
        (void)fd;
 
@@ -243,20 +262,8 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
 
        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, 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;
 }