X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fconrad-digi-35-cpu%2Fprotocol.c;h=7657b319bc2d59a4e2d4555203794689673a1e2f;hb=d292f767bd031979edbcbf54b7daa39b0aad7812;hp=ce8668804fa880ab71ed2094adcb68ede3f21dbc;hpb=823b4e5817af106e88ab4be2bdb999ac9d1ee50b;p=libsigrok.git
diff --git a/hardware/conrad-digi-35-cpu/protocol.c b/hardware/conrad-digi-35-cpu/protocol.c
index ce866880..7657b319 100644
--- a/hardware/conrad-digi-35-cpu/protocol.c
+++ b/hardware/conrad-digi-35-cpu/protocol.c
@@ -17,24 +17,47 @@
* along with this program. If not, see .
*/
+/**
+ * @file
+ * Conrad DIGI 35 CPU power supply driver
+ * @internal
+ */
+
#include "protocol.h"
-SR_PRIV int conrad_digi_35_cpu_receive_data(int fd, int revents, void *cb_data)
+/**
+ * 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;
}
- return TRUE;
+ /*
+ * Wait 50ms to ensure that the device does not swallow any of the
+ * following commands.
+ */
+ g_usleep(50000);
+
+ return SR_OK;
}