Announcement

Collapse
No announcement yet.

Execute multiple commands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Execute multiple commands

    I'm trying to request some information using the CLI every 20 seconds.
    And I have some trouble with it.
    It works the first time. But any succeeding requests doesn't give any result.
    Am I doing something wrong?


    tlog:
    32 D lighting 167 Start wireless watch thread 00:01:42
    33 D lighting 189 Starting scan. 00:01:42
    ...
    42 D lighting 196 Scan completed. 00:01:52
    43 D lighting 205 RECEIVED: Command Line start 00:01:52
    44 D lighting 205 RECEIVED: ed. >status st 00:01:52
    45 D lighting 205 RECEIVED: atus>wlan status 00:01:52
    46 D lighting 205 RECEIVED: WLAN wlan0>show WLA 00:01:52
    47 D lighting 205 RECEIVED: N wlan0 Status: C 00:01:52
    48 D lighting 205 RECEIVED: onnection State: Dis 00:01:52
    49 D lighting 205 RECEIVED: connected status 00:01:52
    50 D lighting 205 RECEIVED: WLAN wlan0>exit s 00:01:52
    51 D lighting 205 RECEIVED: tatus>exit >exit 00:01:52
    52 D lighting 205 RECEIVED: 00:01:52
    53 D lighting 205 RECEIVED: 00:01:52
    54 D lighting 205 RECEIVED: 00:01:52
    55 D lighting 205 RECEIVED: 00:01:52
    56 D lighting 205 RECEIVED: 00:01:52
    57 D lighting 205 RECEIVED: 00:01:52
    58 D lighting 205 RECEIVED: 00:01:52
    ...
    61 D lighting 189 Starting scan. 00:02:12
    ...
    63 D lighting 196 Scan completed. 00:02:22
    // no output here from CLI ??????
    Code:
    static void wirelessWatchThread(void *opaque)
    {
        (void)opaque;
    
        TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "Start wireless watch thread");
    
        while (true) {
            struct input_stream_from_const_char input_stream;
           struct output_stream_to_buffer output_stream;
           uint8_t buf[500];
           buf[499] = 0;
           buf[0] = 0;
    
           if (!ltrx_output_stream_init_to_buffer(&output_stream , &buf, 499, OUTPUT_STREAM_TO_BUFFER_MODE__BINARY)) {
              TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "Couldn't init buffer");
              ltrx_thread_sleep(s_delayTimeInMilliseconds);
              continue;
           }
    
           if (!ltrx_input_stream_init_from_const_char(&input_st ream, "status\rwlan\rshow\rexit\rexit\rexit")) {
              TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "Couldn't create stream");
              ltrx_thread_sleep(s_delayTimeInMilliseconds);
              continue;
           }
    
           bool running = true;
           TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "Starting scan.");
           ltrx_cli_command_loop(
              &input_stream.inStream, &output_stream.outStream, &running, true
           );
    
           ltrx_thread_sleep(10000);
    
           TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "Scan completed.");
    
           uint8_t buf2[21];
           buf2[20] = 0;
           for (unsigned int i=0; i<output_stream.bufferLength; i+=20) {
              for (unsigned int j=0; j<20; j++) {
                 buf2[j] = buf[i+j];
              }
    
              TLOG(TLOG_SEVERITY_LEVEL__DEBUG, "RECEIVED: %s", buf2);
           }
    
    
           ltrx_input_stream_close(&input_stream.inStream);
    
           ltrx_thread_sleep(s_delayTimeInMilliseconds);
       }
    }

  • #2
    I've fixed it. Instead of using "ltrx_output_stream_init_to_buffer", I wrote my own "struct output_stream". One gotcha here is that the ltrx_cli_command_loop sometimes writes stuff after it has finished. As a result it should not be on the stack. Or at least life longer than the containing function.

    Comment

    Working...
    X