]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/chronovu-la/api.c
sr_dev_close(): Factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / hardware / chronovu-la / api.c
index ea247d42be898213f75e114195490c04c06a00ee..9f793969464261fd113e1651cec8ea572313809f 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>
@@ -44,8 +43,6 @@ static const int32_t trigger_matches[] = {
        SR_TRIGGER_FALLING,
 };
 
-static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-
 static void clear_helper(void *priv)
 {
        struct dev_context *devc;
@@ -291,14 +288,12 @@ static int dev_close(struct sr_dev_inst *sdi)
        int ret;
        struct dev_context *devc;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_OK;
-
        devc = sdi->priv;
 
        if (devc->ftdic && (ret = ftdi_usb_close(devc->ftdic)) < 0)
                sr_err("Failed to close FTDI device (%d): %s.",
                       ret, ftdi_get_error_string(devc->ftdic));
+
        sdi->status = SR_ST_INACTIVE;
 
        return SR_OK;
@@ -340,9 +335,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        switch (key) {
@@ -453,7 +445,7 @@ static int receive_data(int fd, int revents, void *cb_data)
        /* Get one block of data. */
        if ((ret = cv_read_block(devc)) < 0) {
                sr_err("Failed to read data block: %d.", ret);
-               dev_acquisition_stop(sdi);
+               sr_dev_acquisition_stop(sdi);
                return FALSE;
        }
 
@@ -476,7 +468,7 @@ static int receive_data(int fd, int revents, void *cb_data)
        for (i = 0; i < NUM_BLOCKS; i++)
                cv_send_block_to_session_bus(sdi, i);
 
-       dev_acquisition_stop(sdi);
+       sr_dev_acquisition_stop(sdi);
 
        return TRUE;
 }
@@ -487,9 +479,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        uint8_t buf[8];
        int bytes_to_write, bytes_written;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        if (!devc->ftdic) {
@@ -537,7 +526,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        sr_dbg("Hardware acquisition started successfully.");
 
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        /* Time when we should be done (for detecting trigger timeouts). */
        devc->done = (devc->divcount + 1) * devc->prof->trigger_constant +
@@ -553,9 +542,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
-       sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
-       std_session_send_df_end(sdi, LOG_PREFIX);
+       std_session_send_df_end(sdi);
 
        return SR_OK;
 }