Show Posts
Pages: 1 [2] 3 4 ... 31
16  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 06:45:39 pm
@g_ad

That is actually exactly the behavior it "should" have right now when the line is too long. The input buffer is limited to 64 characters (in the current version). It is a configuration variable. The error handling could be improved. Please see the configuration constants: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Shell.hh#L117

I will see what I can do about that in Shell::run() as the too long command lines will result in multiple gets() calls. These will have to be ignored and reported as an error.

Latest update; The script handling will allow parameter binding (standard shell script syntax, $1 for parameter/option one, etc). Please see the updated CosaShell.ino/Commands.cpp. The script blink will require a delay time parameter (in ms).

Cheers!
17  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 12:38:42 pm
I can see new shell function "execute_P", I believe it is taking the input from the prog mem instead of the buffer? I didn't find it in the online documentation.
@g_ad

That one is easy; my dropbox has not yet synced the latest update. But it should be ready now.

Could you please tell me one more small thing that I didn't find the answer for yet - how to understand the uart blocking and non blocking "uart.set_blocking(SLEEP_MODE_IDLE)" what does it actually do?
The issue is what should uart.gets() do when there is no more characters in the input buffer. The non-blocking behavior is to return directly with what was available. That would require building up the command line until the new-line character is seen.

The set_blocking() tells the device to wait for more characters and return when it receives the new-line. The function gets() will call yield() while waiting for more character. And the actual sleep mode is defined by the implementation of yield(). There are two major implementations of yield(). One that uses power down and the second that does context switches.

Links down the rabbit hole.
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/IOStream.cpp#L355
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/main.cpp#L118
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Thread.cpp#L31

Cheers!
18  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 11:40:09 am
@g_ad

Had some time over today so I did an update :-); small steps forward. Refactored the script execution and improved the handling of string literal parameters (e.g. echo "a string parameter"). There is also a bunch of new commands in the example sketch CosaShell. The scripting looks like this:
Code:
#define LF "\n"

static const char BLINK_NAME[] __PROGMEM =
  "blink";
static const char BLINK_HELP[] __PROGMEM =
  "-- turn led on and off";
static const char BLINK_SCRIPT[] __PROGMEM =
  SHELL_SCRIPT_MAGIC        
  "echo -n \"led on\"" LF
  "led on" LF
  "delay 500" LF
  "echo -n \"..off\"" LF
  "led off" LF
  "delay 500" LF
  "echo -n \"..on\"" LF
  "led on" LF
  "delay 500" LF
  "echo \"..off\"" LF
  "led off" LF;
#define blink_action (Shell::action_fn) BLINK_SCRIPT
And the entry in the command table:
Code:
static const Shell::command_t command_vec[] __PROGMEM = {
  ...
  { BLINK_NAME, blink_action, BLINK_HELP },
 ...
};
A nice next step would be to tie the Shell together with the HTTP::Server and view the URL as a command; "http://..../command?arg1=xxx&arg2=yyy" which then translate to the Shell "command arg1=xxx arg2=yyy".

Cheers!
19  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 23, 2014, 06:00:01 pm
@g_ad

Hi Adam. I have added a somewhat better example sketch to show how to use the Shell support; Below is a screenshot.



The command shell example CosaCFFSshell has been one of my test programs for the flash memory file system. Not very good to show how to use the Shell class, especially as it is evolving.

The new example sketch is a tiny Arduino command language with a small blink boot script. Hopefully this will give a better "introduction".

https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/CosaShell.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/Commands.cpp

Cheers!
20  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 23, 2014, 01:59:04 pm
@g_ad

Hi Adam. Lets just say I have had a few more years to work on my programming skills. A lot of trail and error, teaching at university, building large software system, telecom systems and many-core operating systems for base-stations, and other frameworks.

Interesting questions you can back with. Actually the parameter and the options handling was something that I started refactoring after my last answer. Describing how to use something often has that effect :-)

The result after the refactoring is that 1) the expected argument count has been removed. The command action function is always responsible for checking the arguments, 2) there is a new member function that will parse options; shell.get(option, value). Below is a command action function from the update example sketch. It demonstrates the usage:
Code:
static const char ARGS_NAME[] __PROGMEM = "args";
static const char ARGS_HELP[] __PROGMEM = "args OPTS ARGS -- display options and arguments";
static int args_action(int argc, char* argv[])
{
  char* option;
  char* value;
  int i;
  while ((i = shell.get(option, value)) == 0)
    cout << PSTR("option: ") << option << PSTR(" value: ") << value << endl;
  while (i < argc)
    cout << PSTR("argument: ") << argv[i++] << endl;
  return (0);
}
The option syntax is a modified version of the standard getopt() function (and HTTP GET options); 1) -X single character option, 2) -XVALUE with value, 3) OPTION=VALUE option string with value. Below is example of interaction:
Code:
arduino:$ args -x -y10 -zabc a=10 b=nisse c=1.10 arg1 arg2
option: x value:
option: y value: 10
option: z value: abc
option: a value: 10
option: b value: nisse
option: c value: 1.10
argument: arg1
argument: arg2
To sum up the answer of your first question; The expected argument count is removed.

