add broadcast support

This commit is contained in:
IMback 2018-02-05 20:22:37 +01:00
parent 7edc2108a7
commit 6b18e5ee70
2 changed files with 21 additions and 12 deletions

View File

@ -27,7 +27,8 @@ static void printUsage()
-p, --serialport serial port device to use\n\
-P, --port tcp port to use\n\
-b, --baud set baud rate with termios id\n\
-r, --rates list Available baud rates\n";
-r, --rates list Available baud rates\n\
-s, --sinkless run without serial port\n";
}
static void printRates()
@ -63,7 +64,7 @@ public:
std::string portFileName = "/dev/ttyUSB0";
unsigned short port = 6856;
int baud = 0000017;
bool ignMissingSerialport = false;
bool noSerial = false;
};
static int parseCmdArgs(int argc, char** argv, Config *config)
@ -90,9 +91,9 @@ static int parseCmdArgs(int argc, char** argv, Config *config)
if(argc > i) config->baud = atoi(argv[i+1]);
else return -1;
}
else if (std::string(argv[i]) == "-d")
else if (std::string(argv[i]) == "--sinkless" || std::string(argv[i]) == "-s" )
{
config->ignMissingSerialport=true;
config->noSerial=true;
}
else if (std::string(argv[i]) == "-r" || std::string(argv[i]) == "--rates")
@ -127,13 +128,14 @@ int main(int argc, char* argv[])
std::cout<<"UVOS serial mulitplexer v0.2\n";
std::cout<<"Using serial port: "<<config.portFileName<<" at "<<config.baud<<" baud\n";
int serial = serialport_init(config.portFileName.c_str(), config.baud);
if(serial == -1)
int serial = -1;
if(!config.noSerial)
{
if(config.ignMissingSerialport) std::cout<<"Continuing in demo mode\n";
else return 1;
std::cout<<"Using serial port: "<<config.portFileName<<" at "<<config.baud<<" baud\n";
int serial = serialport_init(config.portFileName.c_str(), config.baud);
if(serial == -1) return 1;
}
else std::cout<<"Sinkless mode\n";
std::vector<TCPSocket*> clientSockets;
@ -173,7 +175,15 @@ int main(int argc, char* argv[])
{
std::cout<<"rec: ";
for( int j = 0; j < reclen; j++ )std::cout<<inBuffer[j];
sWrite(serial, inBuffer, reclen);
if(strncmp( inBuffer, "bcst:", 4 ) == 0)
{
std::cout<<"bcst: ";
for( int j = 4; j < reclen; j++ )std::cout<<inBuffer[j];
for(unsigned int j = 0; j < clientSockets.size(); j++) if(i != j) clientSockets[j]->send(inBuffer+5, reclen-5);
std::cout<<std::endl;
}
std::cout<<std::endl;
}
else if(reclen == 0)

View File

@ -5,13 +5,12 @@ struct termios toptions;
void sWrite(int port, char string[], size_t length)
{
if(port != -1) write(port, string, length);
else for( size_t j = 0; j < length; j++ )std::cout<<string[j];
}
void sWrite(int port, const char string[], size_t length)
{
if(port != -1) write(port, string, length);
else for( size_t j = 0; j < length; j++ )std::cout<<string[j];
}
ssize_t sRead(int port, void *buf, size_t count)