mic-985xx: Add support for the MIC 98581.
This device only supports temperature measurements, no humidity.
This commit is contained in:
parent
be6db330f8
commit
6f3e5335ad
|
@ -35,11 +35,18 @@ static const int hwcaps[] = {
|
|||
0,
|
||||
};
|
||||
|
||||
SR_PRIV struct sr_dev_driver mic_98581_driver_info;
|
||||
SR_PRIV struct sr_dev_driver mic_98583_driver_info;
|
||||
|
||||
SR_PRIV const struct mic_dev_info mic_devs[] = {
|
||||
{
|
||||
"MIC", "98583", "38400/8n2", 32000, TRUE, TRUE,
|
||||
"MIC", "98581", "38400/8n2", 32000, TRUE, FALSE, 6,
|
||||
packet_valid_temp,
|
||||
&mic_98581_driver_info, receive_data_MIC_98581,
|
||||
},
|
||||
{
|
||||
"MIC", "98583", "38400/8n2", 32000, TRUE, TRUE, 10,
|
||||
packet_valid_temp_hum,
|
||||
&mic_98583_driver_info, receive_data_MIC_98583,
|
||||
},
|
||||
};
|
||||
|
@ -122,9 +129,11 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx)
|
|||
goto scan_cleanup;
|
||||
sdi->probes = g_slist_append(sdi->probes, probe);
|
||||
|
||||
if (mic_devs[idx].has_humidity) {
|
||||
if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity")))
|
||||
goto scan_cleanup;
|
||||
sdi->probes = g_slist_append(sdi->probes, probe);
|
||||
}
|
||||
|
||||
drvc->instances = g_slist_append(drvc->instances, sdi);
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
@ -323,4 +332,5 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \
|
|||
.priv = NULL, \
|
||||
};
|
||||
|
||||
DRV(mic_98581, MIC_98581, "mic-98581", "MIC 98581")
|
||||
DRV(mic_98583, MIC_98583, "mic-98583", "MIC 98583")
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include "protocol.h"
|
||||
|
||||
#define PACKET_SIZE 10
|
||||
|
||||
static int mic_send(struct sr_serial_dev_inst *serial, const char *cmd)
|
||||
{
|
||||
int ret;
|
||||
|
@ -44,7 +42,18 @@ static int mic_cmd_set_realtime_mode(struct sr_serial_dev_inst *serial)
|
|||
return mic_send(serial, "S 1 M 2 32 3\r");
|
||||
}
|
||||
|
||||
static gboolean packet_valid(const uint8_t *buf)
|
||||
SR_PRIV gboolean packet_valid_temp(const uint8_t *buf)
|
||||
{
|
||||
if (buf[0] != 'v' || buf[1] != ' ' || buf[5] != '\r')
|
||||
return FALSE;
|
||||
|
||||
if (!isdigit(buf[2]) || !isdigit(buf[3]) || !isdigit(buf[4]))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SR_PRIV gboolean packet_valid_temp_hum(const uint8_t *buf)
|
||||
{
|
||||
if (buf[0] != 'v' || buf[1] != ' ' || buf[5] != ' ' || buf[9] != '\r')
|
||||
return FALSE;
|
||||
|
@ -58,11 +67,12 @@ static gboolean packet_valid(const uint8_t *buf)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static int packet_parse(const char *buf, float *temp, float *humidity)
|
||||
static int packet_parse(const char *buf, int idx, float *temp, float *humidity)
|
||||
{
|
||||
char tmp[4];
|
||||
|
||||
/* Packet format: "v ttt hhh\r". */
|
||||
/* Packet format MIC98581: "v ttt\r". */
|
||||
/* Packet format MIC98583: "v ttt hhh\r". */
|
||||
|
||||
/* TODO: Sanity check on buf. For now we assume well-formed ASCII. */
|
||||
|
||||
|
@ -71,8 +81,10 @@ static int packet_parse(const char *buf, float *temp, float *humidity)
|
|||
strncpy((char *)&tmp, &buf[2], 3);
|
||||
*temp = g_ascii_strtoull((const char *)&tmp, NULL, 10) / 10;
|
||||
|
||||
if (mic_devs[idx].has_humidity) {
|
||||
strncpy((char *)&tmp, &buf[6], 3);
|
||||
*humidity = g_ascii_strtoull((const char *)&tmp, NULL, 10) / 10;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
@ -90,7 +102,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
|
||||
devc = sdi->priv;
|
||||
|
||||
ret = packet_parse((const char *)buf, &temperature, &humidity);
|
||||
ret = packet_parse((const char *)buf, idx, &temperature, &humidity);
|
||||
if (ret < 0) {
|
||||
sr_err("Failed to parse packet.");
|
||||
return SR_ERR;
|
||||
|
@ -112,6 +124,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
g_slist_free(l);
|
||||
|
||||
/* Humidity. */
|
||||
if (mic_devs[idx].has_humidity) {
|
||||
l = g_slist_copy(sdi->probes);
|
||||
l = g_slist_remove_link(l, g_slist_nth(l, 0));
|
||||
analog.probes = l;
|
||||
|
@ -120,6 +133,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
analog.data = &humidity;
|
||||
sr_session_send(devc->cb_data, &packet);
|
||||
g_slist_free(l);
|
||||
}
|
||||
|
||||
devc->num_samples++;
|
||||
|
||||
|
@ -144,10 +158,10 @@ static void handle_new_data(struct sr_dev_inst *sdi, int idx)
|
|||
devc->buflen += len;
|
||||
|
||||
/* Now look for packets in that data. */
|
||||
while ((devc->buflen - offset) >= PACKET_SIZE) {
|
||||
if (packet_valid(devc->buf + offset)) {
|
||||
while ((devc->buflen - offset) >= mic_devs[idx].packet_size) {
|
||||
if (mic_devs[idx].packet_valid(devc->buf + offset)) {
|
||||
handle_packet(devc->buf + offset, sdi, idx);
|
||||
offset += PACKET_SIZE;
|
||||
offset += mic_devs[idx].packet_size;
|
||||
} else {
|
||||
offset++;
|
||||
}
|
||||
|
@ -208,4 +222,5 @@ SR_PRIV int receive_data_##ID_UPPER(int fd, int revents, void *cb_data) { \
|
|||
return receive_data(fd, revents, ID_UPPER, cb_data); }
|
||||
|
||||
/* Driver-specific receive_data() wrappers */
|
||||
RECEIVE_DATA(MIC_98581)
|
||||
RECEIVE_DATA(MIC_98583)
|
||||
|
|
|
@ -39,10 +39,11 @@
|
|||
|
||||
/* Note: When adding entries here, don't forget to update MIC_DEV_COUNT. */
|
||||
enum {
|
||||
MIC_98581,
|
||||
MIC_98583,
|
||||
};
|
||||
|
||||
#define MIC_DEV_COUNT 1
|
||||
#define MIC_DEV_COUNT 2
|
||||
|
||||
struct mic_dev_info {
|
||||
char *vendor;
|
||||
|
@ -51,6 +52,8 @@ struct mic_dev_info {
|
|||
uint32_t max_sample_points;
|
||||
gboolean has_temperature;
|
||||
gboolean has_humidity;
|
||||
uint8_t packet_size;
|
||||
gboolean (*packet_valid)(const uint8_t *);
|
||||
struct sr_dev_driver *di;
|
||||
int (*receive_data)(int, int, void *);
|
||||
};
|
||||
|
@ -82,6 +85,10 @@ struct dev_context {
|
|||
int buflen;
|
||||
};
|
||||
|
||||
SR_PRIV gboolean packet_valid_temp(const uint8_t *buf);
|
||||
SR_PRIV gboolean packet_valid_temp_hum(const uint8_t *buf);
|
||||
|
||||
SR_PRIV int receive_data_MIC_98581(int fd, int revents, void *cb_data);
|
||||
SR_PRIV int receive_data_MIC_98583(int fd, int revents, void *cb_data);
|
||||
|
||||
SR_PRIV int mic_cmd_get_device_info(struct sr_serial_dev_inst *serial);
|
||||
|
|
|
@ -96,6 +96,7 @@ extern SR_PRIV struct sr_dev_driver demo_driver_info;
|
|||
extern SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info;
|
||||
#endif
|
||||
#ifdef HAVE_HW_MIC_985XX
|
||||
extern SR_PRIV struct sr_dev_driver mic_98581_driver_info;
|
||||
extern SR_PRIV struct sr_dev_driver mic_98583_driver_info;
|
||||
#endif
|
||||
#ifdef HAVE_HW_NEXUS_OSCIPRIME
|
||||
|
@ -176,6 +177,7 @@ static struct sr_dev_driver *drivers_list[] = {
|
|||
&lascar_el_usb_driver_info,
|
||||
#endif
|
||||
#ifdef HAVE_HW_MIC_985XX
|
||||
&mic_98581_driver_info,
|
||||
&mic_98583_driver_info,
|
||||
#endif
|
||||
#ifdef HAVE_HW_NEXUS_OSCIPRIME
|
||||
|
|
Loading…
Reference in New Issue