Пример #1
0
Файл: main.c Проект: wuwx/simba
int main()
{
    sys_start();

    uart_soft_init(&uart,
                   &pin_d4_dev,
                   &pin_d3_dev,
                   &exti_d3_dev,
                   9600,
                   qinbuf,
                   sizeof(qinbuf));

    fs_command_init(&cmd_at,
                    CSTR("/at"),
                    cmd_at_cb,
                    NULL);
    fs_command_register(&cmd_at);

    std_printf(FSTR("Welcome to HC-0X configuration tool!\r\n"
                    "\r\n"
                    "SETUP: Connect pin34 to VCC so the device enters AT mode.\r\n"
                    "\r\n"
                    "Type 'at' to start communicating with the device.\r\n"));

    shell_init(&shell,
               sys_get_stdin(),
               sys_get_stdout(),
               NULL,
               NULL,
               NULL,
               NULL);
    shell_main(&shell);

    return (0);
}
Пример #2
0
/**
 * def system(command)
 */
static mp_obj_t os_system(mp_obj_t command_in)
{
    int res;
    char command[128];
    struct vstr_chan_t chout;

    strncpy(command, mp_obj_str_get_str(command_in), membersof(command));
    command[membersof(command) - 1] = '\0';

    vstr_chan_init(&chout);

    res = fs_call(command, sys_get_stdin(), &chout, NULL);

    if (res == -ENOENT) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command not found: '%s'",
                                                mp_obj_str_get_str(command_in)));
    } else if (res != 0) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command failed with %d",
                                                res));
    }

    return (mp_obj_new_str_from_vstr(&mp_type_str,
                                     vstr_chan_get_vstr(&chout)));
}