本文整理汇总了C++中px4_close函数的典型用法代码示例。如果您正苦于以下问题:C++ px4_close函数的具体用法?C++ px4_close怎么用?C++ px4_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了px4_close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: px4_open
bool VtolType::init()
{
const char *dev = PWM_OUTPUT0_DEVICE_PATH;
int fd = px4_open(dev, 0);
if (fd < 0) {
PX4_ERR("can't open %s", dev);
return false;
}
int ret = px4_ioctl(fd, PWM_SERVO_GET_MAX_PWM, (long unsigned int)&_max_mc_pwm_values);
if (ret != PX4_OK) {
PX4_ERR("failed getting max values");
px4_close(fd);
return false;
}
ret = px4_ioctl(fd, PWM_SERVO_GET_DISARMED_PWM, (long unsigned int)&_disarmed_pwm_values);
if (ret != PX4_OK) {
PX4_ERR("failed getting disarmed values");
px4_close(fd);
return false;
}
return true;
}
开发者ID:alsaibie,项目名称:Firmware_Dolphin,代码行数:31,代码来源:vtol_type.cpp
示例2: reset
/**
* @brief Resets the driver.
*/
void
reset()
{
if (!instance) {
PX4_WARN("No ll40ls driver running");
return;
}
int fd = px4_open(instance->get_dev_name(), O_RDONLY);
if (fd < 0) {
PX4_ERR("Error opening fd");
return;
}
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
PX4_ERR("driver reset failed");
px4_close(fd);
return;
}
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
PX4_ERR("driver poll restart failed");
px4_close(fd);
return;
}
}
开发者ID:AlexisTM,项目名称:Firmware,代码行数:30,代码来源:ll40ls.cpp
示例3: led_deinit
void led_deinit()
{
if (leds >= 0) {
px4_close(leds);
}
if (rgbleds >= 0) {
px4_close(rgbleds);
}
}
开发者ID:Bjarne-Madsen,项目名称:Firmware,代码行数:10,代码来源:commander_helper.cpp
示例4: px4_open
int uORB::Manager::node_advertise
(
const struct orb_metadata *meta,
int *instance,
int priority
)
{
int fd = -1;
int ret = ERROR;
/* fill advertiser data */
const struct orb_advertdata adv = { meta, instance, priority };
/* open the control device */
fd = px4_open(TOPIC_MASTER_DEVICE_PATH, 0);
if (fd < 0)
goto out;
/* advertise the object */
ret = px4_ioctl(fd, ORBIOCADVERTISE, (unsigned long)(uintptr_t)&adv);
/* it's PX4_OK if it already exists */
if ((PX4_OK != ret) && (EEXIST == errno)) {
ret = PX4_OK;
}
out:
if (fd >= 0)
px4_close(fd);
return ret;
}
开发者ID:afourteia,项目名称:Firmware,代码行数:34,代码来源:uORBManager_posix.cpp
示例5: px4_open
/**
* Adjust idle speed for fw mode.
*/
void VtolType::set_idle_fw()
{
const char *dev = PWM_OUTPUT0_DEVICE_PATH;
int fd = px4_open(dev, 0);
if (fd < 0) {
PX4_WARN("can't open %s", dev);
}
struct pwm_output_values pwm_values;
memset(&pwm_values, 0, sizeof(pwm_values));
for (int i = 0; i < _params->vtol_motor_count; i++) {
pwm_values.values[i] = PWM_MOTOR_OFF;
pwm_values.channel_count++;
}
int ret = px4_ioctl(fd, PWM_SERVO_SET_MIN_PWM, (long unsigned int)&pwm_values);
if (ret != OK) {
PX4_WARN("failed setting min values");
}
px4_close(fd);
}
开发者ID:AlexanderAurora,项目名称:Firmware,代码行数:30,代码来源:vtol_type.cpp
示例6: node_open
orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority)
{
int result, fd;
orb_advert_t advertiser;
//warnx("orb_advertise_multi meta = %p\n", meta);
/* open the node as an advertiser */
fd = node_open(PUBSUB, meta, data, true, instance, priority);
if (fd == ERROR) {
warnx("node_open as advertiser failed.");
return nullptr;
}
/* get the advertiser handle and close the node */
result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
px4_close(fd);
if (result == ERROR) {
warnx("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd);
return nullptr;
}
/* the advertiser must perform an initial publish to initialise the object */
result = orb_publish(meta, advertiser, data);
if (result == ERROR) {
warnx("orb_publish failed");
return nullptr;
}
return advertiser;
}
开发者ID:afourteia,项目名称:Firmware,代码行数:31,代码来源:uORBManager_posix.cpp
示例7: test_gpio
int test_gpio(int argc, char *argv[])
{
int ret = 0;
#ifdef PX4IO_DEVICE_PATH
int fd = px4_open(PX4IO_DEVICE_PATH, 0);
if (fd < 0) {
printf("GPIO: open fail\n");
return ERROR;
}
/* set all GPIOs to default state */
px4_ioctl(fd, GPIO_RESET, ~0);
/* XXX need to add some GPIO waving stuff here */
/* Go back to default */
px4_ioctl(fd, GPIO_RESET, ~0);
px4_close(fd);
printf("\t GPIO test successful.\n");
#endif
return ret;
}
开发者ID:1002victor,项目名称:Firmware,代码行数:31,代码来源:test_gpio.c
示例8: gnssCheck
static bool gnssCheck(orb_advert_t *mavlink_log_pub, bool report_fail)
{
bool success = true;
int gpsSub = orb_subscribe(ORB_ID(vehicle_gps_position));
//Wait up to 2000ms to allow the driver to detect a GNSS receiver module
px4_pollfd_struct_t fds[1];
fds[0].fd = gpsSub;
fds[0].events = POLLIN;
if(px4_poll(fds, 1, 2000) <= 0) {
success = false;
}
else {
struct vehicle_gps_position_s gps;
if ( (OK != orb_copy(ORB_ID(vehicle_gps_position), gpsSub, &gps)) ||
(hrt_elapsed_time(&gps.timestamp_position) > 1000000)) {
success = false;
}
}
//Report failure to detect module
if (!success) {
if (report_fail) {
mavlink_and_console_log_critical(mavlink_log_pub, "PREFLIGHT FAIL: GPS RECEIVER MISSING");
}
}
px4_close(gpsSub);
return success;
}
开发者ID:13920381732,项目名称:Firmware,代码行数:31,代码来源:PreflightCheck.cpp
示例9: px4_open
/**
* Disable all multirotor motors when in fw mode.
*/
void
Standard::set_max_mc(unsigned pwm_value)
{
int ret;
unsigned servo_count;
const char *dev = PWM_OUTPUT0_DEVICE_PATH;
int fd = px4_open(dev, 0);
if (fd < 0) {
PX4_WARN("can't open %s", dev);
}
ret = px4_ioctl(fd, PWM_SERVO_GET_COUNT, (unsigned long)&servo_count);
struct pwm_output_values pwm_values;
memset(&pwm_values, 0, sizeof(pwm_values));
for (int i = 0; i < _params->vtol_motor_count; i++) {
pwm_values.values[i] = pwm_value;
pwm_values.channel_count = _params->vtol_motor_count;
}
ret = px4_ioctl(fd, PWM_SERVO_SET_MAX_PWM, (long unsigned int)&pwm_values);
if (ret != OK) {
PX4_WARN("failed setting max values");
}
px4_close(fd);
}
开发者ID:DonLakeFlyer,项目名称:Firmware,代码行数:32,代码来源:standard.cpp
示例10: start_bus
/**
* Start the driver on a specific bus.
*
* This function only returns if the sensor is up and running
* or could not be detected successfully.
*/
int
start_bus(uint8_t rotation, int i2c_bus)
{
int fd = -1;
if (g_dev != nullptr) {
PX4_ERR("already started");
return PX4_ERROR;
}
/* create the driver */
g_dev = new SF1XX(rotation, i2c_bus);
if (g_dev == nullptr) {
goto fail;
}
if (OK != g_dev->init()) {
goto fail;
}
/* set the poll rate to default, starts automatic data collection */
fd = px4_open(SF1XX_DEVICE_PATH, O_RDONLY);
if (fd < 0) {
goto fail;
}
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
px4_close(fd);
goto fail;
}
px4_close(fd);
return PX4_OK;
fail:
if (g_dev != nullptr) {
delete g_dev;
g_dev = nullptr;
}
return PX4_ERROR;
}
开发者ID:ayu135,项目名称:Firmware,代码行数:51,代码来源:sf1xx.cpp
示例11: px4_open
// 1M 8N1 serial connection to NRF51
int
Syslink::open_serial(const char *dev)
{
#ifndef B1000000
#define B1000000 1000000
#endif
int rate = B1000000;
// open uart
int fd = px4_open(dev, O_RDWR | O_NOCTTY);
int termios_state = -1;
if (fd < 0) {
PX4_ERR("failed to open uart device!");
return -1;
}
// set baud rate
struct termios config;
tcgetattr(fd, &config);
// clear ONLCR flag (which appends a CR for every LF)
config.c_oflag = 0;
config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
// Disable hardware flow control
config.c_cflag &= ~CRTSCTS;
/* Set baud rate */
if (cfsetispeed(&config, rate) < 0 || cfsetospeed(&config, rate) < 0) {
warnx("ERR SET BAUD %s: %d\n", dev, termios_state);
px4_close(fd);
return -1;
}
if ((termios_state = tcsetattr(fd, TCSANOW, &config)) < 0) {
PX4_WARN("ERR SET CONF %s\n", dev);
px4_close(fd);
return -1;
}
return fd;
}
开发者ID:airmind,项目名称:OpenMindPX,代码行数:46,代码来源:syslink_main.cpp
示例12: test_tone
int test_tone(int argc, char *argv[])
{
int fd, result;
unsigned long tone;
fd = px4_open(TONEALARM0_DEVICE_PATH, O_WRONLY);
if (fd < 0) {
printf("failed opening " TONEALARM0_DEVICE_PATH "\n");
goto out;
}
tone = 1;
if (argc == 2) {
tone = atoi(argv[1]);
}
if (tone == 0) {
result = px4_ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
if (result < 0) {
printf("failed clearing alarms\n");
goto out;
} else {
printf("Alarm stopped.\n");
}
} else {
result = px4_ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
if (result < 0) {
printf("failed clearing alarms\n");
goto out;
}
result = px4_ioctl(fd, TONE_SET_ALARM, tone);
if (result < 0) {
printf("failed setting alarm %lu\n", tone);
} else {
printf("Alarm %lu (disable with: tests tone 0)\n", tone);
}
}
out:
if (fd >= 0) {
px4_close(fd);
}
return 0;
}
开发者ID:DonLakeFlyer,项目名称:Firmware,代码行数:55,代码来源:test_hrt.cpp
示例13: defined
int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
{
/*
* Generate the path to the node and try to open it.
*/
char path[orb_maxpath];
int inst = instance;
int ret = uORB::Utils::node_mkpath(path, meta, &inst);
if (ret != OK) {
errno = -ret;
return PX4_ERROR;
}
#if defined(__PX4_NUTTX)
struct stat buffer;
ret = stat(path, &buffer);
#else
ret = px4_access(path, F_OK);
#ifdef ORB_COMMUNICATOR
if (ret == -1 && meta != nullptr && !_remote_topics.empty()) {
ret = (_remote_topics.find(meta->o_name) != _remote_topics.end()) ? OK : PX4_ERROR;
}
#endif /* ORB_COMMUNICATOR */
#endif
if (ret == 0) {
// we know the topic exists, but it's not necessarily advertised/published yet (for example
// if there is only a subscriber)
// The open() will not lead to memory allocations.
int fd = px4_open(path, 0);
if (fd >= 0) {
unsigned long is_published;
if (px4_ioctl(fd, ORBIOCISPUBLISHED, (unsigned long)&is_published) == 0) {
if (!is_published) {
ret = PX4_ERROR;
}
}
px4_close(fd);
}
}
return ret;
}
开发者ID:muyangren499,项目名称:Firmware,代码行数:51,代码来源:uORBManager.cpp
示例14: switch
void Tiltrotor::set_rear_motor_state(rear_motor_state state)
{
int pwm_value = PWM_DEFAULT_MAX;
// map desired rear rotor state to max allowed pwm signal
switch (state) {
case ENABLED:
pwm_value = PWM_DEFAULT_MAX;
_rear_motors = ENABLED;
break;
case DISABLED:
pwm_value = PWM_LOWEST_MAX;
_rear_motors = DISABLED;
break;
case IDLE:
pwm_value = _params->idle_pwm_mc;
_rear_motors = IDLE;
break;
}
int ret;
unsigned servo_count;
char *dev = PWM_OUTPUT0_DEVICE_PATH;
int fd = px4_open(dev, 0);
if (fd < 0) {PX4_WARN("can't open %s", dev);}
ret = px4_ioctl(fd, PWM_SERVO_GET_COUNT, (unsigned long)&servo_count);
struct pwm_output_values pwm_values;
memset(&pwm_values, 0, sizeof(pwm_values));
for (int i = 0; i < _params->vtol_motor_count; i++) {
if (is_motor_off_channel(i)) {
pwm_values.values[i] = pwm_value;
} else {
pwm_values.values[i] = PWM_DEFAULT_MAX;
}
pwm_values.channel_count = _params->vtol_motor_count;
}
ret = px4_ioctl(fd, PWM_SERVO_SET_MAX_PWM, (long unsigned int)&pwm_values);
if (ret != OK) {PX4_WARN("failed setting max values");}
px4_close(fd);
}
开发者ID:radkog,项目名称:Firmware,代码行数:50,代码来源:tiltrotor.cpp
示例15: accel
static int
accel(int argc, char *argv[], const char *path)
{
printf("\tACCEL: test start\n");
fflush(stdout);
int fd;
struct accel_report buf;
int ret;
fd = px4_open(path, O_RDONLY);
if (fd < 0) {
printf("\tACCEL: open fail, run <mpu6000 start> or <lsm303 start> or <bma180 start> first.\n");
return ERROR;
}
/* wait at least 100ms, sensor should have data after no more than 20ms */
usleep(100000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
if (ret != sizeof(buf)) {
printf("\tACCEL: read1 fail (%d)\n", ret);
return ERROR;
} else {
printf("\tACCEL accel: x:%8.4f\ty:%8.4f\tz:%8.4f m/s^2\n", (double)buf.x, (double)buf.y, (double)buf.z);
}
if (fabsf(buf.x) > 30.0f || fabsf(buf.y) > 30.0f || fabsf(buf.z) > 30.0f) {
warnx("ACCEL acceleration values out of range!");
return ERROR;
}
float len = sqrtf(buf.x * buf.x + buf.y * buf.y + buf.z * buf.z);
if (len < 8.0f || len > 12.0f) {
warnx("ACCEL scale error!");
return ERROR;
}
/* Let user know everything is ok */
printf("\tOK: ACCEL passed all tests successfully\n");
px4_close(fd);
return OK;
}
开发者ID:1002victor,项目名称:Firmware,代码行数:49,代码来源:test_sensors.c
示例16: gyro
static int
gyro(int argc, char *argv[], const char *path)
{
printf("\tGYRO: test start\n");
fflush(stdout);
int fd;
struct gyro_report buf;
int ret;
fd = px4_open(path, O_RDONLY);
if (fd < 0) {
printf("\tGYRO: open fail, run <l3gd20 start> or <mpu6000 start> first.\n");
return ERROR;
}
/* wait at least 5 ms, sensor should have data after that */
usleep(5000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
if (ret != sizeof(buf)) {
printf("\tGYRO: read fail (%d)\n", ret);
return ERROR;
} else {
printf("\tGYRO rates: x:%8.4f\ty:%8.4f\tz:%8.4f rad/s\n", (double)buf.x, (double)buf.y, (double)buf.z);
}
float len = sqrtf(buf.x * buf.x + buf.y * buf.y + buf.z * buf.z);
if (len > 0.3f) {
warnx("GYRO scale error!");
return ERROR;
}
/* Let user know everything is ok */
printf("\tOK: GYRO passed all tests successfully\n");
px4_close(fd);
return OK;
}
开发者ID:1002victor,项目名称:Firmware,代码行数:44,代码来源:test_sensors.c
示例17: mag
static int
mag(int argc, char *argv[], const char *path)
{
printf("\tMAG: test start\n");
fflush(stdout);
int fd;
struct mag_report buf;
int ret;
fd = px4_open(path, O_RDONLY);
if (fd < 0) {
printf("\tMAG: open fail, run <hmc5883 start> or <lsm303 start> first.\n");
return ERROR;
}
/* wait at least 5 ms, sensor should have data after that */
usleep(5000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
if (ret != sizeof(buf)) {
printf("\tMAG: read fail (%d)\n", ret);
return ERROR;
} else {
printf("\tMAG values: x:%8.4f\ty:%8.4f\tz:%8.4f\n", (double)buf.x, (double)buf.y, (double)buf.z);
}
float len = sqrtf(buf.x * buf.x + buf.y * buf.y + buf.z * buf.z);
if (len < 0.25f || len > 3.0f) {
warnx("MAG scale error!");
return ERROR;
}
/* Let user know everything is ok */
printf("\tOK: MAG passed all tests successfully\n");
px4_close(fd);
return OK;
}
开发者ID:1002victor,项目名称:Firmware,代码行数:44,代码来源:test_sensors.c
示例18: magnometerCheck
static bool magnometerCheck(int mavlink_fd, unsigned instance, bool optional)
{
bool success = true;
char s[30];
sprintf(s, "%s%u", MAG_BASE_DEVICE_PATH, instance);
int fd = px4_open(s, 0);
if (fd < 0) {
if (!optional) {
mavlink_and_console_log_critical(mavlink_fd,
"PREFLIGHT FAIL: NO MAG SENSOR #%u", instance);
}
return false;
}
int calibration_devid;
int ret;
int devid = px4_ioctl(fd, DEVIOCGDEVICEID, 0);
sprintf(s, "CAL_MAG%u_ID", instance);
param_get(param_find(s), &(calibration_devid));
if (devid != calibration_devid) {
mavlink_and_console_log_critical(mavlink_fd,
"PREFLIGHT FAIL: MAG #%u UNCALIBRATED", instance);
success = false;
goto out;
}
ret = px4_ioctl(fd, MAGIOCSELFTEST, 0);
if (ret != OK) {
mavlink_and_console_log_critical(mavlink_fd,
"PREFLIGHT FAIL: MAG #%u SELFTEST FAILED", instance);
success = false;
goto out;
}
out:
px4_close(fd);
return success;
}
开发者ID:JW-CHOI,项目名称:Firmware,代码行数:43,代码来源:PreflightCheck.cpp
示例19: baroCheck
static bool baroCheck(int mavlink_fd, unsigned instance, bool optional)
{
bool success = true;
char s[30];
sprintf(s, "%s%u", BARO_BASE_DEVICE_PATH, instance);
int fd = px4_open(s, 0);
if (fd < 0) {
if (!optional) {
mavlink_and_console_log_critical(mavlink_fd,
"PREFLIGHT FAIL: NO BARO SENSOR #%u", instance);
}
return false;
}
px4_close(fd);
return success;
}
开发者ID:JW-CHOI,项目名称:Firmware,代码行数:20,代码来源:PreflightCheck.cpp
示例20: do_import
static int
do_import(const char *param_file_name)
{
int fd = px4_open(param_file_name, O_RDONLY);
if (fd < 0) {
warn("open '%s'", param_file_name);
return 1;
}
int result = param_import(fd);
px4_close(fd);
if (result < 0) {
warnx("error importing from '%s'", param_file_name);
return 1;
}
return 0;
}
开发者ID:Dormanfcbm,项目名称:Firmware,代码行数:20,代码来源:param.c
注:本文中的px4_close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论