int main(int argc, char ** argv) { int error; int cnt = 0; int ind; char* teststr = "cutaway\n\0"; error = setup_serial(); if (error < 0){ printf("serial setup error\n"); return -1; } while (cnt < strlen(teststr)){ //serputc(teststr[cnt],ser_fd); serial_tx(teststr[cnt],ser_fd); cnt++; } //ind = sergetc(ser_fd); ind = serial_rx(ser_fd); printf("sergetc\n"); printf("decimal incoming: %d\n",ind); printf("char incoming: %c\n",(char)ind); // Don't forget to clean up close(ser_fd); return 0; }
void __init start_vmm ( const struct multiboot_info *mbi ) { //Initialize serial port COM1, this must be done before calling outf setup_serial(); outf("\n\n\n!!!!!!!!!!!BEGIN!!!!!!!!!!!\n\n\n"); //Parse the command line that user pass to GRUB struct cmdline_option opt = parse_cmdline ( mbi ); //Set up memory layout and store the layout in pml struct pmem_layout pml; setup_memory(mbi, &opt, &pml); struct vm_info vm; vm_create (&vm, pml.vmm_pmem_start, opt.vmm_pmem_size, &(pml.e820)); outf("\n++++++ New virtual machine created. Going to start the VM\n"); vm_init (&vm); //Debug //e820_print_map(&(pml.e820)); outf ("\n++++++ Going to GRUB for the 2nd time\n"); vm_boot (&vm); }
int misc_init_r(void) { setup_serial(); setup_macaddr(); setup_iodomain(); return 0; }
void setup_uart(int port, int setbaud, int want_ints) { setup_serial(port,setbaud,want_ints?UARTISR:(void*)0); fillPktStart(&uartbuf[port],PT_UART); fillPktByte(&uartbuf[port],port & 0xFF); fillPktInt(&uartbuf[port],setbaud); fillPktFinish(&uartbuf[port]); }
UINT setup_drivers(void) { setup_pseudo_devices(); setup_tty(); setup_serial(); setup_floppy(); setup_ramdisk(); return 0; }
int main(void) { setup_serial(); setup_PWM(); while(1) { receive(); // block waiting for the next command from the PC process_command(); // we've gotten a command, so process it OCR1A = brightness*brightness; // set the brightness of the LED accordingly } return 0; }
int main(int argc, char **argv) { char print_buf[128], dev[IF_NAMESIZE]; log_init(); log_setlevel(LOGLVL_DEBUG); if (argc != 3) { fatal("%s <device> <rate>\n", argv[0]); exit(1); } queue_init(&pan_q); queue_init(&tun_q); init_reconstruct(); if (config_parse("ieee154_interface.conf", &device_config)) { log_fatal_perror("parsing config file failed"); exit(1); } /* set up the serial interface device */ pthread_mutex_init(&pan_lock, NULL); if (setup_serial(argv[1], argv[2], &device_config)) { fatal("opening serial device failed!\n"); exit(1); } snprintf(print_buf, 128, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", device_config.eui64.data[0],device_config.eui64.data[1],device_config.eui64.data[2], device_config.eui64.data[3],device_config.eui64.data[4],device_config.eui64.data[5], device_config.eui64.data[6],device_config.eui64.data[7]); info("device EUI-64: %s\n", print_buf); pthread_create(&pan_writer, NULL, pan_write, NULL); pthread_create(&reconstruct_thread, NULL, age_reconstruct, NULL); /* initialize thes tun */ tun_fd = tun_open(dev); if (tun_fd < 0) { log_fatal_perror("opening tun device failed"); exit(1); } if (tun_setup(dev, device_config.eui64) < 0) { exit(1); } sleep(1); pthread_create(&tun_reader, NULL, tun_dev_read, NULL); pthread_create(&pan_reader, NULL, pan_read, NULL); pthread_join(pan_writer, NULL); }
int main(){ setup_serial(); while(1){ char c; if(read(serialport, &c,1)==1){ printf("AVR sent: %c %x %d\n",c,c,c); }else{ // printf("No Data.\n"); } } }
int main() { setup_serial(); setup(); transmit("setup done"); while(1) { // transmit("SPAM"); char temp[100]; sprintf(temp,"captures: %d",counter); transmit(temp); } return 0; }
int main(void) { setup_serial(); // setup_timer(); sei();// enable global interrupts while(1){ // echos recieved characters back, but with brackets receive(); char temp[23]; sprintf(temp,"[%s]",receive_buffer); transmit(temp); } return 0; }
static int __devinit navman_gps_cf_probe_sleeve(struct sleeve_dev *sleeve_dev, const struct sleeve_device_id *ent) { serial_ioaddr = ioremap(0x30000000 + serial_port, PAGE_SIZE); if (1) printk(__FUNCTION__ ": %s serial_port=%x serial_ioaddr=%p\n", sleeve_dev->driver->name, serial_port, serial_ioaddr); sa1100_h3600_pcmcia_change_sleeves(&h3600_single_sleeve_ops); GPDR &= ~GPIO_H3600_OPT_IRQ; /* GPIO line as input */ set_GPIO_IRQ_edge( GPIO_H3600_OPT_IRQ, GPIO_RISING_EDGE ); /* Rising edge */ serial_line = setup_serial((ioaddr_t) serial_ioaddr, serial_irq); return 0; }
//---------------------------------------------------------------------------- static int usbasp_set_serial(char *SerialNumber) { unsigned char res[4]; unsigned char cmd[USB_CFG_SERIAL_NUMBER_LEN]; int nbytes; setup_serial((char *)cmd, SerialNumber); memset(res, 0, sizeof(res)); nbytes = usbasp_transmit(1, USBASPX_FUNC_SETSERIAL, cmd, res, sizeof(res)); if (nbytes != 1 || res[0] != 0) { fprintf(stderr, "%s: error: set serial: target doesn't answer. %x \n", progname, res[0]); return -1; } return 0; }
int upsdrv_initups(void) { upsfd = ser_open(device_path); setup_serial(device_path); /* upsfd = ser_open(device_path); */ /* ser_set_speed(upsfd, device_path, B1200); */ /* probe ups type */ /* to get variables and flags from the command line, use this: * * first populate with upsdrv_buildvartable above, then... * * set flag foo : /bin/driver -x foo * set variable 'cable' to '1234' : /bin/driver -x cable=1234 * * to test flag foo in your code: * * if (testvar("foo")) * do_something(); * * to show the value of cable: * * if ((cable == getval("cable"))) * printf("cable is set to %s\n", cable); * else * printf("cable is not set!\n"); * * don't use NULL pointers - test the return result first! */ /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ return 1; }
static int multi_config(dev_link_t * link) { client_handle_t handle = link->handle; struct serial_info *info = link->priv; struct serial_cfg_mem *cfg_mem; tuple_t *tuple; u_char *buf; cisparse_t *parse; cistpl_cftable_entry_t *cf; config_info_t config; int i, rc, base2 = 0; cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); if (!cfg_mem) return -1; tuple = &cfg_mem->tuple; parse = &cfg_mem->parse; cf = &parse->cftable_entry; buf = cfg_mem->buf; i = pcmcia_get_configuration_info(handle, &config); if (i != CS_SUCCESS) { cs_error(handle, GetConfigurationInfo, i); rc = -1; goto free_cfg_mem; } link->conf.Vcc = config.Vcc; tuple->TupleData = (cisdata_t *) buf; tuple->TupleOffset = 0; tuple->TupleDataMax = 255; tuple->Attributes = 0; tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; /* First, look for a generic full-sized window */ link->io.NumPorts1 = info->multi * 8; i = first_tuple(handle, tuple, parse); while (i != CS_NO_MORE_ITEMS) { /* The quad port cards have bad CIS's, so just look for a window larger than 8 ports and assume it will be right */ if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = pcmcia_request_io(link->handle, &link->io); base2 = link->io.BasePort1 + 8; if (i == CS_SUCCESS) break; } i = next_tuple(handle, tuple, parse); } /* If that didn't work, look for two windows */ if (i != CS_SUCCESS) { link->io.NumPorts1 = link->io.NumPorts2 = 8; info->multi = 2; i = first_tuple(handle, tuple, parse); while (i != CS_NO_MORE_ITEMS) { if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.BasePort2 = cf->io.win[1].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = pcmcia_request_io(link->handle, &link->io); base2 = link->io.BasePort2; if (i == CS_SUCCESS) break; } i = next_tuple(handle, tuple, parse); } } if (i != CS_SUCCESS) { cs_error(link->handle, RequestIO, i); rc = -1; goto free_cfg_mem; } i = pcmcia_request_irq(link->handle, &link->irq); if (i != CS_SUCCESS) { printk(KERN_NOTICE "serial_cs: no usable port range found, giving up\n"); cs_error(link->handle, RequestIRQ, i); link->irq.AssignedIRQ = 0; } /* Socket Dual IO: this enables irq's for second port */ if (info->multi && (info->manfid == MANFID_SOCKET)) { link->conf.Present |= PRESENT_EXT_STATUS; link->conf.ExtStatus = ESR_REQ_ATTN_ENA; } i = pcmcia_request_configuration(link->handle, &link->conf); if (i != CS_SUCCESS) { cs_error(link->handle, RequestConfiguration, i); rc = -1; goto free_cfg_mem; } /* The Oxford Semiconductor OXCF950 cards are in fact single-port: 8 registers are for the UART, the others are extra registers */ if (info->manfid == MANFID_OXSEMI) { if (cf->index == 1 || cf->index == 3) { setup_serial(handle, info, base2, link->irq.AssignedIRQ); outb(12, link->io.BasePort1 + 1); } else { setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); outb(12, base2 + 1); } rc = 0; goto free_cfg_mem; } setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); /* The Nokia cards are not really multiport cards */ if (info->manfid == MANFID_NOKIA) { rc = 0; goto free_cfg_mem; } for (i = 0; i < info->multi - 1; i++) setup_serial(handle, info, base2 + (8 * i), link->irq.AssignedIRQ); rc = 0; free_cfg_mem: kfree(cfg_mem); return rc; }
static int simple_config(dev_link_t *link) { static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; static int size_table[2] = { 8, 16 }; client_handle_t handle = link->handle; struct serial_info *info = link->priv; struct serial_cfg_mem *cfg_mem; tuple_t *tuple; u_char *buf; cisparse_t *parse; cistpl_cftable_entry_t *cf; config_info_t config; int i, j, try; int s; cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); if (!cfg_mem) return -1; tuple = &cfg_mem->tuple; parse = &cfg_mem->parse; cf = &parse->cftable_entry; buf = cfg_mem->buf; /* If the card is already configured, look up the port and irq */ i = pcmcia_get_configuration_info(handle, &config); if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) { kio_addr_t port = 0; if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) { port = config.BasePort2; info->slave = 1; } else if ((info->manfid == MANFID_OSITECH) && (config.NumPorts1 == 0x40)) { port = config.BasePort1 + 0x28; info->slave = 1; } if (info->slave) { kfree(cfg_mem); return setup_serial(handle, info, port, config.AssignedIRQ); } } link->conf.Vcc = config.Vcc; /* First pass: look for a config entry that looks normal. */ tuple->TupleData = (cisdata_t *) buf; tuple->TupleOffset = 0; tuple->TupleDataMax = 255; tuple->Attributes = 0; tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; /* Two tries: without IO aliases, then with aliases */ for (s = 0; s < 2; s++) { for (try = 0; try < 2; try++) { i = first_tuple(handle, tuple, parse); while (i != CS_NO_MORE_ITEMS) { if (i != CS_SUCCESS) goto next_entry; if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) && (cf->io.win[0].base != 0)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; i = pcmcia_request_io(link->handle, &link->io); if (i == CS_SUCCESS) goto found_port; } next_entry: i = next_tuple(handle, tuple, parse); } } } /* Second pass: try to find an entry that isn't picky about its base address, then try to grab any standard serial port address, and finally try to get any free port. */ i = first_tuple(handle, tuple, parse); while (i != CS_NO_MORE_ITEMS) { if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { link->conf.ConfigIndex = cf->index; for (j = 0; j < 5; j++) { link->io.BasePort1 = base[j]; link->io.IOAddrLines = base[j] ? 16 : 3; i = pcmcia_request_io(link->handle, &link->io); if (i == CS_SUCCESS) goto found_port; } } i = next_tuple(handle, tuple, parse); } found_port: if (i != CS_SUCCESS) { printk(KERN_NOTICE "serial_cs: no usable port range found, giving up\n"); cs_error(link->handle, RequestIO, i); kfree(cfg_mem); return -1; } i = pcmcia_request_irq(link->handle, &link->irq); if (i != CS_SUCCESS) { cs_error(link->handle, RequestIRQ, i); link->irq.AssignedIRQ = 0; } if (info->multi && (info->manfid == MANFID_3COM)) link->conf.ConfigIndex &= ~(0x08); i = pcmcia_request_configuration(link->handle, &link->conf); if (i != CS_SUCCESS) { cs_error(link->handle, RequestConfiguration, i); kfree(cfg_mem); return -1; } kfree(cfg_mem); return setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); }
int main (int argc, char **argv) { int line_fd; FILE *line; speed_t speed; enum operation op; int addr; int len; int orig_len; struct mem_val val; int ret; if (argc != 6) usage(argv[0]); line_fd = open(argv[1], O_RDWR | O_NOCTTY); if (line_fd < 0) { perror(argv[1]); exit(1); } switch (*argv[3]) { case 'r': op = READ; break; case 'w': op = WRITE; break; default: usage(argv[0]); } if (sscanf(argv[4], "0x%x", &addr) != 1) usage(argv[0]); if (sscanf(argv[5], "%d", &len) != 1) usage(argv[0]); fprintf(stderr, "%s: line: %s op: %c addr: 0x%x len: %d\n", argv[0], argv[1], (op == READ) ? 'r' : 'w', addr, len); speed = conv_speed(argv[2]); if (speed < 0) { fprintf(stderr, "Wrong speed."); exit(1); } ret = setup_serial(line_fd, speed); if (ret < 0) { perror("Failed to set up the serial port"); exit(1); } if ((line = fdopen(line_fd, "w+")) < 0) { perror("fdopen"); exit(1); } log_file = fopen("serial-monitor.log", "w"); if (!log_file) { perror("Failed to open the log file"); exit(1); } fprintf(line, "\n"); orig_len = len; if (op == WRITE) { while (len > 0) { val.address = addr; val.value = 0; show_progress(orig_len, len); ret = fread(&val.value, 4, 1, stdin); /* If eof is reached, but len is still positive, write the rest as zeros. */ if (ret < 1 && !feof(stdin)) { perror("Failed to read from file"); exit(1); } // val.value = htobe32(val.value); /* Sent as BE over the serial line. */ my_dbg("stdin: 0x%.8x\n", val.value); ret = put_value(line, &val); len -= 4; addr += 4; } } else { while (len > 0) { val.address = addr; show_progress(orig_len, len); ret = get_value(line, &val); if (ret) exit(1); // val.value = be32toh(val.value); my_dbg ("stdout: 0x%.8x\n", val.value); ret = fwrite(&val.value, 4, 1, stdout); if (ret < 1) { perror("Failed to write to file"); exit(1); } len -= 4; addr += 4; } } return 0; }
void upsdrv_initups () { char temp[256], fcstring[512]; upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B1200); setup_serial(); ups_sync(); fc.model = UNKNOWN; /* Obtain Model */ if (execute("id\r", fcstring, sizeof(fcstring)) < 1) { fatalx(EXIT_FAILURE, "Failed execute in ups_ident()"); } /* response is a one-line packed string starting with $ */ if (memcmp(fcstring, "Unit", 4)) { fatalx(EXIT_FAILURE, "Bad response from formatconfig command in ups_ident()\n" "id: %s\n", fcstring ); } if (debugging) fprintf(stderr, "id: %s\n", fcstring); /* chars 4:2 are a two-digit ascii hex enumerated model code */ memcpy(temp, fcstring+9, 2); temp[2] = '\0'; if (memcmp(temp, "ME", 2) == 0) { fc.model = ME3100; } else if ((memcmp(temp, "RE", 2) == 0)) { fc.model = RE1800; } else if (memcmp(temp, "C1", 2) == 0) { /* Better way to identify unit is using "d 15\r", which results in "15 M# MD1KVA", "id\r" yields "Unit ID "C1K03588"" */ fc.model = MD1KVA; } switch(fc.model) { case ME3100: fc.va = 3100; fc.watts = 2200; /* determine shutdown battery voltage */ if (execute("d 29\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "29 LowBat %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 31\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "31 HiBatt %f", &fc.fullvolts); } fc.fullvolts = 54.20; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; case RE1800: fc.va = 1800; fc.watts = 1200; /* determine shutdown battery voltage */ if (execute("d 29\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "29 LowBat %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 31\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "31 HiBatt %f", &fc.fullvolts); } fc.fullvolts = 54.20; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; case MD1KVA: fc.va = 1100; fc.watts = 770; /* Approximate, based on 0.7 power factor */ /* determine shutdown battery voltage */ if (execute("d 27\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "27 LowBatt %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 28\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "28 Hi Batt %f", &fc.fullvolts); } fc.fullvolts = 13.70; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; default: fatalx(EXIT_FAILURE, "Uknown model %s in ups_ident()", temp); } fc.valid = 1; return; }
void main(void) { setup_serial(); setup_acpi(); setup_pci(); }
static int multi_config(dev_link_t *link) { client_handle_t handle = link->handle; serial_info_t *info = link->priv; tuple_t tuple; u_char buf[256]; cisparse_t parse; cistpl_cftable_entry_t *cf = &parse.cftable_entry; int i, base2 = 0; tuple.TupleData = (cisdata_t *)buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; tuple.Attributes = 0; tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; /* First, look for a generic full-sized window */ link->io.NumPorts1 = info->multi * 8; i = first_tuple(handle, &tuple, &parse); while (i != CS_NO_MORE_ITEMS) { /* The quad port cards have bad CIS's, so just look for a window larger than 8 ports and assume it will be right */ if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = CardServices(RequestIO, link->handle, &link->io); base2 = link->io.BasePort1 + 8; if (i == CS_SUCCESS) break; } i = next_tuple(handle, &tuple, &parse); } /* If that didn't work, look for two windows */ if (i != CS_SUCCESS) { link->io.NumPorts1 = link->io.NumPorts2 = 8; info->multi = 2; i = first_tuple(handle, &tuple, &parse); while (i != CS_NO_MORE_ITEMS) { if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.BasePort2 = cf->io.win[1].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = CardServices(RequestIO, link->handle, &link->io); base2 = link->io.BasePort2; if (i == CS_SUCCESS) break; } i = next_tuple(handle, &tuple, &parse); } } if (i != CS_SUCCESS) { cs_error(link->handle, RequestIO, i); return -1; } i = CardServices(RequestIRQ, link->handle, &link->irq); if (i != CS_SUCCESS) { cs_error(link->handle, RequestIRQ, i); link->irq.AssignedIRQ = 0; } /* Socket Dual IO: this enables irq's for second port */ if (info->multi && (info->manfid == MANFID_SOCKET)) { link->conf.Present |= PRESENT_EXT_STATUS; link->conf.ExtStatus = ESR_REQ_ATTN_ENA; } i = CardServices(RequestConfiguration, link->handle, &link->conf); if (i != CS_SUCCESS) { cs_error(link->handle, RequestConfiguration, i); return -1; } setup_serial(info, link->io.BasePort1, link->irq.AssignedIRQ); /* The Nokia cards are not really multiport cards */ if (info->manfid == MANFID_NOKIA) return 0; for (i = 0; i < info->multi-1; i++) setup_serial(info, base2+(8*i), link->irq.AssignedIRQ); return 0; }
int main( void) { //------------------FOR TEST------------------ strcpy(name,"COM1"); strcpy(name2,"COM2"); //---------------FOR TEST END----------------- // Setup part ackR=0; ackS=0; control_is_txt_img=1; setup_serial(); printf("Select mode( s or r)\t: "); c = getche(); printf("\n"); printf("Enter you name\t: "); gets(name); if(c == 's'||c=='S'){ mode = 1; } else mode = 0; printf("Set up sender time (ms)\t: "); scanf("%d",&sender_timer); while((c= getchar()) != '\n' && c != EOF); //Flushing scanf printf("%s\n", mode?"Sender":"Receiver"); //___________________Initial part___________________\\ //Send+Receive Name & Timer if(mode==1){//SENDER // Send name text_sender(name); // Wait for name setName2(Iframe_receiver()); }else{//RECEIVER // Wait for name setName2(Iframe_receiver()); // Send name text_sender(name); } printf("Name :%s\n", name); printf("Name2 :%s\n", name2); printf("Timer :%d\n",sender_timer ); getch(); //-------------------Initial part-------------------// /* //-------------------Running part-------------------\\ while(1) { if(mode == 0){ while(1){ printf("%s << ",name); received_frame=frame_receiver(); if(strchr(received_frame,24)>=0){ // Send ACK to Sender before EXIT exit(0); } if(isS_Frame(received_frame)){ //--------------------------------SSSSSS-------------------------------- S_Frame_receive(); // Set control_is_txt_img << in HERE }else{ //--------------------------------IIIIII-------------------------------- Iframe_receiver(); // Check control_is_txt_img before receive } } printf("Ending Frame"); mode = 1; // Change to Sender }else if(mode == 1){ printf("%s >> ",name); gets(send_data); if(strcmp(send_data,"send")==0){ //----------------------------------FILE MODE---------------------------------- char file_location[300]; printf("Enter file location : "); gets(file_location); file_sender(file_location); // Pass File data & file size to frame_sender << HERE }else{ //----------------------------------TEXT MODE---------------------------------- text_sender(send_data); } printf("Ending Frame"); mode = 0; // Change to Receiver } } */ return 0; }
int main(int argc, char *argv[]) { int buf_size = 1024; unsigned char buf[buf_size]; unsigned int total_bytes_sent = 0; Frame frame(WIDTH, HEIGHT); int n_frame; int start_millis = millitime(); int last_frame_start_millis = start_millis; std::deque<unsigned char> input; const char* preamble = "OK."; int in_udp_mode = 0; printf("Want It! matrix display (C) 2012 Phillip Pearson, [email protected]\n"); if (argc < 2) { printf("Syntax: %s </path/to/serial/port>\n", argv[0]); exit(1); } portfd = setup_serial(argv[1]); setup_udp(); printf("Flushing serial input in case we have a startup announcement buffered (if this is an Uno)\n"); while (read(portfd, buf, 1) > 0); // VMIN=0, VTIME=5 means this will terminate when we don't get a byte in 0.5 s //test_loop_corruption(); for (n_frame = 0; ; ++n_frame) { int frame_start_millis = millitime(); int ready_for_next = 0; size_t preamble_read_pos = 0; int ms_since_start = frame_start_millis - start_millis; int bytes_per_sec = ms_since_start ? (int)((double)total_bytes_sent * 1000 / ms_since_start) : 0; int ms_per_frame = frame_start_millis - last_frame_start_millis; if (debuglevel >= 1) { printf("%d ms since last frame / %d bytes in %d ms / %d bytes/sec / %.1f fps\n", ms_per_frame, total_bytes_sent, ms_since_start, bytes_per_sec, 1000.0 / ms_per_frame); } last_frame_start_millis = frame_start_millis; while (!ready_for_next) { ssize_t bytes_read = read(portfd, buf, 1); if (bytes_read == 0) { printf("write junk data to kick the avr\n"); if (write(portfd, ".", 1) == -1) { printf("disconnect!\n"); exit(2); } usleep(1000); continue; } if (bytes_read == -1) { perror("error reading from serial port"); continue; } if (debuglevel >= 10) printf("%d: ", (int)bytes_read); for (ssize_t i = 0; i < bytes_read; ++i) { input.push_back(buf[i]); if (debuglevel >= 10) { if (buf[i] < 32) printf("<%02x>", buf[i]); else putchar(buf[i]); } } if (debuglevel >= 10) printf("\n"); while (input.size()) { if (preamble_read_pos == strlen(preamble)) { ready_for_next = 1; break; } unsigned char c = input.front(); input.pop_front(); if (c == preamble[preamble_read_pos]) ++preamble_read_pos; } } if (n_frame == 0) { // arduino just initialized; reset timers last_frame_start_millis = frame_start_millis = start_millis = millitime(); } if (debuglevel >= 2) printf("[waited %d milliseconds]\n", millitime() - frame_start_millis); // do something frame.blank(); //frame.rect(0, 0, WIDTH, HEIGHT, rand() % 256, rand() % 256, rand() % 256); frame.set(n_frame % LEN, 0, 0xff, 0xff, 0xff); //rand() & 0xff, rand() & 0xff, rand() & 0xff); // see if someone sent us something over UDP (Disorient protocol / Processing interface) unsigned char udp_buffer[frame.buffer_len]; int received_udp_frame = check_udp(udp_buffer, frame.buffer_len); if (received_udp_frame) { // received a udp frame -- disable internal pattern generation for now in_udp_mode = 1; } else if (in_udp_mode && !received_udp_frame) { // expecting a udp frame - wait for up to a second, and if we don't get anything, drop back into internal mode if (debuglevel > 5) printf("waiting for a bit to see if we'll get a udp frame\n"); in_udp_mode = 0; for (int udp_try = 0; udp_try < 1000; ++udp_try) { usleep(1000); // 1 ms received_udp_frame = check_udp(udp_buffer, frame.buffer_len); if (received_udp_frame) { in_udp_mode = 1; break; } } } if (received_udp_frame) frame.set_from_buffer(udp_buffer); // clear out any excess udp frames while (check_udp(NULL, 0)) printf("skipped too-fast UDP frame\n"); if (debuglevel >= 1) printf("Sending frame %d%s\n", n_frame, in_udp_mode ? " (UDP)" : ""); //set_blocking(1); buf[0] = buf[1] = '*'; buf[2] = buf[3] = '+'; if (write(portfd, buf, 4) != 4) { printf("failed to write packet start\n"); } //set_blocking(0); while (1) { unsigned char c; while (read(portfd, &c, 1) < 1) { if (debuglevel >= 10) printf("nothing\n"); if (write(portfd, "", 0) == -1) { printf("disconnect!\n"); exit(2); } usleep(10000); } if (c == '#') { if (debuglevel >= 5) printf("received start signal from avr\n"); break; } else if (debuglevel >= 10) { if (c < 32) printf("received junk byte <%02x> from avr\n", (int)c); else printf("received junk byte '%c' from avr\n", (int)c); } } set_blocking(1); ssize_t bytes_written = write(portfd, frame.buffer, 900); total_bytes_sent += bytes_written; if (debuglevel >= 5) printf("(total %d bytes)\n", (int)bytes_written); if (bytes_written != LEN * 3) { printf("not 900?\n"); exit(1); } } close(portfd); return 0; }
static int multi_config(struct pcmcia_device * link) { struct serial_info *info = link->priv; struct serial_cfg_mem *cfg_mem; tuple_t *tuple; u_char *buf; cisparse_t *parse; cistpl_cftable_entry_t *cf; int i, rc, base2 = 0; cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); if (!cfg_mem) return -1; tuple = &cfg_mem->tuple; parse = &cfg_mem->parse; cf = &parse->cftable_entry; buf = cfg_mem->buf; tuple->TupleData = (cisdata_t *) buf; tuple->TupleOffset = 0; tuple->TupleDataMax = 255; tuple->Attributes = 0; tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; /* First, look for a generic full-sized window */ link->io.NumPorts1 = info->multi * 8; i = first_tuple(link, tuple, parse); while (i != CS_NO_MORE_ITEMS) { /* The quad port cards have bad CIS's, so just look for a window larger than 8 ports and assume it will be right */ if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = pcmcia_request_io(link, &link->io); base2 = link->io.BasePort1 + 8; if (i == CS_SUCCESS) break; } i = next_tuple(link, tuple, parse); } /* If that didn't work, look for two windows */ if (i != CS_SUCCESS) { link->io.NumPorts1 = link->io.NumPorts2 = 8; info->multi = 2; i = first_tuple(link, tuple, parse); while (i != CS_NO_MORE_ITEMS) { if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.BasePort2 = cf->io.win[1].base; link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; i = pcmcia_request_io(link, &link->io); base2 = link->io.BasePort2; if (i == CS_SUCCESS) break; } i = next_tuple(link, tuple, parse); } } if (i != CS_SUCCESS) { cs_error(link, RequestIO, i); rc = -1; goto free_cfg_mem; } i = pcmcia_request_irq(link, &link->irq); if (i != CS_SUCCESS) { printk(KERN_NOTICE "serial_cs: no usable port range found, giving up\n"); cs_error(link, RequestIRQ, i); link->irq.AssignedIRQ = 0; } /* * Apply any configuration quirks. */ if (info->quirk && info->quirk->config) info->quirk->config(link); i = pcmcia_request_configuration(link, &link->conf); if (i != CS_SUCCESS) { cs_error(link, RequestConfiguration, i); rc = -1; goto free_cfg_mem; } /* The Oxford Semiconductor OXCF950 cards are in fact single-port: * 8 registers are for the UART, the others are extra registers. * Siemen's MC45 PCMCIA (Possio's GCC) is OXCF950 based too. */ if (info->manfid == MANFID_OXSEMI || (info->manfid == MANFID_POSSIO && info->prodid == PRODID_POSSIO_GCC)) { int err; if (cf->index == 1 || cf->index == 3) { err = setup_serial(link, info, base2, link->irq.AssignedIRQ); base2 = link->io.BasePort1; } else { err = setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ); } info->c950ctrl = base2; /* * FIXME: We really should wake up the port prior to * handing it over to the serial layer. */ if (info->quirk && info->quirk->wakeup) info->quirk->wakeup(link); rc = 0; goto free_cfg_mem; } setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ); for (i = 0; i < info->multi - 1; i++) setup_serial(link, info, base2 + (8 * i), link->irq.AssignedIRQ); rc = 0; free_cfg_mem: kfree(cfg_mem); return rc; }
int main( void) { //int size,i; //char ch; //unsigned char* dataparity; //unsigned char* data; //unsigned char* datain = (unsigned char*)malloc(sizeof(unsigned char)*12); setup_serial(); frame_receiver(); /*size=12; printf("SIZE:%d\n",size); printf("-----------\n"); i=0; while(i<size){ printf("I : %d",i); ch=get_character(); datain[i++]=ch; printf(">> %x\n",datain[i-1]); } puts("RECEIVED\n"); printf("I>S : %d\n ",IgetStart(datain)); printf("I>C : %d\n ",IgetControl(datain)); printf("I>F : %d\n ",IgetFrameno(datain)); printf("I>Z : %d\n ",IgetSize(datain)); dataparity=Igetdata(datain); data=(unsigned char*)malloc(sizeof(unsigned char)*IgetSize(datain)); size=IgetSize(datain); i=0; while(i<=size){ data[i++]=(*dataparity)>>1; dataparity++; } i=0; while(i<size){ printf("D: %c\n",data[i]); data++; i++; }*/ // i=0; // while(size--){ // printf("I : %d",i); // ch=get_character(); // file_ptr[i++]=ch; // printf(">> %c\n",ch); // } // puts("RECEIVED\n"); // file_writer("NEW2.txt",i,file_ptr); puts("SUCCESS\n"); getch(); }
//---------------------------------------------------------------------------- int usbasp_open(char *SerialNumber) { struct usb_bus *bus; struct usb_device *dev; char string[256]; char serial[USB_CFG_SERIAL_NUMBER_LEN+1]; #ifdef WIN32 #ifdef __GNUC__ int old_fd, nul_fd; #endif #endif setup_serial(serial, SerialNumber); int l = 0; while(serial[l]){ serial[l] = toupper(serial[l]); l++; } /* * libusb-win32-0.1.10.1 で usb_find_busses() を実行したときに * "found N busses"がstdoutに出力されるため一時的にstdoutをnulに切換 * libusb-win32-0.1.10.2/ libusb-win32-0.1.12.0で修正されている * とりあえずgccのみ (bcc/bcb6/vc8では正常に動作しない) */ #ifdef WIN32 #ifdef __GNUC__ old_fd = dup(fileno(stdout)); // 標準出力のバックアップを作成 nul_fd = open("nul", O_WRONLY); // 標準出力用に"nul"を開く dup2(nul_fd, fileno(stdout)); // ファイルのディスクリプタのコピーを1番に作成 #endif #endif usb_init(); usb_find_busses(); // この中で不要な printf がある usb_find_devices(); #ifdef WIN32 #ifdef __GNUC__ fflush(stdout); dup2(old_fd, fileno(stdout)); // 標準出力を元に戻す close(old_fd); // 標準出力のバックアップを閉じる close(nul_fd); #endif #endif for (bus = usb_get_busses(); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == USBDEV_VENDOR && dev->descriptor.idProduct == USBDEV_PRODUCT) || (dev->descriptor.idVendor == USBDEV_VENDOR2 && dev->descriptor.idProduct == USBDEV_PRODUCT2)) { usbhandle = usb_open(dev); if (usbhandle) { if (SerialNumber == NULL) return 0; // findfirst // check serial number if (usb_get_string_simple(usbhandle, dev->descriptor.iSerialNumber, string, sizeof(string)) < 0) { // cannot read serial number if (!SerialNumber[0]) return 0; } #ifndef WIN32 int k = 0; while(string[k]){ string[k] = toupper(string[k]); k++; } if (strncmp(serial, string, USB_CFG_SERIAL_NUMBER_LEN) == 0){ #ifdef LINUX setuid(getuid()); #endif return 0; } #else if (strnicmp(serial, string, USB_CFG_SERIAL_NUMBER_LEN) == 0){ return 0; } #endif usb_close(usbhandle); } } } } fprintf(stderr, "%s: usb_open(): did not find any%s USB device \"%.4s\"\n", progname, SerialNumber ? " (matching)": "", serial); return 1; }
static int simple_config(dev_link_t *link) { static ioaddr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; client_handle_t handle = link->handle; serial_info_t *info = link->priv; tuple_t tuple; u_char buf[256]; cisparse_t parse; cistpl_cftable_entry_t *cf = &parse.cftable_entry; config_info_t config; int i, j, try; /* If the card is already configured, look up the port and irq */ i = CardServices(GetConfigurationInfo, handle, &config); if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) { ioaddr_t port = 0; if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) { port = config.BasePort2; info->slave = 1; } else if ((info->manfid == MANFID_OSITECH) && (config.NumPorts1 == 0x40)) { port = config.BasePort1 + 0x28; info->slave = 1; } if (info->slave) return setup_serial(info, port, config.AssignedIRQ); } link->conf.Vcc = config.Vcc; /* First pass: look for a config entry that looks normal. */ tuple.TupleData = (cisdata_t *)buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; tuple.Attributes = 0; tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; /* Two tries: without IO aliases, then with aliases */ for (try = 0; try < 2; try++) { i = first_tuple(handle, &tuple, &parse); while (i != CS_NO_MORE_ITEMS) { if (i != CS_SUCCESS) goto next_entry; if (cf->vpp1.present & (1<<CISTPL_POWER_VNOM)) link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM]/10000; if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; i = CardServices(RequestIO, link->handle, &link->io); if (i == CS_SUCCESS) goto found_port; } next_entry: i = next_tuple(handle, &tuple, &parse); } } /* Second pass: try to find an entry that isn't picky about its base address, then try to grab any standard serial port address, and finally try to get any free port. */ i = first_tuple(handle, &tuple, &parse); while (i != CS_NO_MORE_ITEMS) { if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { link->conf.ConfigIndex = cf->index; for (j = 0; j < 5; j++) { link->io.BasePort1 = base[j]; link->io.IOAddrLines = base[j] ? 16 : 3; i = CardServices(RequestIO, link->handle, &link->io); if (i == CS_SUCCESS) goto found_port; } } i = next_tuple(handle, &tuple, &parse); } found_port: if (i != CS_SUCCESS) { cs_error(link->handle, RequestIO, i); return -1; } i = CardServices(RequestIRQ, link->handle, &link->irq); if (i != CS_SUCCESS) { cs_error(link->handle, RequestIRQ, i); link->irq.AssignedIRQ = 0; } if (info->multi && (info->manfid == MANFID_3COM)) link->conf.ConfigIndex &= ~(0x08); i = CardServices(RequestConfiguration, link->handle, &link->conf); if (i != CS_SUCCESS) { cs_error(link->handle, RequestConfiguration, i); return -1; } return setup_serial(info, link->io.BasePort1, link->irq.AssignedIRQ); }