cwDnsSd, dns_sd/ : Updates to integrate Arduino version with Linux version.
This commit is contained in:
parent
8c685cb517
commit
3c9d4282cd
13
cwDnsSd.cpp
13
cwDnsSd.cpp
@ -145,7 +145,7 @@ namespace cw
|
||||
|
||||
if( dataByteCnt > 0 )
|
||||
{
|
||||
p->fdr->receive( data, dataByteCnt );
|
||||
p->fdr->receive_from_eucon( data, dataByteCnt );
|
||||
}
|
||||
|
||||
time::spec_t t1;
|
||||
@ -166,6 +166,12 @@ namespace cw
|
||||
}
|
||||
}
|
||||
|
||||
// Called by 'fader' to send messages to change the state of the physical control.
|
||||
void physControlCallback( void* arg, const uint8_t* buf, uint8_t bufByteN )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void _pushTextRecdField( dnssd_t* p, const char* text )
|
||||
{
|
||||
text_t* t = mem::allocZ<text_t>();
|
||||
@ -234,7 +240,7 @@ namespace cw
|
||||
p->dnsSd = new dns_sd(udpSendCallback,p,print_callback);
|
||||
|
||||
// create the Surface logic object
|
||||
p->fdr = new fader(print_callback, p->hostMac, hostAddr.sin_addr.s_addr, tcpSendCallback, p, p->ticksPerHeartBeat );
|
||||
p->fdr = new fader(print_callback, p->hostMac, hostAddr.sin_addr.s_addr, tcpSendCallback, p, physControlCallback, p, p->ticksPerHeartBeat );
|
||||
|
||||
// Setup the internal dnsSd object
|
||||
p->dnsSd->setup( p->serviceName, p->serviceType, p->serviceDomain, p->hostName, hostAddr.sin_addr.s_addr, p->hostPort, formatStr );
|
||||
@ -255,6 +261,7 @@ cw::rc_t cw::net::dnssd::createV( handle_t& hRef, const char* name, const char*
|
||||
rc_t rc = kOkRC;
|
||||
unsigned udpRecvBufByteN = 4096;
|
||||
unsigned udpTimeOutMs = 50;
|
||||
unsigned tcpRecvBufByteN = 4096;
|
||||
unsigned tcpTimeOutMs = 50;
|
||||
|
||||
if((rc = destroy(hRef)) != kOkRC )
|
||||
@ -287,6 +294,8 @@ cw::rc_t cw::net::dnssd::createV( handle_t& hRef, const char* name, const char*
|
||||
if((rc = set_multicast_time_to_live( socketHandle(p->udpH), 255 )) != kOkRC )
|
||||
goto errLabel;
|
||||
|
||||
p->tcpRecvBufByteN = tcpRecvBufByteN;
|
||||
|
||||
// create the service TCP socket server
|
||||
if((rc = srv::create(
|
||||
p->tcpH,
|
||||
|
@ -7,7 +7,8 @@
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <utility/util.h>
|
||||
#include <Ethernet.h>
|
||||
#include <utility/w5100.h>
|
||||
#endif
|
||||
|
||||
#include "rpt.h"
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef cwLINUX
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef ARDUINO
|
||||
#include <utility/util.h>
|
||||
#include <Ethernet.h>
|
||||
#include <utility/w5100.h>
|
||||
#endif
|
||||
|
||||
#include "rpt.h"
|
||||
|
377
dns_sd/fader.cpp
377
dns_sd/fader.cpp
@ -11,33 +11,51 @@
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <utility/util.h>
|
||||
#include <Ethernet.h>
|
||||
#include <utility/w5100.h>
|
||||
#endif
|
||||
|
||||
fader::msgRef_t fader::_msgRefA[] =
|
||||
{
|
||||
{ 0x0a, 88 },
|
||||
{ 0x0c, 6 },
|
||||
{ 0x00, 8 },
|
||||
{ 0x19, 1044 },
|
||||
{ 0x04, 4 },
|
||||
{ 0xff, 0 } // end-of-list sentinel (both id and byteN are invalid)
|
||||
{ 0x0a, 88 }, // initial handshake
|
||||
{ 0x0c, 4 }, // secondary handshake
|
||||
{ 0x00, 8 }, //
|
||||
{ 0x19, 1044 }, // 0x19 messages are variable length
|
||||
{ 0x04, 4 }, //
|
||||
{ 0xff, 0 } // end-of-list sentinel (both id and byteN are invalid)
|
||||
};
|
||||
|
||||
fader::fader( printCallback_t printCbFunc, const unsigned char faderMac[6], uint32_t faderInetAddr, hostCallback_t hostCbFunc, void* hostCbArg, unsigned ticksPerHeartBeat, unsigned chN )
|
||||
: _printCbFunc(printCbFunc), _inetAddr(faderInetAddr),_tickN(0),_chArray(nullptr),_hostCbFunc(hostCbFunc),_hostCbArg(hostCbArg),_protoState(kWaitForHandshake_0_Id),_ticksPerHeartBeat(ticksPerHeartBeat),_msgTypeId(0xff),_msgByteIdx(0),_msgByteN(0)
|
||||
fader::fader(
|
||||
printCallback_t printCbFunc,
|
||||
const unsigned char faderMac[6],
|
||||
uint32_t faderInetAddr,
|
||||
euConCbFunc_t euconCbFunc,
|
||||
void* euconCbArg,
|
||||
physCtlCbFunc_t physCtlCbFunc,
|
||||
void* physCtlCbArg,
|
||||
unsigned ticksPerHeartBeat,
|
||||
unsigned chN )
|
||||
: _printCbFunc(printCbFunc),
|
||||
_inetAddr(faderInetAddr),
|
||||
_tickN(0),
|
||||
_chArray(nullptr),
|
||||
_euconCbFunc(euconCbFunc),
|
||||
_euconCbArg(euconCbArg),
|
||||
_physCtlCbFunc(physCtlCbFunc),
|
||||
_physCtlCbArg(physCtlCbArg),
|
||||
_protoState(kWaitForHandshake_0_Id),
|
||||
_ticksPerHeartBeat(ticksPerHeartBeat),
|
||||
_msgTypeId(0xff),
|
||||
_msgByteIdx(0),
|
||||
_msgByteN(0),
|
||||
_mbi(0)
|
||||
{
|
||||
memcpy(_mac,faderMac,6);
|
||||
|
||||
_chArray = new ch_t[chN];
|
||||
_chN = chN;
|
||||
for(unsigned i=0; i<chN; ++i)
|
||||
{
|
||||
_chArray[i].position = 0;
|
||||
_chArray[i].muteFl = false;
|
||||
_chArray[i].incrFl = true;
|
||||
_chArray[i].touchFl = false;
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
fader::~fader()
|
||||
@ -45,102 +63,120 @@ fader::~fader()
|
||||
delete[] _chArray;
|
||||
}
|
||||
|
||||
void fader::reset()
|
||||
{
|
||||
_protoState = kWaitForHandshake_0_Id;
|
||||
_msgTypeId = 0xff;
|
||||
_msgByteIdx = 0;
|
||||
_msgByteN = 0;
|
||||
_mbi = 0;
|
||||
|
||||
for(unsigned i=0; i<_chN; ++i)
|
||||
{
|
||||
_chArray[i].position = 0;
|
||||
_chArray[i].muteFl = false;
|
||||
_chArray[i].touchFl = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fader::rc_t fader::receive( const void* buf, unsigned bufByteN )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
fader::rc_t fader::receive_from_eucon( const void* buf, unsigned bufByteN )
|
||||
{
|
||||
|
||||
rc_t rc = kOkRC;
|
||||
const uint8_t* b = (const uint8_t*)buf; // current msg ptr
|
||||
const uint8_t* bend = b + bufByteN; // end of buffer ptr
|
||||
|
||||
printf("RECV:%i\n",bufByteN);
|
||||
|
||||
while(b<bend)
|
||||
{
|
||||
// if this is the start of a new msg
|
||||
if( _msgByteN == 0 )
|
||||
{
|
||||
// if this is an 0x19 msg which started on the previous packet
|
||||
if( _msgTypeId == 0x19 )
|
||||
{
|
||||
// if not already filled
|
||||
for(int i=0; (_msgByteIdx+i < 8) && ((b+i)<bend); ++i)
|
||||
_msg[_msgByteIdx+i] = b[i];
|
||||
|
||||
// get the count of bytes associated with this 0x19 msg
|
||||
_msgByteN = _get_eucon_msg_byte_count( _msgTypeId, _msg, _msg+8 );
|
||||
|
||||
//rpt(_printCbFunc,"0x19 end: %i\n",_msgByteN);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_msgTypeId = b[0]; // the first byte always contains the type of the msg
|
||||
_msgByteIdx = 0; // empty the _msg[] index
|
||||
_msgByteN = _get_eucon_msg_byte_count( _msgTypeId, b, bend ); // get the length of this mesg
|
||||
|
||||
// if this is a type 0x19 msg then we have to wait 8 bytes for the msg byte count
|
||||
if( _msgByteN == 0 && _msgTypeId == 0x19 )
|
||||
{
|
||||
//_printCbFunc("0x19 begin\n");
|
||||
_msgByteIdx = bend - b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store the size and type of this message
|
||||
_msgTypeId = b[0];
|
||||
_msgByteN = _get_msg_byte_count( _msgTypeId );
|
||||
_msgByteIdx = 0;
|
||||
|
||||
if( _msgByteN == 0 && _msgTypeId != 0x19 )
|
||||
{
|
||||
rpt(_printCbFunc,"Unk Type:0x%x %i\n",_msgTypeId,bufByteN);
|
||||
break;
|
||||
}
|
||||
|
||||
//rpt(_printCbFunc,"T:0x%x %i\n",_msgTypeId,_msgByteN);
|
||||
}
|
||||
|
||||
// if this is a channel message
|
||||
if( _msgTypeId == 0 )
|
||||
// if this is a channel message or the start of a 0x19 msg ...
|
||||
if( _msgTypeId == 0 || (_msgTypeId == 0x19 && _msgByteN==0) )
|
||||
{
|
||||
for(int i=0; _msgByteIdx < sizeof(_msg) && b+i<bend; ++i,++_msgByteIdx)
|
||||
_msg[_msgByteIdx] = b[i];
|
||||
// copy it into _msg[]
|
||||
for(int i=0; (_msgByteIdx+i < 8) && ((b+i)<bend); ++i)
|
||||
_msg[_msgByteIdx+i] = b[i];
|
||||
}
|
||||
|
||||
// if the end, (and possibly the beginning) of the current msg is fully contained in the buffer ...
|
||||
if( (_msgByteN - _msgByteIdx) <= (bend-b) )
|
||||
if( (_msgByteN - _msgByteIdx) <= (bend - b) )
|
||||
{
|
||||
_on_msg_complete(_msgTypeId);
|
||||
b += _msgByteN - _msgByteIdx; // then we have reached the end of the msg
|
||||
_on_eucon_recv_msg_complete(_msgTypeId);
|
||||
b += _msgByteN - _msgByteIdx; // then we have reached the end of the msg
|
||||
_msgByteN = 0;
|
||||
_msgByteIdx = 0;
|
||||
_msgTypeId = 0xff;
|
||||
}
|
||||
else // this msg overflows to the next TCP packet
|
||||
{
|
||||
_msgByteIdx += bend-b;
|
||||
b = bend;
|
||||
//_printCbFunc("Ovr:\n");
|
||||
_msgByteIdx += bend - b;
|
||||
b = bend;
|
||||
}
|
||||
}
|
||||
//rpt(_printCbFunc,"D:\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
fader::rc_t fader::receive_old( const void* buf, unsigned bufByteN )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
const uint8_t* b = (const uint8_t*)buf;
|
||||
|
||||
switch( _protoState )
|
||||
{
|
||||
case kWaitForHandshake_0_Id: // wait for [ 0x0a ... ]
|
||||
if( bufByteN>0 && b[0] == 10 )
|
||||
{
|
||||
_printCbFunc("HS 0 ");
|
||||
_send_response_0(); // send [ 0x0b ... ]
|
||||
_protoState = kWaitForHandshake_Tick_Id;
|
||||
}
|
||||
break;
|
||||
|
||||
case kWaitForHandshake_Tick_Id: // wait for next tick() - send first heart-beat
|
||||
break;
|
||||
|
||||
case kWaitForHandshake_1_Id: // wait for next message after heart-beat - send [ 0x0d, .... ]
|
||||
_printCbFunc("HS 1 ");
|
||||
_send_response_1();
|
||||
_protoState = kWaitForHeartBeat_Id;
|
||||
break;
|
||||
|
||||
case kWaitForHeartBeat_Id:
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
fader::rc_t fader::tick()
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
|
||||
switch( _protoState )
|
||||
{
|
||||
case kWaitForHandshake_0_Id:
|
||||
break;
|
||||
|
||||
{
|
||||
case kWaitForHandshake_Tick_Id:
|
||||
_printCbFunc("HS Tick ");
|
||||
_send_heartbeat();
|
||||
//_printCbFunc("HS Tick ");
|
||||
_send_heartbeat_to_eucon();
|
||||
_protoState = kWaitForHandshake_1_Id;
|
||||
break;
|
||||
|
||||
case kWaitForHandshake_0_Id:
|
||||
case kWaitForHandshake_1_Id:
|
||||
break;
|
||||
|
||||
case kWaitForHeartBeat_Id:
|
||||
//_auto_incr_fader(0);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -149,40 +185,63 @@ fader::rc_t fader::tick()
|
||||
{
|
||||
_tickN = 0;
|
||||
if( _protoState == kWaitForHeartBeat_Id )
|
||||
_send_heartbeat();
|
||||
_send_heartbeat_to_eucon();
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
fader::rc_t fader::physical_fader_touched( uint16_t chanIdx )
|
||||
{
|
||||
(void)chanIdx;
|
||||
return kOkRC;
|
||||
}
|
||||
|
||||
fader::rc_t fader::physical_fader_moved( uint16_t chanIdx, uint16_t value )
|
||||
void fader::physical_control_changed( const uint8_t msg[3] )
|
||||
{
|
||||
(void)chanIdx;
|
||||
(void)value;
|
||||
return kOkRC;
|
||||
}
|
||||
|
||||
fader::rc_t fader::physical_mute_switched( uint16_t chanIdx, uint16_t value )
|
||||
{
|
||||
(void)chanIdx;
|
||||
(void)value;
|
||||
return kOkRC;
|
||||
}
|
||||
// TODO: mask off invalid values (e.g. chan>7, value>0x3ff)
|
||||
|
||||
void fader::_send_response_0()
|
||||
uint8_t type = (msg[0] & 0x70) >> 4;
|
||||
uint8_t chan = (msg[0] & 0x0f);
|
||||
uint16_t value = msg[1];
|
||||
|
||||
value <<= 7;
|
||||
value += msg[2];
|
||||
|
||||
rpt(_printCbFunc,"T:%i Ch:%i V:%x\n",type,chan,value);
|
||||
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case kPhysTouchTId:
|
||||
_send_touch_to_eucon(chan,value != 0);
|
||||
break;
|
||||
|
||||
case kPhysFaderTId:
|
||||
_send_fader_to_eucon(chan,value);
|
||||
break;
|
||||
|
||||
case kPhysMuteTId:
|
||||
_send_mute_to_eucon(chan,value == 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
rpt(_printCbFunc,"Unknown physical ctl id.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void fader::_send_to_eucon( const void* buf, unsigned bufByteN )
|
||||
{
|
||||
return _euconCbFunc(_euconCbArg,buf,bufByteN);
|
||||
}
|
||||
|
||||
|
||||
void fader::_send_response_0_to_eucon()
|
||||
{
|
||||
unsigned char buf[] =
|
||||
{ 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x02,0x03,0xfc,0x01,0x05,
|
||||
0x06,0x00,
|
||||
0x38,0xc9,0x86,0x37,0x44,0xe7, // mac: offset 16
|
||||
0x00,0x00,0x00,0x00,0x00,0x00, // mac: offset 16
|
||||
0x01,0x00,
|
||||
0xc0,0xa8,0x00,0x44, // ip: offset 24
|
||||
0x00,0x00,0x00,0x00, // ip: offset 24
|
||||
0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
@ -190,98 +249,69 @@ void fader::_send_response_0()
|
||||
0x00,0x00
|
||||
};
|
||||
|
||||
// set the mac address
|
||||
memcpy(buf+16,_mac,6);
|
||||
|
||||
// set the 32 bit ip address
|
||||
memcpy((unsigned char *)(buf+24),(unsigned char*)&_inetAddr, 4);
|
||||
|
||||
_send(buf,sizeof(buf));
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
void fader::_send_response_1()
|
||||
void fader::_send_response_1_to_eucon()
|
||||
{
|
||||
unsigned char buf[] = { 0x0d,0x00,0x00,0x00, 0x00,0x00,0x00,0x08 };
|
||||
|
||||
_send(buf,sizeof(buf));
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
void fader::_send_heartbeat()
|
||||
void fader::_send_heartbeat_to_eucon()
|
||||
{
|
||||
const unsigned char buf[] = { 0x03, 0x00, 0x00, 0x00 };
|
||||
_send(buf,sizeof(buf));
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
void fader::_send( const void* buf, unsigned bufByteN )
|
||||
|
||||
void fader::_send_fader_to_eucon( uint16_t chIdx, uint16_t pos )
|
||||
{
|
||||
return _hostCbFunc(_hostCbArg,buf,bufByteN);
|
||||
_chArray[chIdx].position = pos;
|
||||
if( _chArray[chIdx].touchFl )
|
||||
{
|
||||
uint16_t buf[] = { htons(chIdx),htons(0), 0, htons(pos) };
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
}
|
||||
|
||||
void fader::_on_fader_receive( uint16_t chanIdx, uint16_t value )
|
||||
{
|
||||
(void)chanIdx;
|
||||
(void)value;
|
||||
}
|
||||
|
||||
void fader::_on_mute_receive( uint16_t chanIdx, bool value )
|
||||
{
|
||||
(void)chanIdx;
|
||||
(void)value;
|
||||
}
|
||||
|
||||
void fader::_send_fader( uint16_t chIdx )
|
||||
{
|
||||
uint16_t buf[] = { htons(chIdx),htons(0), 0, htons(_chArray[chIdx].position) };
|
||||
_send(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
void fader::_send_touch( uint16_t chIdx, bool touchFl )
|
||||
void fader::_send_touch_to_eucon( uint16_t chIdx, uint16_t touchFl )
|
||||
{
|
||||
_chArray[chIdx].touchFl = touchFl;
|
||||
uint16_t buf[] = { htons(chIdx),htons(1),0, htons((uint16_t)touchFl) };
|
||||
_send(buf,sizeof(buf));
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
void fader::_send_mute( uint16_t chIdx, bool muteFl )
|
||||
void fader::_send_mute_to_eucon( uint16_t chIdx, uint16_t muteFl )
|
||||
{
|
||||
_chArray[chIdx].muteFl = muteFl;
|
||||
uint16_t buf[] = { htons(chIdx),htons(0x200),0, htons((uint16_t)(!muteFl)) };
|
||||
_send(buf,sizeof(buf));
|
||||
_send_to_eucon(buf,sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
void fader::_auto_incr_fader( uint16_t chIdx )
|
||||
uint16_t fader::_get_eucon_msg_byte_count( uint8_t msgTypeId, const uint8_t* b, const uint8_t* bend )
|
||||
{
|
||||
ch_t* ch = _chArray+chIdx;
|
||||
|
||||
if( ch->position == 0 && ch->touchFl==false )
|
||||
if( msgTypeId == 0x19 )
|
||||
{
|
||||
_send_touch(chIdx,true);
|
||||
}
|
||||
|
||||
if( ch->position > 1023 )
|
||||
{
|
||||
ch->position = 1023;
|
||||
ch->incrFl = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ch->position < 0 )
|
||||
const uint16_t* u = (const uint16_t*)b;
|
||||
if( bend < (const uint8_t*)(u+4) )
|
||||
{
|
||||
ch->position = 0;
|
||||
ch->incrFl = true;
|
||||
_send_touch( chIdx, !ch->touchFl );
|
||||
_send_mute( chIdx, !ch->touchFl );
|
||||
//_printCbFunc("0x19 short\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t v = u[3];
|
||||
return ntohs(v);
|
||||
}
|
||||
|
||||
if( ch->touchFl )
|
||||
_send_fader(chIdx);
|
||||
|
||||
ch->position += ch->incrFl ? 5 : -5;
|
||||
|
||||
}
|
||||
|
||||
uint8_t fader::_get_msg_byte_count( uint8_t msgTypeId )
|
||||
{
|
||||
for(int i=0; _msgRefA[i].byteN != 0; ++i)
|
||||
if( msgTypeId == _msgRefA[i].id )
|
||||
return _msgRefA[i].byteN;
|
||||
@ -289,12 +319,20 @@ uint8_t fader::_get_msg_byte_count( uint8_t msgTypeId )
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fader::_handleChMsg(const uint8_t* msg)
|
||||
void fader:: _send_to_phys_control( uint8_t ctlTypeId, uint8_t ch, uint16_t value )
|
||||
{
|
||||
uint8_t msg[3];
|
||||
|
||||
msg[0] = 0x80 + (ctlTypeId << 4) + (ch); // status byte always has high bit set
|
||||
msg[1] = (uint8_t)((value & 0x3f80) >> 7); // get high 7 bits of value (high bit is always cleared)
|
||||
msg[2] = (uint8_t)(value & 0x007f); // get low 7 bits of value (high bit is always cleared)
|
||||
|
||||
_physCtlCbFunc( _physCtlCbArg, msg, sizeof(msg) );
|
||||
}
|
||||
|
||||
|
||||
// called when a new msg is received, b[0] is the msg type id
|
||||
void fader::_on_msg_complete( const uint8_t typeId )
|
||||
void fader::_on_eucon_recv_msg_complete( const uint8_t typeId )
|
||||
{
|
||||
switch( typeId )
|
||||
{
|
||||
@ -302,21 +340,48 @@ void fader::_on_msg_complete( const uint8_t typeId )
|
||||
if( _protoState == kWaitForHandshake_0_Id )
|
||||
{
|
||||
_printCbFunc("HS 0 ");
|
||||
_send_response_0(); // send [ 0x0b ... ]
|
||||
_send_response_0_to_eucon(); // send [ 0x0b ... ]
|
||||
_protoState = kWaitForHandshake_Tick_Id;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0c:
|
||||
//rpt(_printCbFunc,"HB\n");
|
||||
break;
|
||||
|
||||
case 0x00:
|
||||
{
|
||||
const uint16_t* u = (const uint16_t*)_msg;
|
||||
uint8_t ch = _msg[1];
|
||||
if( ch < 8 )
|
||||
{
|
||||
switch( ntohs(u[1]) )
|
||||
{
|
||||
case 0:
|
||||
_chArray[ch].position = ntohs(u[3]);
|
||||
//rpt(_printCbFunc,"F: %2i %4i \n",(int)_msg[1],ntohs(u[3]));
|
||||
_send_to_phys_control(kPhysFaderTId,ch,ntohs(u[3]));
|
||||
|
||||
break;
|
||||
|
||||
case 0x201:
|
||||
_chArray[ch].muteFl = ntohs(u[3]);
|
||||
//rpt(_printCbFunc,"M: %2i %4i \n",(int)_msg[1],ntohs(u[3]));
|
||||
_send_to_phys_control(kPhysMuteTId,ch,ntohs(u[3]));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
//rpt(_printCbFunc,"HB:\n");
|
||||
break;
|
||||
|
||||
case 0x19:
|
||||
//rpt(_printCbFunc,"Skip:\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -327,8 +392,8 @@ void fader::_on_msg_complete( const uint8_t typeId )
|
||||
// kWaitForHandshake_1_Id to kWaitForHeartBeat_Id
|
||||
if( _protoState == kWaitForHandshake_1_Id )
|
||||
{
|
||||
_printCbFunc("HS 1 ");
|
||||
_send_response_1(); //send [ 0x0d, .... ]
|
||||
_printCbFunc("HS 1\n ");
|
||||
_send_response_1_to_eucon(); //send [ 0x0d, .... ]
|
||||
_protoState = kWaitForHeartBeat_Id;
|
||||
}
|
||||
|
||||
|
109
dns_sd/fader.h
109
dns_sd/fader.h
@ -2,17 +2,6 @@
|
||||
#define fader_h
|
||||
|
||||
|
||||
/*
|
||||
1. wait for 0x0a packet
|
||||
send_response_0()
|
||||
wait 50 ms
|
||||
send_heart_beat()
|
||||
2. wait for next host packet
|
||||
send_response_1()
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class fader
|
||||
{
|
||||
public:
|
||||
@ -23,27 +12,39 @@ public:
|
||||
kUnknownMsgRC
|
||||
} rc_t;
|
||||
|
||||
// Function to send TCP messages to the host.
|
||||
typedef void (*hostCallback_t)( void* arg, const void* buf, unsigned bufByteN );
|
||||
// Callback function to send TCP messages to the EuCon.
|
||||
typedef void (*euConCbFunc_t)( void* arg, const void* buf, unsigned bufByteN );
|
||||
|
||||
// Callback function to send virtual control change messages to the physical controls.
|
||||
typedef void (*physCtlCbFunc_t)( void* arg, const uint8_t* buf, uint8_t bufByteN );
|
||||
|
||||
fader(
|
||||
printCallback_t printCbFunc,
|
||||
const unsigned char faderMac[6],
|
||||
uint32_t faderInetAddr,
|
||||
euConCbFunc_t euConCbFunc,
|
||||
void* euConCbArg,
|
||||
physCtlCbFunc_t physCtlCbFunc,
|
||||
void* physCtlCbArg,
|
||||
unsigned ticksPerHeartBeat,
|
||||
unsigned chN = 8 );
|
||||
|
||||
fader( printCallback_t printCbFunc, const unsigned char faderMac[6], uint32_t faderInetAddr, hostCallback_t hostCbFunc, void* cbArg, unsigned ticksPerHeartBeat, unsigned chN = 8 );
|
||||
virtual ~fader();
|
||||
|
||||
void reset();
|
||||
|
||||
// Called by the TCP receive function to update the faders state
|
||||
// based on host state changes.
|
||||
// based on EuCon state changes.
|
||||
// Return kUnknownMsgRC if the received msg is not recognized.
|
||||
rc_t receive( const void* buf, unsigned bufByteN );
|
||||
rc_t receive_old( const void* buf, unsigned bufByteN );
|
||||
rc_t receive_from_eucon( const void* buf, unsigned bufByteN );
|
||||
|
||||
// Called by the application to drive time dependent functions.
|
||||
// Return kTimeOut if the protocol state machine has timed out.
|
||||
rc_t tick();
|
||||
|
||||
// Call these function to generate messages to the host when
|
||||
// the controls physical state changes.
|
||||
rc_t physical_fader_touched( uint16_t chIdx );
|
||||
rc_t physical_fader_moved( uint16_t chIdx, uint16_t newPosition );
|
||||
rc_t physical_mute_switched( uint16_t chIdx, uint16_t newMuteFl );
|
||||
// Call when a physical control changes value.
|
||||
void physical_control_changed( const uint8_t msg[3] );
|
||||
|
||||
|
||||
rc_t virtual_fader_moved( uint16_t chIdx, uint16_t newPosition );
|
||||
rc_t virtual_mute_switched( uint16_t chIdx, uint16_t newMuteFl );
|
||||
@ -57,55 +58,65 @@ private:
|
||||
kWaitForHeartBeat_Id
|
||||
} protoState_t;
|
||||
|
||||
enum
|
||||
{
|
||||
kPhysTouchTId = 0,
|
||||
kPhysFaderTId = 1,
|
||||
kPhysMuteTId = 2
|
||||
};
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t position;
|
||||
bool muteFl;
|
||||
bool incrFl;
|
||||
bool touchFl;
|
||||
int16_t muteFl;
|
||||
int16_t touchFl;
|
||||
|
||||
} ch_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t id; // message prefix - identifies the type of message
|
||||
uint16_t byteN; // length of the message in bytes
|
||||
int byteN; // length of the message in bytes
|
||||
} msgRef_t;
|
||||
|
||||
static msgRef_t _msgRefA[];
|
||||
|
||||
|
||||
printCallback_t _printCbFunc;
|
||||
uint32_t _inetAddr;
|
||||
unsigned _tickN;
|
||||
ch_t* _chArray;
|
||||
unsigned _chN;
|
||||
hostCallback_t _hostCbFunc;
|
||||
void* _hostCbArg;
|
||||
uint32_t _inetAddr;
|
||||
unsigned _tickN;
|
||||
ch_t* _chArray;
|
||||
unsigned _chN;
|
||||
euConCbFunc_t _euconCbFunc;
|
||||
void* _euconCbArg;
|
||||
physCtlCbFunc_t _physCtlCbFunc;
|
||||
void* _physCtlCbArg;
|
||||
|
||||
protoState_t _protoState;
|
||||
unsigned char _mac[6];
|
||||
unsigned _ticksPerHeartBeat;
|
||||
|
||||
uint8_t _msgTypeId; //
|
||||
unsigned _msgByteIdx; // current index into the message being parsed.
|
||||
unsigned _msgByteN; // count of bytes in the message currently being parsed
|
||||
unsigned char _msg[8]; //
|
||||
uint8_t _msgTypeId; // first byte of the current TCP message
|
||||
int _msgByteIdx; // current index into the TCP message being parsed.
|
||||
int _msgByteN; // count of bytes in the message currently being parsed
|
||||
unsigned _mbi;
|
||||
unsigned char _msg[8]; // hold the last 8 bytes of the current incoming TCP messages
|
||||
// (we need these bytes when waiting to determine the length of '0x19' type messages)
|
||||
|
||||
void _send_response_0();
|
||||
void _send_response_1();
|
||||
void _send_heartbeat();
|
||||
void _send( const void* buf, unsigned bufByteN );
|
||||
void _on_fader_receive( uint16_t chanIdx, uint16_t position );
|
||||
void _on_mute_receive( uint16_t chanIdx, bool muteFl );
|
||||
void _send_fader( uint16_t chIdx );
|
||||
void _send_touch( uint16_t chIdx, bool touchFl );
|
||||
void _send_mute( uint16_t chIdx, bool muteFl );
|
||||
void _auto_incr_fader( uint16_t chIdx );
|
||||
void _send_to_eucon( const void* buf, unsigned bufByteN );
|
||||
|
||||
void _send_response_0_to_eucon();
|
||||
void _send_response_1_to_eucon();
|
||||
void _send_heartbeat_to_eucon();
|
||||
void _send_fader_to_eucon( uint16_t chIdx, uint16_t position );
|
||||
void _send_touch_to_eucon( uint16_t chIdx, uint16_t touchFl );
|
||||
void _send_mute_to_eucon( uint16_t chIdx, uint16_t muteFl );
|
||||
|
||||
|
||||
uint8_t _get_msg_byte_count( uint8_t msgTypeId );
|
||||
void _handleChMsg(const uint8_t* msg);
|
||||
void _on_msg_complete( const uint8_t typeId );
|
||||
uint16_t _get_eucon_msg_byte_count( uint8_t msgTypeId, const uint8_t* b, const uint8_t* bend );
|
||||
void _send_to_phys_control( uint8_t ctlTypeId, uint8_t ch, uint16_t value );
|
||||
void _on_eucon_recv_msg_complete( const uint8_t typeId );
|
||||
|
||||
|
||||
};
|
||||
|
@ -3,15 +3,16 @@
|
||||
|
||||
#include "rpt.h"
|
||||
|
||||
#define RPT_BUF_N 64
|
||||
char RPT_BUF[ RPT_BUF_N ];
|
||||
|
||||
void vrpt( printCallback_t printCbFunc, const char* fmt, va_list vl )
|
||||
{
|
||||
if( printCbFunc != nullptr )
|
||||
{
|
||||
const int bufN = 32;
|
||||
char buf[bufN];
|
||||
vsnprintf(buf,bufN,fmt,vl);
|
||||
buf[bufN-1] = '\0';
|
||||
printCbFunc(buf);
|
||||
vsnprintf(RPT_BUF,RPT_BUF_N,fmt,vl);
|
||||
RPT_BUF[RPT_BUF_N-1] = '\0';
|
||||
printCbFunc(RPT_BUF);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user