diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..20880dc --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +# Addresed Networking Over UART (ANOU) +## Elmélet +Ennek a protokollnak a lényege, hogy egy egyszerű L3 réteget lehessen helyezni +az eléggé limitált UART protokoll fölé. diff --git a/src/anou.cpp b/src/anou.cpp index dd3a8a2..362f42e 100644 --- a/src/anou.cpp +++ b/src/anou.cpp @@ -24,17 +24,17 @@ class ANOUServer char* addresses; public: - char ConfigureSerialPort() + int ConfigureSerialPort() { } - char StartListener() + int StartListener() { } - char WriteSerialPort(char* message) + int WriteSerialPort(char* message) { } @@ -47,6 +47,8 @@ public: full_message[0] = TYPE_START + dst_addr << 2; for (char i = 0; i < message_size; i++) full_message[i+1] = message[i]; full_message[message_size+1] = TYPE_STOP + dst_addr << 2; + + return full_message; } char* Response(char address) @@ -82,11 +84,25 @@ public: return message; } - char SHAW(char address, bool force_readdress = false) + int SHAW(char address = -1, bool force_readdress = false) { //Stateful Host Addressing Waterfall protocol //sends out an addressing message with the address it wants to //assign. This will be assigned to the first client without an address + if (address == -1) { + //if no address is effectively specified, select the first available + //address + + for (int i = 0; i < sizeof(addresses)/sizeof(int); i++) + { + if (i != addresses[i]) { + address = i; + break; + } + } + + } + char message[2] = { TYPE_SHAW + address << 2, 0b0 @@ -104,6 +120,9 @@ public: } WriteSerialPort(AssemblePacket(message, ADDR_BROADCAST)); + //no need for response packet; the SHAW packet can only come + //from the host, therefore the clients will always ACK to the + //host address } }; \ No newline at end of file diff --git a/src/anou.h b/src/anou.h index 90ef5dd..626ad7d 100644 --- a/src/anou.h +++ b/src/anou.h @@ -11,11 +11,11 @@ class ANOUServer char* addresses; //known client addresses public: - char ConfigureSerialPort(); //configuring the serial port - char StartListener(); //start listening on the serial port - char WriteSerialPort(char* message); //write the message to the serial port + int ConfigureSerialPort(); //configuring the serial port + int StartListener(); //start listening on the serial port + int WriteSerialPort(char* message); //write the message to the serial port char* AssemblePacket(char src_addr, char dst_addr, char* message); //assemble the full packet, with the source and destination address too - char SHAW(bool force_readdress); //Stateful Host Addressing Waterfall protocol + int SHAW(bool force_readdress); //Stateful Host Addressing Waterfall protocol char* SetVar6(char var_index, int var_value); //used to create a 6 bit long variable altering message char* SetVar12(char var_index, int var_value); //used to create a 12 bit long variable altering message