int main(void) { /* Initialize CSP * Not interfacing to any external devices, so we don't need to register * a route */ printf("Initializing CSP\n"); csp_buffer_init(5, 256); csp_init(MY_ADDRESS); csp_route_start_task(500, 1); /* Initialize example threads */ printf("Starting example tasks\n"); csp_thread_handle_t handle_server; csp_thread_handle_t handle_client; csp_thread_create(csp_server, "CSPSRV", 1000, NULL, 0, &handle_server); csp_thread_create(csp_client, "CSPCLI", 1000, NULL, 0, &handle_client); while (1) { csp_sleep_ms(100000); } return 0; }
int main(int argc, char * argv[]) { /** * Initialise CSP, * No physical interfaces are initialised in this example,NjD * so only the loopback interface is registered. */ /* Init buffer system with 10 packets of maximum 300 bytes each */ printf("Initialising CSP\r\n"); csp_buffer_init(2, 300); /* Init CSP with address MY_ADDRESS */ csp_init(MY_ADDRESS); /* Start router task with 500 word stack, OS task priority 1 */ csp_route_start_task(500, 1); /* Enable debug output from CSP */ if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) { printf("Debug enabed\r\n"); csp_debug_toggle_level(4); printf("Conn table\r\n"); csp_conn_print_table(); printf("Route table\r\n"); csp_route_print_table(); printf("Interfaces\r\n"); csp_route_print_interfaces(); } /** * Initialise example threads, using pthreads. */ HANDLE threads[2]; /* Server */ printf("Starting Server task\r\n"); threads[0] = (HANDLE) _beginthreadex(NULL, 0, task_server, NULL, 0, 0); /* Client */ printf("Starting Client task\r\n"); threads[1] = (HANDLE) _beginthreadex(NULL, 0, task_client, NULL, 0, 0); /* Wait for execution to end, except that is never going to happen here */ WaitForMultipleObjects(2, threads, TRUE, INFINITE); return 0; }
int main(int argc, char * argv[]) { printf("Initialising CSP\r\n"); csp_buffer_init(10, 300); csp_init(MY_ADDRESS); csp_route_start_task(500, 1); printf(argv[1]); printf("Starting server task\r\n"); csp_thread_handle_t handle_server; csp_thread_create(task_server, (signed char *) "SERVER", 1000, NULL, 0, &handle_server); printf("Starting client task\r\n"); // csp_thread_handle_t handle_client; // csp_thread_create(task_client, (signed char *) "CLIENT", 1000, NULL, 0, &handle_client); /* while(1) { csp_sleep_ms(1000); csp_packet_t *packet; csp_conn_t *conn; packet = csp_buffer_get(10); if (packet == NULL) { printf("Failed to get buffer element\n"); return CSP_TASK_RETURN; } conn = csp_connect(CSP_PRIO_NORM, MY_ADDRESS, MY_PORT, 1000, CSP_O_NONE); if(conn == NULL) { printf("Connection failed\n"); csp_buffer_free(packet); return CSP_TASK_RETURN; } char *msg = "Hello world"; msg = argc; strcpy((char *) packet->data, msg); packet->length = strlen(msg); if (!csp_send(conn, packet, 1000)) { printf("Send failed\n"); csp_buffer_free(packet); } csp_close(conn); }*/ sendpacket(); while(1){ csp_sleep_ms(100000); } return 0; }
int main() { csp_buffer_init(10, 300); csp_init(MY_ADDRESS); csp_route_start_task(500,1); printf("Starting client task\r\n"); csp_thread_handle_t handle_client; csp_thread_create(task_client, (signed char *) "CLIENT", 1000, NULL, 0, &handle_client); while(1) { csp_sleep_ms(100000); } return 0; }
int main(int argc, char * argv[]) { /* Init buffer system with 10 packets of maximum 300 bytes each */ csp_buffer_init(2, 800); /* Init CSP with address MY_ADDRESS */ csp_init(MY_ADDRESS); /* Start router task with 500 word stack, OS task priority 1 */ csp_route_start_task(500, 1); /* Enable debug output from CSP */ if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) { printf("Debug eneabled\r\n"); csp_debug_toggle_level(4); printf("Conn table\r\n"); csp_conn_print_table(); printf("Route table\r\n"); csp_route_print_table(); printf("Interfaces\r\n"); csp_route_print_interfaces(); } int iret1, iret2; csp_thread_handle_t handle_server; iret1 = csp_thread_create(task_server, (signed char *) "SERVER", 1000, NULL, 0, &handle_server); csp_thread_handle_t handle_client; iret2 = csp_thread_create(task_client, (signed char *) "CLIENT", 1000, NULL, 0, &handle_client); pthread_join(handle_client, NULL); printf("Client thread returns: %d\n", iret2); pthread_join(handle_server, NULL); printf("Server thread returns: %d\n", iret1); return 0; }
int main(void) { k_uart_console_init(); #ifdef TARGET_LIKE_STM32 k_gpio_init(K_LED_GREEN, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_LED_ORANGE, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_LED_RED, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_LED_BLUE, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_BUTTON_0, K_GPIO_INPUT, K_GPIO_PULL_NONE); #endif #ifdef TARGET_LIKE_MSP430 k_gpio_init(K_LED_GREEN, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_LED_RED, K_GPIO_OUTPUT, K_GPIO_PULL_NONE); k_gpio_init(K_BUTTON_0, K_GPIO_INPUT, K_GPIO_PULL_UP); /* Stop the watchdog. */ WDTCTL = WDTPW + WDTHOLD; __enable_interrupt(); P2OUT = BIT1; #endif button_queue = xQueueCreate(10, sizeof(int)); csp_buffer_init(5, 100); csp_init(MY_ADDRESS); csp_route_start_task(500, 1); xTaskCreate(csp_server, "CSPSRV", configMINIMAL_STACK_SIZE, NULL, 2, NULL); xTaskCreate(csp_client, "CSPCLI", configMINIMAL_STACK_SIZE, NULL, 2, NULL); xTaskCreate(task_button_press, "BUTTON", configMINIMAL_STACK_SIZE, NULL, 3, NULL); xTaskCreate(task_echo, "ECHO", configMINIMAL_STACK_SIZE, NULL, 2, NULL); vTaskStartScheduler(); while (1); return 0; }
/* * Top level */ int main(int argc, char **argv) { struct server *s; log_init(".", DEBUG, EVENT); csp_init(); s = prepare_server("localhost", 6776); /* FIXME: get from the command line */ if (!s) { fprintf(stderr, "couldn't start server\n"); return 1; } event("SERVER_STARTED", ""); csp_spawn((process_fn) listen_loop, s); csp_start(); csp_exit(); log_exit(); return 0; }
int main(int argc, char *argv[]) { int me, other, type; char *message = "Testing CSP"; csp_socket_t *sock = NULL; csp_conn_t *conn = NULL; csp_packet_t *packet = NULL; /* Run as either server or client */ if (argc != 2) { printf("usage: server <server/client>\r\n"); return -1; } /* Set type */ if (strcmp(argv[1], "server") == 0) { me = 1; other = 2; type = TYPE_SERVER; } else if (strcmp(argv[1], "client") == 0) { me = 2; other = 1; type = TYPE_CLIENT; } else { printf("Invalid type. Must be either 'server' or 'client'\r\n"); return -1; } /* Init CSP and CSP buffer system */ if (csp_init(me) != CSP_ERR_NONE || csp_buffer_init(10, 300) != CSP_ERR_NONE) { printf("Failed to init CSP\r\n"); return -1; } if( type == TYPE_SERVER ) { _beginthreadex(NULL, 0, pipe_listener, NULL, 0, 0); } else { pipe = CreateFile( pipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if( pipe == INVALID_HANDLE_VALUE ) { printError(); return -1; } } /* Set default route and start router */ csp_route_set(CSP_DEFAULT_ROUTE, &csp_if_fifo, CSP_NODE_MAC); csp_route_start_task(0, 0); /* Create socket and listen for incoming connections */ if (type == TYPE_SERVER) { sock = csp_socket(CSP_SO_NONE); csp_bind(sock, PORT); csp_listen(sock, 5); } /* Super loop */ while (1) { if (type == TYPE_SERVER) { /* Process incoming packet */ conn = csp_accept(sock, 1000); if (conn) { packet = csp_read(conn, 0); if (packet) printf("Received: %s\r\n", packet->data); csp_buffer_free(packet); csp_close(conn); } } else { /* Send a new packet */ packet = csp_buffer_get(strlen(message)); if (packet) { strcpy((char *) packet->data, message); packet->length = strlen(message); conn = csp_connect(CSP_PRIO_NORM, other, PORT, 1000, CSP_O_NONE); printf("Sending: %s\r\n", message); if (!conn || !csp_send(conn, packet, 1000)) return -1; csp_close(conn); Sleep(1000); } } } return 0; }
int main(int argc, char **argv) { int me, other, type; char *message = "Testing CSP", *rx_channel_name, *tx_channel_name; csp_socket_t *sock; csp_conn_t *conn; csp_packet_t *packet; /* Run as either server or client */ if (argc != 2) { printf("usage: %s <server/client>\r\n", argv[0]); return -1; } /* Set type */ if (strcmp(argv[1], "server") == 0) { me = 1; other = 2; tx_channel_name = "server_to_client"; rx_channel_name = "client_to_server"; type = TYPE_SERVER; } else if (strcmp(argv[1], "client") == 0) { me = 2; other = 1; tx_channel_name = "client_to_server"; rx_channel_name = "server_to_client"; type = TYPE_CLIENT; } else { printf("Invalid type. Must be either 'server' or 'client'\r\n"); return -1; } /* Init CSP and CSP buffer system */ if (csp_init(me) != CSP_ERR_NONE || csp_buffer_init(10, 300) != CSP_ERR_NONE) { printf("Failed to init CSP\r\n"); return -1; } tx_channel = open(tx_channel_name, O_RDWR); if (tx_channel < 0) { printf("Failed to open TX channel\r\n"); return -1; } rx_channel = open(rx_channel_name, O_RDWR); if (rx_channel < 0) { printf("Failed to open RX channel\r\n"); return -1; } /* Start fifo RX task */ pthread_create(&rx_thread, NULL, fifo_rx, NULL); /* Set default route and start router */ csp_route_set(CSP_DEFAULT_ROUTE, &csp_if_fifo, CSP_NODE_MAC); csp_route_start_task(0, 0); /* Create socket and listen for incoming connections */ if (type == TYPE_SERVER) { sock = csp_socket(CSP_SO_NONE); csp_bind(sock, PORT); csp_listen(sock, 5); } /* Super loop */ while (1) { if (type == TYPE_SERVER) { /* Process incoming packet */ conn = csp_accept(sock, 1000); if (conn) { packet = csp_read(conn, 0); if (packet) printf("Received: %s\r\n", packet->data); csp_buffer_free(packet); csp_close(conn); } } else { /* Send a new packet */ packet = csp_buffer_get(strlen(message)); if (packet) { strcpy((char *) packet->data, message); packet->length = strlen(message); conn = csp_connect(CSP_PRIO_NORM, other, PORT, 1000, CSP_O_NONE); printf("Sending: %s\r\n", message); if (!conn || !csp_send(conn, packet, 1000)) return -1; csp_close(conn); } sleep(1); } } close(rx_channel); close(tx_channel); return 0; }