fluke-dmm: parser cleanup

This commit is contained in:
Bert Vermeulen 2012-12-24 10:59:41 +01:00
parent 9fa0968027
commit 4cea0ff7fe
1 changed files with 13 additions and 10 deletions

View File

@ -17,17 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <glib.h>
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "fluke-dmm.h"
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <glib.h>
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "fluke-dmm.h"
static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
char **tokens) char **tokens)
{ {
struct sr_datafeed_analog *analog; struct sr_datafeed_analog *analog;
@ -37,7 +37,7 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi,
(void)sdi; (void)sdi;
if (strcmp(tokens[0], "QM")) if (strcmp(tokens[0], "QM") || !tokens[1])
return NULL; return NULL;
if ((e = strstr(tokens[1], "Out of range"))) { if ((e = strstr(tokens[1], "Out of range"))) {
@ -151,7 +151,7 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi,
return analog; return analog;
} }
static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi, static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi,
char **tokens) char **tokens)
{ {
struct sr_datafeed_analog *analog; struct sr_datafeed_analog *analog;
@ -160,6 +160,9 @@ static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi,
(void)sdi; (void)sdi;
if (!tokens[1])
return NULL;
fvalue = strtof(tokens[0], &eptr); fvalue = strtof(tokens[0], &eptr);
if (fvalue == 0.0 && eptr == tokens[0]) { if (fvalue == 0.0 && eptr == tokens[0]) {
sr_err("Invalid float."); sr_err("Invalid float.");
@ -283,13 +286,13 @@ static void handle_line(const struct sr_dev_inst *sdi)
analog = NULL; analog = NULL;
tokens = g_strsplit(devc->buf, ",", 0); tokens = g_strsplit(devc->buf, ",", 0);
if (tokens[0] && tokens[1]) { if (tokens[0]) {
if (devc->profile->model == FLUKE_187) { if (devc->profile->model == FLUKE_187) {
devc->expect_response = FALSE; devc->expect_response = FALSE;
analog = handle_qm_v1(sdi, tokens); analog = handle_qm_18x(sdi, tokens);
} else if (devc->profile->model == FLUKE_287) { } else if (devc->profile->model == FLUKE_287) {
devc->expect_response = FALSE; devc->expect_response = FALSE;
analog = handle_qm_v2(sdi, tokens); analog = handle_qm_28x(sdi, tokens);
} }
} }
g_strfreev(tokens); g_strfreev(tokens);