serial-dmm: Declare each meter type in only one place.

This commit is contained in:
Martin Ling 2015-03-21 09:07:49 +00:00 committed by Uwe Hermann
parent 4f840ce965
commit bcbef5ed70
4 changed files with 447 additions and 801 deletions

View File

@ -128,50 +128,7 @@ extern SR_PRIV struct sr_dev_driver saleae_logic16_driver_info;
extern SR_PRIV struct sr_dev_driver scpi_pps_driver_info; extern SR_PRIV struct sr_dev_driver scpi_pps_driver_info;
#endif #endif
#ifdef HAVE_HW_SERIAL_DMM #ifdef HAVE_HW_SERIAL_DMM
extern SR_PRIV struct sr_dev_driver bbcgm_m2110_driver_info; extern SR_PRIV struct sr_dev_driver *serial_dmm_drivers[];
extern SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info;
extern SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info;
extern SR_PRIV struct sr_dev_driver metex_me31_driver_info;
extern SR_PRIV struct sr_dev_driver peaktech_3410_driver_info;
extern SR_PRIV struct sr_dev_driver mastech_mas345_driver_info;
extern SR_PRIV struct sr_dev_driver mastech_ms8250b_driver_info;
extern SR_PRIV struct sr_dev_driver va_va18b_driver_info;
extern SR_PRIV struct sr_dev_driver va_va40b_driver_info;
extern SR_PRIV struct sr_dev_driver metex_m3640d_driver_info;
extern SR_PRIV struct sr_dev_driver metex_m4650cr_driver_info;
extern SR_PRIV struct sr_dev_driver peaktech_4370_driver_info;
extern SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info;
extern SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info;
extern SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info;
extern SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info;
extern SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m3650cr_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_me42_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc830_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc870_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc920_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc940_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_vc960_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut60a_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut60e_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut60g_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut61b_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut61c_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut71a_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut71b_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut71c_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut71d_ser_driver_info;
extern SR_PRIV struct sr_dev_driver uni_t_ut71e_ser_driver_info;
extern SR_PRIV struct sr_dev_driver iso_tech_idm103n_driver_info;
extern SR_PRIV struct sr_dev_driver tenma_72_7745_ser_driver_info;
extern SR_PRIV struct sr_dev_driver tenma_72_7750_ser_driver_info;
extern SR_PRIV struct sr_dev_driver brymen_bm25x_driver_info;
#endif #endif
#ifdef HAVE_HW_SYSCLK_LWLA #ifdef HAVE_HW_SYSCLK_LWLA
extern SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info; extern SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info;
@ -341,52 +298,7 @@ SR_PRIV struct sr_dev_driver **drivers_lists[] = {
(DRVS) {&scpi_pps_driver_info, NULL}, (DRVS) {&scpi_pps_driver_info, NULL},
#endif #endif
#ifdef HAVE_HW_SERIAL_DMM #ifdef HAVE_HW_SERIAL_DMM
(DRVS) { serial_dmm_drivers,
&bbcgm_m2110_driver_info,
&digitek_dt4000zc_driver_info,
&tekpower_tp4000zc_driver_info,
&metex_me31_driver_info,
&peaktech_3410_driver_info,
&mastech_mas345_driver_info,
&mastech_ms8250b_driver_info,
&va_va18b_driver_info,
&va_va40b_driver_info,
&metex_m3640d_driver_info,
&metex_m4650cr_driver_info,
&peaktech_4370_driver_info,
&pce_pce_dm32_driver_info,
&radioshack_22_168_driver_info,
&radioshack_22_805_driver_info,
&radioshack_22_812_driver_info,
&tecpel_dmm_8061_ser_driver_info,
&voltcraft_m3650cr_driver_info,
&voltcraft_m3650d_driver_info,
&voltcraft_m4650cr_driver_info,
&voltcraft_me42_driver_info,
&voltcraft_vc820_ser_driver_info,
&voltcraft_vc830_ser_driver_info,
&voltcraft_vc840_ser_driver_info,
&voltcraft_vc870_ser_driver_info,
&voltcraft_vc920_ser_driver_info,
&voltcraft_vc940_ser_driver_info,
&voltcraft_vc960_ser_driver_info,
&uni_t_ut60a_ser_driver_info,
&uni_t_ut60e_ser_driver_info,
&uni_t_ut60g_ser_driver_info,
&uni_t_ut61b_ser_driver_info,
&uni_t_ut61c_ser_driver_info,
&uni_t_ut61d_ser_driver_info,
&uni_t_ut61e_ser_driver_info,
&uni_t_ut71a_ser_driver_info,
&uni_t_ut71b_ser_driver_info,
&uni_t_ut71c_ser_driver_info,
&uni_t_ut71d_ser_driver_info,
&uni_t_ut71e_ser_driver_info,
&iso_tech_idm103n_driver_info,
&tenma_72_7745_ser_driver_info,
&tenma_72_7750_ser_driver_info,
&brymen_bm25x_driver_info,
NULL},
#endif #endif
#ifdef HAVE_HW_SYSCLK_LWLA #ifdef HAVE_HW_SYSCLK_LWLA
(DRVS) {&sysclk_lwla_driver_info, NULL}, (DRVS) {&sysclk_lwla_driver_info, NULL},

File diff suppressed because it is too large Load Diff

View File

@ -39,8 +39,9 @@ static void log_dmm_packet(const uint8_t *buf)
} }
static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
int dmm, void *info) void *info)
{ {
struct dmm_info *dmm = (struct dmm_info *) sdi->driver;
float floatval; float floatval;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog; struct sr_datafeed_analog analog;
@ -55,12 +56,12 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
analog.num_samples = 1; analog.num_samples = 1;
analog.mq = -1; analog.mq = -1;
dmms[dmm].packet_parse(buf, &floatval, &analog, info); dmm->packet_parse(buf, &floatval, &analog, info);
analog.data = &floatval; analog.data = &floatval;
/* If this DMM needs additional handling, call the resp. function. */ /* If this DMM needs additional handling, call the resp. function. */
if (dmms[dmm].dmm_details) if (dmm->dmm_details)
dmms[dmm].dmm_details(&analog, info); dmm->dmm_details(&analog, info);
if (analog.mq != -1) { if (analog.mq != -1) {
/* Got a measurement. */ /* Got a measurement. */
@ -72,13 +73,14 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
} }
/** Request packet, if required. */ /** Request packet, if required. */
SR_PRIV int req_packet(struct sr_dev_inst *sdi, int dmm) SR_PRIV int req_packet(struct sr_dev_inst *sdi)
{ {
struct dmm_info *dmm = (struct dmm_info *) sdi->driver;
struct dev_context *devc; struct dev_context *devc;
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
int ret; int ret;
if (!dmms[dmm].packet_request) if (!dmm->packet_request)
return SR_OK; return SR_OK;
devc = sdi->priv; devc = sdi->priv;
@ -90,20 +92,21 @@ SR_PRIV int req_packet(struct sr_dev_inst *sdi, int dmm)
return SR_OK; return SR_OK;
} }
ret = dmms[dmm].packet_request(serial); ret = dmm->packet_request(serial);
if (ret < 0) { if (ret < 0) {
sr_err("Failed to request packet: %d.", ret); sr_err("Failed to request packet: %d.", ret);
return ret; return ret;
} }
if (dmms[dmm].req_timeout_ms) if (dmm->req_timeout_ms)
devc->req_next_at = g_get_monotonic_time() + (dmms[dmm].req_timeout_ms * 1000); devc->req_next_at = g_get_monotonic_time() + (dmm->req_timeout_ms * 1000);
return SR_OK; return SR_OK;
} }
static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info) static void handle_new_data(struct sr_dev_inst *sdi, void *info)
{ {
struct dmm_info *dmm = (struct dmm_info *) sdi->driver;
struct dev_context *devc; struct dev_context *devc;
int len, i, offset = 0; int len, i, offset = 0;
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
@ -123,18 +126,18 @@ static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
devc->buflen += len; devc->buflen += len;
/* Now look for packets in that data. */ /* Now look for packets in that data. */
while ((devc->buflen - offset) >= dmms[dmm].packet_size) { while ((devc->buflen - offset) >= dmm->packet_size) {
if (dmms[dmm].packet_valid(devc->buf + offset)) { if (dmm->packet_valid(devc->buf + offset)) {
handle_packet(devc->buf + offset, sdi, dmm, info); handle_packet(devc->buf + offset, sdi, info);
offset += dmms[dmm].packet_size; offset += dmm->packet_size;
/* Request next packet, if required. */ /* Request next packet, if required. */
if (!dmms[dmm].packet_request) if (!dmm->packet_request)
break; break;
if (dmms[dmm].req_timeout_ms || dmms[dmm].req_delay_ms) if (dmm->req_timeout_ms || dmm->req_delay_ms)
devc->req_next_at = g_get_monotonic_time() + devc->req_next_at = g_get_monotonic_time() +
dmms[dmm].req_delay_ms * 1000; dmm->req_delay_ms * 1000;
req_packet(sdi, dmm); req_packet(sdi);
} else { } else {
offset++; offset++;
} }
@ -146,11 +149,13 @@ static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
devc->buflen -= offset; devc->buflen -= offset;
} }
static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data) int receive_data(int fd, int revents, void *cb_data)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct dev_context *devc; struct dev_context *devc;
struct dmm_info *dmm;
int64_t time; int64_t time;
void *info;
(void)fd; (void)fd;
@ -160,12 +165,16 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
if (!(devc = sdi->priv)) if (!(devc = sdi->priv))
return TRUE; return TRUE;
dmm = (struct dmm_info *) sdi->driver;
if (revents == G_IO_IN) { if (revents == G_IO_IN) {
/* Serial data arrived. */ /* Serial data arrived. */
handle_new_data(sdi, dmm, info); info = malloc(dmm->info_size);
handle_new_data(sdi, info);
free(info);
} else { } else {
/* Timeout; send another packet request if DMM needs it. */ /* Timeout; send another packet request if DMM needs it. */
if (dmms[dmm].packet_request && (req_packet(sdi, dmm) < 0)) if (dmm->packet_request && (req_packet(sdi) < 0))
return FALSE; return FALSE;
} }
@ -186,54 +195,3 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
return TRUE; return TRUE;
} }
#define RECEIVE_DATA(ID_UPPER, DMM_DRIVER) \
SR_PRIV int receive_data_##ID_UPPER(int fd, int revents, void *cb_data) { \
struct DMM_DRIVER##_info info; \
return receive_data(fd, revents, ID_UPPER, &info, cb_data); }
/* Driver-specific receive_data() wrappers */
RECEIVE_DATA(BBCGM_M2110, metex14) /* metex14_info used as a dummy. */
RECEIVE_DATA(DIGITEK_DT4000ZC, fs9721)
RECEIVE_DATA(TEKPOWER_TP4000ZC, fs9721)
RECEIVE_DATA(METEX_ME31, metex14)
RECEIVE_DATA(PEAKTECH_3410, metex14)
RECEIVE_DATA(MASTECH_MAS345, metex14)
RECEIVE_DATA(MASTECH_MS8250B, fs9721)
RECEIVE_DATA(VA_VA18B, fs9721)
RECEIVE_DATA(VA_VA40B, fs9721)
RECEIVE_DATA(METEX_M3640D, metex14)
RECEIVE_DATA(METEX_M4650CR, metex14)
RECEIVE_DATA(PEAKTECH_4370, metex14)
RECEIVE_DATA(PCE_PCE_DM32, fs9721)
RECEIVE_DATA(RADIOSHACK_22_168, metex14)
RECEIVE_DATA(RADIOSHACK_22_805, metex14)
RECEIVE_DATA(RADIOSHACK_22_812, rs9lcd)
RECEIVE_DATA(TECPEL_DMM_8061_SER, fs9721)
RECEIVE_DATA(VOLTCRAFT_M3650CR, metex14)
RECEIVE_DATA(VOLTCRAFT_M3650D, metex14)
RECEIVE_DATA(VOLTCRAFT_M4650CR, metex14)
RECEIVE_DATA(VOLTCRAFT_ME42, metex14)
RECEIVE_DATA(VOLTCRAFT_VC820_SER, fs9721)
RECEIVE_DATA(VOLTCRAFT_VC830_SER, fs9922)
RECEIVE_DATA(VOLTCRAFT_VC840_SER, fs9721)
RECEIVE_DATA(VOLTCRAFT_VC870_SER, vc870)
RECEIVE_DATA(VOLTCRAFT_VC920_SER, ut71x)
RECEIVE_DATA(VOLTCRAFT_VC940_SER, ut71x)
RECEIVE_DATA(VOLTCRAFT_VC960_SER, ut71x)
RECEIVE_DATA(UNI_T_UT60A_SER, fs9721)
RECEIVE_DATA(UNI_T_UT60E_SER, fs9721)
RECEIVE_DATA(UNI_T_UT60G_SER, es519xx)
RECEIVE_DATA(UNI_T_UT61B_SER, fs9922)
RECEIVE_DATA(UNI_T_UT61C_SER, fs9922)
RECEIVE_DATA(UNI_T_UT61D_SER, fs9922)
RECEIVE_DATA(UNI_T_UT61E_SER, es519xx)
RECEIVE_DATA(UNI_T_UT71A_SER, ut71x)
RECEIVE_DATA(UNI_T_UT71B_SER, ut71x)
RECEIVE_DATA(UNI_T_UT71C_SER, ut71x)
RECEIVE_DATA(UNI_T_UT71D_SER, ut71x)
RECEIVE_DATA(UNI_T_UT71E_SER, ut71x)
RECEIVE_DATA(ISO_TECH_IDM103N, es519xx)
RECEIVE_DATA(TENMA_72_7745_SER, fs9721)
RECEIVE_DATA(TENMA_72_7750_SER, es519xx)
RECEIVE_DATA(BRYMEN_BM25X, bm25x)

