English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 19 January 2015, 11:57   #1
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 679
Serial Console

Hi Guys,
I’m writing a serial console into a program (hardware has UART) to be accessed by remote terminal over standard serial.

I have so far handled the messages/replies being sent to the terminal,
and can also individually receive bytes from the terminal.

I’m wondering if there’s a “standard way” to qualify commands that may or may not also contain data.. i.e..

“HELP”, “SET TIME 12:23:56”, “SET SPEED SLOW”, etc.

So far I’m shifting the bytes into a buffer one by one until the CR byte arrives,
and looking at the entire receive buffer then.
I have also handled the backspace value (dec 8) by rotating the buffer right.
From here I’m not sure I’m qualifying commands/data the best way.
Would you cycle a lookup table for a bunch of commands to see if the buffer matches any?

By the time someone enters “HELP” my buffer would look like this:
(CR,P,L,E,H,X,X,X,X,X,X,X).... where X could be any unknown rubbish.

Any ideas appreciated!
Cheers, Art.
xArtx is offline  
Old 19 January 2015, 13:06   #2
ajk
Registered User
ajk's Avatar
 
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,286
I have made various embedded gadgets with a serial terminal. What do you mean by command and data in this instance? If it's a terminal intended to be used by humans, everything is just ASCII data and you can design your own set of commands. Something like "set parameter=value" is certainly pretty common, and reasonably easy to interpret in the code. If you are programming in C, there are lots of string handling functions for you to use. In assembly you'll have to roll your own but it might still be worthwhile to see what exists.

Of course having everything in ASCII wastes bandwidth over binary, so if it's a protocol for communicating between devices, you may want to use another approach.

I suggest also looking into the VT100 and related terminals, and their escape codes, if you want to have more complex features in your terminal (like arrow key handling etc.) See this Wikipedia article for starters.
ajk is offline  
Old 20 January 2015, 06:41   #3
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 679
Hi, yes it’s for Human controlled remote terminal.
I figure the way I had in mind works ok, it’s just not of much use looking at it backwards.
It will be necessary to count the bytes in to know the length of the command to qualify
the command first, then the data... and also decrement the count, and reverse rotate the input array for backspace.
xArtx is offline  
Old 20 January 2015, 09:28   #4
ajk
Registered User
ajk's Avatar
 
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,286
Hmm... I don't know what kind of input routine you have, but basically you should just collect all entered characters into a buffer (string), and then when you receive an end-of-line, you process what is in the buffer.

So you might have for example the following string in the buffer: "set mode= 2". First just use strtok, sscanf or other string handling functions to break it up into parts. Then look at the first part, "set" and see if it matches any of your supported commands - you can use a simple for loop with strncmp, or if you have a lot of commands, it may be worthwhile to implement a faster search function of some sort (again assuming C here, since you didn't say otherwise... the same principles apply with assembly or any other language but you may need to code some of the functions yourself).

If you find a valid command, then look at the other parts and decide if they represent valid options/parameters for that command or if you should print an error message.

For handling backspaces and arrow keys you should have the concept of a cursor. The cursor is basically just a number telling you where in the buffer you are. When the user enters a new character, add it to the current position and increment the cursor by one. If the user presses backspace, remove the current character and decrement the cursor by one. If the cursor is already at 0, backspace will do nothing. You can also allow arrow keys to edit in the middle of a line.

You probably also want some maximum limit for the buffer so the user can't enter more than, let's say, 80 characters. When you need to redraw the current line in the terminal, those VT100 commands will come in handy.

The most important thing with this stuff is to make it robust, so no matter what the user might type in, your program won't crash - it'll just politely say syntax error or something
ajk is offline  
Old 20 January 2015, 12:43   #5
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 679
Pretty much did all that for one command.. what I tried to explain there
In my first post I was loading not a buffer until I see enter key (dec 13),
but had not made it to discover the reason for a counter to look forward from he beginning of the entry to the end.

So as well as some commands with no parameters, now I have also handled
“TIME = HH:MM:SS”
where the time is checked as valid digits, also a valid time (not 88:99:91), and also either of the spaces can be missing.

I’d hate to be writing a BASIC interpreter or something like that!
xArtx is offline  
Old 21 January 2015, 11:39   #6
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 945
ít seems to me you're asking two questions here:

1. is there a standard format for specifying/entering commands and their parameters?

2. how to parse these commands and parameters?

in both cases, you could compare this to specifying and parsing command line parameters, so I guess you could find one with a format you like and just use that.

judging from your example commands, something like the SCPI standard might be useful for formatting (http://en.wikipedia.org/wiki/Standar...le_Instruments)

there is an open source parser here: https://github.com/j123b567/scpi-parser
hooverphonique is offline  
Old 29 January 2015, 15:13   #7
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 679
I meant qualifying commands programmatically more than syntax,
but I’m happy with what I’ve come up with.
For syntax I tried to think back to Sega SC3000H BASIC and went with that
It’s slow and steady for now with big character spacing.
It will take some time for me to properly relate this to the Amiga,
the terminal used here is iPhone Get Console App.

[ Show youtube player ]
xArtx is offline  
Old 30 January 2015, 18:04   #8
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,686
One of the best terminals i know https://sites.google.com/site/terminalbpp/ - can be a good inspiration
pandy71 is offline  
Old 31 January 2015, 04:39   #9
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 679
Looks nice, but I assume it’s Windows from the screenshot.
I might be after a Mac terminal, but probably not Windows.
xArtx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
PC Serial to Amiga Serial lesta_smsc support.Hardware 48 02 December 2015 10:14
Wii Console Only scrappysphinx MarketPlace 3 26 March 2010 21:00
HELP Finding Out the name of this console jak69 Retrogaming General Discussion 6 24 March 2007 20:20
Amstrad console???? Fred the Fop Retrogaming General Discussion 23 14 January 2004 19:05
How do you like my new console? Akira Retrogaming General Discussion 3 06 August 2002 20:36

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:04.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06881 seconds with 13 queries