divisor = 1;
for (i = 0; i < 5; i++) {
- segments = decode_pair(buf + 1 + 2*i);
+ segments = decode_pair(buf + 1 + (2 * i));
for (j = 0; j < ARRAY_SIZE(lookup); j++) {
if (lookup[j] == (segments & ~DECIMAL_POINT_MASK)) {
value += j * pow(10, i);
#include "protocol.h"
+#define NUM_CHANNELS 4
+
struct center_info {
- float temp[4];
+ float temp[NUM_CHANNELS];
gboolean rec, std, max, min, maxmin, t1t2, rel, hold, lowbat, celsius;
gboolean memfull, autooff;
gboolean mode_std, mode_rel, mode_max, mode_min, mode_maxmin;
info->autooff = (buf[2] & (1 << 7)) != 0;
/* Byte 7+8/9+10/11+12/13+14: channel T1/T2/T3/T4 temperature. */
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < NUM_CHANNELS; i++) {
temp_u16 = buf[8 + (i * 2)];
temp_u16 |= ((uint16_t)buf[7 + (i * 2)] << 8);
info->temp[i] = (float)temp_u16;
}
/* Byte 43: Specifies whether we need to divide the value(s) by 10. */
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < NUM_CHANNELS; i++) {
/* Bit = 0: Divide by 10. Bit = 1: Don't divide by 10. */
if ((buf[43] & (1 << i)) == 0)
info->temp[i] /= 10;
}
/* Bytes 39-42: Overflow/overlimit bits, depending on mode. */
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < NUM_CHANNELS; i++) {
if (info->mode_std && ((buf[39] & (1 << i)) != 0))
info->temp[i] = INFINITY;
/* TODO: Rel. Not available on all models. */
analog.num_samples = 1;
/* Send the values for T1 - T4. */
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < NUM_CHANNELS; i++) {
l = NULL;
l = g_slist_append(l, g_slist_nth_data(sdi->channels, i));
analog.channels = l;
while (timeout_us > g_get_monotonic_time()) {
/* Receive reply (14 bytes) */
devc->buflen = 0;
- for (cnt = 0; cnt < 14; cnt++) {
+ for (cnt = 0; cnt < GMC_REPLY_SIZE; cnt++) {
byte = read_byte(serial, timeout_us);
if (byte != -1)
devc->buf[devc->buflen++] = (byte & MASK_6BITS);
}
- if (devc->buflen != 14)
+ if (devc->buflen != GMC_REPLY_SIZE)
continue;
devc->addr = devc->buf[0];
{
guchar cnt, chs;
- for (chs = 0, cnt = 0; cnt < 13; cnt++)
+ for (chs = 0, cnt = 0; cnt < (GMC_REPLY_SIZE - 1); cnt++)
chs += dta[cnt];
return (64 - chs) & MASK_6BITS;
*/
void create_cmd_14(guchar addr, guchar func, guchar* params, guchar* buf)
{
- uint8_t dta[14]; /* Unencoded message */
+ uint8_t dta[GMC_REPLY_SIZE]; /* Unencoded message */
int cnt;
if (!params || !buf)
/* 4-12: Copy further parameters */
for (cnt = 0; cnt < 9; cnt++)
- dta[cnt+4] = (params[cnt] & MASK_6BITS);
+ dta[cnt + 4] = (params[cnt] & MASK_6BITS);
/* 13: Checksum (b complement) */
dta[13] = calc_chksum_14(dta);
/* The whole message is packed into 3 bytes per byte now (lower 6 bits only) the most
* peculiar way I have ever seen. Possibly to improve IR communication? */
- for (cnt = 0; cnt < 14; cnt++) {
- buf[3*cnt] = (dta[cnt] & 0x01 ? 0x0f : 0) | (dta[cnt] & 0x02 ? 0xf0 : 0);
- buf[3*cnt + 1] = (dta[cnt] & 0x04 ? 0x0f : 0) | (dta[cnt] & 0x08 ? 0xf0 : 0);
- buf[3*cnt + 2] = (dta[cnt] & 0x10 ? 0x0f : 0) | (dta[cnt] & 0x20 ? 0xf0 : 0);
+ for (cnt = 0; cnt < GMC_REPLY_SIZE; cnt++) {
+ buf[(3 * cnt) + 0] = (dta[cnt] & 0x01 ? 0x0f : 0) | (dta[cnt] & 0x02 ? 0xf0 : 0);
+ buf[(3 * cnt) + 1] = (dta[cnt] & 0x04 ? 0x0f : 0) | (dta[cnt] & 0x08 ? 0xf0 : 0);
+ buf[(3 * cnt) + 2] = (dta[cnt] & 0x10 ? 0x0f : 0) | (dta[cnt] & 0x20 ? 0xf0 : 0);
}
}
#define LOG_PREFIX "gmc-mh-1x-2x"
-#define GMC_BUFSIZE 266
+#define GMC_BUFSIZE 266
+#define GMC_REPLY_SIZE 14
/** Message ID bits 4, 5 */
#define MSGID_MASK 0x30 /**< Mask to get message ID bits */
#define NUM_TIMEBASE 10
#define NUM_VDIV 8
+#define NUM_BUFFER_SIZES 2
+
static const uint32_t scanopts[] = {
SR_CONF_CONN,
};
break;
case SR_CONF_BUFFERSIZE:
tmp_u64 = g_variant_get_uint64(data);
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < NUM_BUFFER_SIZES; i++) {
if (devc->profile->buffersizes[i] == tmp_u64) {
devc->framesize = tmp_u64;
break;
}
}
- if (i == 2)
+ if (i == NUM_BUFFER_SIZES)
ret = SR_ERR_ARG;
break;
case SR_CONF_TIMEBASE:
return SR_ERR_ARG;
devc = sdi->priv;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
- devc->profile->buffersizes, 2, sizeof(uint64_t));
+ devc->profile->buffersizes, NUM_BUFFER_SIZES, sizeof(uint64_t));
break;
case SR_CONF_TIMEBASE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
#include "libsigrok-internal.h"
#include "dso.h"
+#define NUM_CHANNELS 2
+
extern struct sr_dev_driver hantek_dso_driver_info;
static int send_begin(const struct sr_dev_inst *sdi)
* since that's how voltage offsets are submitted back to the DSO.
* Convert to host order now, so we can use them natively.
*/
- for (chan = 0; chan < 2; chan++) {
+ for (chan = 0; chan < NUM_CHANNELS; chan++) {
for (v = 0; v < 9; v++) {
devc->channel_levels[chan][v][0] =
g_ntohs(devc->channel_levels[chan][v][0]);
if (sr_log_loglevel_get() >= SR_LOG_DBG) {
gs = g_string_sized_new(128);
- for (chan = 0; chan < 2; chan++) {
+ for (chan = 0; chan < NUM_CHANNELS; chan++) {
g_string_printf(gs, "CH%d:", chan + 1);
for (v = 0; v < 9; v++) {
g_string_append_printf(gs, " %.4x-%.4x",
#include "protocol.h"
+#define LINE_LENGTH 20
+
SR_PRIV const struct nmadmm_req nmadmm_requests[] = {
{ NMADMM_REQ_IDN, "IDN?" },
{ NMADMM_REQ_IDN, "STATUS?" },
devc = sdi->priv;
- devc->buf[20] = '\0';
+ devc->buf[LINE_LENGTH] = '\0';
sr_spew("Received line '%s'.", devc->buf);
/* Check line. */
- if (strlen((const char *)devc->buf) != 20) {
+ if (strlen((const char *)devc->buf) != LINE_LENGTH) {
sr_err("line: Invalid status '%s', must be 20 hex digits.",
devc->buf);
devc->buflen = 0;
return;
}
- for (pos = 0; pos < 20; pos++) {
+ for (pos = 0; pos < LINE_LENGTH; pos++) {
if (!isxdigit(devc->buf[pos])) {
sr_err("line: Expected hex digit in '%s' at pos %d!",
devc->buf, pos);
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
GSList *l, *devices;
- int ret, i;
+ int ret;
+ unsigned int i;
const char *conn, *serialcomm;
char buf[8];
sdi->model = g_strdup("Logic Analyzer");
sdi->version = g_strdup("v1.0");
sdi->driver = di;
- for (i = 0; i < 32; i++)
+ for (i = 0; i < ARRAY_SIZE(ols_channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
ols_channel_names[i]);
devc = ols_dev_new();
struct sr_dev_inst *sdi;
struct sr_config *src;
GSList *usb_devices, *devices, *l;
- int i;
+ unsigned int i;
const char *conn;
drvc = di->priv;
sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;
- for (i = 0; i < 3; i++)
+ for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
channel_names[i]);
devc = g_malloc0(sizeof(struct dev_context));