2017-11-06 22:36:44 +00:00
|
|
|
#include <cc65.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../inc/ip65.h"
|
|
|
|
|
|
|
|
#define LEN 500
|
|
|
|
#define SRV "192.168.0.10"
|
|
|
|
|
|
|
|
unsigned char buf[1500];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
void error_exit(void)
|
|
|
|
{
|
|
|
|
printf("Error $%X\n", ip65_error);
|
|
|
|
if (doesclrscrafterexit())
|
|
|
|
{
|
|
|
|
printf("Press any key\n");
|
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-11-07 22:05:05 +00:00
|
|
|
void tcp_recv(const unsigned char* tcp_buf, int tcp_len)
|
2017-11-06 22:36:44 +00:00
|
|
|
{
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-11-07 22:05:05 +00:00
|
|
|
len = tcp_len;
|
2017-11-06 22:36:44 +00:00
|
|
|
if (len != -1)
|
|
|
|
{
|
2017-11-07 22:05:05 +00:00
|
|
|
memcpy(buf, tcp_buf, len);
|
2017-11-06 22:36:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned long srv;
|
|
|
|
char key;
|
|
|
|
|
|
|
|
if(!(srv = parse_dotted_quad(SRV)))
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Init\n");
|
2019-05-02 12:44:24 +00:00
|
|
|
if (ip65_init(ETH_INIT_DEFAULT))
|
2017-11-06 22:36:44 +00:00
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("DHCP\n");
|
|
|
|
if (dhcp_init())
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("IP Addr: %s\n", dotted_quad(cfg_ip));
|
|
|
|
printf("Netmask: %s\n", dotted_quad(cfg_netmask));
|
|
|
|
printf("Gateway: %s\n", dotted_quad(cfg_gateway));
|
|
|
|
printf("DNS Srv: %s\n", dotted_quad(cfg_dns));
|
|
|
|
|
|
|
|
printf("Connect to %s\n", SRV);
|
|
|
|
if (tcp_connect(srv, 6502, tcp_recv))
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("(T)CP or e(X)it\n");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (kbhit())
|
|
|
|
{
|
|
|
|
key = cgetc();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == 't')
|
|
|
|
{
|
|
|
|
printf("Send Len %d", LEN);
|
|
|
|
for (i = 0; i < LEN; ++i)
|
|
|
|
{
|
|
|
|
buf[i] = i;
|
|
|
|
}
|
|
|
|
if (tcp_send(buf, LEN))
|
|
|
|
{
|
|
|
|
printf("!\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf(".\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 21:57:15 +00:00
|
|
|
ip65_process();
|
|
|
|
|
2017-11-06 22:36:44 +00:00
|
|
|
if (len == -1)
|
|
|
|
{
|
|
|
|
printf("Disconnect\n");
|
|
|
|
}
|
|
|
|
else if (len)
|
|
|
|
{
|
|
|
|
printf("Recv Len %d", len);
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
if ((i % 11) == 0)
|
|
|
|
{
|
|
|
|
ip65_process();
|
2017-11-07 21:57:15 +00:00
|
|
|
|
2017-11-06 22:36:44 +00:00
|
|
|
printf("\n$%04X:", i);
|
|
|
|
}
|
|
|
|
printf(" %02X", buf[i]);
|
|
|
|
}
|
|
|
|
len = 0;
|
|
|
|
printf(".\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (key != 'x' && len != -1);
|
|
|
|
|
|
|
|
printf("Close\n");
|
|
|
|
if (tcp_close())
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Done\n");
|
|
|
|
}
|