Skip to content

Commit 83e0418

Browse files
committed
2 parents e4d05c6 + 9dec964 commit 83e0418

File tree

5 files changed

+31
-79
lines changed

5 files changed

+31
-79
lines changed

Xenon/CompileProd.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
make CROSS_COMPILE=xenon-
3+
mv Xenon.elf32 xenon.elf

Xenon/Xenon.elf

1.17 MB
Binary file not shown.

Xenon/source/server.c

Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,38 @@
11
#include "server.h"
22
#include "controller.h"
33

4-
void conn_err(void *arg, err_t err) {
5-
printf("error!\n");
6-
}
7-
8-
void close_conn(struct tcp_pcb *pcb) {
9-
tcp_arg(pcb, NULL);
10-
tcp_sent(pcb, NULL);
11-
tcp_recv(pcb, NULL);
12-
tcp_poll(pcb, NULL, 0);
13-
tcp_err(pcb, NULL);
14-
tcp_close(pcb);
15-
}
164

175

18-
void reply_controller_data(struct tcp_pcb* pcb) {
19-
unsigned char* buffer = (unsigned char*)malloc(14); // 14 bytes for controller data, see controller.c for more info
20-
read_controller_data(buffer);
21-
tcp_write(pcb, buffer, 14, 0);
22-
tcp_sent(pcb, NULL); // no cb
23-
}
246

25-
void accept_controller_data(unsigned char* buffer) {
7+
void udp_server_recv(void *arg, struct udp_pcb *pcb, struct pbuf* p, struct ip_addr *addr, u16_t port) {
8+
9+
LWIP_UNUSED_ARG(arg);
10+
if(p == NULL)
11+
return;
12+
unsigned char* data = (unsigned char*)p->payload;
13+
unsigned char command = data[0];
14+
pbuf_free(p);
15+
if(command == 1) {
16+
unsigned char* cdata_buffer = (unsigned char*)malloc(14);
17+
read_controller_data(cdata_buffer);
18+
struct pbuf* t_pbuf = pbuf_alloc(PBUF_TRANSPORT, 14, PBUF_REF);
19+
t_pbuf->payload = cdata_buffer;
20+
t_pbuf->len = t_pbuf->tot_len = 14;
21+
udp_sendto(pcb, t_pbuf, addr, port);
22+
pbuf_free(t_pbuf);
23+
free(cdata_buffer);
24+
}else if(command == 2) {
25+
//TODO: turn console off
26+
}else if(command == 3) {
27+
write_controller_data(data + 1);
28+
}
2629

27-
write_controller_data(buffer);
2830
}
2931

30-
err_t server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) {
31-
32-
if(err == ERR_OK && p != NULL){
33-
//Inform about data being taken
34-
tcp_recved(pcb, p->tot_len);
35-
36-
37-
unsigned char command = ((unsigned char*)p->payload)[0];
38-
if(command == 1) {
39-
reply_controller_data(pcb);
40-
}else if(command == 2) {
41-
close_conn(pcb);
42-
}else if(command == 3) {
43-
accept_controller_data((unsigned char*)p->payload + 1);
44-
}
45-
46-
pbuf_free(p);
47-
48-
tcp_sent(pcb, NULL);
49-
50-
}else if(err == ERR_OK && p == NULL){
51-
close_conn(pcb);
52-
}else {
53-
return err;
54-
}
55-
return ERR_OK;
56-
57-
}
58-
59-
err_t server_accept(void *arg, struct tcp_pcb *pcb, err_t err) {
60-
LWIP_UNUSED_ARG(arg);
61-
LWIP_UNUSED_ARG(err);
62-
tcp_setprio(pcb, TCP_PRIO_MIN);
63-
64-
tcp_arg(pcb, NULL);
65-
tcp_recv(pcb, server_recv);
66-
tcp_err(pcb, conn_err);
67-
tcp_poll(pcb, NULL, 0); // no polling
68-
return ERR_OK;
69-
}
7032

7133
void start_server(void) {
7234

73-
listen_pcb = tcp_new();
74-
tcp_bind(listen_pcb, IP_ADDR_ANY, 1182);
75-
76-
listen_pcb = tcp_listen(listen_pcb);
77-
tcp_accept(listen_pcb, server_accept);
35+
upcb = udp_new();
36+
udp_bind(upcb, IP_ADDR_ANY, 1182);
37+
udp_recv(upcb, udp_server_recv, NULL);
7838
}
79-
80-
81-
82-
83-
84-

Xenon/source/server.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#include <network/network.h>
2-
#include <lwip/tcp.h>
2+
#include <lwip/udp.h>
33
#include <stdlib.h>
44

55
#ifndef _S360_H_
66
#define _S360_H_
77

8-
struct tcp_pcb* listen_pcb;
8+
struct udp_pcb* upcb;
99

10-
void conn_err(void *arg, err_t err);
11-
void close_conn(struct tcp_pcb *pcb);
12-
void reply_controller_data(struct tcp_pcb* pcb);
13-
void accept_controller_data(unsigned char* buffer);
14-
err_t server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
15-
err_t server_accept(void *arg, struct tcp_pcb *pcb, err_t err);
10+
void udp_server_recv(void *arg, struct udp_pcb *pcb, struct pbuf* p, struct ip_addr *addr, u16_t port);
1611
void start_server(void);
1712

1813
#endif

Xenon/xenon.elf

261 KB
Binary file not shown.

0 commit comments

Comments
 (0)