void arch_init() { // Initialise the library #ifdef __SDL__ arch_sdl_init(); #endif #ifdef __SVGALIB__ arch_svgalib_init(); #endif if (!FindArg( "-nojoystick" )) { if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_6); joy_init(); } //added 06/09/99 Matt Mueller - fix nonetwork compile #ifdef NETWORK //end addition -MM //added on 10/19/98 by Victor Rachels to add serial support (from DPH) if(!(FindArg("-noserial"))) com_init(); //end this section addition - Victor //added 06/09/99 Matt Mueller - fix nonetwork compile #endif //end addition -MM timer_init(); key_init(); }
/*----------------------------------------------------------------------------*/ void init_disp(void) { init_disp_buf(); seg_init(); com_init(); LCD_BACKLIGHT_INIT(); LCD_BACKLIGHT_ON(); }
int systerm_init() { clock_init(); gpio_init(); com_init(); return 0; }
C_RESULT init_com_server(void) { config.connection = COM_BLUETOOTH; config.localAdapterName = DEVICENAME; config.localIpAddress = SERVERHOST; config.localIpSubmask = SUBMASK; if(FAILED(com_init(&config))) return C_FAIL; return C_OK; }
void kern_main(multiboot_info_t *boot_info) { term_clear(); term_color(TERM_GREEN, TERM_BLACK); term_print("Booting\n"); term_print("Initializing memory manager\n"); if (mm_init(boot_info)) { term_print("Failed to initialize memory manager\n"); return; } com_init(); com_print(COM1, "Hello COM1!\n"); log_info("This is a logging test!"); return; }
int main(int argc, char **argv) { void *p; com_result_t r; int n; size_t s; IMalloc *allocator; (void) argc; (void) argv; com_init("com.googlecode.libcom.test-1"); p = CoTaskMemAlloc(64); if(NULL == p) { fprintf(stderr, "Failed to allocate 64 bytes via CoTaskMemAlloc()\n"); exit(EXIT_FAILURE); } if(COM_S_OK != (r = CoGetMalloc(1, &allocator))) { fprintf(stderr, "Failed to obtain reference to task allocator; result = 0x%08x\n", r); exit(EXIT_FAILURE); } if(1 != (n = IMalloc_DidAlloc(allocator, p))) { if(0 == n) { fprintf(stderr, "IMalloc::DidAlloc() claims task allocator was not responsible for allocated block\n"); } else { fprintf(stderr, "IMalloc::DidAlloc() could not determine responsibility for allocated block\n"); } exit(EXIT_FAILURE); } if(64 != (s = IMalloc_GetSize(allocator, p))) { fprintf(stderr, "IMalloc::GetSize() returned an incorrect size (%ul bytes)\n", s); exit(EXIT_FAILURE); } IMalloc_Free(allocator, p); puts("PASS"); com_shutdown(); return 0; }
void arch_init() { // Initialise the library arch_sdl_init(); //added 06/09/99 Matt Mueller - fix nonetwork compile #ifdef NETWORK //end addition -MM //added on 10/19/98 by Victor Rachels to add serial support (from DPH) if(!(FindArg("-noserial"))) com_init(); //end this section addition - Victor //added 06/09/99 Matt Mueller - fix nonetwork compile #endif //end addition -MM key_init(); }
int main(void) { platform_init(); debug_init(); DEBUG_PRINT("Booting...\n\n"); com_init(); spi_init(); init_framebuffer(framebuffer1); init_framebuffer(framebuffer2); DEBUG_PRINT("Booted.\n"); while(1); }
main() { com_init(); for (k=0; k<count1; k++) { if (!comm_sen(2,15)) o_err=1; } for (k=0; k<count2; k++) { if (!comm_rec(5, &i_mesg)) i_err=1; } }
int main(int argc, char *argv[]) { arg_init(argc,argv); #else int main(void) { #endif sched_init(); //init scheduler--THIS MUST BE FIRST mos_led_init(); //init leds early, to allow led debugging elsewhere com_init(); //init com system #ifdef MOS_DEBUG mos_debug_init(); #endif mos_thread_new(pre_start, START_STACK_SIZE, PRIORITY_NORMAL); //start the scheduler (never returns) mos_sched_start(); return 0; }
void ICACHE_FLASH_ATTR tfp_open_connection(void) { // Common initialisations. ringbuffer_init(&tfp_rb, tfp_rb_buffer, TFP_RING_BUFFER_SIZE); brickd_init(); com_init(); for(uint8_t i = 0; i < TFP_MAX_CONNECTIONS; i++) { tfp_init_con(i); } /* * When mesh mode is enabled all the socket setup is done from mesh specific * callbacks. Existing TFP socket callbacks and implementation are used but as * a layer underneath the mesh layer. */ if(!configuration_current.mesh_enable) { ets_memset(&tfp_con_listen, 0, sizeof(struct espconn)); // Initialize the ESPConn espconn_create(&tfp_con_listen); tfp_con_listen.type = ESPCONN_TCP; tfp_con_listen.state = ESPCONN_NONE; // Make it a TCP connection tfp_con_listen.proto.tcp = &tfp_con_listen_tcp; tfp_con_listen.proto.tcp->local_port = configuration_current.general_port; espconn_regist_reconcb(&tfp_con_listen, tfp_reconnect_callback); espconn_regist_connectcb(&tfp_con_listen, tfp_connect_callback); // Start listening espconn_accept(&tfp_con_listen); // Set server timeout (in seconds) espconn_regist_time(&tfp_con_listen, 7200, 0); } else { logi("MSH:TFP init\n"); } }
int main(int argc, char **argv) { IClassFactory *client; ITester2 *p; com_result_t r; int v; (void) argc; (void) argv; com_init("com.googlecode.libcom.test-2"); test2_server_init(); if(COM_S_OK != (r = com_getclass(&CLSID_Test2, COM_CTX_ALL, NULL, &IID_IClassFactory, (void **) &client))) { fprintf(stderr, "Failed to connect to registered factory. Result = 0x%08x\n", r); exit(EXIT_FAILURE); } if(COM_S_OK != (r = IClassFactory_CreateInstance(client, NULL, &IID_ITester2, (void **) &p))) { fprintf(stderr, "IClassFactory::CreateInstance() failed. Result = 0x%08x\n", r); exit(EXIT_FAILURE); } IClassFactory_Release(client); p->lpVtbl->Set(p, 5678); if(5678 != (v = p->lpVtbl->Get(p))) { fprintf(stderr, "ITester2::Get() returned an unexpected value (got = %d, expected = 5678)\n", v); exit(EXIT_FAILURE); } fprintf(stderr, "ITester2::Get() = %d\n", p->lpVtbl->Get(p)); p->lpVtbl->Release(p); puts("PASS"); return 0; }
int Matctcl_Init() { extern VARIABLE *elm_gradient(), *elm_divergence(),*elm_rotor_3D(),*elm_rotor_2D(); #if 1 com_init( "grad", FALSE, FALSE, elm_gradient, 1, 1, "r = grad(f): compute gradient of a scalar variable f.\n" ); com_init( "div", FALSE, FALSE, elm_divergence, 1, 1, "r = div(v): compute divergence of a vector variable v.\n" ); com_init( "curl3d", FALSE, FALSE, elm_rotor_3D, 1, 1, "r = curl3d(v): compute curl of a vector variable v (in 3D).\n" ); com_init( "curl2d", FALSE, FALSE, elm_rotor_2D, 1, 1, "r = curl2d(v): compute curl of a vector variable v (in 2D).\n" ); #endif com_init( "tcl", FALSE, FALSE, matc_tcl, 1, 1, "str = tcl(str): execute a command in tcl part of ElmerPost.\n" ); com_init( "element", FALSE, FALSE, matc_element, 1, 2, "r = element(v): return element topology for elements given in vector v.\n" ); return TCL_OK; }
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(void) { int ch; char comm[256]; struct stat st; printf("RECV -- 99/4A ROM dump receiver by Edward Swartz.\n\n" "Companion to TRANS on the 99/4A.\n\n"); if (stat("MODULES",&st) || stat("ROMS",&st) || stat("MODULES.INF",&st)) { printf("This program needs to be run from the directory where V9t9.EXE,\n" "MODULES.INF, etc., are located. (Use RECV.BAT from that directory.)\n"); exit(1); } printf("In order to use this program, TRANS must be running on a\n" "99/4A system connected to this PC by a serial cable.\n" "It's best to start the 99/4A TRANS before running this program.\n\n" "Press <Enter> to continue, or <Esc> to exit RECV:"); do ch=getch(); while (ch!=13 && ch!=27); if (ch==27) exit(1); do { printf("\n\n\nEnter the DOS serial port you are using to connect\n" "to the 99/4A. Valid values are 1-4.\n\n: "); comm[0]=2; port=atoi(cgets(comm)); } while (port<1 || port>4); do { printf("\n\n\nEnter the IRQ of COM%d. Typical value is %d.\n\n: ", port, ((port==1 || port==3) ? 4 : 3)); comm[0]=2; irq=atoi(cgets(comm)); } while (irq<0 || irq>7); port--; // fix port to 0-3 do { printf("\n\n\nEnter the baud rate you used to initialize the RS232\n" "in TRANS. Valid baud rates are\n" "\t110 300 600 1200 2400 4800 9600.\n\n: "); comm[0]=5; baudrate=atoi(cgets(comm)); } while (baudrate<110 || baudrate>9600); com_init(port,baudrate,irq); printf("\n\nRECV is ready to go.\n\n" "Press a key at any time to abort.\n\n"); while (!kbhit()) { // ch=bioscom(_COM_RECEIVE,0,port); buf_init(); if (!gs(comm)) switch(comm[0]) { case 'S': ps("G"); if (dump()) Err(); break; case 'M': getbasename(); ps("N"); break; case 'N': closemodule(); ps("M"); break; default: Err(); break; } else Err(); } com_off(); return 0; }
void app_usart_init(void) { com_para_t com_para; #if defined (CAR_DB44_V1_0_20130315_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for speed*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_SPEED_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined (DouLunJi_CAR_GBC_V1_2_130511_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for ZGB*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined(DouLunJi_AIS_BASE_STATION_V1_0_130513_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for ZGB*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined(DouLunJi_CAR_TRUCK_1_3_140303_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for ZGB*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined(CAR_TRUCK_1_5_140325_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for ZGB*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for CAM*/ com_para.baudrate = 38400; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_CAM_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined(HC_CONTROLER_) /*for network*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_NET_NUM; com_para.twoStopBits = false; com_init(&com_para); com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB1_NUM; com_para.twoStopBits = false; com_init(&com_para); com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_ZGB2_NUM; com_para.twoStopBits = false; com_init(&com_para); com_para.baudrate = 2400; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_WB_NUM; com_para.twoStopBits = false; com_init(&com_para); #elif defined(CAR_TRUCK_1_3_140303_) /*for gprs*/ com_para.baudrate = 115200; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPRS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for gps*/ com_para.baudrate = 9600; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_GPS_NUM; com_para.twoStopBits = false; com_init(&com_para); /*for CAM*/ com_para.baudrate = 38400; com_para.data_9bit = false; com_para.parity = 0; com_para.port = USART_CAM_NUM; com_para.twoStopBits = false; com_init(&com_para); #endif }
/*----------------------------------------------------------------------------*/ void init_seg_lcd_disp(void) { clear_seg_lcd(); seg_init(); com_init(); }
int main(void) { const int flash_burn = 0; int testcpu; initboard(); initsdram(); com_init(); sendtocom0("LH-1008 Satellite Navigation System\n\n\n"); initmodules(); //TestCPU testcpu = (0xabcddcba * 0x56899865 + 0xccdd) / 0xaabb; testcpu <<= 16; testcpu = ~testcpu; if (testcpu == 0x11DCFFFF) { sendtocom0("Satellite Navigation System Start\n\n"); } //Test Flash if (flash_burn == 1) { Flash_Chip_Erase(); printf("Flash Erase Complete\n"); Flash_Writem(FLASH_BASE_ADDR, 0x000, 0x48); Flash_Writem(FLASH_BASE_ADDR+0x400, (Uint32*)0x400, 0x5b30); printf("Flash Write Complete\n"); } test_entry(); /* printf("TEST SDRAMing... Write 0x00000000\t\n"); for (i=0; i<0x1000000; i++) write16((0x80000000 + i*2), 0x0); for (i=0; i<0x1000000; i++) { tmptest = read16(0x80000000 + i*2); if (tmptest != 0) { printf("SDRAM Check failed...\t\n"); printf("i=0x%x\r\n", i); printf("tmptest=0x%x\r\n", tmptest); printf("testram=0x%x\r\n", testram); } } printf("SDRAM Check 0x00000000 OK\t\n"); printf("TEST SDRAMing... Write 0xFFFFFFFF\t\n"); for (i=0; i<0x1000000; i++) write16((0x80000000 + i*2), 0xffff); for (i=0; i<0x1000000; i++) { tmptest = read16(0x80000000 + i*2); if (tmptest != 0xffff) { printf("SDRAM Check failed...\t\n"); printf("i=0x%x\r\n", i); printf("tmptest=0x%x\r\n", tmptest); printf("testram=0x%x\r\n", testram); } } printf("SDRAM Check 0xFFFFFFFF OK\t\n"); printf("TEST SDRAMing... Write 0xAAAAAAAA\t\n"); for (i=0;i<0x1000000; i++) write16((0x80000000 + i*2), 0xaaaa); for (i=0; i<0x1000000; i++) { tmptest = read16(0x80000000 + i*2); if (tmptest != 0xaaaa) { printf("SDRAM Check failed...\t\n"); printf("i=0x%x\r\n", i); printf("tmptest=0x%x\r\n", tmptest); printf("testram=0x%x\r\n", testram); } } printf("SDRAM Check 0xAAAAAAAA OK\t\n"); printf("TEST SDRAMing... Write 0x55555555\t\n"); for (i=0; i<0x1000000; i++) write16((0x80000000 + i*2), 0x5555); for (i=0; i<0x1000000; i++) { tmptest = read16(0x80000000 + i*2); if (tmptest != 0x5555) { printf("SDRAM Check failed...\t\n"); printf("i=0x%x\r\n", i); printf("tmptest=0x%x\r\n", tmptest); printf("testram=0x%x\r\n", testram); } } printf("SDRAM Check 0x55555555 OK\t\n"); printf("TEST SDRAMing...Write Accumulation \t\n"); for (i=0, testram=TESTCOUNT; i<0x1000000; i++, testram--) write16((0x80000000 + i*2), testram); for (i=0, testram=TESTCOUNT; i<0x1000000; i++, testram--) { tmptest = read16(0x80000000 + i*2); if (tmptest != testram) { printf("SDRAM Check failed...\t\n"); printf("i=0x%x\r\n", i); printf("tmptest=0x%x\r\n", tmptest); printf("testram=0x%x\r\n", testram); } } printf("SDRAM Test good\n"); initsdram(); */ }
void net_init() { com_init(); }
int main(int argc, char **argv) { com_init(); //设置一个socket地址结构server_addr,代表服务器internet地址, 端口 struct sockaddr_in server_addr; bzero(&server_addr,sizeof(server_addr)); //把一段内存区的内容全部设置为0 server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htons(INADDR_ANY); server_addr.sin_port = htons(HELLO_WORLD_SERVER_PORT); //创建用于internet的流协议(TCP)socket,用server_socket代表服务器socket int server_socket = socket(PF_INET,SOCK_STREAM,0); if( server_socket < 0) { printf("Create Socket Failed!"); exit(1); } { int opt =1; setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt)); } //把socket和socket地址结构联系起来 if( bind(server_socket,(struct sockaddr*)&server_addr,sizeof(server_addr))) { printf("Server Bind Port : %d Failed!", HELLO_WORLD_SERVER_PORT); exit(1); } //server_socket用于监听 if ( listen(server_socket, LENGTH_OF_LISTEN_QUEUE) ) { printf("Server Listen Failed!"); exit(1); } printf("Server Start Listen!\n"); while (1) //服务器端要一直运行 { //定义客户端的socket地址结构client_addr struct sockaddr_in client_addr; socklen_t length = sizeof(client_addr); //接受一个到server_socket代表的socket的一个连接 //如果没有连接请求,就等待到有连接请求--这是accept函数的特性 //accept函数返回一个新的socket,这个socket(new_server_socket)用于同连接到的客户的通信 //new_server_socket代表了服务器和客户端之间的一个通信通道 //accept函数把连接到的客户端信息填写到客户端的socket地址结构client_addr中 int new_server_socket = accept(server_socket,(struct sockaddr*)&client_addr,&length); if ( new_server_socket < 0) { printf("Server Accept Failed!\n"); break; } char buffer[BUFFER_SIZE]; bzero(buffer, BUFFER_SIZE); length = recv(new_server_socket,buffer,BUFFER_SIZE,0); if (length < 0) { printf("Server Recieve Data Failed!\n"); break; } if(length > 0){ printf("the receive string is %s \n", buffer); if(!strcmp("close led",buffer)){ send_cmd(0x01); printf("close led \n"); } else if(!strcmp("open led",buffer)){ send_cmd(0x02); printf("open led \n"); } else if(!strcmp("close fan",buffer)){ send_cmd(0x03); printf("close fan \n"); } else if(!strcmp("fan 1",buffer)){ send_cmd(0x04); printf("fan 1 \n"); } else if(!strcmp("fan 2",buffer)){ send_cmd(0x05); printf("fan 2 \n"); } } //关闭与客户端的连接 //close(new_server_socket); } //关闭监听用的socket close(server_socket); 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; }
void main (int argc, char *argv[]) { union REGS r; DPMI_CALLREGS dr; struct SREGS sr; char *lowp; unsigned short __far *alias; void far *fh; WORD orig_rm_seg; WORD orig_rm_off; DWORD orig_pm_off; WORD orig_pm_sel; int c; int doprot = 1; int doreal = 1; while (argc-- > 1) { if (argv[argc][0] != '-') { badarg: printf ("Invalid argument '%s'\n", argv[argc]); printf ("Valid options are:\n"); printf ("\t-p Don't install protected mode handler\n"); printf ("\t-r Don't install real mode handler\n"); printf ("\t-2 Use COM2 instead of COM1 for testing\n"); exit (1); } switch (argv[argc][1]) { case 'p': { doprot = 0; printf ("Not hooking in protected mode\n"); break; } case 'r': { doreal = 0; printf ("Not hooking in real mode\n"); break; } case '2': { com_id = 2; com_int = 0x0B; com_port = 0x2F8; printf ("Using COM2 instead of COM1 for testing\n"); break; } default: goto badarg; } if (argv[argc][2]) goto badarg; } /* Save the starting real-mode and protected-mode handler addresses. */ r.x.eax = 0x0204; /* DPMI get protected mode vector */ r.h.bl = com_int; int386 (0x31, &r, &r); orig_pm_sel = (WORD) r.x.ecx; orig_pm_off = r.x.edx; r.x.eax = 0x0200; /* DPMI get real mode vector */ r.h.bl = com_int; int386 (0x31, &r, &r); orig_rm_seg = (WORD) r.x.ecx; orig_rm_off = (WORD) r.x.edx; /* Patch the code of the real mode handler so it knows which com port is doing the communications. This is done before the handler is copied low, to take advantage of the label "com_port_low" while it's still valid. */ alias = &com_port_low; fh = (void __far *) &com_port; *(alias = MK_FP(FP_SEG(fh), FP_OFF(alias))) = com_port; /* Allocate 128 bytes of DOS memory for the real-mode handler, which must of course be less than 128 bytes long, plus 1029 bytes for the data. Then copy the real-mode handler to DOS memory and initialize the data to zero. */ if (! (lowp = D32DosMemAlloc (128 + 4 + 1024 + 1, &lowmem_seg))) { printf ("Couldn't get low memory!\n"); exit (1); } _fmemcpy ((char __far *) lowp, (void __far *) rmhandler, 128); _fmemset ((char __far *) lowp + 128, 0, 4 + 1024 + 1); fh = (void __far *) pmhandler; /* Install the new handlers. The memory touched by the protected mode handler needs to be locked, in case we are running under VMM or an external DPMI host. */ if (doprot) { r.x.eax = 0x0205; /* DPMI set protected mode vector */ r.x.ebx = (DWORD) com_int; r.x.ecx = (DWORD) FP_SEG(fh); r.x.edx = FP_OFF(fh); int386 (0x31, &r, &r); r.x.eax = 0x0600; /* DPMI lock linear region */ r.x.ebx = ((DWORD) pmhandler) >> 16; r.x.ecx = ((DWORD) pmhandler) & 0xFFFF; r.x.esi = 0; r.x.edi = 256; /* lock 256 bytes */ int386 (0x31, &r, &r); r.x.eax = 0x0600; r.x.ebx = ((DWORD) &com_port) >> 16; r.x.ecx = ((DWORD) &com_port) & 0xFFFF; r.x.esi = 0; r.x.edi = sizeof(WORD); /* lock 2 bytes */ int386 (0x31, &r, &r); } if (doreal) { r.x.eax = 0x0201; /* DPMI set real mode vector */ r.x.ebx = (DWORD) com_int; r.x.ecx = D32RealSeg(lowp); /* CX:DX == real mode &handler */ r.x.edx = D32RealOff(lowp); int386 (0x31, &r, &r); } /* Initialize COM port. */ com_init (); puts ("Move the mouse or transmit data; press ESC to cancel\n"); /* Wait for the ESC key to be pressed. This loop has a good mix of time spent in real mode and protected mode, so the upper left hand corner of your color screen will toggle between 'R' and 'P'. */ while (1) { /* Explicitly go down to real mode to ask if a key is ready. (The kbhit() call is simpler to code, but extra transfers to real mode may be optimized out by the DOS extender.) */ r.x.eax = 0x300; /* DPMI signal real mode interrupt */ r.x.ebx = 0x16; r.x.ecx = 0; fh = (void far *) &dr; _fmemset (fh, 0, sizeof(DPMI_CALLREGS)); dr.eax = 0x0100; sr.ds = 0; sr.es = FP_SEG(fh); r.x.edi = FP_OFF(fh); int386x (0x31, &r, &r, &sr); if (! (dr.flags & 0x40)) /* Test zero flag */ { if (((c = getch ()) & 0xff) == 27) break; putch (c); } /* Here we just check for an overflow, update our count of interrupts, and reset the buffer. You would process the data before flushing the buffer. */ _disable (); if (*(lowp + 128 + 4 + 1024)) /* Overflow? */ break; total_count += *((unsigned long *)(lowp + 128)); *((unsigned long *)(lowp + 128)) = 0; _enable (); } /* Clean up. */ r.x.eax = 0x0201; /* DPMI set real mode vector */ r.x.ebx = (DWORD) com_int; r.x.ecx = (DWORD) orig_rm_seg; /* CX:DX == real mode &handler */ r.x.edx = (DWORD) orig_rm_off; int386 (0x31, &r, &r); r.x.eax = 0x0205; /* DPMI set protected mode vector */ r.x.ebx = (DWORD) com_int; r.x.ecx = (DWORD) orig_pm_sel; r.x.edx = orig_pm_off; int386 (0x31, &r, &r); if (*(lowp + 128 + 4 + 1024)) printf ("\nOverflow! Increase data receive buffer size or check the\nbuffer more often.\n"); else printf ("\n%lu interrupts processed (%lu in protected mode, %lu real mode).\n", total_count, pm_count, total_count - pm_count); }