How to send string to shell command parser ?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

How to send string to shell command parser ?

Post by Polux »

Hi,

I have a running project with various modules. They use shell on SD2 serial line for configuration.
I want to add CANbus for application purposes, and add configuration commands too, in order to configure modules from main controller, a PC, while still keeping the shell on serial serial port.

I plan sending a string through CAN messages, with same format used for serial line. No problems on this.

The question is: when extracted from CAN, how to redirect this string "as is" to the shell parser, so command execution will be done with the same code, as it was comming from serial line ?
Should I sent it to the BaseSequentialStream ?
The second option is to copy few line of the shell thread function, to decode command and parameters, and call the corresponding function.

Some examples would be appreciated.

Regards from a hardware guy :roll:
Angelo
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to send string to shell command parser ?

Post by Giovanni »

Hi,

The shell can work with anything implementing the "stream" interface, you need to create an object implementing that interface. The serial driver is such an object, the serial-over-usb is another example, the memory stream object is another example.

Giovanni
Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: How to send string to shell command parser ?

Post by Polux »

Hi,

I will give it a try.
And if my application require ethernet, I would add a telnet port. So the check and configuration could be done either by serial, CAN or Ethernet. Or all 3 at the same time.

The application is to drive old roadrail modeltrains. They are not digital, and it would be nice if the complete system runs unattended during expo and shows.


Angelo
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to send string to shell command parser ?

Post by Giovanni »

You can spawn multiple shells on different streams, no problems.

Giovanni
Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: How to send string to shell command parser ?

Post by Polux »

Hello,

I think I got it. Will check tomorrow.
I should create a buffer and a memorystream. Init the stream. Then create a new shell thread on this stream, using the existing command table. And finaly put/write chars extracted from the CANBUS protocol to the memorystream. And tadaaaaaaa, existing command code will do the job as it do on the serial port. And so on for the ethernet port.

Angelo
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to send string to shell command parser ?

Post by Giovanni »

You could skip the memory stream and implement your own buffers (one per direction).

HAL queues could do that.

Giovanni
mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: How to send string to shell command parser ?

Post by mikeprotts »

For Ethernet, it's fairly easy to create a basic web server (see $CHIBIOS/ext/lwip/src/apps/httpd directory). That allows simple web pages to interface with the system, possibly with a bit of javascript if you want to dynamically update the display.

If you add a level of abstraction from the shell interface code, most of the code can be used for either interface.

Mike
Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: How to send string to shell command parser ?

Post by Polux »

Hi,

I tested with memory stream. Everything compiles and execute well. But, it doesn't work. As buffer is unique for in and out, when starting, the shell sends itself the welcome message and first prompt. And loop continously trying to decode the previous error message as a new input command.

So I need to use buffer or queues. But as a "hardware oriented guy"I didn't understand anything about all this stuff. :roll:

A little big help would be appreciated.

Angelo
Polux
Posts: 27
Joined: Thu Apr 28, 2016 11:52 am
Been thanked: 7 times

Re: How to send string to shell command parser ?

Post by Polux »

mikeprotts wrote:For Ethernet, it's fairly easy to create a basic web server (see $CHIBIOS/ext/lwip/src/apps/httpd directory). That allows simple web pages to interface with the system, possibly with a bit of javascript if you want to dynamically update the display.

:cry: let's make things simple. At least for me :lol:

mikeprotts wrote:.... most of the code can be used for either interface.

Exactly what I want.

Angelo
mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: How to send string to shell command parser ?

Post by mikeprotts »

A simple example is in the demo code, e.g.:
ChibiOS_18.2.1/demos/STM32/RT-STM32F107-OLIMEX_P107-LWIP/web/web.c

The basic for a simple web server is to handle GET only. The server reads the URL send by the client, which might be (if board has IP address 192.168.1.32) to sound whistle once with short blast:
http://192.168.1.32/whistle?1&short

The server will see:
GET /whistle?1&short HTTP/1.1

So the server can perform the required process (maybe startWhistleMilliseconds(1000) which would probably run asynchronously on another thread) and send back a simple page with results. The web page can start simple:
<http>
<head>
<title>
Whistle result
</title>
</head>
<body>
<p>
One short blast requested
</p>
</body>
</html>

Once that's working you could add fancy stuff with javascript and images loaded from an SD card or a separate server (I use a Raspberry Pi for that).

Mike
Post Reply