navitron
 
Renewable Energy and Sustainability Forum
UK's most popular Renewable Energy Forum May 23, 2012, 12:45:32 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Anyone wishing to register as a new member on the forum is strongly recommended to use a "proper" email address - following recent spam/hack attempts on the forum, all security is set to "high", and "disposable" email addresses like Gmail, Yahoo and Hotmail tend to be viewed with suspicion, and the application rejected if there is any doubt whatsoever
 
Recent Articles: UPDATE ON DECC APPLICATION FOR LEAVE TO APPEAL TO THE SUPREME COURT | Yingli Green Energy's PV Module Ranks No.2 in TUV Rheinland Energy Yield Test | Navitron Solar Showers at Glastonbury for Year 5!
   Home   Help Search Login Register  
Pages: 1 [2]   Go Down
  Print  
Author Topic: More Arduino Toys  (Read 2599 times)
KenB
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2691


Energy Self Enlightenment


WWW
« Reply #15 on: August 06, 2010, 08:29:23 PM »

Stephen, Baz,

Upon reflection I think it would be wise to augment the command format at this stage - so as to allow for sub-addressing and longer arguments. However I'm reluctant to make it too unwieldy.

May I suggest the following format

Leading character   - this can be A-Z, a-z or most of the ascii punctuation characters including @ # ? ! etc
Sub-address           - in the range 0 to 255
delimiter                - use a comma  (marks the end of the sub-address field)
Argument              - a 16 bit integer in the range 0-65535
                           - further arguments could be added here separated by commas
CR/LF                    - marks the end of the Argument field and the end of the command

A parser would be needed that strips off the various fields and feeds them to the command executor.  Remember that we need to fit this into a few kB, so that it doesn't take too much overhead.

The simplest commands could be just the leading character followed by the sub-address.


any thoughts?


Ken



Logged
stephendv
Sr. Member
****
Offline Offline

Posts: 437



WWW
« Reply #16 on: August 06, 2010, 11:24:53 PM »

I think that's nailed it.  So one can use optional arguments if required, and if you just need to read a value then a simple 2 character command will do it.
For my SMS parser I ended up using the string library 'cause it was the fastest route to something that works, but yes, for a nicely optimised solution you'd probably want to build a character parser.

Logged

http://www.casanogaldelasbrujas.com
2.8kW PV, SMA Sunny Island 5048, 5 PzS 700 battery bank, stinky diesel.
Baz
Hero Member
*****
Offline Offline

Posts: 1386


« Reply #17 on: August 07, 2010, 01:07:16 AM »

Yes that extra leading character adds long term expandability. You don't need the delimiter as you are character counting so it complicates both command creation and parsing. Only use <CR> not <CRLF> but make <LF> benign, ie always ignored, and <CR> both terminator and reset the parser. Hence you can hit <cr> a few times without effect just like you do on any console.
Make the reply message end with <CR> as most terminals add the LF anyway. Were you thinking of echoing the text message or the original command?
Sorry if I'm stating the obvious. All pretty standard stuff in the seventies - I can probably dig out an example in 6800 machine code if I can find the paper tape.
Logged
stephendv
Sr. Member
****
Offline Offline

Posts: 437



WWW
« Reply #18 on: August 07, 2010, 08:53:43 AM »

I think you would still need the delimiter because the sub address can be 1 to 3 digits long, and also because their can be any number of arguments.
Logged

http://www.casanogaldelasbrujas.com
2.8kW PV, SMA Sunny Island 5048, 5 PzS 700 battery bank, stinky diesel.
Baz
Hero Member
*****
Offline Offline

Posts: 1386


« Reply #19 on: August 07, 2010, 11:32:40 AM »

I was assuming the sub address was a single byte to give 0-255. Ken, you're going to have to write a full RFC now, maybe you can get EU funding!
Logged
KenB
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2691


Energy Self Enlightenment


WWW
« Reply #20 on: August 07, 2010, 08:37:49 PM »

Guys,

I've modified the code so that it now interprets  Command Sub_address,Argument1,Argument2  CR

The sub_address is 0-255, and arg1 and arg2 are 0-65535  but this can readily be changed to suit the application

If you don't put anything in arg1 and arg2 it returns them as zero.

So b1   is decoded as b 1,0,0

b254,65534,32768   becomes b 254,65534,32768

However there appears to be a bizzarre bug in the code/compiler, such that if you try to print out the char variable which holds the command, it sets it to zero, so you can't use it again.


Please PM me if you want a copy of the code



Ken
Logged
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!