void operate(int*num, int*num2, int*num3) // NO printfs allowed here { int *ptr1, *ptr2; if((ptr1 = read_address(1)) && check_address(ptr1, num, num2, num3) && (ptr2 = read_address(2)) && check_address(ptr2, num, num2, num3)) { int operand = read_operand(); // read operand as int char operator = read_operator(); // read operator as char run_operation(ptr1, ptr2, operand, operator); // operate } // endif // done, thank god } // operate();
void operate(int *address1, int *address2, int *address3) { int *ptr1, *ptr2, operand; char operator; ptr1 = read_address(1); // if the user inputs 2 addresses and they are both true call for operand and operator if (check_address(ptr1, address1, address2, address3) && (ptr2 = read_address(2)) && check_address(ptr2, address1, address2, address3)) { operand = read_operand(); operator = read_operator(); run_operation(ptr1, ptr2, operand, operator); } return; }//operate()
static int skfp_open(struct net_device *dev) { struct s_smc *smc = netdev_priv(dev); int err; pr_debug(KERN_INFO "entering skfp_open\n"); err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED, dev->name, dev); if (err) return err; read_address(smc, NULL); memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6); init_smt(smc, NULL); smt_online(smc, 1); STI_FBI(); mac_clear_multicast(smc); mac_drv_rx_mode(smc, RX_DISABLE_PROMISC); netif_start_queue(dev); return (0); }
static netdef_t *netdef_parse (char *str) { unsigned int ipaddr, netmask; netdef_t *netdef; char ipbuf[DOTTED_QUAD_LEN + 1]; if (strcmp (str, "any") == 0) { ipaddr = 0; netmask = 0; } else { read_address (&str, ipbuf); ipaddr = inet_addr (ipbuf); if (ipaddr == INADDR_NONE) return NULL; if (*str == 0) netmask = 0xfffffffful; else if (*str != '/') return NULL; else { str++; if (read_address (&str, ipbuf) == 0) { /* netmask length */ unsigned int len = strtoul (ipbuf, NULL, 0); if (len > 32) return NULL; netmask = 0xfffffffful >> (32 - len); netmask <<= (32 - len); /*FIXME: hostorder? */ } else netmask = inet_network (ipbuf); netmask = htonl (netmask); }
int main() { uart_init(); stdout = &mystdout; sei(); DDRB = 0x20; twi_master_init(); _delay_ms(20); uint8_t buffer[64]; for(uint8_t i; i < 64; i++) buffer[i] = i; write_page_address(0x00, &buffer, 64); _delay_ms(250); for(uint8_t i; i < 64; i++) buffer[i] = i; write_page_address(0x10, &buffer, 20); for(uint8_t i = 0; i < 64; i++) buffer[i] = 0; _delay_ms(250); read_page_address(0x00, &buffer, 64); for(uint8_t i = 0 ; i < 64; i++) printf("%d ", buffer[i]); printf("\n\n"); _delay_ms(250); printf("%d %d \n", read_address(0x00), read_address(0x01)); }
void read_all(void) { char *line; int ctr; ctr = 1; while ((line = read_address(ctr)) != NULL) { strtok(line, "\n"); _dbgmsg("Entry %2i: %s\n", ctr, line); data_to_address(ctr); ctr++; } free(line); }
/* * FDDI card soft reset */ void init_board(struct s_smc *smc, u_char *mac_addr) { card_start(smc) ; read_address(smc,mac_addr) ; if (!(inp(ADDR(B0_DAS)) & DAS_AVAIL)) smc->s.sas = SMT_SAS ; /* Single att. station */ else smc->s.sas = SMT_DAS ; /* Dual att. station */ if (!(inp(ADDR(B0_DAS)) & DAS_BYP_ST)) smc->mib.fddiSMTBypassPresent = 0 ; /* without opt. bypass */ else smc->mib.fddiSMTBypassPresent = 1 ; /* with opt. bypass */ }
static std::vector< Address > read_addrs( const char* file_name ) { std::wifstream is( file_name ); json_spirit::wValue value; read( is, value ); const json_spirit::wArray& addr_array = value.get_array(); std::vector< Address > addrs; for( unsigned int i = 0; i < addr_array.size(); ++i ) { addrs.push_back( read_address( addr_array[i].get_obj() ) ); } return addrs; }
/* * This program acts as a generic gateway. It listens for connections * to a local address ('-l' option). Upon accepting a client connection, * it connects to the specified remote address ('-r' option) and then * just pumps the data through without any modification. */ int main(int argc, char *argv[]) { extern char *optarg; int opt, sock, n; int laddr, raddr, num_procs; int serialize_accept = 0; struct sockaddr_in lcl_addr, cli_addr; st_netfd_t cli_nfd, srv_nfd; prog = argv[0]; num_procs = laddr = raddr = 0; /* Parse arguments */ while((opt = getopt(argc, argv, "l:r:p:Sh")) != EOF) { switch (opt) { case 'l': read_address(optarg, &lcl_addr); laddr = 1; break; case 'r': read_address(optarg, &rmt_addr); if (rmt_addr.sin_addr.s_addr == INADDR_ANY) { fprintf(stderr, "%s: invalid remote address: %s\n", prog, optarg); exit(1); } raddr = 1; break; case 'p': num_procs = atoi(optarg); if (num_procs < 1) { fprintf(stderr, "%s: invalid number of processes: %s\n", prog, optarg); exit(1); } break; case 'S': /* * Serialization decision is tricky on some platforms. For example, * Solaris 2.6 and above has kernel sockets implementation, so supposedly * there is no need for serialization. The ST library may be compiled * on one OS version, but used on another, so the need for serialization * should be determined at run time by the application. Since it's just * an example, the serialization decision is left up to user. * Only on platforms where the serialization is never needed on any OS * version st_netfd_serialize_accept() is a no-op. */ serialize_accept = 1; break; case 'h': case '?': fprintf(stderr, "Usage: %s -l <[host]:port> -r <host:port> " "[-p <num_processes>] [-S]\n", prog); exit(1); } } if (!laddr) { fprintf(stderr, "%s: local address required\n", prog); exit(1); } if (!raddr) { fprintf(stderr, "%s: remote address required\n", prog); exit(1); } if (num_procs == 0) num_procs = cpu_count(); fprintf(stderr, "%s: starting proxy daemon on %s:%d\n", prog, inet_ntoa(lcl_addr.sin_addr), ntohs(lcl_addr.sin_port)); /* Start the daemon */ start_daemon(); /* Initialize the ST library */ if (st_init() < 0) { print_sys_error("st_init"); exit(1); } /* Create and bind listening socket */ if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { print_sys_error("socket"); exit(1); } n = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) < 0) { print_sys_error("setsockopt"); exit(1); } if (bind(sock, (struct sockaddr *)&lcl_addr, sizeof(lcl_addr)) < 0) { print_sys_error("bind"); exit(1); } listen(sock, 128); if ((srv_nfd = st_netfd_open_socket(sock)) == NULL) { print_sys_error("st_netfd_open"); exit(1); } /* See the comment regarding serialization decision above */ if (num_procs > 1 && serialize_accept && st_netfd_serialize_accept(srv_nfd) < 0) { print_sys_error("st_netfd_serialize_accept"); exit(1); } /* Start server processes */ set_concurrency(num_procs); for ( ; ; ) { n = sizeof(cli_addr); cli_nfd = st_accept(srv_nfd, (struct sockaddr *)&cli_addr, &n, -1); if (cli_nfd == NULL) { print_sys_error("st_accept"); exit(1); } if (st_thread_create(handle_request, cli_nfd, 0, 0) == NULL) { print_sys_error("st_thread_create"); exit(1); } } /* NOTREACHED */ return 1; }
static int skfp_driver_init(struct net_device *dev) { struct s_smc *smc = netdev_priv(dev); skfddi_priv *bp = &smc->os; int err = -EIO; pr_debug(KERN_INFO "entering skfp_driver_init\n"); bp->base_addr = dev->base_addr; smc->hw.irq = dev->irq; spin_lock_init(&bp->DriverLock); bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA); if (!bp->LocalRxBuffer) { printk("could not allocate mem for "); printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE); goto fail; } bp->SharedMemSize = mac_drv_check_space(); pr_debug(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize); if (bp->SharedMemSize > 0) { bp->SharedMemSize += 16; bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev, bp->SharedMemSize, &bp->SharedMemDMA); if (!bp->SharedMemSize) { printk("could not allocate mem for "); printk("hardware module: %ld byte\n", bp->SharedMemSize); goto fail; } bp->SharedMemHeap = 0; } else { bp->SharedMemAddr = NULL; bp->SharedMemHeap = 0; } memset(bp->SharedMemAddr, 0, bp->SharedMemSize); card_stop(smc); pr_debug(KERN_INFO "mac_drv_init()..\n"); if (mac_drv_init(smc) != 0) { pr_debug(KERN_INFO "mac_drv_init() failed.\n"); goto fail; } read_address(smc, NULL); pr_debug(KERN_INFO "HW-Addr: %02x %02x %02x %02x %02x %02x\n", smc->hw.fddi_canon_addr.a[0], smc->hw.fddi_canon_addr.a[1], smc->hw.fddi_canon_addr.a[2], smc->hw.fddi_canon_addr.a[3], smc->hw.fddi_canon_addr.a[4], smc->hw.fddi_canon_addr.a[5]); memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6); smt_reset_defaults(smc, 0); return (0); fail: if (bp->SharedMemAddr) { pci_free_consistent(&bp->pdev, bp->SharedMemSize, bp->SharedMemAddr, bp->SharedMemDMA); bp->SharedMemAddr = NULL; } if (bp->LocalRxBuffer) { pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE, bp->LocalRxBuffer, bp->LocalRxBufferDMA); bp->LocalRxBuffer = NULL; } return err; }
static int data_to_address(int n) { _dbgmsg("parsing data from file for entry %i", n); char *line; char c; int i; /* data segment */ int pos; /* position in data segment */ int ctr; /* position in inputline */ int ret; char *firstname; char *lastname; char *street; char *nr; int *number; char *zp; int *zipcode; char *city; i = 0; ctr = 0; pos = 0; line = read_address(n); if (line == NULL) { return -1; } _dbgmsg("read data entry as \"%s\"", line); /* prepare the memory for the data */ firstname = malloc(strlen(line)); lastname = malloc(strlen(line)); street = malloc(strlen(line)); number = malloc(sizeof(int)); nr = malloc(strlen(line)); zipcode = malloc(sizeof(int)); zp = malloc(strlen(line)); city = malloc(strlen(line)); /* initialize the data */ firstname[0] = '\0'; lastname[0] = '\0'; street[0] = '\0'; nr[0] = '\0'; zp[0] = '\0'; city[0] = '\0'; while (((c = line[ctr]) != ';') && (i <= 5)) { if (c == '#') { _dbgwarn("found comment -> skipping rest of line"); return 0; } else if (c == '\n') { _dbgwarn("found newline -> skipping rest of line"); return 0; } else if (c == ',') { i++; ctr++; pos = 0; } else { if (c == ' ') { ctr++; } else { switch (i) { case 0: firstname[pos] = c; firstname[pos+1] = '\0'; break; case 1: lastname[pos] = c; lastname[pos+1] = '\0'; break; case 2: street[pos] = c; street[pos+1] = '\0'; break; case 3: nr[pos] = c; nr[pos+1] = '\0'; break; case 4: zp[pos] = c; zp[pos+1] = '\0'; break; case 5: city[pos] = c; city[pos+1] = '\0'; break; default: _dbgerr("something went wrong at parsing " "\"%c\"", c); break; } pos++; ctr++; } } } /* fitting memory and data */ firstname = realloc(firstname, strlen(firstname)); lastname = realloc(lastname, strlen(lastname)); street = realloc(street, strlen(street)); *number = atoi(nr); free(nr); *zipcode = atoi(zp); free(zp); city = realloc(city, strlen(city)); _dbgmsg("finished parsing -> adding new address entry"); ret = add_address(firstname, lastname, street, number, zipcode, city); free(firstname); free(lastname); free(street); free(number); free(zipcode); free(city); _dbgnice("freed all address data for entry %i", n); return ret; }
static void server_poll (void) { gsocketp s = server_socket; if (!s) { return; } for (;;) { UDPpacket *packet = socket_rx_dequeue(s); if (!packet) { break; } gsocketp s = socket_find_server_side_remote_ip(read_address(packet)); if (!s) { char *tmp = iptodynstr(read_address(packet)); ERR("Server: No serer side socket found for %s", tmp); myfree(tmp); continue; } uint8_t *data; uint8_t *odata; uint8_t *pdata; uint8_t uncompressed; /* * Remove any optional header */ packet = packet_definalize(s, packet); /* * Uncompress the packet if it has an invalid type. */ pdata = packet->data; data = packet_decompress(packet, &uncompressed); odata = data; msg_type type = (typeof(type)) *data++; socket_count_inc_pak_rx(s, type); switch (type) { case MSG_PING: socket_rx_ping(s, packet, data); break; case MSG_PONG: socket_rx_pong(s, packet, data); break; case MSG_CLIENT_STATUS: socket_rx_client_status(s, packet, data); break; case MSG_CLIENT_JOIN: if (socket_rx_client_join(s, packet, data)) { server_rx_client_join(s); } break; case MSG_CLIENT_LEAVE: if (socket_rx_client_leave(s, packet, data)) { server_rx_client_leave(s); } break; case MSG_CLIENT_CLOSE: server_rx_client_close(s); socket_rx_client_close(s, packet, data); break; case MSG_CLIENT_SHOUT: socket_rx_client_shout(s, packet, data); break; case MSG_TELL: socket_rx_tell(s, packet, data); break; case MSG_CLIENT_PLAYER_MOVE: socket_server_rx_player_move(s, packet, data); break; case MSG_CLIENT_PLAYER_ACTION: socket_server_rx_player_action(s, packet, data); break; case MSG_SERVER_CLOSE: ERR("MSG_SERVER_CLOSE received unexpected on server"); break; case MSG_SERVER_STATUS: ERR("MSG_SERVER_STATUS received unexpected on server"); break; case MSG_SERVER_SHOUT: ERR("MSG_SERVER_SHOUT received unexpected on server"); break; case MSG_SERVER_MAP_UPDATE: ERR("MSG_SERVER_MAP_UPDATE received unexpected on server"); break; default: ERR("Unknown server message type received [%u]", type); } if (uncompressed) { packet->data = pdata; myfree(odata); } packet_free(packet); } }
/*---------------------------------------------------------------------------*/ int main(void) { uint8_t rv; uint8_t i = 0; uint8_t mcp3421_addr; uint8_t mcp9800_addr; uint8_t tmpReadout[4]; /* Variables for cold junction moving average filter */ int16_t movAvg_read; int8_t movAvg_ind = 0; int32_t movAvg_sum = 0; uint8_t movAvg_stabil = 0; int16_t movAvg_mem[8] = {0,0,0,0,0,0,0,0}; gainSetting = 0; timer0_counter = 0; initSerialNumber(); usb_init(); I2C_Init(); timer_init(); pinMode(B,1,OUTPUT); /*-----------------------------------------------------------------------*/ /* Search for viable MCP3421 address options */ /*-----------------------------------------------------------------------*/ for(i=0x68;i<0x70;i++) { I2C_Start(); rv = I2C_Write(write_address(i)); I2C_Stop(); if(rv == 0) { mcp3421_addr = i; } } /*-----------------------------------------------------------------------*/ /* Search for viable MCP9800 address options */ /*-----------------------------------------------------------------------*/ I2C_Start(); rv = I2C_Write(write_address(0x48)); I2C_Stop(); if(rv == 0) { mcp9800_addr = 0x48; } else { mcp9800_addr = 0x4D; } /*-----------------------------------------------------------------------*/ /* Set MCP9800 to 12 bit resolution */ /*-----------------------------------------------------------------------*/ I2C_Start(); I2C_Write(write_address(mcp9800_addr)); I2C_Write(0x01); I2C_Write((1<<7)|(1<<6)|(1<<5)); I2C_Stop(); /*-----------------------------------------------------------------------*/ /* Set MCP9800 Register Pointer to Ambient Temperature */ /*-----------------------------------------------------------------------*/ I2C_Start(); I2C_Write(write_address(mcp9800_addr)); I2C_Write(0x00); I2C_Stop(); while(1) { /*-------------------------------------------------------------------*/ /* MCP9800: Cold junction channel */ /*-------------------------------------------------------------------*/ usbPoll(); I2C_Start(); debug[0] = I2C_Write(read_address(mcp9800_addr)); tmpReadout[0] = I2C_Read(ACK); tmpReadout[1] = I2C_Read(NO_ACK); I2C_Stop(); movAvg_read = ((int16_t)tmpReadout[0] << 8) + ((int16_t)tmpReadout[1]); movAvg_sum -= movAvg_mem[movAvg_ind]; movAvg_sum += movAvg_read; movAvg_mem[movAvg_ind] = movAvg_read; if(movAvg_ind == 7) { movAvg_ind = 0; movAvg_stabil = 1; } else { movAvg_ind++; } if(movAvg_stabil == 1) { movAvg_read = movAvg_sum >> 3; } usbPoll(); cli(); coldJunctionReadout[0] = movAvg_read >> 8; coldJunctionReadout[1] = movAvg_read & 0xFF; sei(); /*-------------------------------------------------------------------*/ /* MCP3421: 3.75 SPS + 18 Bits + Initiate new conversion /*-------------------------------------------------------------------*/ usbPoll(); I2C_Start(); I2C_Write(write_address(mcp3421_addr)); I2C_Write((1<<7)|(1<<3)|(1<<2)|gainSetting); I2C_Stop(); /*-------------------------------------------------------------------*/ /* Small delay ... /*-------------------------------------------------------------------*/ timer0_counter = 250; while(timer0_counter) { usbPoll(); } /*-------------------------------------------------------------------*/ /* MCP3421 /*-------------------------------------------------------------------*/ usbPoll(); I2C_Start(); I2C_Write(read_address(mcp3421_addr)); tmpReadout[0] = I2C_Read(ACK); tmpReadout[1] = I2C_Read(ACK); tmpReadout[2] = I2C_Read(ACK); tmpReadout[3] = I2C_Read(NO_ACK); I2C_Stop(); usbPoll(); cli(); thermocoupleReadout[0] = tmpReadout[0]; thermocoupleReadout[1] = tmpReadout[1]; thermocoupleReadout[2] = tmpReadout[2]; thermocoupleReadout[3] = tmpReadout[3]; sei(); }
Command *parser(char *path, int *size_com, int *num_str, int *err) { Command *commands; Label *labels; int point_com = 0, point_lbl = 0; FILE *input; *num_str = 0; input = fopen(path, "r"); commands = (Command *)malloc(sizeof(Command) * SIZE_COMMAND); labels = (Label *)malloc(sizeof(Label) * SIZE_LABEL); while(!feof(input)) { char str[SIZE_STRING], *lexeme; int point_str = 0; str[0] = 0; ++(*num_str); if ((point_com - 1) % SIZE_COMMAND == 0) commands = (Command *)realloc(commands, sizeof(Command) * (point_com + SIZE_COMMAND)); if ((point_lbl - 1) % SIZE_LABEL == 0) labels = (Label *)realloc(labels, sizeof(Label) * (point_lbl + SIZE_LABEL)); fgets(str, SIZE_STRING - 1, input); lexeme = read_word(str, &point_str, err); if (*err != 0) { clean_arrays(commands, point_com, labels, point_lbl); return NULL; } commands[point_com].opcode = is_command(lexeme); if (commands[point_com].opcode == LDC) commands[point_com].number = read_number(str, &point_str, err); else if ((commands[point_com].opcode == LD) || (commands[point_com].opcode == ST)) commands[point_com].address = read_address(str, &point_str, err); else if ((commands[point_com].opcode == BR) || (commands[point_com].opcode == JMP)) { commands[point_com].label = read_word(str, &point_str, err); if (*err == 1) *err = 5; if (*err == 0) { if (is_command(commands[point_com].label) == LBL) put_in_array(labels, &point_lbl, commands[point_com].label, -1, *num_str, err); else *err = 5; } } else if (commands[point_com].opcode == LBL) { while ((str[point_str] == ' ') || (str[point_str] == 9)) ++point_str; if (str[point_str++] == ':') put_in_array(labels, &point_lbl, lexeme, point_com, *num_str, err); else *err = 6; } if (*err != 0) { clean_arrays(commands, point_com + 1, labels, point_lbl); return NULL; } while ((str[point_str] == ' ') || (str[point_str] == 9)) ++point_str; if ((str[point_str] != ';') && (str[point_str] != 0) && (str[point_str] != '\n')) { *err = 8; clean_arrays(commands, point_com + 1, labels, point_lbl); return NULL; } if ((commands[point_com].opcode != LBL) && (commands[point_com].opcode != NUL)) { commands[point_com].num_str = *num_str; ++point_com; } } replacement(commands, point_com, labels, point_lbl, num_str, err); if (*err != 0) { clean_arrays(commands, point_com, labels, point_lbl); return NULL; } else { *size_com = point_com; return commands; } }