C_RESULT run_com_server(COM_PROTOCOL protocol) { srv.socket = COM_SERVER; srv.protocol = protocol; if(protocol == COM_RFCOMM) { srv.scn = BTADDR_SCN; } else if(protocol == COM_BNEP) { srv.port = BTADDR_PORT; srv.serverHost = SERVERHOST; } else return C_FAIL; if(FAILED(com_open(&srv,&read,&write))) return C_FAIL; com_passKey(PIN_CODE); if(FAILED(com_accept(&srv,&clt))) return C_FAIL; return C_OK; }
STATUS_E download_images(const struct image *download_agent, const struct image *download_agent_TCM, const struct image *nor_flash_table, const struct image *nand_flash_table, const struct image *download_EPP, const struct image *bootLoader, const struct image *extBootLoader, const struct image *dspBootLoader, const struct image *rom, const struct image *secondRom, const struct image *dspRom, const struct image *demand_paging_rom, struct image *linux_images, const struct ExternalMemorySetting *externalMemorySetting, unsigned int num_linux_images, unsigned int bmt_address, int isUSB, int isNFB) { COM_HANDLE com_handle = INVALID_COM_HANDLE; STATUS_E status; if(isUSB){ int retry = 0; while(1) { Sleep(100); //if (com_open(&com_handle, 19200) == COM_STATUS_DONE) if (com_open(&com_handle, 115200) == COM_STATUS_DONE) { log_output("handle (%d)\n", com_handle); log_feedback("SUCCESS:handle port (%d)\n",com_handle); break; }else{ log_output("faile handle (%d)\n", com_handle); log_feedback("FAIL:handle port (%d)\n",com_handle); com_close(&com_handle); if (++retry > 10) return S_COM_PORT_OPEN_FAIL; } } }else{ if (com_open(&com_handle, 115200) != COM_STATUS_DONE) { log_output("Failed to open the communication port\n"); return S_COM_PORT_OPEN_FAIL; } } status = bootrom_stage(com_handle, download_agent,download_agent_TCM, download_EPP, externalMemorySetting, isUSB, isNFB); if (status != S_DONE) { log_output("Download failed in BootROM stage: error=%u\n", status); //com_close(&com_handle); return status; } status = da_stage(com_handle, nor_flash_table, nand_flash_table, bootLoader,extBootLoader,dspBootLoader, rom, secondRom, dspRom, demand_paging_rom, linux_images, num_linux_images, isUSB, isNFB, bmt_address); if (status != S_DONE) { log_output("Download failed in DA stage: error=%u\n", status); //com_close(&com_handle); //Sleep(5000); return status; } log_feedback("FINISHED UPDATE"); log_output("FINISHED UPDATAE!\n"); if (com_close(&com_handle) != COM_STATUS_DONE) { log_output("Failed to close the communication port\n"); //Sleep(5000); } //Sleep(5000); return S_DONE; }
void main() { int e_flag; /* event flag */ int rc; /* function return code */ char buffer[BUFLEN+2]; /* general buffer */ char prompt[BUFLEN+2]; /* prompt buffer */ int prlen; int length; long tstart; /* open com port */ rc = com_open( (int*) &e_flag, 1200); if ( rc != 0) { printf("\nOPEN failed!\n"); printf("error code = %d\n",rc); abort_test(); } /* setup prompt string */ strcpy(prompt, "\r\nEnter string: "); prlen = strlen(prompt); /* prompt and read until "quit" is typed */ buffer[0] = NULCH; while (strcmp(buffer,"quit\r\n") != 0) { /* display the prompt */ e_flag = 0; rc = com_write((char*) prompt, (int*) &prlen); if (rc != 0) { printf("\nerror displaying prompt!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on prompt\n"); printf("event flag not set\n"); exit(); } } /* read a string */ length = BUFLEN-1; e_flag = 0; rc = com_read((char*) buffer, (int*) &length); if (rc != 0) { printf("\nerror reading string!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until input is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > RD_TIME_LIMIT) { printf("\ntimeout on input\n"); printf("event flag not set\n"); abort_test(); } } /* display the input string */ e_flag = 0; if (buffer[length-1] == '\n') { buffer[length-1] = NULCH; length--; } strcat(buffer,"\r\n"); length = length + 2; printf("%s",buffer); rc = com_write((char*) buffer, (int*) &length); if (rc != 0) { printf("\nerror displaying string!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on output\n"); printf("event flag not set\n"); abort_test(); } } } /* end of while loop */ /* print final message */ e_flag = 0; length = 29; printf("\nEnd of Com Driver IO Test\n"); rc = com_write((char*) "\r\nEnd of Com Driver IO Test\r\n", (int*) &length); if (rc != 0) { printf("\nWRITE error on final message!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > WR_TIME_LIMIT) { printf("\ntimeout on final message\n"); printf("event flag not set\n"); abort_test(); } } /* close the com port */ rc = com_close(); if ( rc != 0) { printf("\nCLOSE failed!\n"); printf("error code = %d\n",rc); exit(); } printf("Test completed successfully!\n"); }
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; }
void main(void) { int e_flag; /* event flag */ int ix; /* loop index */ int rc; /* function return code */ char buffer[BUFLEN]; /* output buffer */ int length; long tstart; /* open com port */ rc = com_open( (int *) &e_flag, 1200); if ( rc != 0) { printf("\nOPEN failed!\n"); printf("error code = %d\n",rc); abort_test(); } /* fill buffer with Xs */ for (ix=0; ix<BUFLEN; ix++) buffer[ix] = 'X'; /* insert test string */ strcpy(buffer,"This is a test of com driver output "); strcat(buffer,"abcdefghijklmnopqrstuvwxyz 0123456789\012\015"); length = strlen(buffer); /* output test string the specified number of times */ for (ix=1; ix<=REPEAT_COUNT; ix++) { e_flag = 0; rc = com_write((char *) buffer, (int *) &length); if (rc != 0) { printf("\nWRITE error!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > TIME_LIMIT) { printf("\nTIMEOUT: event flag not set\n"); abort_test(); } } } /* output final message */ e_flag = 0; length = 31; rc = com_write((char *) "End of Com Driver Output Test\012\015", (int *) &length); if (rc != 0) { printf("\nWRITE error on final message!\n"); printf("error code = %d\n",rc); abort_test(); } /* loop until output is done */ tstart = time(NULL); while (e_flag == 0) { if ((time(NULL) - tstart) > TIME_LIMIT) { printf("\nTIMEOUT: event flag not set\n"); abort_test(); } } /* close the com port */ rc = com_close(); if ( rc != 0) { printf("\nCLOSE failed!\n"); printf("error code = %d\n",rc); exit(); } printf("Test completed successfully!\n"); }
/** * Main, startup */ int main(int argc, char *argv[]) { // Filename of the HEX File const char * hexfile = NULL; // 1 if verify, 2 if programm char verify = 0; // Serial device const char * device = "/dev/ttyS0"; // Baudrate int baud = 4800; int baudid = -1; // if crc is supported (not supportet if 2) int crc_on; // The path to the binary (for finding devices.txt) readlink("/proc/self/exe", devices_file_p, 255); // symlink to this binary chp = strrchr (devices_file_p,'/'); // get the last path separator if (chp) strcpy (chp+1,DEVICES_FILE); // copy the device filename after the path separator // print header printf("\n"); printf("=================================================\n"); printf("| BOOTLOADER, Target: V2.1 |\n"); printf("=================================================\n"); // Parsing / checking parameter int i; int type = 0; for(i = 1; i < argc; i++) { if(*argv[i] == '-') { type = argv[i][1]; } else { switch(type) { case 'd': device = argv[i]; break; case 'b': baud = atoi(argv[i]); break; case 'v': verify = 1; hexfile = argv[i]; break; case 'p': verify = 2; hexfile = argv[i]; break; default: printf("Wrong parameter!\n"); usage(); } type = 0; } } if(hexfile == NULL) { printf("No hexfile specified!\n"); usage(); } if(verify == 0) { printf("No Verify / Programm specified!\n"); usage(); } // Checking baudrate for(i = 0; i < BAUD_CNT; i++) { if (baud_value[i] == baud) { baudid = i; break; } } if(baudid == -1) { printf("Unknown baudrate (%i)!\n", baud); usage(); } printf("Device : %s\n", device); printf("Baudrate : %i\n", baud); printf("%s: %s\n", (verify == 1 ? "Verify " : "Program "), hexfile); printf("-------------------------------------------------\n"); if(!com_open(device, baud_const[baudid])) { printf("Open com port failed!\n"); exit(2); } connect_device(); crc_on = check_crc(); read_info(); /*if(read_info()) { } else { printf("Reading device information failed!\n"); }*/ if(crc_on != 2) { crc_on = check_crc(); switch(crc_on) { case 2: printf("No CRC support.\n"); break; case 0: printf("CRC enabled and OK.\n"); break; case 3: printf("CRC check failed!\n"); break; default: printf("Checking CRC Error (%i)!\n", crc_on); break; } } else { printf("No CRC support.\n"); } flash(verify==1, hexfile); if( crc_on != 2 ) { if( check_crc() ) printf( "CRC-Error !\n"); else printf("CRC: o.k.\n"); } #ifdef SHOW_TIME_MS //time @ ms printf("Elapsed time: %d s\n", elapsed_msecs (&t_start)); #endif #ifdef SHOW_TIME_S printf("Elapsed time: %.3f seconds\n", elapsed_secs (&t_start)); #endif printf("...starting application\n\n"); sendcommand(START);//start application sendcommand(START); com_close();//close opened com port return 0; }
void CreateIOCB(){ TerminalQueue = sys_alloc_mem(sizeof(IOCB)); Com_PortQueue = sys_alloc_mem(sizeof(IOCB)); trm_open(&TerminalQueue->event_flag); com_open(&Com_PortQueue->event_flag,1200); }
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; }
int main(int argc, char *argv[]) { int it = 0; int done = 0; nmeaINFO info; nmeaPARSER parser; int select_result = -1; // value returned frome select() struct timeval select_timeout; int nfds = 0; fd_set rset; char rs232_device; int bytes_read; char rs232_buffer[1024]; char *token; char nmea_message[256]; rs232_device = com_open("/dev/ttyO2", 4800, 'N', 8, 1); if(rs232_device < 0) perror("com_open"); // Select UART2_TX and set it as output printf("Setting tx. . .\n"); sprintf(rs232_buffer, "echo 11 > /sys/kernel/debug/omap_mux/spi0_d0"); if(system(rs232_buffer) < 0) perror("setting tx"); // Select UART1_RX and set it as input pulled up printf("Setting rx. . .\n"); sprintf(rs232_buffer, "echo 39 > /sys/kernel/debug/omap_mux/spi0_sclk"); if(system(rs232_buffer) < 0) perror("setting rx"); const char *buff[] = { "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69\r\n", "$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70\r\n", "$GPGSV,2,1,08,01,05,005,80,02,05,050,80,03,05,095,80,04,05,140,80*7f\r\n", "$GPGSV,2,2,08,05,05,185,80,06,05,230,80,07,05,275,80,08,05,320,80*71\r\n", "$GPGSA,A,3,01,02,03,04,05,06,07,08,00,00,00,00,0.0,0.0,0.0*3a\r\n", "$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50\r\n", "$GPVTG,217.5,T,208.8,M,000.00,N,000.01,K*4C\r\n" }; select_timeout.tv_sec = 1; select_timeout.tv_usec = 0; nmea_zero_INFO(&info); nmea_parser_init(&parser); while(!done) { fflush(stdout); FD_ZERO(&rset); if(rs232_device > 0) { FD_SET(rs232_device, &rset); nfds = max(nfds, rs232_device); } select_result = select(nfds + 1, &rset, NULL, NULL, NULL); if(select_result == -1 && errno == EAGAIN) { perror("select"); continue; } if(select_result == -1) { perror("main:"); return 1; } if(rs232_device > 0) { if(FD_ISSET(rs232_device, &rset)) { //bytes_read = read(rs232_device, rs232_buffer, sizeof(rs232_buffer)); bytes_read = rs232_read(rs232_device); if(bytes_read > 0) { if(rs232_check_last_char('\n')) { bytes_read = rs232_unload_rx(rs232_buffer); if(bytes_read > 0) { rs232_buffer[bytes_read] = 0; token = strtok(rs232_buffer, "\n"); while(token != NULL) { sprintf(nmea_message, "%s\n", token); nmea_parse(&parser, nmea_message, (int)strlen(nmea_message), &info); if(it > 0) { printf("\033[21A"); } else it++; printf("Time: %i/%i/%i %i:%i:%i.%i \n", info.utc.day, info.utc.mon + 1, info.utc.year + 1900, info.utc.hour, info.utc.min, info.utc.sec, info.utc.hsec); if(info.smask == GPGGA) { switch(info.sig) { case 0: printf("Signal: INVALID \n"); break; case 1: printf("Signal: FIX \n"); break; case 2: printf("Signal: DIFFERENTIAL \n"); break; case 3: printf("Signal: SENSITIVE \n"); break; default: printf("Signal: INVALID \n"); break; } } else printf("Signal: NOT AVAILABLE \n"); if(info.smask == GPGGA) { switch(info.fix) { case 1: printf("Operating mode: FIX NOT AVAILABLE \n"); break; case 2: printf("Operating mode: 2D \n"); break; case 3: printf("Operating mode: 3D \n"); break; default: printf("Operating mode: UNKNOWN \n"); break; } } else printf("Opearating mode: NOT AVAILABLE \n"); printf("Position Diluition of Precision: %f \n", info.PDOP); printf("Horizontal Diluition of Precision: %f \n", info.HDOP); printf("Vertical Diluition of Precisione: %f \n", info.VDOP); printf("Latitude: %f \n", info.lat); printf("Longitude: %f \n", info.lon); printf("Elevation: %f m \n", info.elv); printf("Speed: %f km/h \n", info.speed); printf("Direction: %f degrees \n", info.direction); printf("Magnetic variation degrees: %f \n", info.declination); printf("Magnetic sensor heading: %f \n", info.magnetic_sensor_heading); printf("Magnetic sensor deviation: %f \n", info.magnetic_sensor_deviation); printf("Magnetic sensor variation: %f \n", info.magnetic_sensor_variation); printf("Rate turn: %f \n", info.rate_turn); printf("Pitch oscillation: %f \n", info.pitch_osc); printf("Roll oscillation: %f \n", info.roll_osc); printf("\nSatellite: \tin view: %i\n\t\tin use: %i \n", info.satinfo.inview, info.satinfo.inuse); token = strtok(NULL, "\n"); } } } } } } //int smask; /**< Mask specifying types of packages from which data have been obtained */ //nmeaTIME utc; /**< UTC of position */ //int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */ //int fix; /**< Operating mode, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */ //double PDOP; /**< Position Dilution Of Precision */ //double HDOP; /**< Horizontal Dilution Of Precision */ //double VDOP; /**< Vertical Dilution Of Precision */ //double lat; /**< Latitude in NDEG - +/-[degree][min].[sec/60] */ //double lon; /**< Longitude in NDEG - +/-[degree][min].[sec/60] */ //double elv; /**< Antenna altitude above/below mean sea level (geoid) in meters */ //double speed; /**< Speed over the ground in kilometers/hour */ //double direction; /**< Track angle in degrees True */ //double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */ //nmeaSATINFO satinfo; /**< Satellites information */ /*it++; if(it > 6) done = 1; select_timeout.tv_sec = 1; select_timeout.tv_usec = 0;*/ } nmea_parser_destroy(&parser); return 0; }