Right now it is a pretty simple system:
ArdPyth.Start(DataSize,FlagChars,Baud,Port)
ArdPyth.Send(Data)
ArdPyth.Read()
ArdPyth.Close(Port)
ArdPyth.Interrupt --- To be implemented.
Start is just how it sounds, you declare the size of data you expect(However many characters long). Then you add in the "FlagChars" which are the end of data signals such as "/f/" or "&P&" just anything you do not expect to see in your data transmission. Baud & Port are straight forward. This program then uses a startup routine on the other end that waits for a startup sequence then sets itself up to work with the parameters. Some of things I still have to implement on the other side is data-sanitizing, possibly data fragmentation, and some various optimizing ideas I have.
Send is pretty straightforward, just takes the data to be sent off(int, strings, whatever) and converts it to a string then fires that off, along with its orginal variable type. On the other end the program accepts it and rebuilds it as its previous type. This is currently async, which means there is no way to verify the data's arrival or correctness.
Read is basically the exact oppisote of send. Takes the data in, sanitizes it*, then converts it back to its previous data type and this is read in as a variable. This is where the problems start though, C doesn't like dynamic typing as a language.. so how can you use it?
You can't just say:
Blah = ArdPyth.Read();
What if the data its reading is a floating point variable and blah is a string? Well! One of my ideas(read: not written yet) is to add in a type command on the ArdPyth.Read command. So it would be like this:
Blah = ArdPyth.Read(integer);
This would tell the read command that the output has to be an integer, if the data inside is a string though and does not conform to integers then it would produce an error code in the integer. A quick if statement on the C side of things, and WHAM! Done. I still got to write this out and see how it works in real world.. but thats later.
ArdPyth.Close(Port) is the single most straightforward command. It wipes the buffer, then closes connection.
The interrupt command is something I keep playing with in my head, it would be only useful for the arduino to arduino communication though. It would allow me to demand the other arduino read its buffer until it finds a certain character, then do whatever it tells it do. This could be useful if I have 2 or 3 arduino's together that are doing something time sensitive like balancing, if one accelermator detects an anamoloy(Oh no! I'm falling!! Aaah!) it would interrupt the other 2 and tell them to check. If all 3 agree, it does something. Thats a poor example because even that would take too long I imagine..
Anyways, code will be up sunday night.
* It does not currently sanitize the data. I have been waaaaay too lazy to bother coding this, its a lot of work to make fast.
No comments:
Post a Comment