cwDnsSd.cpp,cwEuCon.cpp : Updates to support EuCon simulation.

This commit is contained in:
kpl 2020-02-29 00:15:18 -05:00
parent 9f2ccef9aa
commit 2710eb9ef7
2 changed files with 51 additions and 63 deletions

View File

@ -123,6 +123,9 @@ namespace cw
void tcpSendCallback( void* arg, const void* buf, unsigned bufByteN )
{
rc_t rc;
printf("Send:%i\n",bufByteN);
dnssd_t* p = (dnssd_t*)arg;
if((rc = srv::send(p->tcpH,buf,bufByteN)) != kOkRC )
cwLogError(rc,"TCP send failed.");
@ -239,7 +242,8 @@ namespace cw
free(formatStr);
p->dnsSd->gen_question();
//p->dnsSd->gen_question();
p->dnsSd->gen_response();
return rc;
}
@ -395,7 +399,7 @@ cw::rc_t cw::net::dnssd::start( handle_t h )
cw::rc_t cw::net::dnssd::test()
{
rc_t rc = kOkRC;
const char* netIFace = "wlp3s0";
const char* netIFace = "ens9";
const char* serviceName = "MC Mix - 1";
const char* serviceType = "_EuConProxy._tcp";
const char* serviceDomain = "local";
@ -427,9 +431,9 @@ cw::rc_t cw::net::dnssd::test()
//
// Override the host name and mac address to match the example Wireshark captures
//
strcpy(hostname,"Euphonix-MC-0090D580F4DE");
unsigned char tmp_mac[] = { 0x00, 0x90, 0xd5, 0x80, 0xf4, 0xde };
memcpy(hostMac,tmp_mac,6);
//strcpy(hostname,"Euphonix-MC-0090D580F4DE");
//unsigned char tmp_mac[] = { 0x00, 0x90, 0xd5, 0x80, 0xf4, 0xde };
//memcpy(hostMac,tmp_mac,6);
// create the DNS-SD server

View File

@ -348,14 +348,14 @@ namespace cw
return rc;
}
rc_t _send_response( socket::handle_t sockH, const char* packet )
rc_t _send_response( socket::handle_t sockH, const char* packet, unsigned packetN )
{
rc_t rc = kOkRC;
// send the initial handshake
if((rc = socket::send( sockH, packet, strlen(packet) )) != kOkRC )
if((rc = socket::send( sockH, packet, packetN )) != kOkRC )
{
rc = cwLogError(rc,"TCP '%s' request failed.");
rc = cwLogError(rc,"TCP '%s' send failed.");
}
return rc;
@ -363,40 +363,12 @@ namespace cw
rc_t _sendHandshake_0( socket::handle_t sockH, const char* label )
{
/*
rc_t rc = kOkRC;
unsigned char buf[88];
memset(buf,0,88);
buf[0] = 0x0a;
// send the initial handshake
if((rc = socket::send( sockH, buf, 88 )) != kOkRC )
{
rc = cwLogError(rc,"Initial TCP '%s' request failed.",label);
}
return rc;
*/
return _send_response(sockH,RESPONSE_1);
return _send_response(sockH,RESPONSE_1,sizeof(RESPONSE_1)-1);
}
rc_t _sendHandshake_1( socket::handle_t sockH )
{
/*
rc_t rc = kOkRC;
unsigned char buf[4];
memset(buf,0,4);
buf[0] = 0x0c;
// send the initial handshake
if((rc = socket::send( sockH, buf, 4 )) != kOkRC )
{
rc = cwLogError(rc,"TCP '%s' request failed.");
}
return rc;
*/
return _send_response(sockH,RESPONSE_2);
return _send_response(sockH,RESPONSE_2,sizeof(RESPONSE_2)-1);
}
@ -465,7 +437,7 @@ namespace cw
{
if( dataByteCnt >= 4 )
{
printHex(data,dataByteCnt);
//printHex(data,dataByteCnt);
unsigned hdr = *(const unsigned*)data;
@ -476,6 +448,7 @@ namespace cw
{
p->protoState = kWaitForHandshake_2_Id;
_sendHandshake_1( socketHandle(p->tcpH) );
printf("Rcvd Beat - sent 0xc\n");
}
break;
@ -483,41 +456,52 @@ namespace cw
if( hdr == 0x0d )
{
p->protoState = kResponse_3_A_Id;
printf("Rcvd 0xd\n");
}
break;
case kResponse_3_A_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_3_A);
p->protoState = kResponse_3_B_Id;
break;
case kResponse_3_B_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_3_B);
p->protoState = kResponse_4_A_Id;
break;
case kResponse_4_A_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_4_A);
p->protoState = kResponse_4_B_Id;
break;
case kResponse_4_B_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_4_B);
p->protoState = kRunning_Id;
break;
}
}
}
switch(p->protoState)
{
case kResponse_3_A_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_3_A,sizeof(RESPONSE_3_A)-1);
p->protoState = kResponse_3_B_Id;
break;
case kResponse_3_B_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_3_B,sizeof(RESPONSE_3_B)-1);
p->protoState = kResponse_4_A_Id;
break;
case kResponse_4_A_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_4_A,sizeof(RESPONSE_4_A)-1);
p->protoState = kResponse_4_B_Id;
break;
case kResponse_4_B_Id:
_send_response(socketHandle(p->tcpH),RESPONSE_4_B,sizeof(RESPONSE_4_B)-1);
p->protoState = kRunning_Id;
break;
case kRunning_Id:
printf("Rcv: %i : ",dataByteCnt );
for(unsigned i=0; i<dataByteCnt; ++i)
printf("0x%02x ",((uint8_t*)data)[i]);
printf("\n");
}
p->cbCnt+=1;
if( p->cbCnt % 20 == 0 )
{
time::spec_t t1;
time::get(t1);
unsigned ms = time::elapsedMs( &p->t0, &t1 );
printf("cb: %i %i\n",p->cbCnt,ms);
//unsigned ms = time::elapsedMs( &p->t0, &t1 );
//printf("cb: %i %i\n",p->cbCnt,ms);
}
}