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[]) { 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; }
void csp_client(void *p) { (void) p; csp_packet_t * packet; csp_conn_t * conn; portBASE_TYPE status; int signal; /** * Try ping */ csp_sleep_ms(200); #ifdef TARGET_LIKE_MSP430 blink(K_LED_RED); #else blink(K_LED_ORANGE); #endif int result = csp_ping(MY_ADDRESS, 100, 100, CSP_O_NONE); if (result) { #ifdef TARGET_LIKE_MSP430 blink(K_LED_RED); #else blink(K_LED_ORANGE); #endif } /** * Try data packet to server */ while (1) { status = xQueueReceive(button_queue, &signal, portMAX_DELAY); if (status != pdTRUE) { continue; } /* Get packet buffer for data */ packet = csp_buffer_get(100); if (packet == NULL) { /* Could not get buffer element */ return; } /* Connect to host HOST, port PORT with regular UDP-like protocol and 1000 ms timeout */ blink(K_LED_RED); conn = csp_connect(CSP_PRIO_NORM, MY_ADDRESS, MY_PORT, 1000, CSP_O_NONE); if (conn == NULL) { /* Connect failed */ /* Remember to free packet buffer */ csp_buffer_free(packet); return; } blink(K_LED_RED); /* Copy dummy data to packet */ char *msg = "Hello World"; strcpy((char *) packet->data, msg); /* Set packet length */ packet->length = strlen(msg); /* Send packet */ if (!csp_send(conn, packet, 1000)) { /* Send failed */ csp_buffer_free(packet); } blink(K_LED_RED); /* Close connection */ csp_close(conn); } }