From: Uwe Hermann Date: Thu, 26 Dec 2013 11:51:18 +0000 (+0100) Subject: gmc-mh-1x-2x: Cosmetics, whitespace, cleanups. X-Git-Tag: libsigrok-0.3.0~409 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fc348b770a2a9354cdf407f7501c5098b63e4bd7;p=libsigrok.git gmc-mh-1x-2x: Cosmetics, whitespace, cleanups. --- diff --git a/hardware/gmc-mh-1x-2x/api.c b/hardware/gmc-mh-1x-2x/api.c index 2938c36a..c95f3523 100644 --- a/hardware/gmc-mh-1x-2x/api.c +++ b/hardware/gmc-mh-1x-2x/api.c @@ -18,7 +18,6 @@ */ #include - #include "protocol.h" /* Serial communication parameters for Metrahit 1x/2x with 'RS232' adaptor */ @@ -40,20 +39,20 @@ static const int32_t hwcaps[] = { SR_CONF_CONTINUOUS, }; -/** Driver init function */ static int init_1x_2x_rs232(struct sr_context *sr_ctx) { return std_init(sr_ctx, &gmc_mh_1x_2x_rs232_driver_info, LOG_PREFIX); } - -/** Read single byte from serial port. - * \retval -1 Timeout or error. - * \retval other Byte. +/** + * Read single byte from serial port. + * + * @retval -1 Timeout or error. + * @retval other Byte. */ static int read_byte(struct sr_serial_dev_inst *serial, gint64 timeout) { - guint8 result = 0; + uint8_t result = 0; int rc = 0; for (;;) { @@ -68,11 +67,13 @@ static int read_byte(struct sr_serial_dev_inst *serial, gint64 timeout) } } -/** Try to detect GMC 1x/2x multimeter model in send mode for max. 1 second. - * \param serial Configured, open serial port. +/** + * Try to detect GMC 1x/2x multimeter model in send mode for max. 1 second. * - * \retval NULL Detection failed. - * \retval other Model code. + * @param serial Configured, open serial port. + * + * @retval NULL Detection failed. + * @retval other Model code. */ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) { @@ -81,10 +82,12 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) gint64 timeout_us; model = SR_METRAHIT_NONE; - timeout_us = g_get_monotonic_time() + 1*1000*1000; + timeout_us = g_get_monotonic_time() + 1 * 1000 * 1000; - /* Try to find message consisting of device code and several - * (at least 4) data bytes. */ + /* + * Try to find message consisting of device code and several + * (at least 4) data bytes. + */ for (bytecnt = 0; bytecnt < 100; bytecnt++) { byte = read_byte(serial, timeout_us); if ((byte == -1) || (timeout_us < g_get_monotonic_time())) @@ -92,7 +95,7 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) if ((byte & MSGID_MASK) == MSGID_INF) { if (!(model = sr_gmc_decode_model_sm(byte & MSGC_MASK))) break; - /* Now expect (at least) 4 data bytes */ + /* Now expect (at least) 4 data bytes. */ for (cnt = 0; cnt < 4; cnt++) { byte = read_byte(serial, timeout_us); if ((byte == -1) || @@ -110,11 +113,14 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) return model; } -/** Scan for Metrahit 1x and Metrahit 2x in send mode using Gossen Metrawatt - * 'RS232' interface. The older 1x models use 8192 and the newer 2x 9600 baud. - * The DMM usually sends up to about 20 messages per second. However, depending - * on configuration and measurement mode the intervals can be much larger and - * then the detection might not work. +/** + * Scan for Metrahit 1x and Metrahit 2x in send mode using Gossen Metrawatt + * 'RS232' interface. + * + * The older 1x models use 8192 baud and the newer 2x 9600 baud. + * The DMM usually sends up to about 20 messages per second. However, depending + * on configuration and measurement mode the intervals can be much larger and + * then the detection might not work. */ static GSList *scan_1x_2x_rs232(GSList *options) { @@ -168,8 +174,10 @@ static GSList *scan_1x_2x_rs232(GSList *options) model = scan_model_sm(serial); - /* If detection failed and no user-supplied parameters, - * try second baud rate. */ + /* + * If detection failed and no user-supplied parameters, + * try second baud rate. + */ if ((model == SR_METRAHIT_NONE) && !serialcomm_given) { serialcomm = SERIALCOMM_1X_RS232; g_free(serial->serialcomm); @@ -209,7 +217,6 @@ static GSList *scan_1x_2x_rs232(GSList *options) return devices; } -/** Driver device list function */ static GSList *dev_list_1x_2x_rs232(void) { return ((struct drv_context *)(gmc_mh_1x_2x_rs232_driver_info.priv)) @@ -323,7 +330,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } static int dev_acq_start_1x_2x_rs232(const struct sr_dev_inst *sdi, - void *cb_data) + void *cb_data) { struct dev_context *devc; struct sr_serial_dev_inst *serial; diff --git a/hardware/gmc-mh-1x-2x/protocol.c b/hardware/gmc-mh-1x-2x/protocol.c index 0583b2b2..0aa59af6 100644 --- a/hardware/gmc-mh-1x-2x/protocol.c +++ b/hardware/gmc-mh-1x-2x/protocol.c @@ -19,7 +19,6 @@ #include #include - #include "protocol.h" /** Set or clear flags in devc->mqflags. */ @@ -31,9 +30,8 @@ static void setmqf(struct dev_context *devc, uint64_t flags, gboolean set) devc->mqflags &= ~flags; } -/** Decode current type and measured value, Metrahit 12-16. - */ -static void decode_ctmv_16(guchar ctmv, struct dev_context *devc) +/** Decode current type and measured value, Metrahit 12-16. */ +static void decode_ctmv_16(uint8_t ctmv, struct dev_context *devc) { devc->mq = 0; devc->unit = 0; @@ -55,7 +53,7 @@ static void decode_ctmv_16(guchar ctmv, struct dev_context *devc) devc->mqflags |= SR_MQFLAG_AC; if (devc->model >= SR_METRAHIT_16S) devc->mqflags |= SR_MQFLAG_RMS; - } + } break; case 0x05: /* 0101 Hz (15S/16S only) */ case 0x06: /* 0110 kHz (15S/16S only) */ @@ -101,10 +99,12 @@ static void decode_ctmv_16(guchar ctmv, struct dev_context *devc) } } -/** Decode range/sign/acdc byte special chars (Metrahit 12-16). - * \param[in] spc Special characters 1 and 2 (s1 | (s2<<4)). +/** + * Decode range/sign/acdc byte special chars (Metrahit 12-16). + * + * @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)). */ -static void decode_rs_16(guchar rs, struct dev_context *devc) +static void decode_rs_16(uint8_t rs, struct dev_context *devc) { sr_spew("decode_rs_16(%d) scale = %f", rs, devc->scale); @@ -120,7 +120,7 @@ static void decode_rs_16(guchar rs, struct dev_context *devc) switch (rs & 0x03) { case 0: - if (devc->mq == SR_MQ_VOLTAGE) /* V */ + if (devc->mq == SR_MQ_VOLTAGE) /* V */ devc->scale *= 0.1; else if (devc->mq == SR_MQ_CURRENT) /* 000.0 µA */ devc->scale *= 0.0000001; /* Untested! */ @@ -130,8 +130,7 @@ static void decode_rs_16(guchar rs, struct dev_context *devc) devc->mq = SR_MQ_TEMPERATURE; devc->unit = SR_UNIT_CELSIUS; devc->scale *= 0.01; - } - else if ((devc->scale1000 == 2)) { + } else if ((devc->scale1000 == 2)) { /* 16I Iso 500/1000V 3 GOhm */ devc->scale *= 0.1; } @@ -149,10 +148,12 @@ static void decode_rs_16(guchar rs, struct dev_context *devc) } } -/** Decode special chars, Metrahit 12-16. - * \param[in] spc Special characters 1 and 2 (s1 | (s2<<4)). +/** + * Decode special chars, Metrahit 12-16. + * + * @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)). */ -static void decode_spc_16(guchar spc, struct dev_context *devc) +static void decode_spc_16(uint8_t spc, struct dev_context *devc) { /* xxxx1xxx ON */ /* TODO: What does that mean? Power on? The 16I sets this. */ @@ -172,9 +173,8 @@ static void decode_spc_16(guchar spc, struct dev_context *devc) setmqf(devc, SR_MQFLAG_MAX, spc & 0x10); } -/** Decode current type and measured value, Metrahit 18. - */ -static void decode_ctmv_18(guchar ctmv, struct dev_context *devc) +/** Decode current type and measured value, Metrahit 18. */ +static void decode_ctmv_18(uint8_t ctmv, struct dev_context *devc) { devc->mq = 0; devc->unit = 0; @@ -197,7 +197,7 @@ static void decode_ctmv_18(guchar ctmv, struct dev_context *devc) devc->mq = SR_MQ_RESISTANCE; devc->unit = SR_UNIT_OHM; break; - case 0x05: /* 0101 Diode/Diode with buzzer*/ + case 0x05: /* 0101 Diode/Diode with buzzer */ devc->mq = SR_MQ_VOLTAGE; devc->unit = SR_UNIT_VOLT; devc->mqflags |= SR_MQFLAG_DIODE; @@ -245,10 +245,12 @@ static void decode_ctmv_18(guchar ctmv, struct dev_context *devc) } } -/** Decode range/sign/acdc byte special chars, Metrahit 18. - * \param[in] rs Rance/sign byte +/** + * Decode range/sign/acdc byte special chars, Metrahit 18. + * + * @param[in] rs Rance/sign byte. */ -static void decode_rs_18(guchar rs, struct dev_context *devc) +static void decode_rs_18(uint8_t rs, struct dev_context *devc) { int range; @@ -263,7 +265,8 @@ static void decode_rs_18(guchar rs, struct dev_context *devc) case SR_MQ_VOLTAGE: if (devc->unit == SR_UNIT_DECIBEL_VOLT) { devc->scale *= pow(10.0, -2); - /* When entering relative mode, the device switches + /* + * When entering relative mode, the device switches * from 10 byte to 6 byte msg format. Unfortunately * it switches back to 10 byte when the second value * is measured, so that's not sufficient to @@ -297,10 +300,12 @@ static void decode_rs_18(guchar rs, struct dev_context *devc) } } -/** Decode special chars, Metrahit 18. - * \param[in] spc Special characters 1 and 2 (s1 | (s2<<4)). +/** + * Decode special chars, Metrahit 18. + * + * @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)). */ -static void decode_spc_18(guchar spc, struct dev_context *devc) +static void decode_spc_18(uint8_t spc, struct dev_context *devc) { /* xxxx1xxx ZERO */ /* xxxxx1xx BEEP */ @@ -310,8 +315,7 @@ static void decode_spc_18(guchar spc, struct dev_context *devc) if (devc->mq == SR_MQ_TIME) { /* xxx1xxxx Clock running: 1; stop: 0 */ sr_spew("Clock running: %d", spc >> 4); - } - else { + } else { /* 1xxxxxxx MAN */ setmqf(devc, SR_MQFLAG_AUTORANGE, !(spc & 0x80)); @@ -326,13 +330,15 @@ static void decode_spc_18(guchar spc, struct dev_context *devc) } } -/** Decode current type and measured value, Metrahit 2x. - * \param[in] ctmv Current type and measured value (v1 | (v2<<4)). +/** + * Decode current type and measured value, Metrahit 2x. + * + * @param[in] ctmv Current type and measured value (v1 | (v2 << 4)). */ -static void decode_ctmv_2x(guchar ctmv, struct dev_context *devc) +static void decode_ctmv_2x(uint8_t ctmv, struct dev_context *devc) { if ((ctmv > 0x1c) || (!devc)) { - sr_err("decode_ct_mv_2x(%d): invalid param(s)!", ctmv); + sr_err("decode_ctmv_2x(%d): invalid param(s)!", ctmv); return; } @@ -404,8 +410,7 @@ static void decode_ctmv_2x(guchar ctmv, struct dev_context *devc) devc->mq = SR_MQ_VOLTAGE; devc->mqflags |= SR_MQFLAG_DIODE; devc->scale *= 0.1; - } - else { + } else { devc->mq = SR_MQ_CONTINUITY; devc->scale *= 0.00001; } @@ -466,15 +471,18 @@ static void decode_ctmv_2x(guchar ctmv, struct dev_context *devc) break; default: sr_err("decode_ctmv_2x(%d, ...): Unknown ctmv!"); + break; } } -/** Decode range/sign/acdc byte special chars, Metrahit 2x. - * \param[in] rs Rance/sign byte +/** + * Decode range/sign/acdc byte special chars, Metrahit 2x. + * + * @param[in] rs Rance/sign byte. */ -static void decode_rs_2x(guchar rs, struct dev_context *devc) +static void decode_rs_2x(uint8_t rs, struct dev_context *devc) { - int range; + int range; /* Sign */ if (((devc->scale > 0) && (rs & 0x08)) || @@ -485,9 +493,8 @@ static void decode_rs_2x(guchar rs, struct dev_context *devc) range = rs & 0x07; switch (devc->mq) { case SR_MQ_VOLTAGE: - if (devc->unit == SR_UNIT_DECIBEL_VOLT) { + if (devc->unit == SR_UNIT_DECIBEL_VOLT) devc->scale *= pow(10.0, -3); - } else if (devc->vmains_29S) devc->scale *= pow(10.0, range - 2); else if(devc->mqflags & SR_MQFLAG_AC) @@ -509,10 +516,8 @@ static void decode_rs_2x(guchar rs, struct dev_context *devc) devc->scale *= pow(10.0, range - 3); break; case SR_MQ_TEMPERATURE: - if (range == 4) { /* Indicator for °F */ + if (range == 4) /* Indicator for °F */ devc->unit = SR_UNIT_FAHRENHEIT; - } - devc->scale *= pow(10.0, - 2); break; case SR_MQ_CAPACITANCE: @@ -522,10 +527,12 @@ static void decode_rs_2x(guchar rs, struct dev_context *devc) } } -/** Decode special chars (Metrahit 2x). - * \param[in] spc Special characters 1 and 2 (s1 | (s2<<4)). +/** + * Decode special chars (Metrahit 2x). + * + * @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)). */ -static void decode_spc_2x(guchar spc, struct dev_context *devc) +static void decode_spc_2x(uint8_t spc, struct dev_context *devc) { /* xxxxxxx1 Fuse */ @@ -591,20 +598,18 @@ static void process_msg_dta_6(struct sr_dev_inst *sdi) { struct dev_context *devc; int cnt; - guchar dgt; + uint8_t dgt; devc = sdi->priv; clean_rs_v(devc); /* Byte 0, range and sign */ - if (devc->model <= SR_METRAHIT_16X) { + if (devc->model <= SR_METRAHIT_16X) decode_rs_16(bc(devc->buf[0]), devc); - } - else if (devc->model < SR_METRAHIT_2X){ + else if (devc->model < SR_METRAHIT_2X) decode_rs_18(bc(devc->buf[0]), devc); - } else { + else decode_rs_2x(bc(devc->buf[0]), devc); - } /* Bytes 1-5, digits (ls first). */ for (cnt = 0; cnt < 5; cnt++) { @@ -649,13 +654,11 @@ static void process_msg_inf_5(struct sr_dev_inst *sdi) decode_ctmv_16(bc(devc->buf[1]), devc); decode_spc_16(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc); decode_rs_16(bc(devc->buf[4]), devc); - } - else if (devc->model <= SR_METRAHIT_18S) { + } else if (devc->model <= SR_METRAHIT_18S) { decode_ctmv_18(bc(devc->buf[1]), devc); decode_spc_18(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc); decode_rs_18(bc(devc->buf[4]), devc); - } - else { /* Must be Metrahit 2x */ + } else { /* Must be Metrahit 2x */ decode_ctmv_2x(bc(devc->buf[1]), devc); decode_spc_2x(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc); decode_rs_2x(bc(devc->buf[4]), devc); @@ -667,7 +670,7 @@ static void process_msg_inf_10(struct sr_dev_inst *sdi) { struct dev_context *devc; int cnt; - guchar dgt; + uint8_t dgt; devc = sdi->priv; @@ -694,26 +697,43 @@ static void process_msg_inf_10(struct sr_dev_inst *sdi) } /** Decode send interval (Metrahit 2x only). */ -static const char* decode_send_interval(guchar si) +static const char *decode_send_interval(uint8_t si) { switch (si) { - case 0x00: return "0.05"; - case 0x01: return "0.1"; - case 0x02: return "0.2"; - case 0x03: return "0.5"; - case 0x04: return "00:01"; - case 0x05: return "00:02"; - case 0x06: return "00:05"; - case 0x07: return "00:10"; - case 0x08: return "00:20"; - case 0x09: return "00:30"; - case 0x0a: return "01:00"; - case 0x0b: return "02:00"; - case 0x0c: return "05:00"; - case 0x0d: return "10:00"; - case 0x0e: return "----"; - case 0x0f: return "data"; - default: return "Unknown value"; + case 0x00: + return "0.05"; + case 0x01: + return "0.1"; + case 0x02: + return "0.2"; + case 0x03: + return "0.5"; + case 0x04: + return "00:01"; + case 0x05: + return "00:02"; + case 0x06: + return "00:05"; + case 0x07: + return "00:10"; + case 0x08: + return "00:20"; + case 0x09: + return "00:30"; + case 0x0a: + return "01:00"; + case 0x0b: + return "02:00"; + case 0x0c: + return "05:00"; + case 0x0d: + return "10:00"; + case 0x0e: + return "----"; + case 0x0f: + return "data"; + default: + return "Unknown value"; } } @@ -723,7 +743,7 @@ static void process_msg_inf_13(struct sr_dev_inst *sdi) struct dev_context *devc; enum model model; int cnt; - guchar dgt; + uint8_t dgt; devc = sdi->priv; @@ -765,14 +785,14 @@ static void process_msg_inf_13(struct sr_dev_inst *sdi) send_value(sdi); } - SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; - unsigned char buf, msgt; + uint8_t buf, msgt; int len; + gdouble elapsed_s; (void)fd; @@ -793,8 +813,10 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data) sr_spew("read 0x%02x/%d/%d", buf, buf, buf & MSGC_MASK); devc->buflen += len; if (!devc->settings_ok) { - /* If no device type/settings record processed - * yet, wait for one. */ + /* + * If no device type/settings record processed + * yet, wait for one. + */ if ((devc->buf[0] & MSGID_MASK) != MSGID_INF) { devc->buflen = 0; continue; @@ -809,20 +831,22 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data) process_msg_inf_13(sdi); devc->buflen = 0; continue; - } - else if ((devc->buflen == 10) && + } else if ((devc->buflen == 10) && (devc->model <= SR_METRAHIT_18S)) { process_msg_inf_10(sdi); devc->buflen = 0; continue; } else if ((devc->buflen >= 5) && - (devc->buf[devc->buflen-1] & + (devc->buf[devc->buflen - 1] & MSGID_MASK) != MSGID_DATA) { - /* Char just received is beginning - * of next message */ + /* + * Char just received is beginning + * of next message. + */ process_msg_inf_5(sdi); - devc->buf[0] =devc->buf[devc->buflen-1]; + devc->buf[0] = + devc->buf[devc->buflen - 1]; devc->buflen = 1; continue; } @@ -843,23 +867,20 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data) } /* If number of samples or time limit reached, stop aquisition. */ - if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) { + if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) sdi->driver->dev_acquisition_stop(sdi, cb_data); - } if (devc->limit_msec) { - gdouble elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL); - if ((elapsed_s * 1000) >= devc->limit_msec) { + elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL); + if ((elapsed_s * 1000) >= devc->limit_msec) sdi->driver->dev_acquisition_stop(sdi, cb_data); - } } return TRUE; } - -/** Decode model in "send mode" */ -SR_PRIV int sr_gmc_decode_model_sm(guchar mcode) +/** Decode model in "send mode". */ +SR_PRIV int sr_gmc_decode_model_sm(uint8_t mcode) { if (mcode > 0xf) { sr_err("decode_model(%d): Model code 0..15 expected!", mcode); @@ -867,33 +888,33 @@ SR_PRIV int sr_gmc_decode_model_sm(guchar mcode) } switch(mcode) { - case 0x04: /* 0100b */ + case 0x04: /* 0100b */ return SR_METRAHIT_12S; - case 0x08: /* 1000b */ + case 0x08: /* 1000b */ return SR_METRAHIT_13S14A; - case 0x09: /* 1001b */ + case 0x09: /* 1001b */ return SR_METRAHIT_14S; - case 0x0A: /* 1010b */ + case 0x0A: /* 1010b */ return SR_METRAHIT_15S; - case 0x0B: /* 1011b */ + case 0x0B: /* 1011b */ return SR_METRAHIT_16S; - case 0x06: /* 0110b (undocumented by GMC!) */ + case 0x06: /* 0110b (undocumented by GMC!) */ return SR_METRAHIT_16I; - case 0x0D: /* 1101b */ + case 0x0D: /* 1101b */ return SR_METRAHIT_18S; - case 0x02: /* 0010b */ + case 0x02: /* 0010b */ return SR_METRAHIT_22SM; - case 0x03: /* 0011b */ + case 0x03: /* 0011b */ return SR_METRAHIT_23S; - case 0x0f: /* 1111b */ + case 0x0f: /* 1111b */ return SR_METRAHIT_24S; - case 0x05: /* 0101b */ + case 0x05: /* 0101b */ return SR_METRAHIT_25SM; - case 0x01: /* 0001b */ + case 0x01: /* 0001b */ return SR_METRAHIT_26S; - case 0x0c: /* 1100b */ + case 0x0c: /* 1100b */ return SR_METRAHIT_28S; - case 0x0e: /* 1110b */ + case 0x0e: /* 1110b */ return SR_METRAHIT_29S; default: sr_err("Unknown model code %d!", mcode); @@ -901,28 +922,37 @@ SR_PRIV int sr_gmc_decode_model_sm(guchar mcode) } } -/** Decode model in bidirectional mode. - \param[in] mcode Model code. - - \return Model code -*/ -SR_PRIV int sr_gmc_decode_model_bidi(guchar mcode) +/** + * Decode model in bidirectional mode. + * + * @param[in] mcode Model code. + * + * @return Model code. + */ +SR_PRIV int sr_gmc_decode_model_bidi(uint8_t mcode) { - switch(mcode) { - case 2: return SR_METRAHIT_22SM; - case 3: return SR_METRAHIT_23S; - case 4: return SR_METRAHIT_24S; - case 5: return SR_METRAHIT_25SM; - case 1: return SR_METRAHIT_26S; - case 12: return SR_METRAHIT_28S; - case 14: return SR_METRAHIT_29S; + switch (mcode) { + case 2: + return SR_METRAHIT_22SM; + case 3: + return SR_METRAHIT_23S; + case 4: + return SR_METRAHIT_24S; + case 5: + return SR_METRAHIT_25SM; + case 1: + return SR_METRAHIT_26S; + case 12: + return SR_METRAHIT_28S; + case 14: + return SR_METRAHIT_29S; default: sr_err("Unknown model code %d!", mcode); return SR_METRAHIT_NONE; } } -SR_PRIV const char* sr_gmc_model_str(enum model mcode) +SR_PRIV const char *sr_gmc_model_str(enum model mcode) { switch (mcode) { case SR_METRAHIT_NONE: diff --git a/hardware/gmc-mh-1x-2x/protocol.h b/hardware/gmc-mh-1x-2x/protocol.h index 711dd1c0..d5b2dc10 100644 --- a/hardware/gmc-mh-1x-2x/protocol.h +++ b/hardware/gmc-mh-1x-2x/protocol.h @@ -37,25 +37,26 @@ #define GMC_BUFSIZE 266 /** Message ID bits 4, 5 */ -#define MSGID_MASK 0x30 /**< Mask to get message ID bits */ -#define MSGID_INF 0x00 /**< Start of message with device info */ -#define MSGID_D10 0x10 /**< Start of data message, non-displayed intermediate */ -#define MSGID_DTA 0x20 /**< Start of data message, displayed, averaged */ -#define MSGID_DATA 0x30 /**< Data byte in message */ +#define MSGID_MASK 0x30 /**< Mask to get message ID bits */ +#define MSGID_INF 0x00 /**< Start of message with device info */ +#define MSGID_D10 0x10 /**< Start of data message, non-displayed intermediate */ +#define MSGID_DTA 0x20 /**< Start of data message, displayed, averaged */ +#define MSGID_DATA 0x30 /**< Data byte in message */ -#define MSGC_MASK 0x0f /**< Mask to get message byte contents */ +#define MSGC_MASK 0x0f /**< Mask to get message byte contents */ #define MSGSRC_MASK 0xc0 /**< Mask to get bits related to message source */ #define bc(x) (x & MSGC_MASK) /**< Get contents from a byte */ -#define MASK_6BITS 0x3f /**< Mask lower six bits. */ +#define MASK_6BITS 0x3f /**< Mask lower six bits. */ -/** Internal multimeter model codes. In opposite to the multimeter models from - * protocol (see decode_model()), these codes allow working with ranges. +/** + * Internal multimeter model codes. In opposite to the multimeter models from + * protocol (see decode_model()), these codes allow working with ranges. */ enum model { - SR_METRAHIT_NONE = 0, /**< Value for uninitialized variable */ + SR_METRAHIT_NONE = 0, /**< Value for uninitialized variable */ SR_METRAHIT_12S = 12, SR_METRAHIT_13S14A = 13, SR_METRAHIT_14S = 14, @@ -65,7 +66,7 @@ enum model { SR_METRAHIT_16X = SR_METRAHIT_16I, /**< All Metrahit 16 */ /* A Metrahit 17 exists, but seems not to have an IR interface. */ SR_METRAHIT_18S = 18, - SR_METRAHIT_2X = 20, /**< For model type comparisons */ + SR_METRAHIT_2X = 20, /**< For model type comparisons */ SR_METRAHIT_22SM = 22, SR_METRAHIT_23S = 23, SR_METRAHIT_24S = 24, @@ -76,27 +77,19 @@ enum model { }; /** Convert GMC model code in send mode to sigrok-internal one. */ -SR_PRIV int sr_gmc_decode_model_sm(guchar mcode); +SR_PRIV int sr_gmc_decode_model_sm(uint8_t mcode); -/** Convert GMC model code in bidirectional mode to sigrok-internal one. - \param[in] mcode Model code. - - \return Model code -*/ -SR_PRIV int sr_gmc_decode_model_bidi(guchar mcode); - -/** Create 14-bytes (42 byte) message used in bidirectional mode. - * \param[in] addr Target address. 0..15, 0=Broadcast. - * \param[in] func Function code. - * \param[in] params Further parameters, &char[9]. Unused bytes must be 0. - * \param[out] buf &guchar[42] Output buffer (3*14). +/** + * Convert GMC model code in bidirectional mode to sigrok-internal one. * + * @param[in] mcode Model code. + * + * @return Model code. */ -void create_msg_14(guchar addr, guchar func, guchar* params, guchar* buf); +SR_PRIV int sr_gmc_decode_model_bidi(uint8_t mcode); -/** Get model string from sigrok-internal model code. - */ -SR_PRIV const char* sr_gmc_model_str(enum model mcode); +/** Get model string from sigrok-internal model code. */ +SR_PRIV const char *sr_gmc_model_str(enum model mcode); /** Private, per-device-instance driver context. */ struct dev_context { @@ -124,8 +117,8 @@ struct dev_context { /* Temporary state across callbacks */ uint64_t num_samples; /**< Current #samples for limit_samples */ - GTimer* elapsed_msec; /**< Used for sampling with limit_msec */ - unsigned char buf[GMC_BUFSIZE]; /**< Buffer for read callback */ + GTimer *elapsed_msec; /**< Used for sampling with limit_msec */ + uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */ int buflen; /**< Data len in buf */ };