]> sigrok.org Git - libsigrok.git/blobdiff - hardware/conrad-digi-35-cpu/protocol.c
conrad-digi-35-cpu: Implemented driver.
[libsigrok.git] / hardware / conrad-digi-35-cpu / protocol.c
index ce8668804fa880ab71ed2094adcb68ede3f21dbc..0937bf6d9081cb374197bc5504ea2771a7d2c9ee 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/** @file
+ *  <em>Conrad DIGI 35 CPU</em> power supply driver
+ *  @internal
+ */
+
 #include "protocol.h"
 
-SR_PRIV int conrad_digi_35_cpu_receive_data(int fd, int revents, void *cb_data)
+#include <errno.h>
+#include <string.h>
+
+/** Send command with parameter.
+ *
+ *  @param[in] cmd Command
+ *  @param[in] param Parameter (0..999, depending on command).
+ *
+ *  @retval SR_OK Success
+ *  @retval SR_ERR_ARG Invalid argument.
+ *  @retval SR_ERR Error.
+ */
+SR_PRIV int send_msg1(const struct sr_dev_inst *sdi, char cmd, int param)
 {
-       const struct sr_dev_inst *sdi;
-       struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
+       char buf[5];
 
-       (void)fd;
+       if (!sdi || !(serial = sdi->conn))
+               return SR_ERR_ARG;
 
-       if (!(sdi = cb_data))
-               return TRUE;
+       snprintf(buf, sizeof(buf), "%c%03d", cmd, param);
+       buf[4] = '\r';
 
-       if (!(devc = sdi->priv))
-               return TRUE;
+       sr_spew("send_msg1(): %c%c%c%c\\r", buf[0], buf[1], buf[2], buf[3]);
 
-       if (revents == G_IO_IN) {
-               /* TODO */
+       if (serial_write(serial, buf, sizeof(buf)) == -1) {
+               sr_err("Write error for cmd=%c: %d %s", cmd, errno, strerror(errno));
+               return SR_ERR;
        }
+       g_usleep(50000); /* Wait 50 ms to ensure that the device does not swallow following commands. */
 
-       return TRUE;
+       return SR_OK;
 }