104 |
{ |
{ |
105 |
state = off; |
state = off; |
106 |
} |
} |
107 |
|
|
108 |
|
|
109 |
char network_send_hello( unsigned char termid ) |
char network_send_hello( unsigned char termid ) |
110 |
{ |
{ |
111 |
char error = 0; |
char gotArp = 0; // if gotArp is 0, the embedded haven't talked to the server since boot. |
|
char gotArp = 0; |
|
112 |
static char isBound = 0; |
static char isBound = 0; |
113 |
|
if ( DHCPIsBound() && isBound == 0 ){ |
114 |
if ( DHCPIsBound() && isBound == 0 ){ |
state = DhcpIsBound; |
115 |
state = DhcpIsBound; |
isBound = 1; |
116 |
isBound = 1; |
} |
|
} |
|
|
|
|
117 |
switch (state) |
switch (state) |
118 |
{ |
{ |
119 |
case DhcpIsBound: |
case DhcpIsBound: |
150 |
return 0; |
return 0; |
151 |
|
|
152 |
case TcpSend: |
case TcpSend: |
153 |
for (i = net_INT; i >= 0; i--) |
TCPPut( tsock1, 0x00 ); |
154 |
{ |
TCPPut( tsock1, termid ); |
|
TCPPut(tsock1, termid ); |
|
|
} |
|
155 |
TCPFlush(tsock1); |
TCPFlush(tsock1); |
156 |
|
TCPDiscard( tsock1 ); |
157 |
|
|
158 |
|
|
159 |
state = TcpReadyToSend; |
state = TcpReadyToSend; |
160 |
return 0; |
return 0; |
161 |
} |
} |
162 |
return 1; |
return 1; |
163 |
} |
} |
164 |
/* |
|
165 |
void network_send_hello( unsigned char termid ) |
char network_send_scan_frame( unsigned char stregkode, unsigned char buflen ) |
166 |
{ |
{ |
167 |
if (DHCPIsBound()) |
switch (state) |
168 |
{ |
{ |
169 |
RA3 = 0; |
TCPPut( tsock1, 0x01 ); |
170 |
if (sock_open == 0) |
for (i = buflen; i >= 0; i--) |
171 |
{ |
{ |
172 |
if (ARPIsTxReady()) |
TCPPut(tsock1, stregkode ); |
173 |
{ |
} |
174 |
ARPResolve( &rnode.IPAddr); |
TCPFlush(tsock1); |
175 |
is_resolved = 1; |
state = TcpReadyToSend; |
176 |
} |
return 1; |
177 |
else |
} |
178 |
{ |
} |
179 |
if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr)) |
char network_send_goodbye(void) |
180 |
//if (MyArp( &rnode)) |
{ |
181 |
{ |
switch (state) |
182 |
usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP |
{ |
183 |
sock_open=1; |
case TcpReadyToSend: |
184 |
} |
if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) |
185 |
} |
state = TcpSend; |
186 |
} |
|
187 |
} |
case TcpSend: |
188 |
|
TCPPut( tsock1, 0x06 ); |
189 |
if (UDPIsPutReady(usock1) && datagrams_to_send>0) |
TCPFlush( tsock1 ); |
190 |
{ |
state = SockClosing; |
191 |
UDPPut( rnode.MACAddr.v[0] ); |
return 0; |
192 |
UDPPut( rnode.MACAddr.v[1] ); |
|
193 |
UDPPut( rnode.MACAddr.v[2] ); |
case SockClosing: |
194 |
UDPPut( rnode.MACAddr.v[3] ); |
TCPDisconnect( tsock1 ); |
195 |
UDPPut( rnode.MACAddr.v[4] ); |
state = SockClosed; |
196 |
UDPPut( rnode.MACAddr.v[5] ); |
return 1; |
197 |
UDPPut('D'); |
} |
198 |
UDPPut('a'); |
return 3; // Didn't close the socket properly; |
199 |
UDPPut('w'); |
} |
|
UDPPut(0); |
|
|
UDPFlush(); |
|
|
datagrams_to_send--; |
|
|
} |
|
|
} |
|
|
} |
|
|
*/ |
|
200 |
|
|
201 |
void main(void) |
void main(void) |
202 |
{ |
{ |
257 |
|
|
258 |
while(1) |
while(1) |
259 |
{ |
{ |
260 |
|
unsigned char antal = 8; |
261 |
|
unsigned char stregkode[] = "12345678"; |
262 |
/* |
/* |
263 |
* Blink SYSTEM LED every second. |
* Blink SYSTEM LED every second. |
264 |
*/ |
*/ |
280 |
* configuration since last reset. |
* configuration since last reset. |
281 |
*/ |
*/ |
282 |
|
|
283 |
a = network_send_hello( 1 ); |
a = network_send_hello( 0x01 ); |
284 |
/* if (DHCPIsBound()) |
// a = network_send_scan_frame( stregkode, antal ); |
285 |
{ |
a = network_send_goodbye(); |
286 |
RA3 =0; |
|
|
if (has_arp == 0) |
|
|
{ |
|
|
if (ARPIsTxReady()) |
|
|
{ |
|
|
if (is_resolved == 0) |
|
|
{ |
|
|
ARPResolve( &rnode.IPAddr); |
|
|
is_resolved = 1; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr)) |
|
|
{ |
|
|
has_arp = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
if (has_arp == 1) |
|
|
{ |
|
|
if (sock_state == 0) |
|
|
{ |
|
|
usock1=TCPConnect(&rnode,3000); |
|
|
sock_state = 1; |
|
|
} |
|
|
/* if (sock_state ==1 && TCPIsConnected(usock1) && TCPIsPutReady(usock1)) |
|
|
{ |
|
|
TCPPut(usock1,'D'); |
|
|
TCPPut(usock1,'a'); |
|
|
TCPPut(usock1,'w'); |
|
|
TCPPut(usock1,0); |
|
|
TCPFlush(usock1); |
|
|
sock_state = 2; |
|
|
} |
|
|
|
|
|
if (sock_state == 2 && TCPIsPutReady(usock1)) |
|
|
{ |
|
|
TCPDisconnect(usock1); |
|
|
lastTick = TickGet(); |
|
|
sock_state =3; |
|
|
} |
|
|
tick = TickGet(); |
|
|
diffTicks = TickGetDiff(tick, lastTick); |
|
|
|
|
|
if ( sock_state == 3 && diffTicks > ((TICK)TICK_SECOND * (TICK)2) ) |
|
|
sock_state = 0; |
|
|
|
|
|
} |
|
|
} */ |
|
287 |
} |
} |
288 |
} |
} |
289 |
|
|