From 27c1e10fed06b29cd80a5837b60b5f20eb4883ee Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Wed, 3 Apr 2019 11:50:27 +0200 Subject: [PATCH] Improved error reporting --- examples/example.py | 29 +++++++++++++++++++++++++++++ moberg_device.c | 8 +++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 examples/example.py diff --git a/examples/example.py b/examples/example.py new file mode 100755 index 0000000..07fb0ac --- /dev/null +++ b/examples/example.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +import moberg + +def scan(): + result = [[], [], [], [], []] + m = moberg.Moberg() + for i, f in enumerate([m.analog_in, m.analog_out, + m.digital_in, m.digital_out, + m.encoder_in]): + for j in range(0, 100): + try: + result[i].append((j, f(j))) + pass + except: + pass + pass + pass + return result + +def main(): + channels = scan() + for c in channels: + print(len(c)) + pass + pass + +if __name__ == '__main__': + main() diff --git a/moberg_device.c b/moberg_device.c index 038974b..015591f 100644 --- a/moberg_device.c +++ b/moberg_device.c @@ -151,16 +151,22 @@ static struct moberg_status map( struct moberg_channel *channel) { struct moberg_status result = MOBERG_ERRNO(EINVAL); - + if (device->range->kind != channel->kind) { + fprintf(stderr, "Mapping wrong kind of channel %d != %d\n", + device->range->kind, channel->kind); return MOBERG_ERRNO(EINVAL); } if (device->range->min > device->range->max) { + fprintf(stderr, "Mapping outside range %d > %d\n", + device->range->min, device->range->max); return MOBERG_ERRNO(ENOSPC); } result = add_channel(device, device->range->kind, device->range->min, (union channel) { .channel=channel }); if (! OK(result)) { + fprintf(stderr, "Failed to add channel kind=%d, index=%d\n", + device->range->kind, device->range->min); return result; } device->range->min++; -- GitLab