cwEuCon.h/cpp : Allow the Fader service port to be set from the program arguments (even though it should be read from DNS-SD).
This commit is contained in:
parent
f2bfc13419
commit
3a840015cf
51
cwEuCon.cpp
51
cwEuCon.cpp
@ -328,10 +328,11 @@ namespace cw
|
|||||||
|
|
||||||
typedef struct eucon_str
|
typedef struct eucon_str
|
||||||
{
|
{
|
||||||
sock::handle_t sockMgrH;
|
sock::handle_t sockMgrH; // socket mgr handle
|
||||||
fbank_t* fbankL;
|
fbank_t* fbankL; // List of fader banks
|
||||||
unsigned maxFaderBankN;
|
unsigned maxFaderBankN; // maximum number of fader banks
|
||||||
unsigned sockTimeOutMs;
|
unsigned sockTimeOutMs; // socket time out
|
||||||
|
unsigned faderTcpPort; // Fader TCP port TODO: we shouuld be getting this from the MDNS SRV record
|
||||||
|
|
||||||
} eucon_t;
|
} eucon_t;
|
||||||
|
|
||||||
@ -353,10 +354,18 @@ namespace cw
|
|||||||
rc_t rc0;
|
rc_t rc0;
|
||||||
|
|
||||||
fbank_t* fb = p->fbankL;
|
fbank_t* fb = p->fbankL;
|
||||||
for(; fb!=nullptr; fb=fb->link)
|
while( fb!=nullptr )
|
||||||
|
{
|
||||||
|
fbank_t* fb0 = fb->link;
|
||||||
|
|
||||||
if((rc0 = _destroyFBank(p,fb)) != kOkRC )
|
if((rc0 = _destroyFBank(p,fb)) != kOkRC )
|
||||||
rc = rc0;;
|
rc = rc0;;
|
||||||
|
|
||||||
|
mem::release(fb);
|
||||||
|
|
||||||
|
fb = fb0;
|
||||||
|
}
|
||||||
|
|
||||||
if( p->sockMgrH.isValid() )
|
if( p->sockMgrH.isValid() )
|
||||||
if((rc = sock::destroyMgr(p->sockMgrH)) != kOkRC )
|
if((rc = sock::destroyMgr(p->sockMgrH)) != kOkRC )
|
||||||
return rc;
|
return rc;
|
||||||
@ -459,7 +468,8 @@ namespace cw
|
|||||||
cwLogError(kOpFailRC,"Fader bank not found. TCP message not delivered.");
|
cwLogError(kOpFailRC,"Fader bank not found. TCP message not delivered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
if( data!=nullptr && dataByteCnt >= 4 )
|
if( data!=nullptr && dataByteCnt >= 4 )
|
||||||
{
|
{
|
||||||
//printHex(data,dataByteCnt);
|
//printHex(data,dataByteCnt);
|
||||||
@ -473,7 +483,7 @@ namespace cw
|
|||||||
{
|
{
|
||||||
fb->protoState = kWaitForHandshake_2_Id;
|
fb->protoState = kWaitForHandshake_2_Id;
|
||||||
_sendHandshake_1( fb );
|
_sendHandshake_1( fb );
|
||||||
printf("Rcvd (0x0b) HS 1 - sent 0x0c\n");
|
printf("%i : Rcvd (0x0b) HS 1 - sent 0x0c\n", fb->fbIndex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -481,7 +491,7 @@ namespace cw
|
|||||||
if( hdr == 0x0d )
|
if( hdr == 0x0d )
|
||||||
{
|
{
|
||||||
fb->protoState = kResponse_3_A_Id;
|
fb->protoState = kResponse_3_A_Id;
|
||||||
printf("Rcvd (0x0d) HS 2 - Sending setup data\n");
|
printf("%i : Rcvd (0x0d) HS 2 - Sending setup data\n",fb->fbIndex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -511,7 +521,7 @@ namespace cw
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kRunning_Id:
|
case kRunning_Id:
|
||||||
printf("Rcv: %i : ",dataByteCnt );
|
printf("%i : Rcv: %i : ",fb->fbIndex, dataByteCnt );
|
||||||
for(unsigned i=0; i<dataByteCnt; ++i)
|
for(unsigned i=0; i<dataByteCnt; ++i)
|
||||||
printf("0x%02x ",((uint8_t*)data)[i]);
|
printf("0x%02x ",((uint8_t*)data)[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -527,16 +537,14 @@ namespace cw
|
|||||||
//unsigned ms = time::elapsedMs( &p->t0, &t1 );
|
//unsigned ms = time::elapsedMs( &p->t0, &t1 );
|
||||||
//printf("cb: %i %i\n",p->cbCnt,ms);
|
//printf("cb: %i %i\n",p->cbCnt,ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc_t _on_McMix_DNS_SD_TXT( eucon_t* p, const char* numberText, unsigned numberTextCharN, const struct sockaddr_in* fromAddr )
|
||||||
rc_t _on_McMix_DNS_SD_SRV( eucon_t* p, const char* numberText, unsigned numberTextCharN, const struct sockaddr_in* fromAddr )
|
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
unsigned tcpFlags = sock::kTcpFl | sock::kBlockingFl | sock::kStreamFl | sock::kReuseAddrFl | sock::kReusePortFl;
|
unsigned tcpFlags = sock::kTcpFl | sock::kBlockingFl | sock::kStreamFl | sock::kReuseAddrFl | sock::kReusePortFl;
|
||||||
fbank_t* fb = nullptr;
|
fbank_t* fb = nullptr;
|
||||||
unsigned fbIndex = 0;
|
unsigned fbIndex = 0;
|
||||||
sock::portNumber_t fbPort = fromAddr->sin_port;
|
|
||||||
char fbIP[ INET_ADDRSTRLEN+1 ];
|
char fbIP[ INET_ADDRSTRLEN+1 ];
|
||||||
|
|
||||||
// copy the "MC Mix" suffix number into a zero terminated string
|
// copy the "MC Mix" suffix number into a zero terminated string
|
||||||
@ -550,7 +558,7 @@ namespace cw
|
|||||||
|
|
||||||
// validate the value
|
// validate the value
|
||||||
if( !(0 < fbIndex && fbIndex <= p->maxFaderBankN ) )
|
if( !(0 < fbIndex && fbIndex <= p->maxFaderBankN ) )
|
||||||
return cwLogError(kInvalidArgRC,"The fader bank index %i is not valid.", fbIndex );
|
return cwLogError(kInvalidArgRC,"The fader bank number %i is not valid.", fbIndex );
|
||||||
|
|
||||||
// convert fbIndex to a zero based index
|
// convert fbIndex to a zero based index
|
||||||
fbIndex -= 1;
|
fbIndex -= 1;
|
||||||
@ -568,7 +576,7 @@ namespace cw
|
|||||||
return cwLogError(rc,"IP address to string conversion failed.", fbIndex);
|
return cwLogError(rc,"IP address to string conversion failed.", fbIndex);
|
||||||
|
|
||||||
// create the TCP socket
|
// create the TCP socket
|
||||||
if((rc = sock::create( p->sockMgrH, fb->sockUserId, sock::kInvalidPortNumber, tcpFlags, p->sockTimeOutMs, _tcpCallback, p, fbIP, fbPort )) != kOkRC )
|
if((rc = sock::create( p->sockMgrH, fb->sockUserId, sock::kInvalidPortNumber, tcpFlags, p->sockTimeOutMs, _tcpCallback, p, fbIP, p->faderTcpPort )) != kOkRC )
|
||||||
return cwLogError(rc,"The TCP socket for fader bank index %i failed. ", fbIndex);
|
return cwLogError(rc,"The TCP socket for fader bank index %i failed. ", fbIndex);
|
||||||
|
|
||||||
fb->remoteAddr = fromAddr->sin_addr.s_addr;
|
fb->remoteAddr = fromAddr->sin_addr.s_addr;
|
||||||
@ -601,9 +609,9 @@ namespace cw
|
|||||||
if( strncmp(label, name+1, strlen(label)) == 0 )
|
if( strncmp(label, name+1, strlen(label)) == 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned n = strlen(label) + 1;
|
unsigned n = strlen(label);
|
||||||
|
|
||||||
if((rc = _on_McMix_DNS_SD_SRV( p, name+n, name[0]-n, fromAddr )) != kOkRC )
|
if((rc = _on_McMix_DNS_SD_TXT( p, name+n+1, name[0]-n, fromAddr )) != kOkRC )
|
||||||
cwLogError(rc,"%.*s initialization failed.",name[0],name+1);
|
cwLogError(rc,"%.*s initialization failed.",name[0],name+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -655,6 +663,7 @@ cw::rc_t cw::net::eucon::create( handle_t& hRef, const args_t& args )
|
|||||||
|
|
||||||
p->maxFaderBankN = args.maxFaderBankN;
|
p->maxFaderBankN = args.maxFaderBankN;
|
||||||
p->sockTimeOutMs = args.sockTimeOutMs;
|
p->sockTimeOutMs = args.sockTimeOutMs;
|
||||||
|
p->faderTcpPort = args.faderTcpPort;
|
||||||
hRef.set(p);
|
hRef.set(p);
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
@ -710,6 +719,7 @@ bool quitFl = false;
|
|||||||
|
|
||||||
void sighandler(int sig)
|
void sighandler(int sig)
|
||||||
{
|
{
|
||||||
|
printf("Signal caught!\n");
|
||||||
quitFl = true;
|
quitFl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,14 +734,15 @@ cw::rc_t cw::net::eucon::test()
|
|||||||
args.mdnsPort = 5353;
|
args.mdnsPort = 5353;
|
||||||
args.sockTimeOutMs = 50;
|
args.sockTimeOutMs = 50;
|
||||||
args.maxFaderBankN = 8;
|
args.maxFaderBankN = 8;
|
||||||
|
args.faderTcpPort = 49168;
|
||||||
args.maxSockN = 50;
|
args.maxSockN = 50;
|
||||||
|
|
||||||
|
|
||||||
cw::log::createGlobal();
|
// Create the EuCon controller
|
||||||
|
|
||||||
// create the EuCon controller
|
|
||||||
if((rc = create( h, args )) != kOkRC )
|
if((rc = create( h, args )) != kOkRC )
|
||||||
return cwLogError(rc,"Unable to create EuCon server.");
|
return cwLogError(rc,"Unable to create EuCon server.");
|
||||||
|
|
||||||
|
cwLogInfo("EuCon controller waiting ...");
|
||||||
while( !quitFl )
|
while( !quitFl )
|
||||||
{
|
{
|
||||||
exec(h,args.sockTimeOutMs);
|
exec(h,args.sockTimeOutMs);
|
||||||
|
14
cwEuCon.h
14
cwEuCon.h
@ -18,13 +18,13 @@ namespace cw
|
|||||||
|
|
||||||
typedef struct args_str
|
typedef struct args_str
|
||||||
{
|
{
|
||||||
unsigned recvBufByteN;
|
unsigned recvBufByteN; // Socket receive buffer size
|
||||||
const char* mdnsIP;
|
const char* mdnsIP; // MDNS IP (always: "224.0.0.251")
|
||||||
sock::portNumber_t mdnsPort;
|
sock::portNumber_t mdnsPort; // MDNS port (always 5353)
|
||||||
unsigned sockTimeOutMs;
|
unsigned sockTimeOutMs; // socket poll time out in milliseconds (also determines the cwEuCon update rate)
|
||||||
sock::portNumber_t tcpPort;
|
sock::portNumber_t faderTcpPort; // Fader TCP port (e.g. 49168)
|
||||||
unsigned maxSockN;
|
unsigned maxSockN; // maximum number of socket to allow in the socket manager
|
||||||
unsigned maxFaderBankN;
|
unsigned maxFaderBankN; // maximum number of fader banks to support
|
||||||
} args_t;
|
} args_t;
|
||||||
|
|
||||||
rc_t create( handle_t& hRef, const args_t& a );
|
rc_t create( handle_t& hRef, const args_t& a );
|
||||||
|
Loading…
Reference in New Issue
Block a user