Page 1 of 2
How to send string to shell command parser ?
Posted: Mon Jul 22, 2019 12:31 pm
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
Angelo
Re: How to send string to shell command parser ?
Posted: Mon Jul 22, 2019 1:33 pm
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
Re: How to send string to shell command parser ?
Posted: Mon Jul 22, 2019 3:21 pm
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
Re: How to send string to shell command parser ?
Posted: Mon Jul 22, 2019 6:19 pm
by Giovanni
You can spawn multiple shells on different streams, no problems.
Giovanni
Re: How to send string to shell command parser ?
Posted: Tue Jul 23, 2019 12:10 pm
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
Re: How to send string to shell command parser ?
Posted: Tue Jul 23, 2019 12:34 pm
by Giovanni
You could skip the memory stream and implement your own buffers (one per direction).
HAL queues could do that.
Giovanni
Re: How to send string to shell command parser ?
Posted: Wed Jul 24, 2019 4:05 pm
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
Re: How to send string to shell command parser ?
Posted: Wed Jul 24, 2019 8:20 pm
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.
A
little big help would be appreciated.
Angelo
Re: How to send string to shell command parser ?
Posted: Thu Jul 25, 2019 12:01 pm
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.

let's make things simple. At least for me
mikeprotts wrote:.... most of the code can be used for either interface.
Exactly what I want.
Angelo
Re: How to send string to shell command parser ?
Posted: Thu Jul 25, 2019 2:44 pm
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