This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting console Input from within a Zephyr shell command

I'm trying to create a Zephyr Shell command where I can write a certificate to the modem.  Putting the certificate in the command line doesn't work, so I was going to use the getchar() command to read it in as part of the command operation.  getchar doesn't work.  If I try to use console_getchar() it crashes.  If I power up with console_init then the shell locks up.

I was hoping that there was going to be a shell_getchar() or something similar to the shell_print which I could use to get input.  But I haven't found anything like that.

Is there a way to crack this nut?

Parents
  • Here is my implementation:

    char* shell_getline(const struct shell *shell, char *buf, const size_t len) {
        if (!buf)
            return NULL;
        
        char *p = buf;
        memset(buf, 0, len);
    
        for (size_t i = 0; i < (len - 1); i++) {
            char c;
            size_t cnt;
    
            shell->iface->api->read(shell->iface, &c, sizeof(c), &cnt);
            while (cnt == 0) {    
                k_busy_wait(100);
                shell->iface->api->read(shell->iface, &c, sizeof(c), &cnt);
            }
            shell->iface->api->write(shell->iface, &c, sizeof(c), &cnt);
            if (c == '\n' || c == '\r') {
                break; // end of line
            }
            *p++ = c;
        }
    
        return buf;
    }
    

Reply
  • Here is my implementation:

    char* shell_getline(const struct shell *shell, char *buf, const size_t len) {
        if (!buf)
            return NULL;
        
        char *p = buf;
        memset(buf, 0, len);
    
        for (size_t i = 0; i < (len - 1); i++) {
            char c;
            size_t cnt;
    
            shell->iface->api->read(shell->iface, &c, sizeof(c), &cnt);
            while (cnt == 0) {    
                k_busy_wait(100);
                shell->iface->api->read(shell->iface, &c, sizeof(c), &cnt);
            }
            shell->iface->api->write(shell->iface, &c, sizeof(c), &cnt);
            if (c == '\n' || c == '\r') {
                break; // end of line
            }
            *p++ = c;
        }
    
        return buf;
    }
    

Children
No Data
Related