cwEuCon.h/cpp : Implemented sendMsg() and use cwEuConDecls.h.
This commit is contained in:
parent
0ca908f7b8
commit
c36ba83b7b
84
cwEuCon.cpp
84
cwEuCon.cpp
@ -15,6 +15,7 @@
|
|||||||
#include "cwNumericConvert.h"
|
#include "cwNumericConvert.h"
|
||||||
|
|
||||||
#include "dns_sd/dns_sd_const.h"
|
#include "dns_sd/dns_sd_const.h"
|
||||||
|
#include "cwEuConDecls.h"
|
||||||
|
|
||||||
#define HEART_BEAT "\x04\x00\x00\x00"
|
#define HEART_BEAT "\x04\x00\x00\x00"
|
||||||
|
|
||||||
@ -335,7 +336,7 @@ namespace cw
|
|||||||
fbank_t* fbankL; // List of fader banks
|
fbank_t* fbankL; // List of fader banks
|
||||||
unsigned maxFaderBankN; // maximum number of fader banks
|
unsigned maxFaderBankN; // maximum number of fader banks
|
||||||
unsigned sockTimeOutMs; // socket time out
|
unsigned sockTimeOutMs; // socket time out
|
||||||
unsigned faderTcpPort; // Fader TCP port TODO: we shouuld be getting this from the MDNS SRV record
|
unsigned fdrTcpPort; // Fader TCP port TODO: we shouuld be getting this from the MDNS SRV record
|
||||||
unsigned heartBeatPeriodMs;
|
unsigned heartBeatPeriodMs;
|
||||||
} eucon_t;
|
} eucon_t;
|
||||||
|
|
||||||
@ -415,6 +416,39 @@ namespace cw
|
|||||||
{ return _send_response(fb,RESPONSE_2,sizeof(RESPONSE_2)-1); }
|
{ return _send_response(fb,RESPONSE_2,sizeof(RESPONSE_2)-1); }
|
||||||
|
|
||||||
|
|
||||||
|
rc_t _send_app_msg( fbank_t* fb, uint16_t chIdx, uint16_t msgTypeId, uint16_t value )
|
||||||
|
{
|
||||||
|
if( fb->protoState != kRunning_Id )
|
||||||
|
return kOkRC;
|
||||||
|
|
||||||
|
typedef struct fields_str
|
||||||
|
{
|
||||||
|
uint16_t channel;
|
||||||
|
uint16_t typeId;
|
||||||
|
uint16_t zero;
|
||||||
|
uint16_t value;
|
||||||
|
} fields_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
uint8_t buf[8];
|
||||||
|
fields_t f;
|
||||||
|
} u;
|
||||||
|
} buf_t;
|
||||||
|
|
||||||
|
uint16_t v = value;
|
||||||
|
|
||||||
|
buf_t b;
|
||||||
|
b.u.f.channel = chIdx;
|
||||||
|
b.u.f.typeId = msgTypeId;
|
||||||
|
b.u.f.zero = 0;
|
||||||
|
b.u.f.value = ((v & 0xff00) >> 8) + ((v & 0x00ff) << 8);
|
||||||
|
|
||||||
|
return _send_response(fb,(char*)(b.u.buf),sizeof(b.u.buf));
|
||||||
|
}
|
||||||
|
|
||||||
fbank_t* _createFBank( eucon_t* p, unsigned fbIndex )
|
fbank_t* _createFBank( eucon_t* p, unsigned fbIndex )
|
||||||
{
|
{
|
||||||
fbank_t* fb = mem::allocZ<fbank_t>();
|
fbank_t* fb = mem::allocZ<fbank_t>();
|
||||||
@ -473,12 +507,13 @@ namespace cw
|
|||||||
|
|
||||||
while( bi<bufByteN )
|
while( bi<bufByteN )
|
||||||
{
|
{
|
||||||
char type = 'U';
|
char type = 'U';
|
||||||
uint16_t numb = 0;
|
uint16_t numb = 0;
|
||||||
uint16_t id = 0;
|
uint16_t id = 0;
|
||||||
unsigned incr = 8;
|
unsigned incr = 8;
|
||||||
|
|
||||||
if( buf[bi] == 0x03 )
|
// if this is a heartbeat msg
|
||||||
|
if( buf[bi] == kChHb_EuProtoId )
|
||||||
{
|
{
|
||||||
type='H';
|
type='H';
|
||||||
incr = 4;
|
incr = 4;
|
||||||
@ -491,19 +526,19 @@ namespace cw
|
|||||||
|
|
||||||
switch(id )
|
switch(id )
|
||||||
{
|
{
|
||||||
case 0x00:
|
case kFPosnEuconId:
|
||||||
type = 'F';
|
type = 'F';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x01:
|
case kTouchEuconId:
|
||||||
type = 'T';
|
type = 'T';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x200:
|
case kMuteEuconId:
|
||||||
type = 'M';
|
type = 'M';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x400:
|
case kPingEuconId:
|
||||||
type = 'P';
|
type = 'P';
|
||||||
_send_response(fb,(const char*)(buf+bi),8);
|
_send_response(fb,(const char*)(buf+bi),8);
|
||||||
break;
|
break;
|
||||||
@ -513,7 +548,7 @@ namespace cw
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( type != 'F' && type != 'H' )
|
if( type != 'H' )
|
||||||
printf("%i %c (0x%x) %i (0x%x)\n",fb->fbIndex,type,id,numb,numb);
|
printf("%i %c (0x%x) %i (0x%x)\n",fb->fbIndex,type,id,numb,numb);
|
||||||
|
|
||||||
bi += incr;
|
bi += incr;
|
||||||
@ -563,19 +598,19 @@ namespace cw
|
|||||||
switch( fb->protoState )
|
switch( fb->protoState )
|
||||||
{
|
{
|
||||||
case kWaitForHandshake_1_Id:
|
case kWaitForHandshake_1_Id:
|
||||||
if( hdr == 0x0b )
|
if( hdr == kHs1_b_EuProtoId )
|
||||||
{
|
{
|
||||||
fb->protoState = kWaitForHandshake_2_Id;
|
fb->protoState = kWaitForHandshake_2_Id;
|
||||||
_sendHandshake_1( fb );
|
_sendHandshake_1( fb );
|
||||||
printf("%i : Rcvd (0x0b) HS 1 - sent 0x0c\n", fb->fbIndex);
|
cwLogInfo("%i : Rcvd (0x0b) HS 1 - sent 0x0c\n", fb->fbIndex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kWaitForHandshake_2_Id:
|
case kWaitForHandshake_2_Id:
|
||||||
if( hdr == 0x0d )
|
if( hdr == kHs3_d_EuProtoId )
|
||||||
{
|
{
|
||||||
fb->protoState = kResponse_3_A_Id;
|
fb->protoState = kResponse_3_A_Id;
|
||||||
printf("%i : Rcvd (0x0d) HS 2 - Sending setup data\n",fb->fbIndex);
|
cwLogInfo("%i : Rcvd (0x0d) HS 2 - Sending setup data\n",fb->fbIndex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -662,7 +697,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, p->faderTcpPort )) != kOkRC )
|
if((rc = sock::create( p->sockMgrH, fb->sockUserId, sock::kInvalidPortNumber, tcpFlags, p->sockTimeOutMs, _tcpCallback, p, fbIP, p->fdrTcpPort )) != 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;
|
||||||
@ -751,7 +786,7 @@ cw::rc_t cw::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;
|
p->fdrTcpPort = args.fdrTcpPort;
|
||||||
p->heartBeatPeriodMs = args.heartBeatPeriodMs;
|
p->heartBeatPeriodMs = args.heartBeatPeriodMs;
|
||||||
hRef.set(p);
|
hRef.set(p);
|
||||||
|
|
||||||
@ -842,11 +877,20 @@ cw::rc_t cw::eucon::getMsgs( handle_t h, msgCallback_t cbFunc, void* cbArg )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cw::rc_t cw::eucon::sendMsg( handle_t h, unsigned flags, unsigned channel, unsigned ivalue, float fvalue )
|
cw::rc_t cw::eucon::sendMsg( handle_t h, unsigned fbIndex, unsigned fbChIndex, unsigned msgTypeId, unsigned value )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
//eucon_t* p = _handleToPtr(h);
|
|
||||||
|
eucon_t* p = _handleToPtr(h);
|
||||||
|
|
||||||
|
fbank_t* fb = p->fbankL;
|
||||||
|
while( fb != nullptr )
|
||||||
|
if( fb->fbIndex == fbIndex )
|
||||||
|
{
|
||||||
|
rc = _send_app_msg(fb, fbChIndex, msgTypeId, value );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,7 +974,7 @@ cw::rc_t cw::eucon::test()
|
|||||||
args.mdnsPort = 5353;
|
args.mdnsPort = 5353;
|
||||||
args.sockTimeOutMs = 50;
|
args.sockTimeOutMs = 50;
|
||||||
args.maxFaderBankN = 8;
|
args.maxFaderBankN = 8;
|
||||||
args.faderTcpPort = 49168;
|
args.fdrTcpPort = 49168;
|
||||||
args.maxSockN = 50;
|
args.maxSockN = 50;
|
||||||
args.heartBeatPeriodMs = 4000;
|
args.heartBeatPeriodMs = 4000;
|
||||||
|
|
||||||
|
17
cwEuCon.h
17
cwEuCon.h
@ -5,6 +5,7 @@ namespace cw
|
|||||||
{
|
{
|
||||||
namespace eucon
|
namespace eucon
|
||||||
{
|
{
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kUdpSockUserId=1,
|
kUdpSockUserId=1,
|
||||||
@ -16,13 +17,13 @@ namespace cw
|
|||||||
|
|
||||||
typedef struct args_str
|
typedef struct args_str
|
||||||
{
|
{
|
||||||
unsigned recvBufByteN; // Socket receive buffer size
|
unsigned recvBufByteN; // Socket receive buffer size
|
||||||
const char* mdnsIP; // MDNS IP (always: "224.0.0.251")
|
const char* mdnsIP; // MDNS IP (always: "224.0.0.251")
|
||||||
sock::portNumber_t mdnsPort; // MDNS port (always 5353)
|
sock::portNumber_t mdnsPort; // MDNS port (always 5353)
|
||||||
unsigned sockTimeOutMs; // socket poll time out in milliseconds (also determines the cwEuCon update rate)
|
unsigned sockTimeOutMs; // socket poll time out in milliseconds (also determines the cwEuCon update rate)
|
||||||
sock::portNumber_t faderTcpPort; // Fader TCP port (e.g. 49168)
|
sock::portNumber_t fdrTcpPort; // Fader TCP port (e.g. 49168)
|
||||||
unsigned maxSockN; // maximum number of socket to allow in the socket manager
|
unsigned maxSockN; // maximum number of socket to allow in the socket manager
|
||||||
unsigned maxFaderBankN; // maximum number of fader banks to support
|
unsigned maxFaderBankN; // maximum number of fader banks to support
|
||||||
unsigned heartBeatPeriodMs; // time between heart-beat messages from/to the fader banks
|
unsigned heartBeatPeriodMs; // time between heart-beat messages from/to the fader banks
|
||||||
} args_t;
|
} args_t;
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ namespace cw
|
|||||||
|
|
||||||
// Send a message to the EuCon manager or to a physical control.
|
// Send a message to the EuCon manager or to a physical control.
|
||||||
// Note that flags is formed by <msgTId> | <msgFlags>
|
// Note that flags is formed by <msgTId> | <msgFlags>
|
||||||
rc_t sendMsg( handle_t h, unsigned flags, unsigned channel, unsigned ivalue, float fvalue );
|
rc_t sendMsg( handle_t h, unsigned fbIndex, unsigned fbChIndex, unsigned msgTypeId, unsigned value );
|
||||||
|
|
||||||
|
|
||||||
rc_t test();
|
rc_t test();
|
||||||
|
Loading…
Reference in New Issue
Block a user