/* * card_device_init - open card read used uart * @return : status */ int card_device_init(void) { int ret; int fd; switch(g_port) { case 1: fd = open_uart(PORT_0, O_RDWR); if (fd < 0) { debug_msg("Card Device Init Failed\n"); return -ETAX_OPEN_CARD; } break; case 2: fd = open_uart(PORT_1, O_RDWR); if (fd < 0) { debug_msg("Card Device Init Failed\n"); return -ETAX_OPEN_CARD; } break; case 3: fd = open_uart(PORT_2, O_RDWR); if (fd < 0) { debug_msg("Card Device Init Failed\n"); return -ETAX_OPEN_CARD; } break; case 4: fd = open_uart(PORT_3, O_RDWR); if (fd < 0) { debug_msg("Card Device Init Failed\n"); return -ETAX_OPEN_CARD; } break; default: return 1; break; } ret = card_uart_setup(fd); if (ret < 0) { close(fd); return FAIL; } card_dev = fd; return SUCCESS; }
float get_umidade_relativa() { int uart_descriptor = open_uart(); if (uart_descriptor == -1) return 0; unsigned char buffer[5]; buffer[0] = 0x06; buffer[1] = 3; buffer[2] = 2; buffer[3] = 9; buffer[4] = 8; if (write_uart(uart_descriptor, buffer, 5) == -1) return 0; printf("Escrita completa!\n"); float umidade; if (read_uart(uart_descriptor, (void*) &umidade, 4) == -1) return 0; printf("Leitura completa!\n"); close(uart_descriptor); return umidade; }
int test_hott_telemetry(int argc, char *argv[]) { PX4_INFO("HoTT Telemetry Test Requirements:"); PX4_INFO("- Radio on and Electric Air. Mod on (telemetry -> sensor select)."); PX4_INFO("- Receiver telemetry port must be in telemetry mode."); PX4_INFO("- Connect telemetry wire to /dev/ttyS1 (USART2)."); PX4_INFO("Testing..."); const char device[] = "/dev/ttyS1"; int fd = open_uart(device); if (fd < 0) { close(fd); return ERROR; } #ifdef TIOCSSINGLEWIRE /* Activate single wire mode */ ioctl(fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED); #endif char send = 'a'; write(fd, &send, 1); /* Since TX and RX are now connected we should be able to read in what we wrote */ const int timeout = 1000; struct pollfd fds[] = { { .fd = fd, .events = POLLIN } };
int hott_sensors_thread_main(int argc, char *argv[]) { warnx("starting"); thread_running = true; const char *device = DEFAULT_UART; /* read commandline arguments */ for (int i = 0; i < argc && argv[i]; i++) { if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set if (argc > i + 1) { device = argv[i + 1]; } else { thread_running = false; errx(1, "missing parameter to -d\n%s", commandline_usage); } } } /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ const int uart = open_uart(device); if (uart < 0) { errx(1, "Failed opening HoTT UART, exiting."); thread_running = false; } init_pub_messages(); uint8_t buffer[MAX_MESSAGE_BUFFER_SIZE]; size_t size = 0; uint8_t id = 0; while (!thread_should_exit) { // Currently we only support a General Air Module sensor. build_gam_request(&buffer[0], &size); send_poll(uart, buffer, size); // The sensor will need a little time before it starts sending. usleep(5000); recv_data(uart, &buffer[0], &size, &id); // Determine which moduel sent it and process accordingly. if (id == GAM_SENSOR_ID) { publish_gam_message(buffer); } else { warnx("Unknown sensor ID: %d", id); } } warnx("exiting"); close(uart); thread_running = false; return 0; }
void main(){ open_uart(); // open uart signal(SIGINT, INThandler); send(); close(fd); // close uart }
int hott_telemetry_thread_main(int argc, char *argv[]) { warnx("starting"); thread_running = true; const char *device = DEFAULT_UART; /* read commandline arguments */ for (int i = 0; i < argc && argv[i]; i++) { if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set if (argc > i + 1) { device = argv[i + 1]; } else { thread_running = false; errx(1, "missing parameter to -d\n%s", commandline_usage); } } } /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ const int uart = open_uart(device); if (uart < 0) { errx(1, "Failed opening HoTT UART, exiting."); thread_running = false; } init_sub_messages(); uint8_t buffer[MAX_MESSAGE_BUFFER_SIZE]; size_t size = 0; uint8_t id = 0; bool connected = true; while (!thread_should_exit) { // Listen for and serve poll from the receiver. if (recv_req_id(uart, &id) == OK) { if (!connected) { connected = true; warnx("OK"); } switch (id) { case EAM_SENSOR_ID: build_eam_response(buffer, &size); break; case GAM_SENSOR_ID: build_gam_response(buffer, &size); break; case GPS_SENSOR_ID: build_gps_response(buffer, &size); break; default: continue; // Not a module we support. } send_data(uart, buffer, size); } else { connected = false; warnx("syncing"); } } warnx("exiting"); close(uart); thread_running = false; return 0; }
/// \cond int main(int argc, char **argv) { int fd; char *s; unsigned char ope_code; unsigned char prev_code; unsigned char data_size; unsigned char prev_size; int len; int baud; char ret; printf("bcm2835_for_java ver1.01 start priority=%d\n", nice(1) ); if( argc != 2 ) { printf("bcm2835_for_java needs 1 parameter like as /tmp/shared_mem\n"); exit ( -1 ); } else { fd = open( argv[1], O_RDWR); if( fd == -1 ) { printf("file %s can't open\n",argv[1]); exit(-1); } else { s = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if( s == MAP_FAILED ) { printf("we can't create mapping file\n"); } } } r_buff = (struct ring_buff *)s; w_buff = (struct ring_buff *)(s+sizeof(struct ring_buff) ); bi_send_buff = (char *)( s + 2*sizeof(struct ring_buff) ); bi_rec_buff = (char *)( bi_send_buff + TEMP_BUFF_SIZE ); sync_code = (int *)( bi_rec_buff + TEMP_BUFF_SIZE ); reply_code = (int *)( sync_code + 1 ); init_ring_buff(w_buff,WRITER_INIT); init_ring_buff(r_buff,READER_INIT); bi_status = STATUS_FINE; while( 1 ) { if( calc_data_size( r_buff ) != 0 ) { prev_code = ope_code; prev_size = data_size; get_ope_code(); ope_code = buff[0]; data_size = calc_data_size( r_buff ); switch( ope_code ) { case OPE_INIT: bcm_init(); break; case OPE_CLOSE: bcm_close(); break; case OPE_SET_DEBUG: ope_set_debug(); break; case OPE_PERI_READ: ope_peri_read(); break; case OPE_PERI_READ_NB: ope_peri_read_nb(); break; case OPE_PERI_WRITE: ope_peri_write(); break; case OPE_PERI_WRITE_NB: ope_peri_write_nb(); break; case OPE_PERI_SET_BITS: ope_peri_set_bits(); break; case OPE_GPIO_FSEL: ope_gpio_fsel(); break; case OPE_GPIO_SET: ope_gpio_set(); break; case OPE_GPIO_CLR: ope_gpio_clr(); break; case OPE_GPIO_SET_MULTI: ope_gpio_set_multi(); break; case OPE_GPIO_CLR_MULTI: ope_gpio_clr_multi(); break; case OPE_GPIO_LEV: ope_gpio_lev(); break; case OPE_GPIO_EDS: ope_gpio_eds(); break; case OPE_GPIO_SET_EDS: ope_gpio_set_eds(); break; case OPE_GPIO_REN: ope_gpio_ren(); break; case OPE_GPIO_CLR_REN: ope_gpio_clr_ren(); break; case OPE_GPIO_FEN: ope_gpio_fen(); break; case OPE_GPIO_CLR_FEN: ope_gpio_clr_fen(); break; case OPE_GPIO_HEN: ope_gpio_hen(); break; case OPE_GPIO_CLR_HEN: ope_gpio_clr_hen(); break; case OPE_GPIO_LEN: ope_gpio_len(); break; case OPE_GPIO_CLR_LEN: ope_gpio_clr_len(); break; case OPE_GPIO_AREN: ope_gpio_aren(); break; case OPE_GPIO_CLR_AREN: ope_gpio_clr_aren(); break; case OPE_GPIO_AFEN: ope_gpio_afen(); break; case OPE_GPIO_CLR_AFEN: ope_gpio_clr_afen(); break; case OPE_GPIO_PUD: ope_gpio_pud(); break; case OPE_GPIO_PUDCLK: ope_gpio_pudclk(); break; case OPE_GPIO_WRITE: ope_gpio_write(); break; case OPE_GPIO_PAD: ope_gpio_pad(); break; case OPE_GPIO_SET_PAD: ope_gpio_set_pad(); break; case OPE_DELAY: ope_delay(); break; case OPE_DELAYMICROSECONDS: ope_delaymicroseconds(); break; case OPE_GPIO_WRITE_MULTI: ope_gpio_write_multi(); break; case OPE_GPIO_WRITE_MASK: ope_gpio_write_mask(); break; case OPE_GPIO_SET_PUD: ope_gpio_set_pud(); break; case OPE_SPI_BEGIN: ope_spi_begin(); break; case OPE_SPI_END: ope_spi_end(); break; case OPE_SPI_SETBITORDER: ope_spi_setbitorder(); break; case OPE_SPI_SETCLOCKDIVIDER: ope_spi_setclockdivider(); break; case OPE_SPI_SETDATAMODE: ope_spi_setdatamode(); break; case OPE_SPI_CHIPSELECT: ope_spi_chipselect(); break; case OPE_SPI_SETCHIPSELECTPOLARITY: ope_spi_setchipselectpolarity(); break; case OPE_SPI_TRANSFER: ope_spi_transfer(); break; case OPE_SPI_TRANSFERNB: ope_spi_transfernb(); break; case OPE_SPI_TRANSFERN: ope_spi_transfern(); break; case OPE_SPI_WRITENB: ope_spi_writenb(); break; case OPE_I2C_BEGIN: ope_i2c_begin(); break; case OPE_I2C_END: ope_i2c_end(); break; case OPE_I2C_SETSLAVEADDRESS: ope_i2c_setslaveaddress(); break; case OPE_I2C_SETCLOCKDIVIDER: ope_i2c_setclockdivider(); break; case OPE_I2C_SET_BAUDRATE: ope_i2c_set_baudrate(); break; case OPE_I2C_WRITE: ope_i2c_write(); break; case OPE_I2C_READ: ope_i2c_read(); break; case OPE_I2C_READ_REGISTER_RS: ope_i2c_read_register_rs(); break; case OPE_ST_READ: ope_st_read(); break; case OPE_ST_DELAY: ope_st_delay(); break; case OPE_HELLO: get_int_code(); len = *(int *)(buff+1); set_ope_code( OPE_REPLY ); strcpy( bi_rec_buff, "Nice to meet you." ); set_int_code( strlen(bi_rec_buff) ); put_reply(); mark_sync(); usleep(5000); break; case OPE_SYNC: mark_sync(); break; case OPE_EXIT: goto BREAK_LINE; break; case OPE_OPEN_UART: open_uart(); break; case OPE_CONFIG_UART: configure_uart(); break; case OPE_SEND_UART: send_uart(); break; case OPE_RECEIVE_UART: receive_uart(); break; case OPE_CLOSE_UART: close_uart(); break; default: printf("prev_code %02x \n",prev_code); printf("prev_size %d \n",prev_size); printf("ope_code error %02x \n",ope_code); printf("data_size=%d \n",data_size); break; } } else { usleep(5000); } } BREAK_LINE: printf("Close bcm2835_for_java\n"); exit(0); }
void IridiumSBD::main_loop(int argc, char *argv[]) { CDev::init(); pthread_mutex_init(&_tx_buf_mutex, NULL); pthread_mutex_init(&_rx_buf_mutex, NULL); int arg_i = 3; int arg_uart_name = 0; while (arg_i < argc) { if (!strcmp(argv[arg_i], "-d")) { arg_i++; arg_uart_name = arg_i; } else if (!strcmp(argv[arg_i], "-v")) { PX4_WARN("verbose mode ON"); _verbose = true; } arg_i++; } if (arg_uart_name == 0) { PX4_WARN("no Iridium SBD modem UART port provided!"); _task_should_exit = true; return; } if (open_uart(argv[arg_uart_name]) != SATCOM_UART_OK) { PX4_WARN("failed to open UART port!"); _task_should_exit = true; return; } // disable flow control write_at("AT&K0"); if (read_at_command() != SATCOM_RESULT_OK) { PX4_WARN("modem not responding"); _task_should_exit = true; return; } // disable command echo write_at("ATE0"); if (read_at_command() != SATCOM_RESULT_OK) { PX4_WARN("modem not responding"); _task_should_exit = true; return; } param_t param_pointer; param_pointer = param_find("ISBD_READ_INT"); param_get(param_pointer, &_param_read_interval_s); param_pointer = param_find("ISBD_SBD_TIMEOUT"); param_get(param_pointer, &_param_session_timeout_s); if (_param_session_timeout_s < 0) { _param_session_timeout_s = 60; } param_pointer = param_find("ISBD_STACK_TIME"); param_get(param_pointer, &_param_stacking_time_ms); if (_param_stacking_time_ms < 0) { _param_stacking_time_ms = 0; } VERBOSE_INFO("read interval: %d s", _param_read_interval_s); VERBOSE_INFO("SBD session timeout: %d s", _param_session_timeout_s); VERBOSE_INFO("SBD stack time: %d ms", _param_stacking_time_ms); while (!_task_should_exit) { switch (_state) { case SATCOM_STATE_STANDBY: standby_loop(); break; case SATCOM_STATE_CSQ: csq_loop(); break; case SATCOM_STATE_SBDSESSION: sbdsession_loop(); break; case SATCOM_STATE_TEST: test_loop(); break; } if (_new_state != _state) { VERBOSE_INFO("SWITCHING STATE FROM %s TO %s", satcom_state_string[_state], satcom_state_string[_new_state]); _state = _new_state; publish_iridium_status(); } else { publish_iridium_status(); usleep(100000); // 100ms } } }
int hott_telemetry_thread_main(int argc, char *argv[]) { warnx("starting"); connect_count = perf_alloc(PC_COUNT, "reconnects "); recon_port = perf_alloc(PC_COUNT, "reopen port "); reqs_count = perf_alloc(PC_COUNT, "requests "); bin_reply = perf_alloc(PC_COUNT, "bin replies "); txt_reply = perf_alloc(PC_COUNT, "text replies "); bad_reply = perf_alloc(PC_COUNT, "unknown replies "); dead_reply = perf_alloc(PC_COUNT, "dead replies "); thread_running = true; const char *device = DEFAULT_UART; /* read commandline arguments */ for (int i = 0; i < argc && argv[i]; i++) { if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set if (argc > i + 1) { device = argv[i + 1]; } else { thread_running = false; errx(1, "missing parameter to -d\n%s", commandline_usage); } } } /* enable UART, writes potentially an empty buffer, but multiplexing is disabled */ int uart = open_uart(device); if (uart < 0) { errx(1, "Failed opening HoTT UART, exiting."); thread_running = false; } init_sub_messages(); uint8_t buffer[MAX_MESSAGE_BUFFER_SIZE]; size_t size = 0; uint8_t id = 0; bool connected = true; int recon = 0; while (!thread_should_exit) { // Listen for and serve poll from the receiver. if (recv_req_id(uart, &id) == OK) { if (!connected) { connected = true; warnx("OK"); } switch (id) { case EAM_SENSOR_ID: build_eam_response(buffer, &size); perf_count(bin_reply); break; case GAM_SENSOR_ID: build_gam_response(buffer, &size); perf_count(bin_reply); break; case GPS_SENSOR_ID: build_gps_response(buffer, &size); perf_count(bin_reply); break; case BINARY_MODE_REQUEST_ID: perf_count(dead_reply); break; default: perf_count(bad_reply); continue; // Not a module we support. } send_data(uart, buffer, size); } else { if (connected) { connected = false; } else { recon++; } if (recon > 100) { perf_count(recon_port); close(uart); uart = open_uart(device); perf_reset(reqs_count); perf_reset(bin_reply); perf_reset(txt_reply); perf_reset(dead_reply); perf_reset(bad_reply); } } } warnx("exiting"); close(uart); thread_running = false; perf_free(connect_count); perf_free(recon_port); perf_free(reqs_count); perf_free(bin_reply); perf_free(txt_reply); perf_free(bad_reply); perf_free(dead_reply); return 0; }