From 3a840015cfacda7b86f5e6ba6123fefe49baa227 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Fri, 3 Apr 2020 17:42:07 -0400 Subject: [PATCH 1/3] cwEuCon.h/cpp : Allow the Fader service port to be set from the program arguments (even though it should be read from DNS-SD). --- cwEuCon.cpp | 51 +++++++++++++++++++++++++++++++-------------------- cwEuCon.h | 14 +++++++------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/cwEuCon.cpp b/cwEuCon.cpp index f16094e..92cdf7f 100644 --- a/cwEuCon.cpp +++ b/cwEuCon.cpp @@ -328,10 +328,11 @@ namespace cw typedef struct eucon_str { - sock::handle_t sockMgrH; - fbank_t* fbankL; - unsigned maxFaderBankN; - unsigned sockTimeOutMs; + sock::handle_t sockMgrH; // socket mgr handle + fbank_t* fbankL; // List of fader banks + unsigned maxFaderBankN; // maximum number of fader banks + unsigned sockTimeOutMs; // socket time out + unsigned faderTcpPort; // Fader TCP port TODO: we shouuld be getting this from the MDNS SRV record } eucon_t; @@ -353,10 +354,18 @@ namespace cw rc_t rc0; 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 ) rc = rc0;; + mem::release(fb); + + fb = fb0; + } + if( p->sockMgrH.isValid() ) if((rc = sock::destroyMgr(p->sockMgrH)) != kOkRC ) return rc; @@ -459,7 +468,8 @@ namespace cw cwLogError(kOpFailRC,"Fader bank not found. TCP message not delivered."); return; } - + + // if( data!=nullptr && dataByteCnt >= 4 ) { //printHex(data,dataByteCnt); @@ -473,7 +483,7 @@ namespace cw { fb->protoState = kWaitForHandshake_2_Id; _sendHandshake_1( fb ); - printf("Rcvd (0x0b) HS 1 - sent 0x0c\n"); + printf("%i : Rcvd (0x0b) HS 1 - sent 0x0c\n", fb->fbIndex); } break; @@ -481,7 +491,7 @@ namespace cw if( hdr == 0x0d ) { 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; @@ -511,7 +521,7 @@ namespace cw break; case kRunning_Id: - printf("Rcv: %i : ",dataByteCnt ); + printf("%i : Rcv: %i : ",fb->fbIndex, dataByteCnt ); for(unsigned i=0; it0, &t1 ); //printf("cb: %i %i\n",p->cbCnt,ms); } - } + } - - rc_t _on_McMix_DNS_SD_SRV( eucon_t* p, const char* numberText, unsigned numberTextCharN, const struct sockaddr_in* fromAddr ) + rc_t _on_McMix_DNS_SD_TXT( eucon_t* p, const char* numberText, unsigned numberTextCharN, const struct sockaddr_in* fromAddr ) { rc_t rc = kOkRC; unsigned tcpFlags = sock::kTcpFl | sock::kBlockingFl | sock::kStreamFl | sock::kReuseAddrFl | sock::kReusePortFl; fbank_t* fb = nullptr; unsigned fbIndex = 0; - sock::portNumber_t fbPort = fromAddr->sin_port; char fbIP[ INET_ADDRSTRLEN+1 ]; // copy the "MC Mix" suffix number into a zero terminated string @@ -550,7 +558,7 @@ namespace cw // validate the value 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 fbIndex -= 1; @@ -568,7 +576,7 @@ namespace cw return cwLogError(rc,"IP address to string conversion failed.", fbIndex); // 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); fb->remoteAddr = fromAddr->sin_addr.s_addr; @@ -601,9 +609,9 @@ namespace cw 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); } @@ -655,6 +663,7 @@ cw::rc_t cw::net::eucon::create( handle_t& hRef, const args_t& args ) p->maxFaderBankN = args.maxFaderBankN; p->sockTimeOutMs = args.sockTimeOutMs; + p->faderTcpPort = args.faderTcpPort; hRef.set(p); errLabel: @@ -710,6 +719,7 @@ bool quitFl = false; void sighandler(int sig) { + printf("Signal caught!\n"); quitFl = true; } @@ -724,14 +734,15 @@ cw::rc_t cw::net::eucon::test() args.mdnsPort = 5353; args.sockTimeOutMs = 50; args.maxFaderBankN = 8; + args.faderTcpPort = 49168; args.maxSockN = 50; + - cw::log::createGlobal(); - - // create the EuCon controller + // Create the EuCon controller if((rc = create( h, args )) != kOkRC ) return cwLogError(rc,"Unable to create EuCon server."); + cwLogInfo("EuCon controller waiting ..."); while( !quitFl ) { exec(h,args.sockTimeOutMs); diff --git a/cwEuCon.h b/cwEuCon.h index 824e1c6..d04c78f 100644 --- a/cwEuCon.h +++ b/cwEuCon.h @@ -18,13 +18,13 @@ namespace cw typedef struct args_str { - unsigned recvBufByteN; - const char* mdnsIP; - sock::portNumber_t mdnsPort; - unsigned sockTimeOutMs; - sock::portNumber_t tcpPort; - unsigned maxSockN; - unsigned maxFaderBankN; + unsigned recvBufByteN; // Socket receive buffer size + const char* mdnsIP; // MDNS IP (always: "224.0.0.251") + sock::portNumber_t mdnsPort; // MDNS port (always 5353) + unsigned sockTimeOutMs; // socket poll time out in milliseconds (also determines the cwEuCon update rate) + sock::portNumber_t faderTcpPort; // Fader TCP port (e.g. 49168) + unsigned maxSockN; // maximum number of socket to allow in the socket manager + unsigned maxFaderBankN; // maximum number of fader banks to support } args_t; rc_t create( handle_t& hRef, const args_t& a ); From c266475c9917d7214eee6db7418ca0cae07820b7 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Sat, 4 Apr 2020 09:28:32 -0400 Subject: [PATCH 2/3] cwEuCon.cpp : Fixed bug where multiple handshake-0's could be sent. --- cwEuCon.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cwEuCon.cpp b/cwEuCon.cpp index 92cdf7f..cc34978 100644 --- a/cwEuCon.cpp +++ b/cwEuCon.cpp @@ -571,21 +571,24 @@ namespace cw return cwLogError(kOpFailRC,"The fader bank index %i failed.", fbIndex ); } - // convert the fromAddr to a string - if((rc = sock::addrToString( fromAddr, fbIP, INET_ADDRSTRLEN)) != kOkRC ) - return cwLogError(rc,"IP address to string conversion failed.", fbIndex); + if( fb->protoState == kSendHandshake_0_Id ) + { + // convert the fromAddr to a string + if((rc = sock::addrToString( fromAddr, fbIP, INET_ADDRSTRLEN)) != kOkRC ) + return cwLogError(rc,"IP address to string conversion failed.", fbIndex); - // create the TCP socket - 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); + // create the TCP socket + 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); - fb->remoteAddr = fromAddr->sin_addr.s_addr; + fb->remoteAddr = fromAddr->sin_addr.s_addr; - // Send the initial handshake to the fader bank - _sendHandshake_0( fb ); - - fb->protoState = kWaitForHandshake_1_Id; + // Send the initial handshake to the fader bank + _sendHandshake_0( fb ); + fb->protoState = kWaitForHandshake_1_Id; + } + return rc; } @@ -608,7 +611,6 @@ namespace cw // if this a 'MC Mix' DNS-SD SRV reply if( strncmp(label, name+1, strlen(label)) == 0 ) { - unsigned n = strlen(label); if((rc = _on_McMix_DNS_SD_TXT( p, name+n+1, name[0]-n, fromAddr )) != kOkRC ) From 86c641c4ab9ebeff7ee13abdeb7dc86c8077eb39 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 4 Apr 2020 20:53:20 +0000 Subject: [PATCH 3/3] Minor changes for Raspberry Pi Build. --- Makefile.am | 58 +++++++++++++++++++++---------------------- cwAudioDeviceAlsa.cpp | 6 ++--- cwEuCon.cpp | 2 +- cwObject.cpp | 4 +-- cwUi.cpp | 4 +-- 5 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Makefile.am b/Makefile.am index 623390e..6700236 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,49 +1,47 @@ -dir = src/libcw - libcwHDR = libcwSRC = -libcwHDR += $(dir)/cwCommon.h $(dir)/cwCommonImpl.h $(dir)/cwMem.h $(dir)/cwLog.h $(dir)/cwUtility.h -libcwSRC += $(dir)/cwCommonImpl.cpp $(dir)/cwMem.cpp $(dir)/cwLog.cpp $(dir)/cwUtility.cpp +libcwHDR += src/libcw/cwCommon.h src/libcw/cwCommonImpl.h src/libcw/cwMem.h src/libcw/cwLog.h src/libcw/cwUtility.h +libcwSRC += src/libcw/cwCommonImpl.cpp src/libcw/cwMem.cpp src/libcw/cwLog.cpp src/libcw/cwUtility.cpp -libcwHDR += $(dir)/cwFileSys.h $(dir)/cwText.h $(dir)/cwFile.h $(dir)/cwTime.h $(dir)/cwLex.h $(dir)/cwNumericConvert.h -libcwSRC += $(dir)/cwFileSys.cpp $(dir)/cwText.cpp $(dir)/cwFile.cpp $(dir)/cwTime.cpp $(dir)/cwLex.cpp +libcwHDR += src/libcw/cwFileSys.h src/libcw/cwText.h src/libcw/cwFile.h src/libcw/cwTime.h src/libcw/cwLex.h src/libcw/cwNumericConvert.h +libcwSRC += src/libcw/cwFileSys.cpp src/libcw/cwText.cpp src/libcw/cwFile.cpp src/libcw/cwTime.cpp src/libcw/cwLex.cpp -libcwHDR += $(dir)/cwObject.h $(dir)/cwObjectTemplate.h $(dir)/cwTextBuf.h -libcwSRC += $(dir)/cwObject.cpp $(dir)/cwTextBuf.cpp +libcwHDR += src/libcw/cwObject.h src/libcw/cwObjectTemplate.h src/libcw/cwTextBuf.h +libcwSRC += src/libcw/cwObject.cpp src/libcw/cwTextBuf.cpp -libcwHDR += $(dir)/cwThread.h $(dir)/cwMutex.h $(dir)/cwMpScNbQueue.h -libcwSRC += $(dir)/cwThread.cpp $(dir)/cwMutex.cpp +libcwHDR += src/libcw/cwThread.h src/libcw/cwMutex.h src/libcw/cwMpScNbQueue.h +libcwSRC += src/libcw/cwThread.cpp src/libcw/cwMutex.cpp -libcwHDR += $(dir)/cwWebSock.h $(dir)/cwWebSockSvr.h $(dir)/cwLib.h -libcwSRC += $(dir)/cwWebSock.cpp $(dir)/cwWebSockSvr.cpp $(dir)/cwLib.cpp +libcwHDR += src/libcw/cwWebSock.h src/libcw/cwWebSockSvr.h src/libcw/cwLib.h +libcwSRC += src/libcw/cwWebSock.cpp src/libcw/cwWebSockSvr.cpp src/libcw/cwLib.cpp -libcwHDR += $(dir)/cwUiDecls.h $(dir)/cwUi.h $(dir)/cwUiTest.h -libcwSRC += $(dir)/cwUi.cpp $(dir)/cwUiTest.cpp +libcwHDR += src/libcw/cwUiDecls.h src/libcw/cwUi.h src/libcw/cwUiTest.h +libcwSRC += src/libcw/cwUi.cpp src/libcw/cwUiTest.cpp -libcwHDR += $(dir)/cwSerialPortDecls.h $(dir)/cwSerialPort.h $(dir)/cwSerialPortSrv.h -libcwSRC += $(dir)/cwSerialPort.cpp $(dir)/cwSerialPortSrv.cpp +libcwHDR += src/libcw/cwSerialPortDecls.h src/libcw/cwSerialPort.h src/libcw/cwSerialPortSrv.h +libcwSRC += src/libcw/cwSerialPort.cpp src/libcw/cwSerialPortSrv.cpp -libcwHDR += $(dir)/cwMidiDecls.h $(dir)/cwMidi.h $(dir)/cwMidiPort.h -libcwSRC += $(dir)/cwMidi.cpp $(dir)/cwMidiPort.cpp $(dir)/cwMidiAlsa.cpp +libcwHDR += src/libcw/cwMidiDecls.h src/libcw/cwMidi.h src/libcw/cwMidiPort.h +libcwSRC += src/libcw/cwMidi.cpp src/libcw/cwMidiPort.cpp src/libcw/cwMidiAlsa.cpp -libcwHDR += $(dir)/cwAudioDeviceDecls.h $(dir)/cwAudioDevice.h $(dir)/cwAudioDeviceAlsa.h -libcwSRC += $(dir)/cwAudioDevice.cpp $(dir)/cwAudioDeviceAlsa.cpp $(dir)/cwAudioDeviceTest.cpp +libcwHDR += src/libcw/cwAudioDeviceDecls.h src/libcw/cwAudioDevice.h src/libcw/cwAudioDeviceAlsa.h +libcwSRC += src/libcw/cwAudioDevice.cpp src/libcw/cwAudioDeviceAlsa.cpp src/libcw/cwAudioDeviceTest.cpp -libcwHDR += $(dir)/cwAudioBufDecls.h $(dir)/cwAudioBuf.h -libcwSRC += $(dir)/cwAudioBuf.cpp +libcwHDR += src/libcw/cwAudioBufDecls.h src/libcw/cwAudioBuf.h +libcwSRC += src/libcw/cwAudioBuf.cpp -libcwHDR += $(dir)/cwSocketDecls.h $(dir)/cwSocket.h -libcwSRC += $(dir)/cwSocket.cpp +libcwHDR += src/libcw/cwSocketDecls.h src/libcw/cwSocket.h +libcwSRC += src/libcw/cwSocket.cpp -libcwHDR += $(dir)/cwIo.h $(dir)/cwIoTest.h -libcwSRC += $(dir)/cwIo.cpp $(dir)/cwIoTest.cpp +libcwHDR += src/libcw/cwIo.h src/libcw/cwIoTest.h +libcwSRC += src/libcw/cwIo.cpp src/libcw/cwIoTest.cpp -libcwHDR += $(dir)/cwTcpSocket.h $(dir)/cwTcpSocketSrv.h $(dir)/cwTcpSocketTest.h -libcwSRC += $(dir)/cwTcpSocket.cpp $(dir)/cwTcpSocketSrv.cpp $(dir)/cwTcpSocketTest.cpp +libcwHDR += src/libcw/cwTcpSocket.h src/libcw/cwTcpSocketSrv.h src/libcw/cwTcpSocketTest.h +libcwSRC += src/libcw/cwTcpSocket.cpp src/libcw/cwTcpSocketSrv.cpp src/libcw/cwTcpSocketTest.cpp -libcwHDR += $(dir)/cwMdns.h $(dir)/cwEuCon.h $(dir)/cwDnsSd.h $(dir)/dns_sd/dns_sd.h $(dir)/dns_sd/dns_sd_print.h $(dir)/dns_sd/dns_sd_const.h $(dir)/dns_sd/fader.h $(dir)/dns_sd/rpt.h -libcwSRC += $(dir)/cwMdns.cpp $(dir)/cwEuCon.cpp $(dir)/cwDnsSd.cpp $(dir)/dns_sd/dns_sd.cpp $(dir)/dns_sd/dns_sd_print.cpp $(dir)/dns_sd/fader.cpp $(dir)/dns_sd/rpt.cpp +libcwHDR += src/libcw/cwMdns.h src/libcw/cwEuCon.h src/libcw/cwDnsSd.h src/libcw/dns_sd/dns_sd.h src/libcw/dns_sd/dns_sd_print.h src/libcw/dns_sd/dns_sd_const.h src/libcw/dns_sd/fader.h src/libcw/dns_sd/rpt.h +libcwSRC += src/libcw/cwMdns.cpp src/libcw/cwEuCon.cpp src/libcw/cwDnsSd.cpp src/libcw/dns_sd/dns_sd.cpp src/libcw/dns_sd/dns_sd_print.cpp src/libcw/dns_sd/fader.cpp src/libcw/dns_sd/rpt.cpp diff --git a/cwAudioDeviceAlsa.cpp b/cwAudioDeviceAlsa.cpp index 945b85c..f93c12e 100644 --- a/cwAudioDeviceAlsa.cpp +++ b/cwAudioDeviceAlsa.cpp @@ -166,7 +166,7 @@ namespace cw case SND_PCM_STATE_PAUSED: return "paused"; case SND_PCM_STATE_SUSPENDED: return "suspended"; case SND_PCM_STATE_DISCONNECTED: return "disconnected"; - case SND_PCM_STATE_PRIVATE1: return "private1"; + //case SND_PCM_STATE_PRIVATE1: return "private1"; } return ""; @@ -491,7 +491,7 @@ namespace cw case SND_PCM_STATE_DRAINING: case SND_PCM_STATE_PAUSED: case SND_PCM_STATE_DISCONNECTED: - case SND_PCM_STATE_PRIVATE1: + //case SND_PCM_STATE_PRIVATE1: //case SND_PCM_STATE_LAST: break; } @@ -872,7 +872,7 @@ namespace cw case SND_PCM_STATE_DRAINING: case SND_PCM_STATE_PAUSED: case SND_PCM_STATE_DISCONNECTED: - case SND_PCM_STATE_PRIVATE1: + //case SND_PCM_STATE_PRIVATE1: continue; case SND_PCM_STATE_RUNNING: diff --git a/cwEuCon.cpp b/cwEuCon.cpp index cc34978..faa5ba9 100644 --- a/cwEuCon.cpp +++ b/cwEuCon.cpp @@ -606,7 +606,7 @@ namespace cw const char* name = (const char*)(u+6); const char* label = "MC Mix - "; - printf("%.*s|%li\n", name[0], name+1, strlen(label) ); + printf("%.*s|%i\n", name[0], name+1, strlen(label) ); // if this a 'MC Mix' DNS-SD SRV reply if( strncmp(label, name+1, strlen(label)) == 0 ) diff --git a/cwObject.cpp b/cwObject.cpp index adc4a15..be1a9b1 100644 --- a/cwObject.cpp +++ b/cwObject.cpp @@ -124,8 +124,8 @@ namespace cw void _objTypePrintUInt16( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.u16); } void _objTypePrintInt32( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.i32); } void _objTypePrintUInt32( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.u32); } - void _objTypePrintInt64( const object_t* o, print_ctx_t& c ) { printf("%li",o->u.i64); } - void _objTypePrintUInt64( const object_t* o, print_ctx_t& c ) { printf("%li",o->u.u64); } + void _objTypePrintInt64( const object_t* o, print_ctx_t& c ) { printf("%lli",o->u.i64); } + void _objTypePrintUInt64( const object_t* o, print_ctx_t& c ) { printf("%lli",o->u.u64); } void _objTypePrintBool( const object_t* o, print_ctx_t& c ) { printf("%s",o->u.b ? "true" : "false"); } void _objTypePrintFloat( const object_t* o, print_ctx_t& c ) { printf("%f",o->u.f); } void _objTypePrintDouble( const object_t* o, print_ctx_t& c ) { printf("%f",o->u.d); } diff --git a/cwUi.cpp b/cwUi.cpp index 5c759e1..17e3d9d 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -285,7 +285,7 @@ namespace cw { rc_t rc = kOkRC; const object_t* oo; - ele_t* parent_ele; + //ele_t* parent_ele; const char* jsId; // find the parent pair @@ -304,7 +304,7 @@ namespace cw //} - + return rc; }