make some fixes, refactor some variables, finish most of the packet code
This commit is contained in:
+56
-12
@@ -1,5 +1,5 @@
|
||||
#include "anou.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define TYPE_DATA 0b0
|
||||
#define TYPE_START 0b1
|
||||
@@ -9,44 +9,89 @@
|
||||
#define ADDR_BROADCAST 0b111111
|
||||
#define ADDR_HOST 0b0
|
||||
|
||||
#define MODE_SETVAR6 0x01
|
||||
#define MODE_SETVAR12 0x02
|
||||
#define MODE_RESPONSE 0x3d
|
||||
#define ACK 0x03
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ANOUServer
|
||||
{
|
||||
char* portname;
|
||||
string portname;
|
||||
char buffer[1024];
|
||||
|
||||
int* addresses;
|
||||
char* addresses;
|
||||
|
||||
public:
|
||||
int ConfigureSerialPort()
|
||||
char ConfigureSerialPort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int StartListener()
|
||||
char StartListener()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int WriteSerialPort(char* message)
|
||||
char WriteSerialPort(char* message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* AssemblePacket(int src_addr = ADDR_HOST, int dst_addr, char** message)
|
||||
char* AssemblePacket(char* message, char dst_addr, char src_addr = ADDR_HOST)
|
||||
{
|
||||
char message_size = sizeof(message)/sizeof(char);
|
||||
char full_message[message_size + 2];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char* AssembleMessage(int type, char* mode, char* value)
|
||||
char* Response(char address)
|
||||
{
|
||||
char message[2] {
|
||||
TYPE_DATA + MODE_RESPONSE<<2,
|
||||
TYPE_DATA + address<<2
|
||||
};
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
int SHAW(bool force_readdress)
|
||||
char* SetVar6(char var_index, int var_value)
|
||||
{
|
||||
char message[3] = {
|
||||
TYPE_DATA + MODE_SETVAR6<<2,
|
||||
TYPE_DATA + var_index<<2,
|
||||
TYPE_DATA + var_value<<2
|
||||
};
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
char* SetVar12(char var_index, int var_value)
|
||||
{
|
||||
char message[4] = {
|
||||
TYPE_DATA + MODE_SETVAR6<<2,
|
||||
TYPE_DATA + var_index<<2,
|
||||
TYPE_DATA + (var_value>>6)<<2,
|
||||
TYPE_DATA + var_value<<2<<6
|
||||
};
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
char SHAW(char address, 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
|
||||
char message[2] = {
|
||||
TYPE_SHAW + address << 2,
|
||||
0b0
|
||||
};
|
||||
|
||||
if (force_readdress)
|
||||
{
|
||||
//force readdressing ignores, whether the clients have
|
||||
@@ -55,11 +100,10 @@ public:
|
||||
//a force readdress SHAW packet downstream with addr 2 and force_readdress
|
||||
//enabled
|
||||
|
||||
WriteSerialPort(AssemblePacket())
|
||||
|
||||
message[1] = 0b1;
|
||||
}
|
||||
|
||||
|
||||
WriteSerialPort(AssemblePacket(message, ADDR_BROADCAST));
|
||||
}
|
||||
|
||||
};
|
||||
+14
-8
@@ -1,19 +1,25 @@
|
||||
#ifndef ANOU_H
|
||||
#define ANOU_H
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class ANOUServer
|
||||
{
|
||||
char* portname; //name of the serial port (eg.: /dev/ttyUSB1)
|
||||
string portname; //name of the serial port eg.: /dev/ttyUSB1)
|
||||
char buffer[1024]; //message buffer
|
||||
int* addresses; //known client addresses
|
||||
char* addresses; //known client addresses
|
||||
|
||||
public:
|
||||
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(int src_addr, int dst_addr, char** message)
|
||||
char* AssembleMessage(int type, char* mode, char* value); //append the value and the message type to the message mode
|
||||
int SHAW(bool force_readdress); //Stateful Host Addressing Waterfall protocol
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
char* Response(char address); //specifies an address the client should make a response to
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user