unsigned char net_receive() { if (!com_check()) return NET_NOTHING; com_connect(); unsigned char cCommand = com_get_command(); switch (cCommand) { case (CMD_MA_OUT): com_receive_chunk(&com_receive_buffer_size); com_disconnect(); return NET_RECEIVED; break; case (CMD_MA_REQ): sbi(COM_INT_PORT, COM_INT_PIN); com_config(BUS_OUTPUT); com_send_chunk(com_send_buffer_size); com_disconnect(); return NET_SENT; break; } return NET_NOTHING; }
void net_send(uint8_t uiLen) { com_connect(); com_set_command(CMD_MA_OUT); com_config(BUS_OUTPUT); com_send_chunk(uiLen); com_disconnect(); }
// Process to connect with URG int urg_connect(urg_state_t* state, const char* port, const long baudrate) { const long try_baudrate[] = { 19200,57600,115200 }; for (size_t i = 0; i < sizeof(try_baudrate)/sizeof(try_baudrate[0]); ++i) { com_connect(port,try_baudrate[i]); int recv_n = 0; urg_sendMessage("SCIP2.0", Timeout, &recv_n); if (recv_n <= 0) { // If there is no reply it is considered as baud rate incompatibility, try with different baud rate com_disconnect(); continue; } // Change the baud rate if not match the setting if (try_baudrate[i] != baudrate) { urg_changeBaudrate(baudrate); com_disconnect(); com_connect(port,baudrate); } // Read parameter if (urg_getParameters(state) < 0) { ErrorMessage = "PP command fail."; return -1; } state->last_timestamp = 0; urg_changeMotor(5); // URG is detected return 0; } // URG is not detected return -1; }
void net_receive() { if (!com_check()) return; com_connect(); com_set_command(CMD_MA_REQ); com_config(BUS_INPUT); uint8_t uiLen =0; com_receive_chunk(&uiLen); com_disconnect(); cDataReq = 0; sbi(GICR,INT0); uiLen = parser_parse(); net_send(uiLen); }
/* ************************************************************************************************** * main ************************************************************************************************** * Main function ************************************************************************************************** * Params: * std main params ************************************************************************************************** */ int main(int argc, char **argv) { int res; srand((unsigned long)time(NULL)); /* if (fork()) exit(0); */ atexit(quit_do_cleanup); signal(SIGINT, quit_got_signal); signal(SIGTERM, quit_got_signal); signal(SIGHUP, sighup_rehash); if ((res = conf_load())) quit_service(res); if ((res = log_open())) quit_service(res); log_command(LOG_SERVICES, NULL, "", "Services startup"); log_write("#############################################################################\n"); if ((res = dbase_load_persistant())) quit_service(res); if ((res = queue_init())) quit_service(res); help_load(); nickserv_dbase_checkold(NULL); chanserv_dbase_check_expire(NULL); pthread_mutex_init(&sock_mutex, NULL); irc = com_sock_create(SOCK_SERVER); if (!com_connect(irc)) quit_service(ERROR_SERVER_COULD_NOT_CONNECT); irc->buffer[0] = '\0'; res = com_mainloop(); pthread_mutex_destroy(&sock_mutex); quit_service(res); return res; }
/**** Main program ***********************************************************/ int main( int argc, char *argv[]) { char Buffer[MAXBUFFERSIZE]; printf("Khepera3 server program (C) K-Team S.A\r\n"); if(!initKH3()) { printf("Init ok...\r\n"); kh3_revision((char *)Buffer, dsPic); printf("\r\n%c,%4.4u,%4.4u => Version = %u, Revision = %u\r\n", Buffer[0], (Buffer[1] | Buffer[2]<<8), (Buffer[3] | Buffer[4]<<8), (Buffer[1] | Buffer[2]<<8), (Buffer[3] | Buffer[4]<<8)); if (argc == 2) { strcpy(Buffer,argv[1]); // use serial port given by parameter } else { strcpy(Buffer,SERIAL_PORT); // copy default } // open serial port if ((porthandle=com_connect(Buffer,BAUDRATE))<0) { printf("\nError: Serial port %s could not be open!\n",Buffer); return -1; } printf("\nParsing commands from serial port %s, baudrate %ld.\nPush CTRL-C for quitting!\n",Buffer,VAL_BAUDRATE); // loop while (!quitReq) { #ifdef DEBUG printf("\n> "); #endif process_command(); } printf("Exiting...\r\n"); } else printf("Fatal error, unable to initialize\r\n"); // close serial port if (porthandle>=0) close(porthandle); return 0; }
int main(int argc,char* argv[]) { com_config_t cfg; vp_com_connection_t conn; printf("---------- Network Adapter Inquiry ----------\n"); com_networkAdapterLookUp(COM_BLUETOOTH,adapterinquiry_df); printf("---------------------------------------------\n"); cfg.connection = COM_BLUETOOTH; cfg.localAdapterName = DEVICENAME; cfg.localIpAddress = LOCALHOST; cfg.localIpSubmask = "255.255.255.0"; printf("--------------- INITIALISATION --------------\n"); if(FAILED(com_init(&cfg))) { printf("Failed to init\n"); com_shutdown(); return -1; } /* printf("----------- Remote Device Inquiry -----------\n"); com_inquire(deviceinquiry,60000); printf("---------------------------------------------\n"); */ printf("---------- Tentative de connection ----------\n"); com_strToAddress(BTADDR_SERVER,&conn.address); com_passKey("1234"); if(FAILED(com_connect(&conn,1))) { printf("Failed to connect\n"); com_shutdown(); return -1; } printf("Connected to BTT\n"); printf("---------- BNEP Connection ----------\n"); {// Test d'execution bnep com_socket_t socket; Read read; socket.socket = VP_COM_CLIENT; socket.protocol = COM_BNEP; socket.serverHost = SERVERHOST; socket.port = BTADDR_PORT; if(SUCCEED(com_open(&socket,&read,0))) { char buffer[10]; int r = 10; printf("Connection BNEP succeeded\n"); if(SUCCEED(read((void*)&socket,buffer,&r))) printf("Read succeed\n"); printf("socket closed\n"); com_close(&socket); } } sleep(1); printf("---------- RFCOMM Connection ----------\n"); {// Test d'execution rfcomm com_socket_t socket; Write write; socket.socket = VP_COM_CLIENT; socket.protocol = COM_RFCOMM; socket.scn = BTADDR_SCN; if(SUCCEED(com_open(&socket,0,&write))) { char buffer[10]; int r = 10; printf("Connection RFCOMM succeeded\n"); if(SUCCEED(write((void*)&socket,buffer,&r))) printf("Write succeed\n"); printf("socket closed\n"); com_close(&socket); } } sleep(1); printf("Deconnection\n"); com_disconnect(); printf("End of program\n"); com_shutdown(); return 0; }
int main(void) { com_config_t config; vp_com_connection_t connection; config.connection = VP_COM_WIFI; config.localAdapterName = "rausb0"; connection.essid = "Drone"; connection.channel = 10; if(FAILED(com_init(&config))) PRINT("com_init failed\n"); if(FAILED(com_passKey("9F1C3EE11CBA230B27BF1C1B6F"))) PRINT("com_passKey failed\n"); if(FAILED(com_connect(&connection,1))) PRINT("com_connect failed\n"); clt.socket = VP_COM_CLIENT; clt.port = DRONE_PORT; clt.serverHost = DRONE_HOST; if(SUCCEED(com_open(&clt,&my_read,&my_write))) { int32_t i = 0; float st = timeGetTime(); float et = timeGetTime(); float db = 0.0f; float d = 0.0f; for(i=0; i < TIME_TO_SEND;i++) { int32_t received; PRINT("\r reception n° %d... ",i); received = 0; size = SIZE_TO_SEND; while(received != SIZE_TO_SEND) { my_read(&clt,buffer,&size); received += size; size = SIZE_TO_SEND - received; } PRINT("%d bytes ",received); } et = timeGetTime(); d = (et - st) / 1000.0f; if(d > 0) { float tx = SIZE_TO_SEND * TIME_TO_SEND / 1024.0f; db = tx / d; } PRINT("\n---------------\n"); PRINT("Start Time : %f\n",st); PRINT("End Time : %f\n",et); PRINT("%d Kbytes sent in %f time\n",SIZE_TO_SEND * TIME_TO_SEND / 1024,d); PRINT("Debit: %f\n",db); PRINT("\n---------------\n"); } else { PRINT("snif... pas connecte a la socket\n"); } PRINT("Waiting for disconnection\n"); vp_delay(5000); com_disconnect(); PRINT("Disconnected\n"); com_shutdown(); return 0; }