Skip to content

Commit

Permalink
Assign SERVER TC PORT
Browse files Browse the repository at this point in the history
  • Loading branch information
Apaisal committed Sep 21, 2024
1 parent c202fcb commit ba8684d
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions examples/csp_server_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ int client_start(void);

/* Server port, the port the server listens on for incoming connections from the client. */
#define MY_SERVER_PORT 10
#define SERVER_TC_PORT 13
#define SERVER_ACK_PORT 14
#define SERVER_STATUS_PORT 15
#define SERVER_TC_PORT MY_SERVER_PORT

/* Commandline options */
static uint8_t server_address = 10;
Expand All @@ -46,6 +46,7 @@ void server(void) {

csp_packet_t *packet;
int dport;
// int sport;

csp_print("Server task started\n");

Expand All @@ -69,15 +70,16 @@ void server(void) {
continue;
}

/* Read packets on connection, timout is 1000 mS */
while ((packet = csp_read(conn, 1000)) != NULL) {
/* Read packets on connection, timout is 50 mS */
while ((packet = csp_read(conn, 50)) != NULL) {
dport = csp_conn_dport(conn);
// sport = csp_conn_sport(conn);
switch (dport) {
case SERVER_STATUS_PORT:
csp_print("Status received on PORT %d: %s\n", dport, (char *) packet->data);
csp_buffer_free(packet);
break;
case MY_SERVER_PORT:
case SERVER_TC_PORT:
/* Process packet here */
csp_print("Packet received on PORT %d: %s\n", dport, (char *) packet->data);
csp_buffer_free(packet);
Expand Down Expand Up @@ -119,22 +121,23 @@ void client(void) {

usleep(test_mode ? 200000 : 1000000);

while(successful_ping == 0) {
/* Send ping to server, timeout 1000 mS, ping size 10 bytes */
int result = csp_ping(server_address, 1000, 10, CSP_O_NONE);
csp_print("Ping address: %u, result %d [mS]\n", server_address, result);
// Increment successful_ping if ping was successful
if (result >= 0) {
++successful_ping;
}
else
{
/* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */
csp_reboot(server_address);
csp_print("reboot system request sent to address: %u\n", server_address);
}
/* Send ping to server, timeout 1000 mS, ping size 10 bytes */
int result = csp_ping(server_address, 1000, 10, CSP_O_NONE);
csp_print("Ping address: %u, result %d [mS]\n", server_address, result);
// Increment successful_ping if ping was successful
if (result >= 0) {
++successful_ping;
}
else
{
/* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */
csp_reboot(server_address);
csp_print("reboot system request sent to address: %u\n", server_address);
usleep(1000000);
continue;
}


/* Send data packet (string) to server */

/* 1. Get packet buffer for message/data */
Expand Down Expand Up @@ -185,17 +188,6 @@ void client(void) {

/* 5. Send packet */
csp_send(conn, packet);
packet = csp_read(conn, 1000);
if(packet != NULL){
int dp = csp_conn_dport(conn);
csp_print("ACK Packet recv on PORT (%d): %s (%ld)\n",
dp,
(char*) packet->data, packet->length);
}
else
{
successful_ping = 0;
}

/* 6. Close connection */
csp_buffer_free(packet);
Expand Down

0 comments on commit ba8684d

Please sign in to comment.