From 0d7a38d06b3cec7c12a9aaa40f25b0693050e30a Mon Sep 17 00:00:00 2001 From: Vitaly Kravtsov Date: Mon, 28 Jan 2019 00:00:24 +0100 Subject: [PATCH] 2.0a1.dev1 grab ports from JSON --- README | 4 +- README.md | 4 +- lib/mingw/libev3dev-c.a | Bin 152864 -> 154728 bytes source/ev3/app.yu | 4 +- source/ev3/ev3_port-dict.yu | 21 ++- source/ev3/ev3_port.c | 242 ++++++++++++++++++++++++++-------- source/ev3/ev3_port.h | 169 ++++++++++++++---------- source/ev3/ev3_sensor-dict.yu | 4 +- source/ev3/grab/ports.yu | 17 +++ source/ev3/grab/sensors.py | 84 ------------ source/ev3/grab/spec.py | 147 +++++++++++++++++++++ 11 files changed, 472 insertions(+), 224 deletions(-) create mode 100644 source/ev3/grab/ports.yu delete mode 100644 source/ev3/grab/sensors.py create mode 100644 source/ev3/grab/spec.py diff --git a/README b/README index cc1a1cf..e93e2e1 100644 --- a/README +++ b/README @@ -6,10 +6,10 @@ ___ __________________________________ ___ VERSION __________________________________ - ev3dev-c 1.0c3 + ev3dev-c 2.0a1.dev1 2019-01-27 - kernel 4.4.87-22-ev3dev-ev3 + kernel 4.14.80-ev3dev-2.3.1-ev3 ___ ______________________________ ___ WHAT IS IT? ______________________________ diff --git a/README.md b/README.md index 9ba3ad6..d1fc64b 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ ### VERSION - ev3dev-c 1.0c3 + ev3dev-c 2.0a1.dev1 2019-01-27 - kernel 4.4.87-22-ev3dev-ev3 + kernel 4.14.80-ev3dev-2.3.1-ev3 ### WHAT IS IT? diff --git a/lib/mingw/libev3dev-c.a b/lib/mingw/libev3dev-c.a index f4b9dabb89ce6459a6f183d4ce0cda5b2abb0071..a37eb9009436d88dd2f5feaad94403bf0cd278cd 100644 GIT binary patch delta 5697 zcmc(jdvMg%702&gHcLoCHju|AM8XnMK*;+=9t6TuWPri|t+Y@RLV#6BVqA<*ek)l9 zGbwa2!HcaAw2Y+`r!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eD?7X$0ylivagB~hK`lc07c~iY{hn)ab{eVBgy2D4fmPsZXB?% z9E4>CmN;m>nDv9%ae&O8&^mhqEbk6B4pw;wy9B1qVM&O09qb_3257Oy8rEjoXBm~g zwPXuTK+atXl{a3X#KaQlQtVnHyWv`eRtZ)IW|=3;*HL^;8Ck6Mb)(kkHDlJuHE&wO z)||7NABf=7{~%m7>_!%kU1v>t!fMu6ejNNIKZl8*a2V_ZunhLaRgU%nm^nheyN(_S zO-GW~Mara7S{vF3eJN57PtY<;Dg64mA0>~#7BUTOmrE~Fyyae)>^MO*n~YpfW9}?$ zYC2e`C{t>WQawtYQ0lx=W^7irKK4GP)+<%7)PAMHX z^(l2ssdtsSs+1LJZH&!Q>S3k629?j7AZnr9>H5S^D7X*GVC{+>Qmj|85yhsIBGgd2 z9&d$Go0QtC)M2H5;a2jmN}2G+jW9V%Jq=~-(JP9*uGAltx}uZ?pJpSj9*UKo^eTyl4>>>%JXsA-9HY@eKQYVx;tJLq5%0O|Z=~z z)V-)$_{jV&z6WwKh#Uqfaij7Alkursf`&B-tR2??deuQbzXWMSrUph$fE)=TGa%zZB#NI8 zi5VD`0#Y6M;9QggbP@R(a4KPfWD1b4fmMuLei?@gJqa=&x zPE(@nFQ*47Lw;IL4f3!T-}%;!R6mdZW#r}YzYOOPRgvjQ{uh!b|IYoyF?w$)JLKmM J!C~*?{|4yevuFSS diff --git a/source/ev3/app.yu b/source/ev3/app.yu index 53d8516..5a9fbf1 100644 --- a/source/ev3/app.yu +++ b/source/ev3/app.yu @@ -8,10 +8,10 @@ ev3dev-c [ ) ($set VERSION ] -1.0c3 +2.0a1.dev1 [ ) ($set KERNEL ] -4.4.87-22-ev3dev-ev3 +4.14.80-ev3dev-2.3.1-ev3 [ ) ($set DESCRIPTION ] LEGO MINDSTORMS EV3 Debian C library + Python, Ruby and Perl wrappers diff --git a/source/ev3/ev3_port-dict.yu b/source/ev3/ev3_port-dict.yu index 83e2766..5755a70 100644 --- a/source/ev3/ev3_port-dict.yu +++ b/source/ev3/ev3_port-dict.yu @@ -7,19 +7,18 @@ ($set CLASS_PATH "/sys/class/lego-port") ($set CLASS_FOLDER_PREF "port") ($set CLASS_ID ($unq CLASS_FOLDER_PREF)) -($set CLASS_TITLE "EV3 port") +($set CLASS_TITLE "lego port") -($dict CLASS_TYPE - (` CLASS_TYPE_NAME CLASS_TYPE_ID_SHORT CLASS_TYPE_MODES ) - (` - ( "ht-nxt-smux-port" "ht_nxt_smux" ( "analog" "i2c" ) ) - ( "legoev3-input-port" "input" ( "auto" "nxt-analog" "nxt-color" "nxt-i2c" "other-i2c" "ev3-analog" "ev3-uart" "other-uart" "raw" ) ) - ( "legoev3-output-port" "output" ( "auto" "tacho-motor" "dc-motor" "led" "raw" ) ) - ( "ms-ev3-smux-port" "ms_ev3_smux" ( "uart" "analog" ) ) - ( "ms-nxtmmx-out-port" "ms_nxtmmx" ( "tacho-motor" ) ) - ( "wedo-port" "wedo" ( "auto" ) ) - ) +($import "grab/spec.py") + +($!dict CLASS_TYPE + (` CLASS_TYPE_NAME CLASS_TYPE_MODES ) ) +($import { grab_ports( 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/ports.json' ) }) + +($set _TYPE_TO_SHORT \val.($replace,,($replace,,($unq val),,-port,,),,-,,_)) +($set CLASS_TYPE_ID_SHORT ($each-CLASS_TYPE \i.($_TYPE_TO_SHORT ($i CLASS_TYPE_NAME)))) + ($set CLASS_TYPE_ATTR_INDEX ( "mode" )) ($set CLASS_ATTR_INDEX ()) ($set CLASS_ATTR_FLAGS ()) diff --git a/source/ev3/ev3_port.c b/source/ev3/ev3_port.c index 0bd983c..9904b9c 100644 --- a/source/ev3/ev3_port.c +++ b/source/ev3/ev3_port.c @@ -100,18 +100,30 @@ size_t get_port_status( uint8_t sn, char *buf, size_t sz ) const char *ev3_port_type( INX_T type_inx ) { switch ( type_inx ) { + case BRICKPI_OUT_PORT: + return "brickpi-out-port"; + case BRICKPI3_IN_PORT: + return "brickpi3-in-port"; case HT_NXT_SMUX_PORT: return "ht-nxt-smux-port"; - case LEGOEV3_INPUT_PORT: - return "legoev3-input-port"; - case LEGOEV3_OUTPUT_PORT: - return "legoev3-output-port"; + case EV3_OUTPUT_PORT: + return "ev3-output-port"; + case WEDO_PORT: + return "wedo-port"; + case EV3_INPUT_PORT: + return "ev3-input-port"; + case PISTORMS_OUT_PORT: + return "pistorms-out-port"; + case BRICKPI3_OUT_PORT: + return "brickpi3-out-port"; + case PISTORMS_IN_PORT: + return "pistorms-in-port"; + case BRICKPI_IN_PORT: + return "brickpi-in-port"; case MS_EV3_SMUX_PORT: return "ms-ev3-smux-port"; case MS_NXTMMX_OUT_PORT: return "ms-nxtmmx-out-port"; - case WEDO_PORT: - return "wedo-port"; } return ( STR_unknown_ ); @@ -123,12 +135,33 @@ INX_T get_port_type_inx( uint8_t sn ) if ( !get_port_driver_name( sn, buf, sizeof( buf ))) return ( PORT_TYPE__NONE_ ); - if ( strcmp( buf, "ht-nxt-smux-port" ) == 0 ) return HT_NXT_SMUX_PORT; - if ( strcmp( buf, "legoev3-input-port" ) == 0 ) return LEGOEV3_INPUT_PORT; - if ( strcmp( buf, "legoev3-output-port" ) == 0 ) return LEGOEV3_OUTPUT_PORT; - if ( strcmp( buf, "ms-ev3-smux-port" ) == 0 ) return MS_EV3_SMUX_PORT; - if ( strcmp( buf, "ms-nxtmmx-out-port" ) == 0 ) return MS_NXTMMX_OUT_PORT; - if ( strcmp( buf, "wedo-port" ) == 0 ) return WEDO_PORT; + switch ( crc32( 0, buf, strlen( buf ))) { + case 0xe830f5e7L: /* "brickpi-out-port" */ + return BRICKPI_OUT_PORT; + case 0xe5b97ed3L: /* "brickpi3-in-port" */ + return BRICKPI3_IN_PORT; + case 0xf239351bL: /* "ht-nxt-smux-port" */ + return HT_NXT_SMUX_PORT; + case 0x2fdeaddeL: /* "ev3-output-port" */ + return EV3_OUTPUT_PORT; + case 0x371fa871L: /* "wedo-port" */ + return WEDO_PORT; + case 0x8d0f20dcL: /* "ev3-input-port" */ + return EV3_INPUT_PORT; + case 0xc55dcb65L: /* "pistorms-out-port" */ + return PISTORMS_OUT_PORT; + case 0x983f2322L: /* "brickpi3-out-port" */ + return BRICKPI3_OUT_PORT; + case 0xef4a3b29L: /* "pistorms-in-port" */ + return PISTORMS_IN_PORT; + case 0x809b34d6L: /* "brickpi-in-port" */ + return BRICKPI_IN_PORT; + case 0xe2ea87c6L: /* "ms-ev3-smux-port" */ + return MS_EV3_SMUX_PORT; + case 0x9127ffbaL: /* "ms-nxtmmx-out-port" */ + return MS_NXTMMX_OUT_PORT; + + } return ( PORT_TYPE__UNKNOWN_ ); } @@ -220,40 +253,99 @@ bool ev3_search_port_plugged_in( uint8_t port, uint8_t extport, uint8_t *sn, uin const char *ev3_port_mode( INX_T mode_inx ) { switch ( mode_inx ) { + case BRICKPI_OUT_PORT_TACHO_MOTOR: + return "tacho-motor"; + case BRICKPI_OUT_PORT_DC_MOTOR: + return "dc-motor"; + case BRICKPI_OUT_PORT_LED: + return "led"; + + case BRICKPI3_IN_PORT_NONE: + return "none"; + case BRICKPI3_IN_PORT_NXT_ANALOG: + return "nxt-analog"; + case BRICKPI3_IN_PORT_NXT_COLOR: + return "nxt-color"; + case BRICKPI3_IN_PORT_NXT_I2C: + return "nxt-i2c"; + case BRICKPI3_IN_PORT_EV3_ANALOG: + return "ev3-analog"; + case BRICKPI3_IN_PORT_EV3_UART: + return "ev3-uart"; + case HT_NXT_SMUX_PORT_ANALOG: return "analog"; case HT_NXT_SMUX_PORT_I2C: return "i2c"; - case LEGOEV3_INPUT_PORT_AUTO: + case EV3_OUTPUT_PORT_AUTO: + return "auto"; + case EV3_OUTPUT_PORT_TACHO_MOTOR: + return "tacho-motor"; + case EV3_OUTPUT_PORT_DC_MOTOR: + return "dc-motor"; + case EV3_OUTPUT_PORT_LED: + return "led"; + case EV3_OUTPUT_PORT_RAW: + return "raw"; + + case WEDO_PORT_AUTO: return "auto"; - case LEGOEV3_INPUT_PORT_NXT_ANALOG: + + case EV3_INPUT_PORT_AUTO: + return "auto"; + case EV3_INPUT_PORT_NXT_ANALOG: return "nxt-analog"; - case LEGOEV3_INPUT_PORT_NXT_COLOR: + case EV3_INPUT_PORT_NXT_COLOR: return "nxt-color"; - case LEGOEV3_INPUT_PORT_NXT_I2C: + case EV3_INPUT_PORT_NXT_I2C: return "nxt-i2c"; - case LEGOEV3_INPUT_PORT_OTHER_I2C: + case EV3_INPUT_PORT_OTHER_I2C: return "other-i2c"; - case LEGOEV3_INPUT_PORT_EV3_ANALOG: + case EV3_INPUT_PORT_EV3_ANALOG: return "ev3-analog"; - case LEGOEV3_INPUT_PORT_EV3_UART: + case EV3_INPUT_PORT_EV3_UART: return "ev3-uart"; - case LEGOEV3_INPUT_PORT_OTHER_UART: + case EV3_INPUT_PORT_OTHER_UART: return "other-uart"; - case LEGOEV3_INPUT_PORT_RAW: + case EV3_INPUT_PORT_RAW: return "raw"; - case LEGOEV3_OUTPUT_PORT_AUTO: - return "auto"; - case LEGOEV3_OUTPUT_PORT_TACHO_MOTOR: + case PISTORMS_OUT_PORT_TACHO_MOTOR: + return "tacho-motor"; + + case BRICKPI3_OUT_PORT_TACHO_MOTOR: return "tacho-motor"; - case LEGOEV3_OUTPUT_PORT_DC_MOTOR: + case BRICKPI3_OUT_PORT_DC_MOTOR: return "dc-motor"; - case LEGOEV3_OUTPUT_PORT_LED: + case BRICKPI3_OUT_PORT_LED: return "led"; - case LEGOEV3_OUTPUT_PORT_RAW: - return "raw"; + + case PISTORMS_IN_PORT_NONE: + return "none"; + case PISTORMS_IN_PORT_NXT_ANALOG: + return "nxt-analog"; + case PISTORMS_IN_PORT_NXT_COLOR: + return "nxt-color"; + case PISTORMS_IN_PORT_I2C_THRU: + return "i2c-thru"; + case PISTORMS_IN_PORT_EV3_ANALOG: + return "ev3-analog"; + case PISTORMS_IN_PORT_EV3_UART: + return "ev3-uart"; + + case BRICKPI_IN_PORT_NONE: + return "none"; + case BRICKPI_IN_PORT_NXT_ANALOG: + return "nxt-analog"; + case BRICKPI_IN_PORT_NXT_COLOR: + return "nxt-color"; + case BRICKPI_IN_PORT_NXT_I2C: + return "nxt-i2c"; + case BRICKPI_IN_PORT_EV3_ANALOG: + return "ev3-analog"; + case BRICKPI_IN_PORT_EV3_UART: + return "ev3-uart"; case MS_EV3_SMUX_PORT_UART: return "uart"; @@ -263,9 +355,6 @@ const char *ev3_port_mode( INX_T mode_inx ) case MS_NXTMMX_OUT_PORT_TACHO_MOTOR: return "tacho-motor"; - case WEDO_PORT_AUTO: - return "auto"; - } return ( STR_unknown_ ); } @@ -278,31 +367,85 @@ INX_T get_port_mode_inx_of_type( uint8_t sn, INX_T type_inx ) switch ( type_inx ) { + case BRICKPI_OUT_PORT: + if ( strcmp( buf, "tacho-motor" ) == 0 ) return BRICKPI_OUT_PORT_TACHO_MOTOR; + if ( strcmp( buf, "dc-motor" ) == 0 ) return BRICKPI_OUT_PORT_DC_MOTOR; + if ( strcmp( buf, "led" ) == 0 ) return BRICKPI_OUT_PORT_LED; + + break; + + case BRICKPI3_IN_PORT: + if ( strcmp( buf, "none" ) == 0 ) return BRICKPI3_IN_PORT_NONE; + if ( strcmp( buf, "nxt-analog" ) == 0 ) return BRICKPI3_IN_PORT_NXT_ANALOG; + if ( strcmp( buf, "nxt-color" ) == 0 ) return BRICKPI3_IN_PORT_NXT_COLOR; + if ( strcmp( buf, "nxt-i2c" ) == 0 ) return BRICKPI3_IN_PORT_NXT_I2C; + if ( strcmp( buf, "ev3-analog" ) == 0 ) return BRICKPI3_IN_PORT_EV3_ANALOG; + if ( strcmp( buf, "ev3-uart" ) == 0 ) return BRICKPI3_IN_PORT_EV3_UART; + + break; + case HT_NXT_SMUX_PORT: if ( strcmp( buf, "analog" ) == 0 ) return HT_NXT_SMUX_PORT_ANALOG; if ( strcmp( buf, "i2c" ) == 0 ) return HT_NXT_SMUX_PORT_I2C; break; - case LEGOEV3_INPUT_PORT: - if ( strcmp( buf, "auto" ) == 0 ) return LEGOEV3_INPUT_PORT_AUTO; - if ( strcmp( buf, "nxt-analog" ) == 0 ) return LEGOEV3_INPUT_PORT_NXT_ANALOG; - if ( strcmp( buf, "nxt-color" ) == 0 ) return LEGOEV3_INPUT_PORT_NXT_COLOR; - if ( strcmp( buf, "nxt-i2c" ) == 0 ) return LEGOEV3_INPUT_PORT_NXT_I2C; - if ( strcmp( buf, "other-i2c" ) == 0 ) return LEGOEV3_INPUT_PORT_OTHER_I2C; - if ( strcmp( buf, "ev3-analog" ) == 0 ) return LEGOEV3_INPUT_PORT_EV3_ANALOG; - if ( strcmp( buf, "ev3-uart" ) == 0 ) return LEGOEV3_INPUT_PORT_EV3_UART; - if ( strcmp( buf, "other-uart" ) == 0 ) return LEGOEV3_INPUT_PORT_OTHER_UART; - if ( strcmp( buf, "raw" ) == 0 ) return LEGOEV3_INPUT_PORT_RAW; + case EV3_OUTPUT_PORT: + if ( strcmp( buf, "auto" ) == 0 ) return EV3_OUTPUT_PORT_AUTO; + if ( strcmp( buf, "tacho-motor" ) == 0 ) return EV3_OUTPUT_PORT_TACHO_MOTOR; + if ( strcmp( buf, "dc-motor" ) == 0 ) return EV3_OUTPUT_PORT_DC_MOTOR; + if ( strcmp( buf, "led" ) == 0 ) return EV3_OUTPUT_PORT_LED; + if ( strcmp( buf, "raw" ) == 0 ) return EV3_OUTPUT_PORT_RAW; + + break; + + case WEDO_PORT: + if ( strcmp( buf, "auto" ) == 0 ) return WEDO_PORT_AUTO; break; - case LEGOEV3_OUTPUT_PORT: - if ( strcmp( buf, "auto" ) == 0 ) return LEGOEV3_OUTPUT_PORT_AUTO; - if ( strcmp( buf, "tacho-motor" ) == 0 ) return LEGOEV3_OUTPUT_PORT_TACHO_MOTOR; - if ( strcmp( buf, "dc-motor" ) == 0 ) return LEGOEV3_OUTPUT_PORT_DC_MOTOR; - if ( strcmp( buf, "led" ) == 0 ) return LEGOEV3_OUTPUT_PORT_LED; - if ( strcmp( buf, "raw" ) == 0 ) return LEGOEV3_OUTPUT_PORT_RAW; + case EV3_INPUT_PORT: + if ( strcmp( buf, "auto" ) == 0 ) return EV3_INPUT_PORT_AUTO; + if ( strcmp( buf, "nxt-analog" ) == 0 ) return EV3_INPUT_PORT_NXT_ANALOG; + if ( strcmp( buf, "nxt-color" ) == 0 ) return EV3_INPUT_PORT_NXT_COLOR; + if ( strcmp( buf, "nxt-i2c" ) == 0 ) return EV3_INPUT_PORT_NXT_I2C; + if ( strcmp( buf, "other-i2c" ) == 0 ) return EV3_INPUT_PORT_OTHER_I2C; + if ( strcmp( buf, "ev3-analog" ) == 0 ) return EV3_INPUT_PORT_EV3_ANALOG; + if ( strcmp( buf, "ev3-uart" ) == 0 ) return EV3_INPUT_PORT_EV3_UART; + if ( strcmp( buf, "other-uart" ) == 0 ) return EV3_INPUT_PORT_OTHER_UART; + if ( strcmp( buf, "raw" ) == 0 ) return EV3_INPUT_PORT_RAW; + + break; + + case PISTORMS_OUT_PORT: + if ( strcmp( buf, "tacho-motor" ) == 0 ) return PISTORMS_OUT_PORT_TACHO_MOTOR; + + break; + + case BRICKPI3_OUT_PORT: + if ( strcmp( buf, "tacho-motor" ) == 0 ) return BRICKPI3_OUT_PORT_TACHO_MOTOR; + if ( strcmp( buf, "dc-motor" ) == 0 ) return BRICKPI3_OUT_PORT_DC_MOTOR; + if ( strcmp( buf, "led" ) == 0 ) return BRICKPI3_OUT_PORT_LED; + + break; + + case PISTORMS_IN_PORT: + if ( strcmp( buf, "none" ) == 0 ) return PISTORMS_IN_PORT_NONE; + if ( strcmp( buf, "nxt-analog" ) == 0 ) return PISTORMS_IN_PORT_NXT_ANALOG; + if ( strcmp( buf, "nxt-color" ) == 0 ) return PISTORMS_IN_PORT_NXT_COLOR; + if ( strcmp( buf, "i2c-thru" ) == 0 ) return PISTORMS_IN_PORT_I2C_THRU; + if ( strcmp( buf, "ev3-analog" ) == 0 ) return PISTORMS_IN_PORT_EV3_ANALOG; + if ( strcmp( buf, "ev3-uart" ) == 0 ) return PISTORMS_IN_PORT_EV3_UART; + + break; + + case BRICKPI_IN_PORT: + if ( strcmp( buf, "none" ) == 0 ) return BRICKPI_IN_PORT_NONE; + if ( strcmp( buf, "nxt-analog" ) == 0 ) return BRICKPI_IN_PORT_NXT_ANALOG; + if ( strcmp( buf, "nxt-color" ) == 0 ) return BRICKPI_IN_PORT_NXT_COLOR; + if ( strcmp( buf, "nxt-i2c" ) == 0 ) return BRICKPI_IN_PORT_NXT_I2C; + if ( strcmp( buf, "ev3-analog" ) == 0 ) return BRICKPI_IN_PORT_EV3_ANALOG; + if ( strcmp( buf, "ev3-uart" ) == 0 ) return BRICKPI_IN_PORT_EV3_UART; break; @@ -317,11 +460,6 @@ INX_T get_port_mode_inx_of_type( uint8_t sn, INX_T type_inx ) break; - case WEDO_PORT: - if ( strcmp( buf, "auto" ) == 0 ) return WEDO_PORT_AUTO; - - break; - } return ( PORT_MODE__UNKNOWN_ ); } diff --git a/source/ev3/ev3_port.h b/source/ev3/ev3_port.h index d6b90ec..0c245ed 100644 --- a/source/ev3/ev3_port.h +++ b/source/ev3/ev3_port.h @@ -51,77 +51,108 @@ extern "C" { #endif -#define PORT_DIR "/sys/class/lego-port" /**< Directory of EV3 ports. */ +#define PORT_DIR "/sys/class/lego-port" /**< Directory of lego ports. */ /** - * \brief Structure of a EV3 port descriptor. + * \brief Structure of a lego port descriptor. */ typedef struct { - INX_T type_inx; /**< EV3 port type. */ - uint8_t port; /**< EV3 port EV3 port. */ - uint8_t extport; /**< EV3 port extended port. */ - uint8_t addr; /**< EV3 port I2C address. */ + INX_T type_inx; /**< Lego port type. */ + uint8_t port; /**< Lego port EV3 port. */ + uint8_t extport; /**< Lego port extended port. */ + uint8_t addr; /**< Lego port I2C address. */ } EV3_PORT; -#define PORT_DESC__LIMIT_ DESC_LIMIT /**< Limit of EV3 port descriptors. */ +#define PORT_DESC__LIMIT_ DESC_LIMIT /**< Limit of lego port descriptors. */ -#define PORT__NONE_ PORT_DESC__LIMIT_ /**< EV3 port is not found. */ +#define PORT__NONE_ PORT_DESC__LIMIT_ /**< Lego port is not found. */ /** - * \brief Vector of EV3 port descriptors (filled by \ref ev3_port_init). + * \brief Vector of lego port descriptors (filled by \ref ev3_port_init). */ EV3_PORT_VAR( EV3_PORT ev3_port[ PORT_DESC__LIMIT_ ] ); /** - * \brief Identifiers of EV3 port types. + * \brief Identifiers of lego port types. */ enum { PORT_TYPE__NONE_ = 0, /* XXX: memset( 0 ) is used */ + BRICKPI_OUT_PORT, + BRICKPI3_IN_PORT, HT_NXT_SMUX_PORT, - LEGOEV3_INPUT_PORT, - LEGOEV3_OUTPUT_PORT, + EV3_OUTPUT_PORT, + WEDO_PORT, + EV3_INPUT_PORT, + PISTORMS_OUT_PORT, + BRICKPI3_OUT_PORT, + PISTORMS_IN_PORT, + BRICKPI_IN_PORT, MS_EV3_SMUX_PORT, MS_NXTMMX_OUT_PORT, - WEDO_PORT, - PORT_TYPE__COUNT_, /**< Count of EV3 port types. */ + PORT_TYPE__COUNT_, /**< Count of lego port types. */ PORT_TYPE__UNKNOWN_ = PORT_TYPE__COUNT_ }; /** - * \brief Identifiers of EV3 port "mode" attribute. + * \brief Identifiers of lego port "mode" attribute. */ enum { PORT_MODE__NONE_ = 0, + BRICKPI_OUT_PORT_TACHO_MOTOR, BRICKPI_OUT_TACHO_MOTOR = BRICKPI_OUT_PORT_TACHO_MOTOR, + BRICKPI_OUT_PORT_DC_MOTOR, BRICKPI_OUT_DC_MOTOR = BRICKPI_OUT_PORT_DC_MOTOR, + BRICKPI_OUT_PORT_LED, BRICKPI_OUT_LED = BRICKPI_OUT_PORT_LED, + BRICKPI3_IN_PORT_NONE, BRICKPI3_IN_NONE = BRICKPI3_IN_PORT_NONE, + BRICKPI3_IN_PORT_NXT_ANALOG, BRICKPI3_IN_NXT_ANALOG = BRICKPI3_IN_PORT_NXT_ANALOG, + BRICKPI3_IN_PORT_NXT_COLOR, BRICKPI3_IN_NXT_COLOR = BRICKPI3_IN_PORT_NXT_COLOR, + BRICKPI3_IN_PORT_NXT_I2C, BRICKPI3_IN_NXT_I2C = BRICKPI3_IN_PORT_NXT_I2C, + BRICKPI3_IN_PORT_EV3_ANALOG, BRICKPI3_IN_EV3_ANALOG = BRICKPI3_IN_PORT_EV3_ANALOG, + BRICKPI3_IN_PORT_EV3_UART, BRICKPI3_IN_EV3_UART = BRICKPI3_IN_PORT_EV3_UART, HT_NXT_SMUX_PORT_ANALOG, HT_NXT_SMUX_ANALOG = HT_NXT_SMUX_PORT_ANALOG, HT_NXT_SMUX_PORT_I2C, HT_NXT_SMUX_I2C = HT_NXT_SMUX_PORT_I2C, - LEGOEV3_INPUT_PORT_AUTO, INPUT_AUTO = LEGOEV3_INPUT_PORT_AUTO, - LEGOEV3_INPUT_PORT_NXT_ANALOG, INPUT_NXT_ANALOG = LEGOEV3_INPUT_PORT_NXT_ANALOG, - LEGOEV3_INPUT_PORT_NXT_COLOR, INPUT_NXT_COLOR = LEGOEV3_INPUT_PORT_NXT_COLOR, - LEGOEV3_INPUT_PORT_NXT_I2C, INPUT_NXT_I2C = LEGOEV3_INPUT_PORT_NXT_I2C, - LEGOEV3_INPUT_PORT_OTHER_I2C, INPUT_OTHER_I2C = LEGOEV3_INPUT_PORT_OTHER_I2C, - LEGOEV3_INPUT_PORT_EV3_ANALOG, INPUT_EV3_ANALOG = LEGOEV3_INPUT_PORT_EV3_ANALOG, - LEGOEV3_INPUT_PORT_EV3_UART, INPUT_EV3_UART = LEGOEV3_INPUT_PORT_EV3_UART, - LEGOEV3_INPUT_PORT_OTHER_UART, INPUT_OTHER_UART = LEGOEV3_INPUT_PORT_OTHER_UART, - LEGOEV3_INPUT_PORT_RAW, INPUT_RAW = LEGOEV3_INPUT_PORT_RAW, - LEGOEV3_OUTPUT_PORT_AUTO, OUTPUT_AUTO = LEGOEV3_OUTPUT_PORT_AUTO, - LEGOEV3_OUTPUT_PORT_TACHO_MOTOR, OUTPUT_TACHO_MOTOR = LEGOEV3_OUTPUT_PORT_TACHO_MOTOR, - LEGOEV3_OUTPUT_PORT_DC_MOTOR, OUTPUT_DC_MOTOR = LEGOEV3_OUTPUT_PORT_DC_MOTOR, - LEGOEV3_OUTPUT_PORT_LED, OUTPUT_LED = LEGOEV3_OUTPUT_PORT_LED, - LEGOEV3_OUTPUT_PORT_RAW, OUTPUT_RAW = LEGOEV3_OUTPUT_PORT_RAW, + EV3_OUTPUT_PORT_AUTO, EV3_OUTPUT_AUTO = EV3_OUTPUT_PORT_AUTO, + EV3_OUTPUT_PORT_TACHO_MOTOR, EV3_OUTPUT_TACHO_MOTOR = EV3_OUTPUT_PORT_TACHO_MOTOR, + EV3_OUTPUT_PORT_DC_MOTOR, EV3_OUTPUT_DC_MOTOR = EV3_OUTPUT_PORT_DC_MOTOR, + EV3_OUTPUT_PORT_LED, EV3_OUTPUT_LED = EV3_OUTPUT_PORT_LED, + EV3_OUTPUT_PORT_RAW, EV3_OUTPUT_RAW = EV3_OUTPUT_PORT_RAW, + WEDO_PORT_AUTO, WEDO_AUTO = WEDO_PORT_AUTO, + EV3_INPUT_PORT_AUTO, EV3_INPUT_AUTO = EV3_INPUT_PORT_AUTO, + EV3_INPUT_PORT_NXT_ANALOG, EV3_INPUT_NXT_ANALOG = EV3_INPUT_PORT_NXT_ANALOG, + EV3_INPUT_PORT_NXT_COLOR, EV3_INPUT_NXT_COLOR = EV3_INPUT_PORT_NXT_COLOR, + EV3_INPUT_PORT_NXT_I2C, EV3_INPUT_NXT_I2C = EV3_INPUT_PORT_NXT_I2C, + EV3_INPUT_PORT_OTHER_I2C, EV3_INPUT_OTHER_I2C = EV3_INPUT_PORT_OTHER_I2C, + EV3_INPUT_PORT_EV3_ANALOG, EV3_INPUT_EV3_ANALOG = EV3_INPUT_PORT_EV3_ANALOG, + EV3_INPUT_PORT_EV3_UART, EV3_INPUT_EV3_UART = EV3_INPUT_PORT_EV3_UART, + EV3_INPUT_PORT_OTHER_UART, EV3_INPUT_OTHER_UART = EV3_INPUT_PORT_OTHER_UART, + EV3_INPUT_PORT_RAW, EV3_INPUT_RAW = EV3_INPUT_PORT_RAW, + PISTORMS_OUT_PORT_TACHO_MOTOR, PISTORMS_OUT_TACHO_MOTOR = PISTORMS_OUT_PORT_TACHO_MOTOR, + BRICKPI3_OUT_PORT_TACHO_MOTOR, BRICKPI3_OUT_TACHO_MOTOR = BRICKPI3_OUT_PORT_TACHO_MOTOR, + BRICKPI3_OUT_PORT_DC_MOTOR, BRICKPI3_OUT_DC_MOTOR = BRICKPI3_OUT_PORT_DC_MOTOR, + BRICKPI3_OUT_PORT_LED, BRICKPI3_OUT_LED = BRICKPI3_OUT_PORT_LED, + PISTORMS_IN_PORT_NONE, PISTORMS_IN_NONE = PISTORMS_IN_PORT_NONE, + PISTORMS_IN_PORT_NXT_ANALOG, PISTORMS_IN_NXT_ANALOG = PISTORMS_IN_PORT_NXT_ANALOG, + PISTORMS_IN_PORT_NXT_COLOR, PISTORMS_IN_NXT_COLOR = PISTORMS_IN_PORT_NXT_COLOR, + PISTORMS_IN_PORT_I2C_THRU, PISTORMS_IN_I2C_THRU = PISTORMS_IN_PORT_I2C_THRU, + PISTORMS_IN_PORT_EV3_ANALOG, PISTORMS_IN_EV3_ANALOG = PISTORMS_IN_PORT_EV3_ANALOG, + PISTORMS_IN_PORT_EV3_UART, PISTORMS_IN_EV3_UART = PISTORMS_IN_PORT_EV3_UART, + BRICKPI_IN_PORT_NONE, BRICKPI_IN_NONE = BRICKPI_IN_PORT_NONE, + BRICKPI_IN_PORT_NXT_ANALOG, BRICKPI_IN_NXT_ANALOG = BRICKPI_IN_PORT_NXT_ANALOG, + BRICKPI_IN_PORT_NXT_COLOR, BRICKPI_IN_NXT_COLOR = BRICKPI_IN_PORT_NXT_COLOR, + BRICKPI_IN_PORT_NXT_I2C, BRICKPI_IN_NXT_I2C = BRICKPI_IN_PORT_NXT_I2C, + BRICKPI_IN_PORT_EV3_ANALOG, BRICKPI_IN_EV3_ANALOG = BRICKPI_IN_PORT_EV3_ANALOG, + BRICKPI_IN_PORT_EV3_UART, BRICKPI_IN_EV3_UART = BRICKPI_IN_PORT_EV3_UART, MS_EV3_SMUX_PORT_UART, MS_EV3_SMUX_UART = MS_EV3_SMUX_PORT_UART, MS_EV3_SMUX_PORT_ANALOG, MS_EV3_SMUX_ANALOG = MS_EV3_SMUX_PORT_ANALOG, - MS_NXTMMX_OUT_PORT_TACHO_MOTOR, MS_NXTMMX_TACHO_MOTOR = MS_NXTMMX_OUT_PORT_TACHO_MOTOR, - WEDO_PORT_AUTO, WEDO_AUTO = WEDO_PORT_AUTO, - PORT_MODE__COUNT_, /**< Count of EV3 port "mode" attribute. */ + MS_NXTMMX_OUT_PORT_TACHO_MOTOR, MS_NXTMMX_OUT_TACHO_MOTOR = MS_NXTMMX_OUT_PORT_TACHO_MOTOR, + PORT_MODE__COUNT_, /**< Count of lego port "mode" attribute. */ PORT_MODE__UNKNOWN_ = PORT_MODE__COUNT_ }; /** - * \brief Read "address" attribute of the EV3 port. + * \brief Read "address" attribute of the lego port. * \param sn Sequence number. * \param[out] buf Buffer for result. * \param sz Buffer size. @@ -130,7 +161,7 @@ enum { extern size_t get_port_address( uint8_t sn, char *buf, size_t sz ); /** - * \brief Read "driver_name" attribute of the EV3 port. + * \brief Read "driver_name" attribute of the lego port. * \param sn Sequence number. * \param[out] buf Buffer for result. * \param sz Buffer size. @@ -139,7 +170,7 @@ extern size_t get_port_address( uint8_t sn, char *buf, size_t sz ); extern size_t get_port_driver_name( uint8_t sn, char *buf, size_t sz ); /** - * \brief Read "mode" attribute of the EV3 port. + * \brief Read "mode" attribute of the lego port. * \param sn Sequence number. * \param[out] buf Buffer for result. * \param sz Buffer size. @@ -148,7 +179,7 @@ extern size_t get_port_driver_name( uint8_t sn, char *buf, size_t sz ); extern size_t get_port_mode( uint8_t sn, char *buf, size_t sz ); /** - * \brief Write "mode" attribute of the EV3 port. + * \brief Write "mode" attribute of the lego port. * \param sn Sequence number. * \param value Attribute value. @@ -157,7 +188,7 @@ extern size_t get_port_mode( uint8_t sn, char *buf, size_t sz ); extern size_t set_port_mode( uint8_t sn, char *value ); /** - * \brief Write "mode" attribute of several EV3 ports. + * \brief Write "mode" attribute of several lego ports. * \param sn Vector of sequence numbers ending with DESC_LIMIT. * \param value Attribute value. @@ -166,7 +197,7 @@ extern size_t set_port_mode( uint8_t sn, char *value ); extern size_t multi_set_port_mode( uint8_t *sn, char *value ); /** - * \brief Read "modes" attribute of the EV3 port. + * \brief Read "modes" attribute of the lego port. * \param sn Sequence number. * \param[out] buf Buffer for result. * \param sz Buffer size. @@ -175,7 +206,7 @@ extern size_t multi_set_port_mode( uint8_t *sn, char *value ); extern size_t get_port_modes( uint8_t sn, char *buf, size_t sz ); /** - * \brief Write "set_device" attribute of the EV3 port. + * \brief Write "set_device" attribute of the lego port. * \param sn Sequence number. * \param value Attribute value. @@ -184,7 +215,7 @@ extern size_t get_port_modes( uint8_t sn, char *buf, size_t sz ); extern size_t set_port_set_device( uint8_t sn, char *value ); /** - * \brief Write "set_device" attribute of several EV3 ports. + * \brief Write "set_device" attribute of several lego ports. * \param sn Vector of sequence numbers ending with DESC_LIMIT. * \param value Attribute value. @@ -193,7 +224,7 @@ extern size_t set_port_set_device( uint8_t sn, char *value ); extern size_t multi_set_port_set_device( uint8_t *sn, char *value ); /** - * \brief Read "status" attribute of the EV3 port. + * \brief Read "status" attribute of the lego port. * \param sn Sequence number. * \param[out] buf Buffer for result. * \param sz Buffer size. @@ -202,21 +233,21 @@ extern size_t multi_set_port_set_device( uint8_t *sn, char *value ); extern size_t get_port_status( uint8_t sn, char *buf, size_t sz ); /** - * \brief Get name of the specified EV3 port type. - * \param type_inx Index of the EV3 port type. + * \brief Get name of the specified lego port type. + * \param type_inx Index of the lego port type. * \return Requested value. */ extern const char *ev3_port_type( INX_T type_inx ); /** - * \brief Read "driver_name" attribute and get index of the EV3 port type. + * \brief Read "driver_name" attribute and get index of the lego port type. * \param sn Sequence number. * \return Requested value. */ extern INX_T get_port_type_inx( uint8_t sn ); /** - * \brief Read EV3 port attributes that are required for filling the descriptor. + * \brief Read lego port attributes that are required for filling the descriptor. * \param sn Sequence number. * \param desc Buffer for the descriptor. * \return Count of read bytes. @@ -224,42 +255,42 @@ extern INX_T get_port_type_inx( uint8_t sn ); extern size_t get_port_desc( uint8_t sn, EV3_PORT *desc ); /** - * \brief Get descriptor of the EV3 port. + * \brief Get descriptor of the lego port. * \param sn Sequence number. - * \return Pointer to the EV3 port descriptor. + * \return Pointer to the lego port descriptor. */ extern EV3_PORT *ev3_port_desc( uint8_t sn ); /** - * \brief Get type from the EV3 port descriptor. + * \brief Get type from the lego port descriptor. * \param sn Sequence number. * \return Requested value. */ extern INX_T ev3_port_desc_type_inx( uint8_t sn ); /** - * \brief Get EV3 port from the EV3 port descriptor. + * \brief Get EV3 port from the lego port descriptor. * \param sn Sequence number. * \return Requested value. */ extern uint8_t ev3_port_desc_port( uint8_t sn ); /** - * \brief Get extended port from the EV3 port descriptor. + * \brief Get extended port from the lego port descriptor. * \param sn Sequence number. * \return Requested value. */ extern uint8_t ev3_port_desc_extport( uint8_t sn ); /** - * \brief Get I2C address from the EV3 port descriptor. + * \brief Get I2C address from the lego port descriptor. * \param sn Sequence number. * \return Requested value. */ extern uint8_t ev3_port_desc_addr( uint8_t sn ); /** - * \brief Assemble EV3 port name from the EV3 port descriptor. + * \brief Assemble EV3 port name from the lego port descriptor. * \param sn Sequence number. * \param[out] buf Buffer for result. * \return Requested value. @@ -267,67 +298,67 @@ extern uint8_t ev3_port_desc_addr( uint8_t sn ); extern char *ev3_port_port_name( uint8_t sn, char *buf ); /** - * \brief Search of a sequence number of the specified EV3 port type. - * \param type_inx EV3 port type. + * \brief Search of a sequence number of the specified lego port type. + * \param type_inx Lego port type. * \param[out] sn Buffer for the sequence number. * \param from Search initial value. - * \return Flag - the EV3 port is found. + * \return Flag - the lego port is found. */ extern bool ev3_search_port_type( INX_T type_inx, uint8_t *sn, uint8_t from ); /** - * \brief Search of a sequence number the EV3 port by plug-in attributes. + * \brief Search of a sequence number the lego port by plug-in attributes. * \param port EV3 port. * \param extport Extended port. * \param[out] sn Buffer for the sequence number. * \param from Search initial value. - * \return Flag - the EV3 port is found. + * \return Flag - the lego port is found. */ extern bool ev3_search_port_plugged_in( uint8_t port, uint8_t extport, uint8_t *sn, uint8_t from ); /** - * \brief Get name of the specified EV3 port mode. - * \param mode_inx Index of the EV3 port mode. + * \brief Get name of the specified lego port mode. + * \param mode_inx Index of the lego port mode. * \return Requested value. */ extern const char *ev3_port_mode( INX_T mode_inx ); /** - * \brief Read "mode" attribute of the specified EV3 port type and get the index. + * \brief Read "mode" attribute of the specified lego port type and get the index. * \param sn Sequence number. - * \param type_inx Index of the EV3 port type. + * \param type_inx Index of the lego port type. * \return Requested value. */ extern INX_T get_port_mode_inx_of_type( uint8_t sn, INX_T type_inx ); /** - * \brief Read "mode" attribute of the EV3 port and get the index. + * \brief Read "mode" attribute of the lego port and get the index. * \param sn Sequence number. * \return Requested value. * - * This function gets type of the EV3 port from the descriptor. + * This function gets type of the lego port from the descriptor. */ extern INX_T get_port_mode_inx( uint8_t sn ); /** - * \brief Write "mode" attribute of the EV3 port by the index. + * \brief Write "mode" attribute of the lego port by the index. * \param sn Sequence number. - * \param mode_inx Index of the EV3 port mode. + * \param mode_inx Index of the lego port mode. * \return Count of written bytes. */ extern size_t set_port_mode_inx( uint8_t sn, INX_T mode_inx ); /** - * \brief Write "mode" attribute of several EV3 ports by the index. + * \brief Write "mode" attribute of several lego ports by the index. * \param sn Vector of sequence numbers ending with DESC_LIMIT. - * \param mode_inx Index of the EV3 port mode. + * \param mode_inx Index of the lego port mode. * \return Count of written bytes. */ extern size_t multi_set_port_mode_inx( uint8_t *sn, INX_T mode_inx ); /** - * \brief Detect connected EV3 ports. - * \return Number of found EV3 ports or -1 in case of an error. + * \brief Detect connected lego ports. + * \return Number of found lego ports or -1 in case of an error. */ extern int ev3_port_init( void ); diff --git a/source/ev3/ev3_sensor-dict.yu b/source/ev3/ev3_sensor-dict.yu index a1e274e..b8dc334 100644 --- a/source/ev3/ev3_sensor-dict.yu +++ b/source/ev3/ev3_sensor-dict.yu @@ -9,12 +9,12 @@ ($set CLASS_ID ($unq CLASS_FOLDER_PREF)) ($set CLASS_TITLE "sensor") -($import "grab/sensors.py") +($import "grab/spec.py") ($!dict CLASS_TYPE (` CLASS_TYPE_NAME CLASS_TYPE_MODES CLASS_TYPE_COMMANDS ) ) -($import { grab_sensors( 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-jessie/sensors.json' ) }) +($import { grab_sensors( 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.json' ) }) ($set CLASS_TYPE_ID_SHORT_FOR ( "lego_ev3_us" "lego_ev3_gyro" "lego_ev3_color" "lego_ev3_touch" "lego_ev3_ir" )) ($set CLASS_TYPE_ID_SHORT ( "us" "gyro" "color" "touch" "ir" )) diff --git a/source/ev3/grab/ports.yu b/source/ev3/grab/ports.yu new file mode 100644 index 0000000..d4df381 --- /dev/null +++ b/source/ev3/grab/ports.yu @@ -0,0 +1,17 @@ +($dict CLASS_TYPE +(`CLASS_TYPE_NAME CLASS_TYPE_MODES) +(` +("brickpi-out-port" ("tacho-motor" "dc-motor" "led")) +("brickpi3-in-port" ("none" "nxt-analog" "nxt-color" "nxt-i2c" "ev3-analog" "ev3-uart")) +("ht-nxt-smux-port" ("analog" "i2c")) +("ev3-output-port" ("auto" "tacho-motor" "dc-motor" "led" "raw")) +("wedo-port" ("auto")) +("ev3-input-port" ("auto" "nxt-analog" "nxt-color" "nxt-i2c" "other-i2c" "ev3-analog" "ev3-uart" "other-uart" "raw")) +("pistorms-out-port" ("tacho-motor")) +("brickpi3-out-port" ("tacho-motor" "dc-motor" "led")) +("pistorms-in-port" ("none" "nxt-analog" "nxt-color" "i2c-thru" "ev3-analog" "ev3-uart")) +("brickpi-in-port" ("none" "nxt-analog" "nxt-color" "nxt-i2c" "ev3-analog" "ev3-uart")) +("ms-ev3-smux-port" ("uart" "analog")) +("ms-nxtmmx-out-port" ("tacho-motor")) +) +) \ No newline at end of file diff --git a/source/ev3/grab/sensors.py b/source/ev3/grab/sensors.py deleted file mode 100644 index 917c7e0..0000000 --- a/source/ev3/grab/sensors.py +++ /dev/null @@ -1,84 +0,0 @@ -# -*- coding: utf-8 -*- - -# ____ __ ____ ___ ____ __ (((((() -# | |_ \ \ / ) ) | | ) | |_ \ \ / \(@)- / -# |_|__ \_\/ __)_) |_|_/ |_|__ \_\/ /(@)- \ -# ((()))) - -__author__ = "Vitaly Kravtsov" -__author_email__ = "in4lio@gmail.com" -__copyright__ = "See the LICENSE file." - -#pylint: skip-file - -import urllib2 -import json -import os - -DIR = os.path.dirname( os.path.realpath(__file__)) -DICT = os.path.join( DIR, 'sensors.yu' ) -CACHE = os.path.join( DIR, 'sensors.json' ) - -D_BEGIN = '($dict CLASS_TYPE\n(`CLASS_TYPE_NAME CLASS_TYPE_MODES CLASS_TYPE_COMMANDS)\n(`\n' -D_ROW = '("{0}" ({1}) ({2}))\n' -D_END = ')\n)' - -def grab_sensors( url ): - """ - Get sensor types, modes and commands from JSON file and make a dictionary - with the following layout: - - ($dict CLASS_TYPE - (` CLASS_TYPE_NAME CLASS_TYPE_MODES CLASS_TYPE_COMMANDS ) - (` - ( "sensor-name" ( "mode" ... ) ( "command" ... ) ) - ... - ) - ) - """ - if os.path.isfile( DICT ): - return open( DICT, 'r' ).read() - -# -- cache the file from URL - if not os.path.isfile( CACHE ): - j = urllib2.urlopen( urllib2.Request( - url, - headers={ 'User-Agent': 'Mozilla/5.0', 'Content-Type': 'application/json' } - )) - with open( CACHE, 'wb' ) as f: - f.write( j.read()) - -# -- read the cached file - with open( CACHE ) as f: - data = json.load( f ) - -# -- parse data - result = D_BEGIN - - for sensor in data: - if 'mode_info' in sensor: - modes = ' '.join(( '"' + x[ 'name' ] + '"' for x in sensor[ 'mode_info' ])) - else: - modes = '' - - if 'cmd_info' in sensor: - cmds = ' '.join(( '"' + x[ 'name' ] + '"' for x in sensor[ 'cmd_info' ])) - else: - cmds = '' - -# -- append the sensor only if it has any mode or command - if modes or cmds: - result += D_ROW.format( sensor[ 'name' ], modes, cmds ) - print sensor[ 'name' ] - else: - print '{0: <24}(ignored)'.format( sensor[ 'name' ]) - - result += D_END - - with open( DICT, 'w' ) as f: - f.write( result ) - - return result - -if __name__ == '__main__': - grab_sensors( 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-jessie/sensors.json' ) diff --git a/source/ev3/grab/spec.py b/source/ev3/grab/spec.py new file mode 100644 index 0000000..a68a47c --- /dev/null +++ b/source/ev3/grab/spec.py @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- + +# ____ __ ____ ___ ____ __ (((((() +# | |_ \ \ / ) ) | | ) | |_ \ \ / \(@)- / +# |_|__ \_\/ __)_) |_|_/ |_|__ \_\/ /(@)- \ +# ((()))) + +__author__ = "Vitaly Kravtsov" +__author_email__ = "in4lio@gmail.com" +__copyright__ = "See the LICENSE file." + +#pylint: skip-file + +import urllib2 +import json +import os +import urlparse + +# --------------------------------------------------------------------------- +DIR = os.path.dirname( os.path.realpath(__file__)) + +F_SENSOR_DICT = os.path.join( DIR, 'sensors.yu' ) +F_PORT_DICT = os.path.join( DIR, 'ports.yu' ) + +D_SENSOR_BEGIN = '($dict CLASS_TYPE\n(`CLASS_TYPE_NAME CLASS_TYPE_MODES CLASS_TYPE_COMMANDS)\n(`\n' +D_SENSOR_ROW = '("{0}" ({1}) ({2}))\n' +D_SENSOR_END = ')\n)' + +D_PORT_BEGIN = '($dict CLASS_TYPE\n(`CLASS_TYPE_NAME CLASS_TYPE_MODES)\n(`\n' +D_PORT_ROW = '("{0}" ({1}))\n' +D_PORT_END = ')\n)' + +# --------------------------------------------------------------------------- +def cache_json( url, force=False ): + """ + Cache a JSON file. + """ + cache = os.path.join( DIR, os.path.basename( urlparse.urlparse( url ).path )) + + if force or not os.path.isfile( cache ): + j = urllib2.urlopen( urllib2.Request( + url, + headers={ 'User-Agent': 'Mozilla/5.0', 'Content-Type': 'application/json' } + )) + with open( cache, 'wb' ) as f: + f.write( j.read()) + + return cache + +# --------------------------------------------------------------------------- +def grab_sensors( url, force=False ): + """ + Get data of sensors from the specification and make a dictionary + with the following layout: + + ($dict CLASS_TYPE + (` CLASS_TYPE_NAME CLASS_TYPE_MODES CLASS_TYPE_COMMANDS ) + (` + ( "sensor-name" ( "mode" ... ) ( "command" ... ) ) + ... + ) + ) + """ + if not force and os.path.isfile( F_SENSOR_DICT ): + return open( F_SENSOR_DICT, 'r' ).read() + +# -- read the cached file + with open( cache_json( url )) as f: + data = json.load( f ) + +# -- parse data + result = D_SENSOR_BEGIN + + for sensor in data: + if 'mode_info' in sensor: + modes = ' '.join( '"' + x[ 'name' ] + '"' for x in sensor[ 'mode_info' ]) + else: + modes = '' + + if 'cmd_info' in sensor: + cmds = ' '.join( '"' + x[ 'name' ] + '"' for x in sensor[ 'cmd_info' ]) + else: + cmds = '' + +# -- append the sensor only if it has any mode or command + if modes or cmds: + result += D_SENSOR_ROW.format( sensor[ 'name' ], modes, cmds ) + print sensor[ 'name' ] + else: + print '{0: <24}(ignored)'.format( sensor[ 'name' ]) + + result += D_SENSOR_END + + with open( F_SENSOR_DICT, 'w' ) as f: + f.write( result ) + + return result + +# --------------------------------------------------------------------------- +def grab_ports( url, force=False ): + """ + Get data of ports from the specification and make a dictionary + with the following layout: + + ($dict CLASS_TYPE + (` CLASS_TYPE_NAME CLASS_TYPE_MODES ) + (` + ( "port-name" ( "mode" ... ) ) + ... + ) + ) + """ + + if not force and os.path.isfile( F_PORT_DICT ): + return open( F_PORT_DICT, 'r' ).read() + +# -- read the cached file + with open( cache_json( url, force )) as f: + data = json.load( f ) + +# -- parse data + result = D_PORT_BEGIN + + for k in data: + port = data[ k ] + if 'mode_info' in port: + modes = ' '.join( '"' + x[ 'name' ] + '"' for x in port[ 'mode_info' ]) + else: + modes = '' + + result += D_PORT_ROW.format( port[ 'name' ], modes ) + print port[ 'name' ] + + result += D_PORT_END + + with open( F_PORT_DICT, 'w' ) as f: + f.write( result ) + + return result + +# --------------------------------------------------------------------------- +if __name__ == '__main__': +# -- test + grab_sensors( + 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.json', force=True ) + grab_ports( + 'http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/ports.json', force=True )