WIZnet provided easy Hardwired TCP/IP stack.
This is Internet Radio project needed easy stack for Transmit/Receiver from Radio Server.
Please see the YouTube file.
void InternetRadio_tcpc(uint8 s, uint16 port)
{
int32_t ret;
uint16 RSR_len;
uint16 received_len;
uint8 *data_buf = TX_BUF;
uint16 sentsize=0, i=0;
switch (getSn_SR(s))
{
case SOCK_ESTABLISHED: /* if connection is established */
if(RadioSocket_status==1)
{
printf("\r\nConnected Socket: %d\r\n",s);
//printf("\r\n RadioSocket_status=1\r\n");
//Delay_ms(1000);
ret = send(s, RadioRequest, sizeof(RadioRequest));
printf("\r\n Send RadioRequest protocol\r\n");
RadioSocket_status = 2;
}
if ((RSR_len = getSn_RX_RSR(s)) > 0) /* check Rx data */
{
if (RSR_len > DATA_BUF_SIZE) RSR_len = DATA_BUF_SIZE;
received_len = recv(s, data_buf, RSR_len); /* read the received data */
printf("\r\n Receive Data Num %d", received_len);
sentsize =0;
while(received_len != sentsize)
{
while (VS1003_Ready()==Bit_SET)
{
//printf("\r\n VS1003 Data process start\r\n");
for (i=0; i<received_len; i++)
{
VS1003_WriteData(data_buf[i]);
Delay_us(250);
Delay_us(30);
}
//Delay_ms(10);
sentsize += received_len;
if (sentsize>=received_len) return;
}
}
}
break;
case SOCK_CLOSE_WAIT: /* If the client request to close */
printf("\r\n%d : CLOSE_WAIT", s);
if ((RSR_len = getSn_RX_RSR(s)) > 0) /* check Rx data */
{
if (RSR_len > DATA_BUF_SIZE) RSR_len = DATA_BUF_SIZE;
ret = received_len = recv(s, data_buf, RSR_len);
}
RadioSocket_status = 0;
disconnect(s);
break;
case SOCK_CLOSED: /* if a socket is closed */
if(!RadioSocket_status)
{
printf("\r\n%d : Loop-Back TCP Client Started. port: %d\r\n", s, port);
RadioSocket_status = 1;
}
if(socket(s, Sn_MR_TCP, port++, 0x00) == 0) /* reinitialize the socket */
{
printf("\a%d : Fail to create socket.",s);
RadioSocket_status = 0;
any_port=port;
}
break;
case SOCK_INIT: /* if a socket is initiated */
connect(s, Dest_IP, Dest_PORT);
break;
default:
break;
}
}
Comments