It is currently Thu Dec 14, 2017 8:52 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Mar 12, 2009 1:18 pm 
Offline

Joined: Thu May 17, 2007 3:00 pm
Posts: 80
Location: Duesseldorf, Germany
Hello everybody,

I've been playing around with the ContikiOS (2.2.x) telnetd and shell code, writing an additional shell process that reads 5 lines of text (entered by the user who is connected to the system via telnet) and writes them to a REL file. The "post message" part works flawlessly, but the "read message" part that reads the data and displays it on the screen drives me crazy. The "read" process reads the data and even shows the correct records through the log_message() command. But it refuses to display any text through the shell_output_str() function. Also, the "read" process (unlike the "post" process) does not exit properly (dropping back to the Contiki shell process), causing the C64 to lock up.

I've found out so far, that if I comment out the PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input) statement in my "read" code and reading a fixed record number from disk, it works correctly printing all the records through shell_output_str() on the telnet screen and not locking the process. Unfortunately, I need to wait for and process shell input, so the user can type in the number of the message he wants to display.

Here's the code that drives me nuts. Any suggestions on how to get the PROCESS_WAIT_EVENT_UNTIL handled correctly (so that it doesn't lock up the process)?

Code:
PROCESS_THREAD(shell_bbreadmsg_process, ev, data)
{
  struct shell_input *input;
  int uiMsgCount=0;
  int uiMsgNo=0;
  short usCount=0;

  input=data;
  bbsfile.ucDeviceNo = 8; 
  usCount=0;   
 
  PROCESS_BEGIN();
           
  while (1)
  {
    if (usCount == 0)
    {
       strcpy(bbsfile.szFileName, BBS_MSGIDX0);
       ssReadRELFile(&bbsfile, &uiMsgCount, sizeof(uiMsgCount), 1);
       
       sprintf(buffer, "msg count: %u", uiMsgCount);
       shell_output_str(NULL, buffer, "\n");       
       shell_prompt("select message #");
       
       PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
       input=data;     
       uiMsgNo = atoi(input->data1);
       /* uiMsgNo=1; */
       
       strcpy(bbsfile.szFileName, BBS_MSGBASE0);
       ssReadRELFile(&bbsfile, &bbs_msg, sizeof(bbs_msg), uiMsgNo);
    }
   
    if (usCount<=4)
    {
       sprintf(buffer, "> %s\n", bbs_msg.szTextLine[usCount]);
       shell_output_str(NULL, buffer, "\n");
       log_message(buffer, "");
    }
    else
    { 
        PROCESS_EXIT();
    }
   
    usCount++; 
  }
   
  PROCESS_END();

_________________
LOAD ":*",8,1
READY.
RUN


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 13, 2009 12:23 am 
Offline

Joined: Thu Mar 12, 2009 11:19 pm
Posts: 6
I think you need to specify the command (defined in the SHELL_COMMAND() macro) as the first parameter to shell_output_str() for it to work.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 13, 2009 12:25 am 
Offline

Joined: Thu Mar 12, 2009 11:19 pm
Posts: 6
Also, you need to make uiMsgCount, uiMsgNo, and usCount static or else their values will be trashed on every PROCESS_WAIT_EVENT().


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group