View File

@ -22,54 +22,9 @@
#define LOG_PREFIX "serial-dmm" #define LOG_PREFIX "serial-dmm"
enum {
BBCGM_M2110,
DIGITEK_DT4000ZC,
TEKPOWER_TP4000ZC,
METEX_ME31,
PEAKTECH_3410,
MASTECH_MAS345,
MASTECH_MS8250B,
VA_VA18B,
VA_VA40B,
METEX_M3640D,
METEX_M4650CR,
PEAKTECH_4370,
PCE_PCE_DM32,
RADIOSHACK_22_168,
RADIOSHACK_22_805,
RADIOSHACK_22_812,
TECPEL_DMM_8061_SER,
VOLTCRAFT_M3650CR,
VOLTCRAFT_M3650D,
VOLTCRAFT_M4650CR,
VOLTCRAFT_ME42,
VOLTCRAFT_VC820_SER,
VOLTCRAFT_VC830_SER,
VOLTCRAFT_VC840_SER,
VOLTCRAFT_VC870_SER,
VOLTCRAFT_VC920_SER,
VOLTCRAFT_VC940_SER,
VOLTCRAFT_VC960_SER,
UNI_T_UT60A_SER,
UNI_T_UT60E_SER,
UNI_T_UT60G_SER,
UNI_T_UT61B_SER,
UNI_T_UT61C_SER,
UNI_T_UT61D_SER,
UNI_T_UT61E_SER,
UNI_T_UT71A_SER,
UNI_T_UT71B_SER,
UNI_T_UT71C_SER,
UNI_T_UT71D_SER,
UNI_T_UT71E_SER,
ISO_TECH_IDM103N,
TENMA_72_7745_SER,
TENMA_72_7750_SER,
BRYMEN_BM25X,
};
struct dmm_info { struct dmm_info {
/** libsigrok driver info struct. */
struct sr_dev_driver di;
/** Manufacturer/brand. */ /** Manufacturer/brand. */
char *vendor; char *vendor;
/** Model. */ /** Model. */
@ -95,13 +50,11 @@ struct dmm_info {
struct sr_datafeed_analog *, void *); struct sr_datafeed_analog *, void *);
/** */ /** */
void (*dmm_details)(struct sr_datafeed_analog *, void *); void (*dmm_details)(struct sr_datafeed_analog *, void *);
/** libsigrok driver info struct. */ /** Size of chipset info struct. */
struct sr_dev_driver *di; gsize info_size;
/** Data reception function. */
int (*receive_data)(int, int, void *);
}; };
extern SR_PRIV struct dmm_info dmms[]; extern SR_PRIV struct dmm_info *dmms[];
#define DMM_BUFSIZE 256 #define DMM_BUFSIZE 256
@ -131,51 +84,7 @@ struct dev_context {
int64_t req_next_at; int64_t req_next_at;
}; };
SR_PRIV int req_packet(struct sr_dev_inst *sdi, int dmm); SR_PRIV int req_packet(struct sr_dev_inst *sdi);
SR_PRIV int receive_data(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_BBCGM_M2110(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_DIGITEK_DT4000ZC(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_TEKPOWER_TP4000ZC(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_METEX_ME31(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_PEAKTECH_3410(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_MASTECH_MAS345(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_MASTECH_MS8250B(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VA_VA18B(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VA_VA40B(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_METEX_M3640D(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_METEX_M4650CR(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_PEAKTECH_4370(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_PCE_PCE_DM32(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_RADIOSHACK_22_168(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_RADIOSHACK_22_805(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_RADIOSHACK_22_812(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_TECPEL_DMM_8061_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M3650CR(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M3650D(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M4650CR(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_ME42(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC820_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC830_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC840_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC870_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC920_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC940_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_VC960_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT60A_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT60E_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT60G_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT61B_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT61C_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT61D_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT61E_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT71A_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT71B_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT71C_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT71D_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_UNI_T_UT71E_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_ISO_TECH_IDM103N(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_TENMA_72_7745_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_TENMA_72_7750_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_BRYMEN_BM25X(int fd, int revents, void *cb_data);
#endif #endif