The next one; "potential danger with strtoul". Yes, you have to handle scan errors from the function. I took a short cut to show the principle. There are a lot more details to get robust code. The parameter that was NULL should be used to capture the end of scan and check that the whole string was parsed by strtoul. The slightly more robust version would be:
Code:
static int stty_action(int argc, char* argv[])
{
  if (argc != 2) return (-1);
  char* sp;
  uint32_t baudrate = strtoul(argv[2], &sp, 10);
  if (*sp != 0) return (-1);
  if (baudrate < MIN_BAUDRATE || baudrate > MAX_BAUDRATE) return (-1);
  if (strcmp_P(argv[1], PSTR("uart1")) == 0) return (uart1.begin(baudrate) ? 0 : -1);
  if (strcmp_P(argv[1], PSTR("uart2")) == 0) return (uart2.begin(baudrate) ? 0 : -1);
  ...
  return (-1);
}
Please see the latest update; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Shell.hh and https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaCFFSshell/CFFSshell.cpp

The next step of the command shell support will add simple scripting (i.e. reading commands from program memory or eemem). The will actually give two new interesting implementations of the Cosa IOStream::Device interface.  

Cheers!
21  Using Arduino / Installation & Troubleshooting / Re: Help Please! Arduino Mega ADK and GSM fried..IT HURTS ;( on: July 23, 2014, 04:30:15 am
@jrom1384

EDIT: I see now that you have used an AC adapter. That was bad. Must be DC output.

That was a sad story. I would recommend that you contact your supplier and/or arduino sales support http://arduino.cc/en/Main/ContactUs. I cannot see that you have done anything wrong. My guess is that the regulator was overheated due to the 5-7 W it had to dispatch.

I hope that you will get it replaced.


Cheers!
22  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 22, 2014, 05:42:26 pm
Before I dig to get the answer myself, may I ask if the current implementation allow to use the command like:
"set terminal 1 baud 19200"?
or that would be far too complicated command line?
@g_ad

No problem using that command style. The parser will break it into the different elements and the action function will have to check and do any conversions (such as text to number). The linux command is "stty -F /dev/ttyS0 19200" http://pubs.opengroup.org/onlinepubs/007904975/utilities/stty.html or "setserial /dev/ttyS0 19200" if you would like to use that format. I would use something like "stty uart2 19200". Snippet of the action function for this command is:
Code:
static int stty_action(int argc, char* argv[])
{
  uint32_t baudrate = strtoul(argv[2], NULL, 10);
  if (baudrate < MIN_BAUDRATE || baudrate > MAX_BAUDRATE) return (-1);
  if (strcmp_P(argv[1], PSTR("uart1")) == 0) uart1.begin(baudrate);
  else if (strcmp_P(argv[1], PSTR("uart2")) == 0) uart2.begin(baudrate);
  else return (-1);
  return (0);
}
The function strtoul() is available in the AVR library http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#gaea44aa48bda8261f794dcb2d1e7ab2b2
And one more from the code you've shared:
Code:
IOStream cout;
IOStream cin;

void setup()
{
  ...
  cin.set_device(&uart);
  cout.set_device(&uart);
  ...
}
of course that might be clear when I dig into the code but what hits me looking at it is that you declare two IOStreams - cout and cin and somehow for both you do the same set_device(&uart) so they kind of look the same to me.

Might have been clearer to use two device, for instance, cin on uart and cout on lcd. The more important for the example was that the shell.run() is called with the IOStreams as parameters and that a prompt is written to the IOStream cout (if provided).

Cheers!
23  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 21, 2014, 04:53:26 pm
@g_ad

I should work on shorter answers;-) Yes, I have considered porting to Arduino Due but it will take some time.

