/* Safely get string from stdin. 
Function ignores all nonprintable characters. String may be finished by CR or NL. */
static void safe_gets(char *str, size_t nmax)
/* Safely get string from stdin. 
Function ignores all nonprintable characters. String may be finished by CR or NL. */
static void safe_gets(char *str, size_t nmax)
{
    int c;
    char cstr[2] = {0, 0};
    while (1)
    {
        c = NRF_LOG_GETCHAR();
        if (isprint(c))
        {
            *str++ = (char)c;
            cstr[0] = c;
            NRF_LOG_RAW_INFO("%s", nrf_log_push(cstr));
            NRF_LOG_FLUSH();
            if (0 == --nmax)
                break;
        }
        else if ('\n' == c || '\r' == c)
        {
            break;
        }
    }
    *str = '\0';
    cstr[0] = '\n';
    NRF_LOG_RAW_INFO("%s", nrf_log_push(cstr));
    NRF_LOG_FLUSH();
}