Show Posts
Pages: 1 2 [3] 4 5 ... 32
31  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 09:43:08 am
Does this mean that I can use the RFM69/nRF24 also to handle 'shell' commands? In other words I can easily create a serial to LAN/WiFi/Radio translator/gateway??
Not really there yet. You need an IOStream::Driver that will use a Wireless Driver for transportation. There is a mockup https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/IOStream/Driver/WIO.hh that does output only. See the example sketch https://github.com/mikaelpatel/Cosa/blob/master/examples/Wireless/CosaWirelessIOStream/CosaWirelessIOStream.ino. With input handling (i.e. recv) and buffering in the Shell you have all the necessary components for remote commands (at least on the NRF24L01P which has built-in acknowledgement and retransmission).

I am actually working on a telnet and http service that uses the shell. Seems like an interesting challenge. See how much of that ends up in the Cosa source.

BTW: You seem to be working om my secret COSA wish list I have while developing prototype hardware. It's magic  smiley-twist
I have suspected that we have somewhat the same agenda smiley

Cheers!
32  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 07:35:25 am
This is brilliant smiley, thank you for all your hard work.
@g_ad

You are welcome!

I think that the Shell support is now more in line with what you where expecting from the start smiley. The development and refactoring has a lot to do with your input and tests - THANKS. I wanted to start-off with a simple blocking version and move slowly towards non-blocking as in the "final" version. With your input the update and evolution was somewhat faster.

I specifically added the "idle" command to the example sketch (CosaShell) to demonstrate the non-blocking IO and power down sleep that is going on in the background. There are more to be done on scripts; use EEMEM for storage, allow definition as commands, etc, but this will do fine for the release.

Thanks again for collaborating!
33  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 05:30:41 am
The news on the latest updates in Cosa.

1. IOStream
The IOStream class has a new member function to allow simple command line reading; IOStream::readline(buf, size). It will read available characters and append to the given string and return the buffer pointer when the line has been completed. The function will handle backspace, carriage-return and line-feed.

2. Shell
The command line support is now completed. The Shell::run() member function will handle the read, parse and execution of command lines. The function is non-blocking and should be called in the loop(). Below is a screenshot of the example sketch CosaShell. This sketch shows how to setup the shell for serial input, run the top-loop, and how to capture idle time.

As the Shell class uses the new IOStream::readline() function all echo and backspace is handled by this function. Below is a screenshot of using PuTTY with the shell. This is the default PuTTY setting (on Ubuntu).


3. Refactoring
a. SLEEP
The macro SLEEP (Cosa/Types.h) has been removed and the function sleep() should be used instead.
b. IOBuffer::gets()
This member function has been removed and the default implementation (IOStream::Device) is used instead.
c. IOStream::print(const void *ptr, size_t size, Base base, uint8_t max)
This member function is used to dump memory block. An additional base variant is now available that will prefix each line with a source address (i.e. not the given buffers address).

4. Versioning
The Cosa project does not have explicit versioning as it is non-commercial and sharing but to make it simpler for users there are specific snapshots of source and documentation. For more details see the install description and the section "Download Versions". https://github.com/mikaelpatel/Cosa/blob/master/doc/02-install.md#download-versions. Please note that using the build script will require some additional configuration. Please see https://github.com/mikaelpatel/Cosa/blob/master/build/Cosa.mk and previous post on this issue.

Cheers!
34  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 27, 2014, 02:55:21 am
@g_ad

Hi Adam. I use this topic of updates on the development of Cosa. There are questions from users and as other forums users mostly help each other. These questions also get mixed up in this topic.

Bugs, errors and feature requests should be posted on the Issues list on github. In general I do not add new boards, modules, devices, etc, that I cannot test or have my own project for.  Pull requests that cannot be tested are not merged (of the same reason).

Now the more interesting question; handling of NEWLINE. Linux LF, Mac CR and PC both CR+LF, and others. http://en.wikipedia.org/wiki/Newline

I did some tests with configuration of Putty and the Terminal window setting "Implicit CR in every LF" (and local echo auto) fixes one side of the issue. The other will require adding support for translation (as in many Linux tools). The simple fix was to translate CR to LF in gets().

The more elegant solution is to add a translation setting to IOStream::Device and default to a common standard. The NEWLINE handling needs to be abstracted to all type of devices (e.g. terminal, network, files, etc).

I do not use Putty and I work mostly on Linux/Ubuntu. To get the fastest possible development turn-around I have actually added a build script (modified Arduino-Makefile) and miniterm for serial monitor (also modified). This allows build of only what has changed, upload and starting the serial monitor as a single command. The Arduino IDE build is 3-5 times slower in build. A lot of unnecessary operations are performed as it does not use make.

Cheers!
35  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 26, 2014, 06:32:03 am
A new screenshot of the Cosa Shell example sketch. There are a number of new commands; dump memory, play tone, repeat command lines, etc.

The options parser makes it really easy to write action functions with multiple options and variable number of arguments. Below is a snippet from CosaShell Commands. It implemented the memory dump command which has radix options, memory address and block size:
Code:
static const char DUMP_NAME[] __PROGMEM =
  "dump";
static const char DUMP_HELP[] __PROGMEM =
  "[-b|-d] POS [SIZE] -- dump memory";
static int dump_action(int argc, char* argv[])
{
  IOStream::Base base = IOStream::hex;
  uint32_t addr = 0L;
  size_t size = 256;
  char* option;
  char* value;
  char* sp;
  int ix;
  while ((ix = shell.get(option, value)) == 0) {
    if (strcmp_P(option, PSTR("b")) == 0)
      base = IOStream::bin;
    else if (strcmp_P(option, PSTR("d")) == 0)
      base = IOStream::dec;
    else
      return (-1);
  }
  if (ix < argc) {
    addr = strtoul(argv[ix++], &sp, 16);
    if (*sp != 0) return (-1);
  }
  if (ix < argc) {
    size = strtoul(argv[ix++], &sp, 10);
    if (*sp != 0) return (-1);
  }
  if (ix != argc) return (-1);
  cout.print(addr, (void*) addr, size, base);
  return (0);
}
The first section uses Shell::get(option, value) to parse the given options. The next section handles possible parameter; memory address to dump from (default 0), and size of memory block (default 256). For more details please see https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaShell/CosaShell.ino.

The Cosa Flash File System (CFFS) shell has also been updated with some new commands:

For more details please see https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaCFFSshell/Commands.cpp

Cheers!
36  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 25, 2014, 06:07:44 pm
@g_ad

Update available that fixes that for Arduino 1.0.X.

BW: It is better to use the github issues list for this type of problems.

Cheers!
37  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!
38  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!
39  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!
40  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!
41  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!
42  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!
43  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!
44  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!
45  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!
Pages: 1 2 [3] 4 5 ... 32