I just recently updated with a command line interface (Cosa/Shell.hh). That has been on the backlog for a long time, https://github.com/mikaelpatel/Cosa/issues/64. The example sketch is a simple shell with the basic file system commands (for Cosa Flash File System, CFFS, and the S25FL127S 16 Mbyte flash memory). Below is a snippet of some interaction with the example sketch. The "arduino$" is the prompt from the Anarduino Mini-Wireless http://www.anarduino.com/miniwireless/ that I am using for these tests.
Code:
user@host:~/Projects/Cosa/examples/Sandbox/CosaCFFSshell$ cosa miniwireless monitor
...
arduino:$ ls
.. Kalle Folder User
arduino:$ cat Kalle
0:A0 = 282
440876:A0 = 289
440868:A0 = 281
440852:A0 = 277
440844:A0 = 287
...
arduino:$ od Kalle
30 3a 41 30 20 3d 20 32 38 32 0a 34 34 30 38 37
36 3a 41 30 20 3d 20 32 38 39 0a 34 34 30 38 36
38 3a 41 30 20 3d 20 32 38 31 0a 34 34 30 38 35
32 3a 41 30 20 3d 20 32 37 37 0a 34 34 30 38 34
34 3a 41 30 20 3d 20 32 38 37 0a 34 34 30 38 33
...
arduino:$ cd User
arduino:$ ls
.. Nisse
arduino:$ cd Nisse
arduino:$ ls
..
arduino:$ date
2000-01-01 00:02:54
The command line handler will parse the command line into the typical main() function argument vector and count, do a table lookup and call the action function. To use the command line handler you have to define a string for the name of the command, a help string and the action function.  Below is the definition of the command "ls".
Code:
static const char LS_NAME[] __PROGMEM = "ls";
static const char LS_HELP[] __PROGMEM = "ls [--verbose] -- list files";
static int ls_action(int argc, char* argv[])
{
  bool verbose = false;
  if (argc == 2) {
    if (strcmp_P(argv[1], PSTR("--verbose")) == 0)
      verbose = true;
    else return (-1);
  }
  return (CFFS::ls(cout, verbose));
}
All the commands are collected in a table which is then used to drive the command line handler (shell). All data is in program memory. The __PROGMEM is defined in Cosa/Types.h and used to avoid compiler warnings in Arduino 1.0.X.
Code:
static const Shell::command_t command_vec[] __PROGMEM = {
  { 2, CAT_NAME, cat_action, CAT_HELP },
  { 2, CD_NAME, cd_action, CD_HELP },
  { 2, DATE_NAME, date_action, DATE_HELP },
  { 2, LS_NAME, ls_action, LS_HELP },
  { 2, MKDIR_NAME, mkdir_action, MKDIR_HELP },
  { 2, OD_NAME, od_action, OD_HELP },
  { 2, RM_NAME, rm_action, RM_HELP }
};
Shell shell(membersof(command_vec), command_vec);
The typical shell sketch has the following structure:
Code:
IOStream cout;
IOStream cin;

void setup()
{
  ...
  // Initiate UART for blocked read line
  uart.begin(9600);
  uart.set_blocking(SLEEP_MODE_IDLE);
  cin.set_device(&uart);
  cout.set_device(&uart);
  ...
}

void loop()
{
  // The shell command handler will do the top loop
  if (!shell.run(&cin, &cout)) return;
  cout << PSTR("illegal command") << endl;
}
Some links to further details. First the example sketch:
https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaCFFSshell/CosaCFFSshell.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaCFFSshell/CFFSshell.cpp
The interface and implementation of the command line handler:
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Shell.hh
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Shell.cpp

Cheers!
24  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 21, 2014, 01:58:42 pm
@Mispulin

Had another look at the HTTP::Server::run() member function and added an extra timeout after the client socket accept. This will catch client-side socket close before the HTTP message is actually received and gives more robustness. I tried to force the same situation as you described but did not get the web server socket to lock up.

Please give the update a try; https://github.com/mikaelpatel/Cosa/commit/b716ea0f4b3661e85d40d0e34601546c21df5b83

Cheers!
25  Development / Other Software Development / Re: Coroutines library on: July 21, 2014, 09:22:52 am
@renaudbedard

Interesting approach! I have studied and implemented three+ variants in Cosa; Event/FSM driven, proto-threads and coroutines. Below are some links to example sketches.

1. Event driven (and FSM)
https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkEvent/CosaBlinkEvent.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkFSM/CosaBlinkFSM.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkFSM/CosaBenchmarkFSM.ino

2. Proto-threads
https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkProtoThread/CosaBlinkProtoThread.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkProtoThread/CosaBenchmarkProtoThread.ino

3. Coroutines (Cosa Nucleo)
https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkThread/CosaBlinkThread.ino
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkNucleo/CosaBenchmarkNucleo.ino

