Show Posts
Pages: 1 2 [3] 4 5 ... 31
31  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!
32  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!
33  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!
34  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!
35  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!
36  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!
37  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!
38  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!
39  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!
40  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!
41  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!
42  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!
43  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 18, 2014, 04:43:19 pm
@Mispulin

No problems. The intent is more in the line "Please remember to...". And there is no problem with links to the copied code and just posting the changes and some of the context.

Testing new combinations gives insights to new usage and possible conflicts between components or as in this case the drawback with default parameters. They are great when the API is know but while learning they might hide issues.

During the testing I found an issue with the pin numbering in the SNMP part. The SNMP pin index to Cosa Board pin mapping was missing. There is an update with this change and an updated map. Please note that the mapping is not the full Arduino Mega pin set. The SNMP and Web Server part will deliver the same value. https://github.com/mikaelpatel/Cosa/commit/d87eec1a98c4bfd24e2f2731201602b45ec5dbba

Cheers!
44  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 18, 2014, 02:53:14 pm
@Mispulin

The quick answer is add a timeout to the requests and it works fine.
Code:
void loop()
{
   const uint32_t TIMEOUT = 100L;
  // Service incoming requests
  server.run(TIMEOUT);
  
  // Service SNMP requests with given MIB handlers
  SNMP::PDU pdu;
  snmp.request(pdu, TIMEOUT);
}
Tested it on an Arduino Leonardo :-) with an Ethernet Shield.
Code:
user@host: cosa leonardo upload
.....
AVR Memory Usage
----------------
Device: atmega32u4

Program:   22380 bytes (68.3% Full)
(.text + .data + .bootloader)

Data:        793 bytes (31.0% Full)
(.data + .bss + .noinit)
The long answer is if you look at the description of HTTP::Server::run() and SNMP:request() there is a timeout parameter that is default blocking.

Ref.
1. https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/d0/d12/classHTTP_1_1Server.html#adca760526a455a0e034862daa802acd1
2. https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/d8/d36/classSNMP.html#a111be2e37fb479a15df3cc77347097c9

Cheers!

BW: You left out the code in the first post and then in the next post you had removed the copyright notice. And you have only pasted together two example sketches. That is very very very bad practice.

Always post code. Always post environment; board, core, host, versions, versions, version. And always keep copyright notices if you are copying.

45  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 16, 2014, 11:48:44 am
The latest Cosa development have been focused on implementing a file system for the flash device driver (S25FL127S). The device is accessed through SPI and has a total size of 16 Mbyte (128 Mbit). Typical access time with the optimized Cosa SPI functions are approx. 600 Kbyte/s read and 200 Kbyte/s at 16 MHz clock and DIV2 SPI clock (i.e. 8 Mhz).

The Cosa Flash File System takes advantage of the S25FL127S hybrid sector structure with 16 X 4 Kbyte sectors followed by 255 x 64 Kbyte sectors. The file system allows for up to 16 directories with up to 128 files per directory. The total number of data files is limited to 255. The file and directory API is very traditional Linux with open, close, remove, tell, seek, read, write and ls, cd, mkdir and more.

The API follows the Cosa FAT16 interface so that SD and Flash access can replace each other in a sketch. Also the CFFS::File and FAT16::File classes implement the Cosa IOStream interface and all the output functions and operators can be used directly. Both binary and text data can be written to files on the flash. The only restriction is that the last data entry cannot be 0xff. This works fine for text while binary data records must be padded.

Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/FS/CFFS.hh


Example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaCFFS/CosaCFFS.ino

The example sketch demonstrates the file system functionality and binding a file to an iostream for log output in text (i.e. analog sample written to the file). Above is a screen shot of the output.

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