/* Log a byte-array as hex values. */
static void log_buf(const char *message, uint8_t buf[], size_t count)
{
- size_t i;
char buffer[count * 2 + 1];
- for (i = 0; i < count; i++) {
+ for (size_t i = 0; i < count; i++) {
sprintf(&buffer[2 * i], "%02X", buf[i]);
}
/* Send updated configuration values to the load. */
static int send_cfg(struct sr_serial_dev_inst *serial, struct dev_context *devc)
{
- uint8_t send[] =
- { 0xfa, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8 };
+ uint8_t send[] = {0xfa, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8};
encode_value(devc->current_limit, &send[2], &send[3], 1000.0);
encode_value(devc->uvc_threshold, &send[4], &send[5], 100.0);
- send[8] = send[1] ^ send[2] ^ send[3] ^ send[4] ^ send[5]
- ^ send[6] ^ send[7];
+ send[8] = send[1] ^ send[2] ^ send[3] ^ send[4] ^ send[5] ^ send[6] ^ send[7];
return send_cmd(serial, send, 10);
}
/* Send the init/connect sequence; drive starts sending voltage and current. */
SR_PRIV int ebd_init(struct sr_serial_dev_inst *serial, struct dev_context *devc)
{
- uint8_t init[] =
- { 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xf8 };
+ uint8_t init[] = { 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xf8 };
(void)devc;
struct dev_context *devc)
{
int ret;
- uint8_t start[] =
- { 0xfa, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8 };
+ uint8_t start[] = { 0xfa, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8 };
encode_value(devc->current_limit, &start[2], &start[3], 1000.0);
encode_value(devc->uvc_threshold, &start[4], &start[5], 100.0);
- start[8] = start[1] ^ start[2] ^ start[3] ^ start[4] ^ start[5]
- ^ start[6] ^ start[7];
+ start[8] = start[1] ^ start[2] ^ start[3] ^ start[4] ^ start[5] ^ start[6] ^ start[7];
sr_info("Activating load");
ret = send_cmd(serial, start, 10);
SR_PRIV int ebd_loadtoggle(struct sr_serial_dev_inst *serial,
struct dev_context *devc)
{
- uint8_t toggle[] =
- { 0xfa, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xF8 };
+ uint8_t toggle[] = { 0xfa, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xF8 };
- (void) devc;
+ (void)devc;
sr_info("Toggling load");
return send_cmd(serial, toggle, 10);
/* Stop the drive. */
SR_PRIV int ebd_stop(struct sr_serial_dev_inst *serial, struct dev_context *devc)
{
- uint8_t stop[] =
- { 0xfa, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xF8 };
+ uint8_t stop[] = { 0xfa, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xF8 };
- (void) devc;
+ (void)devc;
return send_cmd(serial, stop, 10);
}
while (!message_complete && turn < max_turns) {
/* Wait for header byte. */
message_length = 0;
- while (buf[0] != MSG_FRAME_BEGIN && turn < max_turns) {
- ret = serial_read_blocking(serial, &buf[0], 1,
- serial_timeout(serial, 1));
+ while ((buf[0] != MSG_FRAME_BEGIN) && (turn < max_turns)) {
+ ret = serial_read_blocking(serial, &buf[0], 1, serial_timeout(serial, 1));
if (ret < 0) {
sr_err("Error %d reading byte.", ret);
return ret;
turn++;
}
/* Read until end byte. */
- while (buf[message_length - 1] != MSG_FRAME_END
- && message_length < length && turn < max_turns) {
+ while ((buf[message_length - 1] != MSG_FRAME_END)
+ && (message_length < length) && (turn < max_turns)) {
- ret = serial_read_blocking(serial, &buf[message_length],
- 1, serial_timeout(serial, 1));
+ ret = serial_read_blocking(serial, &buf[message_length], 1, serial_timeout(serial, 1));
if (ret < 0) {
sr_err("Error %d reading byte.", ret);
return ret;
sr_err("No messages received");
devc->running = FALSE;
return 0;
- } else if (ret != 19 ||
- (reply[1] != 0x00 && reply[1] != 0x0a && reply[1] != 0x64 && reply[1] != 0x6e)) {
+ } else if ((ret != 19) ||
+ ((reply[1] != 0x00) && (reply[1] != 0x0a) && (reply[1] != 0x64) && (reply[1] != 0x6e))) {
sr_info("Not measurement message received");
return ret;
}
devc->running = TRUE;
- if (reply[1] == 0x00 || reply[1] == 0x64)
+ if ((reply[1] == 0x00) || (reply[1] == 0x64))
devc->load_activated = FALSE;
- else if (reply[1] == 0x0a || reply[1] == 0x6e)
+ else if ((reply[1] == 0x0a) || (reply[1] == 0x6e))
devc->load_activated = TRUE;
/* Calculate values. */
} else if (!devc->load_activated && !ebd_current_is0(devc)) {
ebd_loadstart(serial, devc);
} else if (devc->load_activated &&
- (current_limit != devc->current_limit || uvc_threshold != devc->uvc_threshold)) {
+ ((current_limit != devc->current_limit) || (uvc_threshold != devc->uvc_threshold))) {
sr_dbg("Adjusting limit from %.03f A %.03f V to %.03f A %.03f V",
current_limit, uvc_threshold, devc->current_limit,