More info can be found on the Cosa blog and the on-line documentation and research papers.

Cheers!
26  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 21, 2014, 01:59:42 am
@g_ad

Around 4400 characters sound about right. That is the number of characters that would get sent before the large IOBuffers are filled up. For every 10 characters on the fast side one(1) character is sent on the slow side.

The next step is to get a measure on the maximum burst size and the minimum time between bursts to calculate the average bps.  

Using the IOBuffers for the UARTs is the simpler solution and it is possible to modify the IOBuffer to allow "any" size (ie remove the power of 2 restriction). This would allow you to use more of the Mega 1280 8K byte SRAM for the buffers.

Yes, it is possible to use SPI or extended SRAM. Typical size is 32 K byte. The interesting design would be to implement the IOBuffer interface with an IOStream::Device driver for these storage types. The UART requires an implementation of the IOStream::Device interface. It is possible to hook any implementation of the interface directly to the UART. The restriction is that putchar() cannot block as the UART will call that from the ISR and the implementation must not take longer time than the minimum time between received characters. Below is the "simple" Cosa OOP ISR for the RX interrupt.
Code:
void UART::on_rx_interrupt()
{
  m_ibuf->putchar(*UDRn());
}

Once and awhile I get the question of porting Cosa to other processors/boards. This will take some time before it happens. There are several issues. The one that is my greatest concern is adding the necessary components and infra-structure to allow scaling and reuse of libraries.

This implies a different approach with a micro kernel/multi-tasking, interfaces for applications and drivers, build system with libraries, delivery and support, etc. Cosa is moving slowly in this direction with the new build system, multi-tasking, etc, but there is a lot left before considering porting. Then there is the next issue which also goes for any hardware/device drivers added to Cosa; the software must be able to regression test. That implies a lot of hardware for other than my own projects. And suddenly this is not simply sharing any more.

I have done the numbers on software development for Due/Teensy3+/ARM with port and it is in the range of 2-3 man months (400-600 h, excluding the time needed to read up on all the hardware and build the necessary test setups). That is also difficult to motivate without a target application/project/etc of my own.

Cheers!
27  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 04:43:26 pm
@g_ad

Hi Adam. I have pushed an IOBuffer update that should fix this issue. Please download and test it. There is also an update of the CosaBenchmarkUART to include large IOBuffers and burst write/measure.

Cheers!
28  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 03:10:47 pm
@g_ad

That was a great test case. I have not pushed the Mega UARTs in this way. That generates a fair amount of interrupt calls and stresses the UART/IOBuffer implementation.

I think we need to do the numbers. The average baud rate cannot be larger than the lowest in the chain. The bursts must leave enough time for the buffer to be transmitted. 10X the baud rate means busts must give at least X10 time period for the average baud rate to avoid buffer overflow.

Assume that you send a burst of 2000 characters at the high baud rate and they are more or less queued directly. It will take X10 the time to empty the buffer. A continues flow at the high baud rate will not work. 2000 character takes about 2 seconds at 9600 to transfer but less than 200 ms at 115200. If you send another burst within the 2 seconds the buffers will just fill up and overflow. Think of the problem as water flow, pipes and buckets ;-)

So more details required; what does your test data feed program look like?

Cheers!
29  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 20, 2014, 01:00:21 pm
@g_ad

Hi Adam. Some more details; What is the chip set on the converters? Need to check the internal buffer size. It sounds like a buffer overflow problem. The smallest buffer in the upward flow will be filled and overflow.

For example, the CP2102 has 640B TX/576B RX buffer. http://www.silabs.com/Support%20Documents/TechnicalDocs/CP2102-9.pdf which seems close to your numbers.

Another this to consider is that the putchar() is blocking when the IOBuffer is full.

As long as the high bps works we can rule out problems in the UART ISR's, i.e. UART internal buffer overrun on the ATmega1280. Right now there is no capture of the error bits in the driver. Might be something to consider.

Cheers!
30  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 19, 2014, 06:09:59 pm
@g_ad

Hi Adam.

The difference between sizeof() and the IOBuffer template size parameter is easy; there is more to the IOBuffer than the storage area/SIZE. The extra memory is for the "hidden" vtable pointer (2 bytes), io-mode (1 byte), head and tail index (2X2=4 bytes).

If you are getting garbage at exactly the same position that is an interesting problem. Need more information to understand this. What is the circuit? Wiring? Length of wires? etc.

Cheers!
Pages: 1 [2] 3 4 ... 31