PROCESS_THREAD(snd_process, ev, data){ static struct etimer et; static struct simple_udp_connection broadcast_connection; static uip_ipaddr_t mcast_allnodes_address; PROCESS_BEGIN(); etimer_set(&et, CLOCK_SECOND*HOW_MUCH_TIME); set_address(); simple_udp_register(&broadcast_connection, UDP_PORT, NULL,UDP_PORT, callback_function); mcast_allnodes_address=get_multicast_all_nodes_addr(); while(1){//A broadcast message is sent periodically PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); simple_udp_sendto(&broadcast_connection, "Hello", 5, (const uip_ipaddr_t*)&mcast_allnodes_address); etimer_reset(&et); } PROCESS_END(); }
int main ( int argc, char **argv) { struct sockaddr_in peer; SOCKET s; INIT(); set_address(argv[1], argv[2], &peer, "upd"); s = socket(AF_INET, SOCK_DGRAM, 0); if (!isvalidsock(s)) error(1, errno, "error in call socket()"); if (connect(s, (struct sockaddr *)&peer, sizeof(peer))) error (1, errno, "error in call connect"); udpclient(s, &peer); EXIT(0); }
int LidarLiteI2C::probe() { // cope with both old and new I2C bus address const uint8_t addresses[2] = {LL40LS_BASEADDR, LL40LS_BASEADDR_OLD}; // more retries for detection _retries = 10; for (uint8_t i = 0; i < sizeof(addresses); i++) { uint8_t who_am_i = 0, max_acq_count = 0; // set the I2C bus address set_address(addresses[i]); /* register 2 defaults to 0x80. If this matches it is almost certainly a ll40ls */ if (read_reg(LL40LS_MAX_ACQ_COUNT_REG, max_acq_count) == OK && max_acq_count == 0x80) { // very likely to be a ll40ls. This is the // default max acquisition counter goto ok; } if (read_reg(LL40LS_WHO_AM_I_REG, who_am_i) == OK && who_am_i == LL40LS_WHO_AM_I_REG_VAL) { // it is responding correctly to a // WHO_AM_I. This works with older sensors (pre-production) goto ok; } debug("probe failed reg11=0x%02x reg2=0x%02x\n", (unsigned)who_am_i, (unsigned)max_acq_count); } // not found on any address return -EIO; ok: _retries = 3; // reset the sensor to ensure it is in a known state with // correct settings return reset_sensor(); }
/* implement wrapper for PX4 I2C driver */ bool PX4_I2C::do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) { if (!init_done) { init_done = true; // we do late init() so we can setup the device paths snprintf(devname, sizeof(devname), "AP_I2C_%u", instance); snprintf(devpath, sizeof(devpath), "/dev/api2c%u", instance); init_ok = (init() == OK); if (init_ok) { instance++; } } if (!init_ok) { return false; } set_address(address); bool ret = (transfer(send, send_len, recv, recv_len) == OK); return ret; }
void Extsram::write_data(uint16_t start_address, uint16_t amount_of_bytes, uint32_t flash_address){ uint16_t a; uint8_t byte; data_p_mode = out; addr_p_mode = out; for(a=0; a<amount_of_bytes; a++){ set_address(start_address+a); byte = pgm_read_byte(Emulator::eeprom1_image_address+a); *data_p = byte; //_delay_us(20); ce = low; we = low; //_delay_us(20); ce = hi; we = hi; //_delay_us(20); } default_mode(); //l.L2 = Leds::off; }
void Extsram::read_data_and_transmit(uint16_t start_address, uint16_t amount_of_bytes, Bluetooth* bt){ /* * reads provided amount of bytes to bt */ uint16_t a; uint8_t byte; read_sram_mode(); oe = low; for(a=0; a<amount_of_bytes; a++){ set_address(start_address+a); //_delay_us(20); ce = low; //_delay_us(20); byte = *data_v; //byte = 'u'; bt->put_c(byte); ce = hi; } default_mode(); }
/* 创建隧道对象函数 */ Tunnel *tunnel_new_client (const char *host, int host_port) { const char *remote; int remote_port; Tunnel *tunnel; tunnel=(Tunnel *)malloc(sizeof(Tunnel)); if(tunnel==NULL) { return NULL; } tunnel->in_fd=INVALID_SOCKET; tunnel->out_fd=INVALID_SOCKET; tunnel->server_socket=INVALID_SOCKET; tunnel->dest.host_name=host; tunnel->dest.host_port=host_port; tunnel->dest.user_agent=NULL; tunnel->content_length=DEFAULT_CONTENT_LENGTH; tunnel->buf_ptr=tunnel->buf; tunnel->buf_len=0; /* tunnel->in_total_raw=0; tunnel->in_total_data=0; tunnel->out_total_raw=0; tunnel->out_total_data=0; */ tunnel->strict_content_length=FALSE; tunnel->bytes=0; remote=tunnel->dest.host_name; remote_port=tunnel->dest.host_port; if(set_address(&tunnel->address,remote,remote_port)==-1) { free(tunnel); return NULL; } //tunnel->keep_alive = DEFAULT_KEEP_ALIVE; //tunnel->max_connection_age = DEFAULT_MAX_CONNECTION_AGE; //tunnel->out_connect_time = DEFAULT_OUT_CONNECTION_TIME; return tunnel; }
/* function to merge two empty gaps if they are next to each other. */ void remove_double_gaps(long *memory) { long index; index = BLOCK_START; while(1) { if(block_is_used(memory[index]) == 0 && block_is_used(memory[get_index(memory[index])]) == 0) { memory[index] = set_address(memory[get_index(memory[index])], 0); /* to take care of a removal between to empty gaps. */ remove_double_gaps(memory); break; } index = get_index(memory[index]); if(index >= memory[BLOCK_MAX_INDEX]) { break; } } }
/* send general call on I2C bus to syncronise all LEDs */ int OREOLED::send_general_call() { int ret = -ENODEV; /* set I2C address to zero */ set_address(0); /* prepare command : 0x01 = general hardware call, 0x00 = I2C address of master (but we don't act as a slave so set to zero)*/ uint8_t msg[] = {0x01, 0x00}; /* send I2C command */ if (transfer(msg, sizeof(msg), nullptr, 0) == OK) { ret = OK; } /* record time */ _last_gencall = hrt_absolute_time(); return ret; }
int new_tcp_client(const char *host, short port) { int fd; struct sockaddr_in address; fd = socket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { perror("socket"); return -1; } set_address(host, port, &address); if (connect(fd, (struct sockaddr*)&address, sizeof(address)) < 0) { perror("connect"); close(fd); return -1; } return fd; }
int TCPSocketConnection::connect(const char *host, const int port) { if (init_socket(SOCK_STREAM, IPPROTO_TCP) < 0) { DBG_SOCKET("Failed to create tcp socket"); return -1; } if (set_address(host, port) != 0) { DBG_SOCKET("Failed to set address (tcp)"); return -1; } if (_cc3000_module->_socket.connect(_sock_fd, (const sockaddr *)&_remote_host, sizeof(_remote_host)) < 0) { DBG_SOCKET("Failed to connect (tcp)"); close(); return -1; } _is_connected = true; return 0; }
int MS5611::probe_address(uint8_t address) { uint8_t cmd = ADDR_RESET_CMD; /* select the address we are going to try */ set_address(address); /* send reset command */ if (OK != transfer(&cmd, 1, nullptr, 0)) return -EIO; /* wait for PROM contents to be in the device (2.8 ms) */ usleep(3000); /* read PROM */ if (OK != read_prom()) return -EIO; return OK; }
bool CMySocket::ConnectServer() { Close(); m_bfirstpack = true; m_bZlib = false; m_zlibIn.Init(); m_zlibDe.Init(); m_sRecvBuf.clear(); struct sockaddr_in peer; if (!set_address(m_szdomian, m_port, &peer)) { g_WriteLog.WriteLog(C_LOG_ERROR, "set_address error, domain:%s, port:%hd", m_szdomian, m_port); return FALSE; } SOCKET s = socket(AF_INET, SOCK_STREAM, 0); if (s == INVALID_SOCKET) { int nerrid = WSAGetLastError(); g_WriteLog.WriteLog(C_LOG_ERROR, "create sock error, errno=%d, %s", errno, FormatLastError(nerrid)); return FALSE; } if (connect(s, (struct sockaddr *)&peer, sizeof(peer))) { int nerrid = WSAGetLastError(); g_WriteLog.WriteLog(C_LOG_ERROR, "connect to %s:%hu,errno=%d, %s", m_szdomian, m_port, errno, FormatLastError(nerrid)); closesocket(s); s = INVALID_SOCKET; return FALSE; } setNonblock(s); setNoDelay(s, true); m_hSocket = s; //赋值后导致recv线程开始执行 return m_hSocket != INVALID_SOCKET; }
Walker::ApplyStatus dw2wtp_do_while_statement_walker::operator () (SuifObject *x) { SuifEnv *env = get_env(); DoWhileStatement *do_while_stmt = to<DoWhileStatement>(x); Expression *do_while_condition = do_while_stmt->get_condition(); do_while_stmt->set_condition(0); Statement *do_while_body = do_while_stmt->get_body(); do_while_stmt->set_body(0); IfStatement *first_iteration = create_if_statement(env, to<Expression>(deep_suif_clone(do_while_condition)), to<Statement>(deep_suif_clone(do_while_body))); WhileStatement *remaining_iterations = create_while_statement(env, do_while_condition, do_while_body); StatementList *replacement = create_statement_list(env); replacement->append_statement(first_iteration); replacement->append_statement(remaining_iterations); do_while_stmt->get_parent()->replace(do_while_stmt, replacement); set_address(replacement); return Walker::Replaced; }
static void dissect_vektor_igrp (tvbuff_t *tvb, proto_tree *igrp_vektor_tree, guint8 network) { union { guint8 addr_bytes[4]; guint32 addr_word; } addr; address ip_addr; if (network != 0) { /* * Interior route; network is the high-order byte, and the three * bytes in the vector are the lower 3 bytes. */ addr.addr_bytes[0]=network; addr.addr_bytes[1]=tvb_get_guint8(tvb,0); addr.addr_bytes[2]=tvb_get_guint8(tvb,1); addr.addr_bytes[3]=tvb_get_guint8(tvb,2); } else { /* * System or exterior route; the three bytes in the vector are * the three high-order bytes, and the low-order byte is 0. */ addr.addr_bytes[0]=tvb_get_guint8(tvb,0); addr.addr_bytes[1]=tvb_get_guint8(tvb,1); addr.addr_bytes[2]=tvb_get_guint8(tvb,2); addr.addr_bytes[3]=0; } set_address(&ip_addr, AT_IPv4, 4, &addr); igrp_vektor_tree = proto_tree_add_subtree_format(igrp_vektor_tree, tvb, 0 ,14, ett_igrp_net, NULL, "Entry for network %s", address_to_str(wmem_packet_scope(), &ip_addr)); proto_tree_add_ipv4(igrp_vektor_tree, hf_igrp_network, tvb, 0, 3, addr.addr_word); proto_tree_add_item(igrp_vektor_tree, hf_igrp_delay, tvb, 3, 3, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_bandwidth, tvb, 6, 3, ENC_BIG_ENDIAN); proto_tree_add_uint_format_value(igrp_vektor_tree, hf_igrp_mtu, tvb, 9, 2, tvb_get_ntohs(tvb,9), "%d bytes", tvb_get_ntohs(tvb,9)); proto_tree_add_item(igrp_vektor_tree, hf_igrp_reliability, tvb, 11, 1, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_load, tvb, 12, 1, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_hop_count, tvb, 13, 1, ENC_BIG_ENDIAN); }
static void set_address (Elf *elf, size_t offset) { if (elf->kind == ELF_K_AR) { Elf *child = elf->state.ar.children; while (child != NULL) { if (child->map_address == NULL) { child->map_address = elf->map_address; child->start_offset -= offset; if (child->kind == ELF_K_AR) child->state.ar.offset -= offset; set_address (child, offset); } child = child->next; } } }
int main(void) { DDRC = 0xFF; uart_init(); // stdout = &mystdout; //setup_timer0(); set_address(0xFFFF); sei(); while(PIND & (1 <<7)); tx_buffer.msg.app_msgs.ping_req.tag = 0x11; send_msg(0x1234, PING_REQ, 0x00); while (1) { } //PORTC = 0xFF; //PORTC = 0x00; //tx_char(0x55); return 1; }
virtual void read(boost::shared_ptr<nscapi::settings_proxy> proxy, bool oneliner, bool is_sample) { //parent::read(proxy, oneliner, is_sample); set_address(this->value); nscapi::settings_helper::settings_registry settings(proxy); nscapi::settings_helper::path_extension root_path = settings.path(get_path()); if (is_sample) root_path.set_sample(); //target_object::options_type options; root_path.add_path() ("TARGET", "Target definition for: " + this->alias) ; root_path.add_key() ("address", sh::string_fun_key<std::string>(boost::bind(&target_object::set_address, this, _1)), "TARGET ADDRESS", "Target host address") ("host", sh::string_fun_key<std::string>(boost::bind(&target_object::set_property_string, this, "host", _1)), "TARGET HOST", "The target server to report results to.", true) ("port", sh::string_fun_key<std::string>(boost::bind(&target_object::set_property_string, this, "port", _1)), "TARGET PORT", "The target server port", true) ("timeout", sh::int_fun_key<int>(boost::bind(&target_object::set_property_int, this, "timeout", _1), 30), "TIMEOUT", "Timeout when reading/writing packets to/from sockets.") ("retries", sh::int_fun_key<int>(boost::bind(&target_object::set_property_int, this, "retries", _1), 3), "RETRIES", "Number of times to retry sending.") ; settings.register_all(); settings.notify(); }
int TRONE::probe() { uint8_t who_am_i = 0; const uint8_t cmd = TRONE_WHO_AM_I_REG; // set the I2C bus address set_address(TRONE_BASEADDR); // can't use a single transfer as TROne need a bit of time for internal processing if (transfer(&cmd, 1, nullptr, 0) == OK) { if (transfer(nullptr, 0, &who_am_i, 1) == OK && who_am_i == TRONE_WHO_AM_I_REG_VAL) { return measure(); } } DEVICE_DEBUG("WHO_AM_I byte mismatch 0x%02x should be 0x%02x\n", (unsigned)who_am_i, TRONE_WHO_AM_I_REG_VAL); // not found on any address return -EIO; }
/* tcp_server - set up for a TCP server */ SOCKET tcp_server( char *hname, char *sname ) { struct sockaddr_in local; SOCKET s; const int on = 1; set_address( hname, sname, &local, "tcp" ); s = socket( AF_INET, SOCK_STREAM, 0 ); if ( !isvalidsock( s ) ) error( 1, errno, "socket call failed" ); if ( setsockopt( s, SOL_SOCKET, SO_REUSEADDR, ( char * )&on, sizeof( on ) ) ) error( 1, errno, "setsockopt failed" ); if ( bind( s, ( struct sockaddr * ) &local, sizeof( local ) ) ) error( 1, errno, "bind failed" ); if ( listen( s, NLISTEN ) ) error( 1, errno, "listen failed" ); return s; }
static Object _php_make_header_object(ENVELOPE *en) { Object ret(SystemLib::AllocStdClassObject()); OBJ_SET_ENTRY(ret, en, "remail", remail); OBJ_SET_ENTRY(ret, en, "date", date); OBJ_SET_ENTRY(ret, en, "Date", date); OBJ_SET_ENTRY(ret, en, "subject", subject); OBJ_SET_ENTRY(ret, en, "Subject", subject); OBJ_SET_ENTRY(ret, en, "in_reply_to", in_reply_to); OBJ_SET_ENTRY(ret, en, "message_id", message_id); OBJ_SET_ENTRY(ret, en, "newsgroups", newsgroups); OBJ_SET_ENTRY(ret, en, "followup_to", followup_to); OBJ_SET_ENTRY(ret, en, "references", references); set_address(ret, "to", en->to); set_address(ret, "from", en->from); set_address(ret, "cc", en->cc); set_address(ret, "bcc", en->bcc); set_address(ret, "reply_to", en->reply_to); set_address(ret, "sender", en->sender); set_address(ret, "return_path", en->return_path); return ret; }
/** * @brief Standard requests handler. * @details This is the standard requests default handler, most standard * requests are handled here, the user can override the standard * handling using the @p requests_hook_cb hook in the * @p USBConfig structure. * * @param[in] usbp pointer to the @p USBDriver object * @return The request handling exit code. * @retval false Request not recognized by the handler or error. * @retval true Request handled. */ static bool default_handler(USBDriver *usbp) { const USBDescriptor *dp; /* Decoding the request.*/ switch (((usbp->setup[0] & (USB_RTYPE_RECIPIENT_MASK | USB_RTYPE_TYPE_MASK)) | (usbp->setup[1] << 8))) { case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_STATUS << 8): /* Just returns the current status word.*/ usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2, NULL); return true; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_CLEAR_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status &= ~2; usbSetupTransfer(usbp, NULL, 0, NULL); return true; } return false; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status |= 2; usbSetupTransfer(usbp, NULL, 0, NULL); return true; } return false; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_ADDRESS << 8): /* The SET_ADDRESS handling can be performed here or postponed after the status packed depending on the USB_SET_ADDRESS_MODE low driver setting.*/ #if USB_SET_ADDRESS_MODE == USB_EARLY_SET_ADDRESS if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && (usbp->setup[1] == USB_REQ_SET_ADDRESS)) set_address(usbp); usbSetupTransfer(usbp, NULL, 0, NULL); #else usbSetupTransfer(usbp, NULL, 0, set_address); #endif return true; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_DESCRIPTOR << 8): /* Handling descriptor requests from the host.*/ dp = usbp->config->get_descriptor_cb( usbp, usbp->setup[3], usbp->setup[2], usbFetchWord(&usbp->setup[4])); if (dp == NULL) return false; usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); return true; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_CONFIGURATION << 8): /* Returning the last selected configuration.*/ usbSetupTransfer(usbp, &usbp->configuration, 1, NULL); return true; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_CONFIGURATION << 8): /* Handling configuration selection from the host.*/ usbp->configuration = usbp->setup[2]; if (usbp->configuration == 0) usbp->state = USB_SELECTED; else usbp->state = USB_ACTIVE; _usb_isr_invoke_event_cb(usbp, USB_EVENT_CONFIGURED); usbSetupTransfer(usbp, NULL, 0, NULL); return true; case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8): case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SYNCH_FRAME << 8): /* Just sending two zero bytes, the application can change the behavior using a hook..*/ usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL); return true; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_GET_STATUS << 8): /* Sending the EP status.*/ if (usbp->setup[4] & 0x80) { switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); return true; case EP_STATUS_ACTIVE: usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); return true; default: return false; } } else { switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0F)) { case EP_STATUS_STALLED: usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); return true; case EP_STATUS_ACTIVE: usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); return true; default: return false; } } case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_CLEAR_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) return false; /* Clearing the EP status, not valid for EP0, it is ignored in that case.*/ if ((usbp->setup[4] & 0x0F) > 0) { if (usbp->setup[4] & 0x80) usb_lld_clear_in(usbp, usbp->setup[4] & 0x0F); else usb_lld_clear_out(usbp, usbp->setup[4] & 0x0F); } usbSetupTransfer(usbp, NULL, 0, NULL); return true; case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SET_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) return false; /* Stalling the EP, not valid for EP0, it is ignored in that case.*/ if ((usbp->setup[4] & 0x0F) > 0) { if (usbp->setup[4] & 0x80) usb_lld_stall_in(usbp, usbp->setup[4] & 0x0F); else usb_lld_stall_out(usbp, usbp->setup[4] & 0x0F); } usbSetupTransfer(usbp, NULL, 0, NULL); return true; case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_DESCRIPTOR << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_CLEAR_FEATURE << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_FEATURE << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_INTERFACE << 8): case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_INTERFACE << 8): /* All the above requests are not handled here, if you need them then use the hook mechanism and provide handling.*/ default: return false; } }
/** * @brief Standard requests handler. * @details This is the standard requests default handler, most standard * requests are handled here, the user can override the standard * handling using the @p requests_hook_cb hook in the * @p USBConfig structure. * * @param[in] usbp pointer to the @p USBDriver object * @return The request handling exit code. * @retval false Request not recognized by the handler or error. * @retval true Request handled. */ static bool default_handler(USBDriver *usbp) { const USBDescriptor *dp; /* Decoding the request.*/ switch ((((uint32_t)usbp->setup[0] & (USB_RTYPE_RECIPIENT_MASK | USB_RTYPE_TYPE_MASK)) | ((uint32_t)usbp->setup[1] << 8U))) { case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_STATUS << 8): /* Just returns the current status word.*/ usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status &= ~2U; usbSetupTransfer(usbp, NULL, 0, NULL); return true; } return false; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_FEATURE << 8): /* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature number is handled as an error.*/ if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) { usbp->status |= 2U; usbSetupTransfer(usbp, NULL, 0, NULL); return true; } return false; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_ADDRESS << 8): /* The SET_ADDRESS handling can be performed here or postponed after the status packed depending on the USB_SET_ADDRESS_MODE low driver setting.*/ #if USB_SET_ADDRESS_MODE == USB_EARLY_SET_ADDRESS if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) && (usbp->setup[1] == USB_REQ_SET_ADDRESS)) { set_address(usbp); } usbSetupTransfer(usbp, NULL, 0, NULL); #else usbSetupTransfer(usbp, NULL, 0, set_address); #endif return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_DESCRIPTOR << 8): /* Handling descriptor requests from the host.*/ dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3], usbp->setup[2], get_hword(&usbp->setup[4])); if (dp == NULL) { return false; } /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL); /*lint -restore*/ return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_CONFIGURATION << 8): /* Returning the last selected configuration.*/ usbSetupTransfer(usbp, &usbp->configuration, 1, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_CONFIGURATION << 8): /* Handling configuration selection from the host only if it is different from the current configuration.*/ if (usbp->configuration != usbp->setup[2]) { /* If the USB device is already active then we have to perform the clear procedure on the current configuration.*/ if (usbp->state == USB_ACTIVE) { /* Current configuration cleared.*/ osalSysLockFromISR (); usbDisableEndpointsI(usbp); osalSysUnlockFromISR (); usbp->configuration = 0U; usbp->state = USB_SELECTED; _usb_isr_invoke_event_cb(usbp, USB_EVENT_UNCONFIGURED); } if (usbp->setup[2] != 0U) { /* New configuration.*/ usbp->configuration = usbp->setup[2]; usbp->state = USB_ACTIVE; _usb_isr_invoke_event_cb(usbp, USB_EVENT_CONFIGURED); } } usbSetupTransfer(usbp, NULL, 0, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_STATUS << 8): case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SYNCH_FRAME << 8): /* Just sending two zero bytes, the application can change the behavior using a hook..*/ /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL); /*lint -restore*/ return true; case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_GET_STATUS << 8): /* Sending the EP status.*/ if ((usbp->setup[4] & 0x80U) != 0U) { switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0FU)) { case EP_STATUS_STALLED: /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); /*lint -restore*/ return true; case EP_STATUS_ACTIVE: /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); /*lint -restore*/ return true; case EP_STATUS_DISABLED: default: return false; } } else { switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0FU)) { case EP_STATUS_STALLED: /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL); /*lint -restore*/ return true; case EP_STATUS_ACTIVE: /*lint -save -e9005 [11.8] Removing const is fine.*/ usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL); /*lint -restore*/ return true; case EP_STATUS_DISABLED: default: return false; } } case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) { return false; } /* Clearing the EP status, not valid for EP0, it is ignored in that case.*/ if ((usbp->setup[4] & 0x0FU) != 0U) { if ((usbp->setup[4] & 0x80U) != 0U) { usb_lld_clear_in(usbp, usbp->setup[4] & 0x0FU); } else { usb_lld_clear_out(usbp, usbp->setup[4] & 0x0FU); } } usbSetupTransfer(usbp, NULL, 0, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SET_FEATURE << 8): /* Only ENDPOINT_HALT is handled as feature.*/ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) { return false; } /* Stalling the EP, not valid for EP0, it is ignored in that case.*/ if ((usbp->setup[4] & 0x0FU) != 0U) { if ((usbp->setup[4] & 0x80U) != 0U) { usb_lld_stall_in(usbp, usbp->setup[4] & 0x0FU); } else { usb_lld_stall_out(usbp, usbp->setup[4] & 0x0FU); } } usbSetupTransfer(usbp, NULL, 0, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_DESCRIPTOR << 8): case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8): case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_FEATURE << 8): case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_INTERFACE << 8): case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_INTERFACE << 8): /* All the above requests are not handled here, if you need them then use the hook mechanism and provide handling.*/ default: return false; } }
int SF1XX::init() { int ret = PX4_ERROR; int hw_model; param_get(param_find("SENS_EN_SF1XX"), &hw_model); switch (hw_model) { case 0: DEVICE_LOG("disabled."); return ret; case 1: /* SF10/a (25m 32Hz) */ _min_distance = 0.01f; _max_distance = 25.0f; _conversion_interval = 31250; break; case 2: /* SF10/b (50m 32Hz) */ _min_distance = 0.01f; _max_distance = 50.0f; _conversion_interval = 31250; break; case 3: /* SF10/c (100m 16Hz) */ _min_distance = 0.01f; _max_distance = 100.0f; _conversion_interval = 62500; break; case 4: /* SF11/c (120m 20Hz) */ _min_distance = 0.01f; _max_distance = 120.0f; _conversion_interval = 50000; break; case 5: /* SF20/LW20 (100m 48-388Hz) */ _min_distance = 0.001f; _max_distance = 100.0f; _conversion_interval = 20834; break; default: DEVICE_LOG("invalid HW model %d.", hw_model); return ret; } /* do I2C init (and probe) first */ if (I2C::init() != OK) { return ret; } /* allocate basic report buffers */ _reports = new ringbuffer::RingBuffer(2, sizeof(distance_sensor_s)); set_address(SF1XX_BASEADDR); if (_reports == nullptr) { return ret; } _class_instance = register_class_devname(RANGE_FINDER_BASE_DEVICE_PATH); /* get a publish handle on the range finder topic */ struct distance_sensor_s ds_report = {}; _distance_sensor_topic = orb_advertise_multi(ORB_ID(distance_sensor), &ds_report, &_orb_class_instance, ORB_PRIO_HIGH); if (_distance_sensor_topic == nullptr) { DEVICE_LOG("failed to create distance_sensor object. Did you start uOrb?"); } // Select altitude register int ret2 = measure(); if (ret2 == 0) { ret = OK; _sensor_ok = true; DEVICE_LOG("(%dm %dHz) with address %d found", (int)_max_distance, (int)(1e6f / _conversion_interval), SF1XX_BASEADDR); } return ret; }
/* Return value becomes exitcode. It's okay to not return at all */ static int do_set(char **argv) { char *dev = NULL; uint32_t mask = 0; uint32_t flags = 0; int qlen = -1; int mtu = -1; char *newaddr = NULL; char *newbrd = NULL; struct ifreq ifr0, ifr1; char *newname = NULL; int htype, halen; static const char keywords[] ALIGN1 = "up\0""down\0""name\0""mtu\0""multicast\0" "arp\0""address\0""dev\0"; enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_multicast, ARG_arp, ARG_addr, ARG_dev }; static const char str_on_off[] ALIGN1 = "on\0""off\0"; enum { PARM_on = 0, PARM_off }; smalluint key; while (*argv) { /* substring search ensures that e.g. "addr" and "address" * are both accepted */ key = index_in_substrings(keywords, *argv); if (key == ARG_up) { mask |= IFF_UP; flags |= IFF_UP; } if (key == ARG_down) { mask |= IFF_UP; flags &= ~IFF_UP; } if (key == ARG_name) { NEXT_ARG(); newname = *argv; } if (key == ARG_mtu) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); mtu = get_unsigned(*argv, "mtu"); } if (key == ARG_multicast) { int param; NEXT_ARG(); mask |= IFF_MULTICAST; param = index_in_strings(str_on_off, *argv); if (param < 0) die_must_be_on_off("multicast"); if (param == PARM_on) flags |= IFF_MULTICAST; else flags &= ~IFF_MULTICAST; } if (key == ARG_arp) { int param; NEXT_ARG(); mask |= IFF_NOARP; param = index_in_strings(str_on_off, *argv); if (param < 0) die_must_be_on_off("arp"); if (param == PARM_on) flags &= ~IFF_NOARP; else flags |= IFF_NOARP; } if (key == ARG_addr) { NEXT_ARG(); newaddr = *argv; } if (key >= ARG_dev) { if (key == ARG_dev) { NEXT_ARG(); } if (dev) duparg2("dev", *argv); dev = *argv; } argv++; } if (!dev) { bb_error_msg_and_die(bb_msg_requires_arg, "\"dev\""); } if (newaddr || newbrd) { halen = get_address(dev, &htype); if (newaddr) { parse_address(dev, htype, halen, newaddr, &ifr0); } if (newbrd) { parse_address(dev, htype, halen, newbrd, &ifr1); } } if (newname && strcmp(dev, newname)) { do_changename(dev, newname); dev = newname; } if (qlen != -1) { set_qlen(dev, qlen); } if (mtu != -1) { set_mtu(dev, mtu); } if (newaddr || newbrd) { if (newbrd) { set_address(&ifr1, 1); } if (newaddr) { set_address(&ifr0, 0); } } if (mask) do_chflags(dev, flags, mask); return 0; }
static int do_set(int argc, char **argv) { char *dev = NULL; __u32 mask = 0; __u32 flags = 0; int qlen = -1; int mtu = -1; char *newaddr = NULL; char *newbrd = NULL; struct ifreq ifr0, ifr1; char *newname = NULL; int htype, halen; while (argc > 0) { if (strcmp(*argv, "up") == 0) { mask |= IFF_UP; flags |= IFF_UP; } else if (strcmp(*argv, "down") == 0) { mask |= IFF_UP; flags &= ~IFF_UP; } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); newname = *argv; } else if (strcmp(*argv, "mtu") == 0) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); if (get_integer(&mtu, *argv, 0)) invarg("Invalid \"mtu\" value\n", *argv); } else if (strcmp(*argv, "multicast") == 0) { NEXT_ARG(); mask |= IFF_MULTICAST; if (strcmp(*argv, "on") == 0) { flags |= IFF_MULTICAST; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_MULTICAST; } else return on_off("multicast"); } else if (strcmp(*argv, "arp") == 0) { NEXT_ARG(); mask |= IFF_NOARP; if (strcmp(*argv, "on") == 0) { flags &= ~IFF_NOARP; } else if (strcmp(*argv, "off") == 0) { flags |= IFF_NOARP; } else return on_off("noarp"); } else if (strcmp(*argv, "addr") == 0) { NEXT_ARG(); newaddr = *argv; } else { if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); } if (dev) duparg2("dev", *argv); dev = *argv; } argc--; argv++; } if (!dev) { bb_error_msg("Not enough of information: \"dev\" argument is required."); exit(-1); } if (newaddr || newbrd) { halen = get_address(dev, &htype); if (halen < 0) return -1; if (newaddr) { if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0) return -1; } if (newbrd) { if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0) return -1; } } if (newname && strcmp(dev, newname)) { if (do_changename(dev, newname) < 0) return -1; dev = newname; } if (qlen != -1) { if (set_qlen(dev, qlen) < 0) return -1; } if (mtu != -1) { if (set_mtu(dev, mtu) < 0) return -1; } if (newaddr || newbrd) { if (newbrd) { if (set_address(&ifr1, 1) < 0) return -1; } if (newaddr) { if (set_address(&ifr0, 0) < 0) return -1; } } if (mask) return do_chflags(dev, flags, mask); return 0; }
ipv6_address::ipv6_address() { set_address(nullptr, 0); }
ipv6_address::ipv6_address(const char* ip, unsigned short port) { set_address(ip, port); }
int WolfSSLConnection::connect(const char* host, const int port) { int result; if(sslContext == NULL) { LogError("NULL SSL context\r\n"); result = __LINE__; } else { if (init_socket(SOCK_STREAM) < 0) { LogError("init_socket failed\r\n"); result = __LINE__; } else { if (set_address(host, port) != 0) { LogError("set_address failed\r\n"); result = __LINE__; } else if (lwip_connect(_sock_fd, (const struct sockaddr *) &_remoteHost, sizeof(_remoteHost)) < 0) { close(); LogError("lwip_connect failed\r\n"); result = __LINE__; } else { wolfSSL_SetIOSend(sslContext, &sendCallback); wolfSSL_SetIORecv(sslContext, &receiveCallback); ssl = wolfSSL_new(sslContext); if(ssl == NULL) { LogError("wolfssl new error\r\n"); result = __LINE__; } else { wolfSSL_set_fd(ssl, _sock_fd); result = wolfSSL_connect(ssl); if (result != SSL_SUCCESS) { LogError("wolfssl connect error=%d\r\n", result); result = __LINE__; } else { result = 0; isConnected = true; } } } } } return result; };
Address::Address(struct sockaddr_in address) { set_address(inet_ntoa(address.sin_addr), address.sin_port); }