SimpleBGC_connection_diagram (1)
- 格式:pdf
- 大小:131.55 KB
- 文档页数:1
【MySQL】源码编译安装和配置MySql5.5.32(单实例)【需求描述】在CentOS环境中,通过编译源码的⽅式,安装并且配置“单实例”的MySQL5.5.32数据库。
MySQL的安装⽬录为:/application/mysql-5.5.32MySQL数据⽂件的安装⽬录为:/application/mysql-5.5.32/dataMySQL默认的字符编码为:UTF8【环境参数】VMware:10.0.1Host:Win7DB:MySql 5.5.32编译⼯具:cmake-2.8.8.tar.gz其他依赖:ncurses-devel-5.7-3.20090208.el6.x86_64.rpmClient:CentOS 6.5 x86_64,i686,最⼩化安装(Minimal)。
在安装⾃定义组件包时,(1)Base System只安装了Base,Compatibility Libraries和Debugging Tools。
(2)Development只安装了Development Tools。
【软件下载】(1)MySql下载地址:选择“Generic Linux (Architecture Independent), Compressed TAR Archive”这个版本的来下载。
(2)下载cmakeCMake是⼀个跨平台的安装(编译)⼯具,可以⽤简单的语句来描述所有平台的安装(编译过程)。
他能够输出各种各样的makefile或者project⽂件,能测试编译器所⽀持的C++特性,类似UNIX下的automake。
只是 CMake 的组态档取名为 CmakeLists.txt。
(3)下载ncurse-devel依赖包的百度云盘分享:【具体步骤】1、查看系统环境[root@centos65-mini ~]# cat /etc/redhat-releaseCentOS release 6.5 (Final)[root@centos65-mini ~]#[root@centos65-mini ~]#[root@centos65-mini ~]# uname -r2.6.32-431.el6.x86_64[root@centos65-mini ~]#2、安装相关软件包(1) 配置、编译和安装cmake编译⼯具①在当前⽬录,解压缩cmake-2.8.8.tar.gz# tar –zxvf cmake-2.8.8.tar.gz②从当前⽬录切换到cmake-2.8.8⽬录中,# cd cmake-2.8.8③执⾏命令“#./configure”来配置cmake⼯具。
出现(linker command failed with exit code 1)错误总结这种问题,通常出现在添加第三方库文件或者多人开发时。
这种问题一般是找不到文件而导致的链接错误。
我们可以从如下几个方面着手排查。
1.以如下错误为例,如果是多人开发,你同步完成后发现出现如下的错误。
[html] view plaincopyUndefined symbols for architecture armv7:"_OBJC_CLASS_$_MyPageLogViewController", referenced from:objc-class-ref in BaiduMobStatAppDelegate.old: symbol(s) not found for architecture armv7clang: error: linker command failed with exit code 1 (use -v to see invocation)错误中出现了“MyPageLogViewController”这个类,你可以找到这个类的.m文件,查看他的Target Membeship,如下图如果没有勾选上,点击勾选。
然后编译查看。
2. 如果是新添加的第三方库,且不是静态库先重复第一步过程,然后找到Buildsettings->Linking->Other Linker Flags将此属性修改成-all_load 或者-ObjC ,这个视情况而定。
总之可以多试几次。
3.如果添加的是第三方静态库(.a文件)[html] view plaincopyUndefined symbols for architecture armv7:"_OBJC_CLASS_$_BaiduMobStat", referenced from: objc-class-ref in BaiduMobStatAppDelegate.oobjc-class-ref in MyPageLogViewController.o(maybe you meant:_OBJC_CLASS_$_BaiduMobStatAppDelegate)ld: symbol(s) not found for architecture armv7clang: error: linker command failed with exit code 1 (use -v to see invocation)在用到这个库的所有文件中都出现了错误,如上BaiduMobStatAppDelegate 类和MyPageLogViewController 类这种情况就可能是这个静态库路径混乱导致的链接错误解决方法:Build settings->Search Path->Library Search Paths 添加静态库的相应路径。
SBGC32_I2C_Drv expansion module reference manualver. 0.2 – 28.03.2015 – first editionver. 0.3 – 11.04.2015 – Add “Q&A”, “Flashing MCU” sections.ver. 0.4 – 27.12.2017 – Add "API and examples" sectionver.0.5 – 05.09.2018 – The list of supported encoders was extended by new models; text was updated to conform with the latest GUI and firmware versions;OverviewThis module is intended to work as a part of the SimpleBGC32 camera stabilizer system,performing a motor driver function. Unlike regular scheme, where all motors and encoders are connected to the main board and driven by the single MCU, in the modular scheme eachmotor is driven by its own MCU, that lets to optimize cabling: encoder is integrated into the PCB for each module, and motor's cable goes to it by the shortest way. See Appendix A for an example of connection. Schematics, firmware and other resources you can find on the product's page: https:///sbgc32_i2c_drv/This expansion module is supported only in the encoder-enabled version of the SimpleBGC32 firmware: https:///encoders/Features:•Flexibility - This module can replace one or two motor+encoder pairs. Using it for all three motors is possible, but not recommended because I2C transfer on 400kHz ratewill not fit into 800us cycle time. There is an option to increase I2C speed to 800kHzfor small systems.•Low cost - Each module consists of entry-level STM32F051 series MCU, cheap magnetic or analog encoder, a FET- or IC-based motor driver and a minimal number of othercomponents.•Better cabling - a 5-wire cable is required to connect main MCU with the I2C_Drv modules and IMU sensor, all connected in parallel.•Compact size - MCU is available in the UFQFPN32 package, allowing ultra-compact design and installation into small motors.•Reliable, low power consumption - rotary encoders allow to apply advanced FOC algorithm for driving motors•Software compatibility - fully compatible with SimpleBGC32 software stack (including GUI, mobile applications, Serial API, etc.)Motor driver output circuitModule provides 6 PWM outputs to drive 3 half-bridges at ultra-sonic frequency. 300-400ns dead-time is inserted. It lets to use simple FET-based output circuit, or use integrated circuits like DRV8839, DRV8313, and any other IC that encloses 3 half-bridges and all protection circuits. Several output driver circuits are provided in the schematics, as an example.EncoderOne of the purposes of this module is to let to integrate encoder and motor driver into single PCB to minimize overall size of a system. For this purpose, a compact-sized magnetic encoder will be the best choice.List of supported encoders with its props and cons:Model Installation Interface Props ConsAS5048A on-axis SPI small size, high resolution(14bit), high update rate,perfect integration expensive compared to other magnetic ICsAS5048B on-axis I2C small size, high resolution(14bit), high update rate,perfect integration expensive; compatible with the 48- or 64-pin MCU only;AMT203on-axisin housing SPI shaft with pass-through holeis possible; easy installationon a shaftbig size; mediumupdate rate;external mountingonly; expensiveMA3 (10bit, 12bit)on-axisin housingPWM external mountingonly; slow updaterate; expensiveAnalog?analog low cost, good integration,high update rate full 360 degree rotation is not possible; friction reduces a life-cycle;AS5600on-axis I2C low cost, good integration,high update rate compatible with the 48- or 64-pin MCU only;AS5050A on-axis SPI low cost, good integration medium updaterate; low resolution AS5055A on-axis SPI low cost, good integration medium update rate RLS "Orbis"off-axisPCB w/outhousingSPI pass-through hole expensiveMA730on-axis SPI low cost; high resolution14bit; ultra-compact size;high update rate;AM4096on-axis I2C low noise, true 12bit big size of ICpackage; compatiblewith the 48- or 64-pin MCU only; Notes:1.Update rate is not crucial parameter for general application of the SimpleBGC system, so all types ofsupported encoders suit well.2.With the on-axis encoder, a special effort is required when designing a system that should support aninfinite 360-degrees rotation of a motor. When using sliprings, pay special attention to normal work of the I2C bus. It may be required to use I2C signal extenders / amplifiers.More information about using and configuring encoders in the SimpleBGC32 system you can find in this document: https:///files/SimpleBGC_32bit_Encoders.pdfNotes on schematicsWe provide a reference schematics, which contains a circuits for some types of supported encoders, several examples of output motor driver circuits and several packages of MCU (you can chose from LQFP32, UFQFPN32, LQFP48, UFQFPN48, UFBGA64 case, 32k or more FLASH). There are 2 options for flashing MCU: via SWD port and ST-Link utility, or via UART port and integrated bootloader. For the second option, additional components are required, as shown on the schematics.For the I2C encoders, 32-pin MCU case is not applicable. Use 48- or 64-pin case.Flashing MCUT o upload firmware, you can use UART port and Flash Loader Demonstrator tool from ST company, or any other flashing tool that can communicate with standard STM32 bootloader, including our GUI "Upgrade" tab in the manual mode. Second option is SWD port and ST-Link tool and utility (can be bought separately or found as a part of some "STM32Discovery" boards). Both interfaces are shown in the schematics, choose one that you like.Configuring SimpleBGC 32bit controller to work with the expansion modules1. Open SimpleBGC GUI , go to “Advanced” tab, “Motor outputs” group. Chose“SBGC32_I2C_drv#1..4” module in the drop-down list for any axis you want. Number 1..4 is configured by setting ADDR0, ADDR1 jumpers on the module: solder jumper to connect address pin to VDD for high level, or leave it floating to set low level (pin is pulled-down internally).Role ADDR0ADDR1SBGC32_I2C_drv#10 (low)0 (low)SBGC32_I2C_drv#2 1 (high)0 (low)SBGC32_I2C_drv#30 (low) 1 (high)SBGC32_I2C_drv#4 1 (high) 1 (high)2. In the “Encoders” tab, chose the same module for corresponding axis. Select a type of encoder, installed on the module, in the drop-down list below.3. It's better to increase the I2C speed by selecting the “I2C high speed” option in the “Hardware” tab, to minimize delays caused by the I2C data transfer. But it may be required to decrease overall resistance of pullups on SDA, SCL lines to 1..2k, otherwise I2C errors may come. Please pay attention to this fact when designing your own system.4. Second (frame) IMU is not required for the encoder-enabled gimbal design and may be omitted.All other settings for motor output and encoder are remain the same as in regular system. You can find further instructions in the "SBGC32 User Manual" and the "Encoders" manual, available to download from our web-site:https:///files/v3/SimpleBGC_32bit_manual_2_6x_eng.pdfhttps:///files/SimpleBGC_32bit_Encoders.pdfLicensingBinary firmware and schematics for SBGC32_I2C_Drv module are provided free of charge, limited to use only as a part of the SimpleBGC 32bit controller-based system. Source code is a property of Basecamelectronics and is not published. It is available for our partners upon a request.Q&AQ: How does it identify the motor pitch and the motor roll?A: There are 2 ADDR pins to chose I2C slave device address from four options. Set any unique address for each module, that defines them as “module 1..4”, than choose corresponding module in the GUI. More information can be found in the section "Configuring SimpleBGC32bit controller to work with the expansion modules".Q: I cannot find a circuit diagram of the main controller to be used in a modular scheme. What canI refer to in order to find it?A: The main controller is based on the regular 32bit board reference schematics. You can remove unused motor drivers and connectors to optimize its size, and add other service electronics like LiPo charger, bluetooth module, smart power switch, etc., that are not present in the original SBGC32 reference design. All functions and interfaces of the main controller are available as before, and you can still use main controller to drive any motor directly, or drive it via I2C_Drv.Q: Is it possible to apply DRV8313 instead of the original motor driver, shown in the schematics? If it is not possible, how can we get increased motor power?A: Yes, you can apply DRV8313 or any other suitable motor driver that has 3 independent full-bridges with the 3x PWM inputs and ENABLE input, compatible with the 3V-level logic.Q: I want to use I2C_Drv with the encoder that is not present in the list. Is it possible?A: You can send a request to the Basecamelectronics team for adding a support of a new model of encoder in the I2C_Drv firmware. Note that it should have I2C or SPI-compatible interface, and should be absolute. Incremental encoders ate not supported! Also consider using the "CAN Driver" module, that acts similar to the I2C_Drv module, but has more advanced motor control algorithms and provides more connection optionshttps:///can_driver/Appendix A: SBGC32_I2C_Drv connection diagramoutput driver)© Basecamelectronics® 2015Appendix B: I2C_Drv API and examplesThe API consists of the definition of I2C registers. The master controller reads and writes them to operate the module.I2C_Drv.h/*This is a part of SimpleBGC project source codeCopyright (c) 2015 Aleksei MoskalenkoSBGC32_i2c_drv - expansion board with brushless driver, encoder and I2C interface*/#ifndef I2C_DRV_H_#define I2C_DRV_H_// Device address (7bit)#define I2C_DRV_START_ADDR 0x19// Device identifier. Check it when discovering#define I2C_DRV_DEVICE_ID 0x14/************** Register map **************************//* Note that though registers are 16bit, lower byte can be read/written by 8bit transactions */// Encoder#define I2C_DRV_REG_ENC_RAW_ANGLE 40#define I2C_DRV_REG_ENC_ANGLE 41#define I2C_DRV_REG_ENC_INFO 6#define I2C_DRV_REG_ENC_ERR_CNTR 42// Motor driver#define I2C_DRV_REG_SET_POWER_ANGLE 0#define I2C_DRV_REG_SET_POWER 0#define I2C_DRV_REG_SET_ANGLE 1#define I2C_DRV_REG_SET_FORCE_POWER 2#define I2C_DRV_REG_SET_ENABLE 3// Configuration#define I2C_DRV_REG_ENC_TYPE 4#define I2C_DRV_REG_ENC_CONF 5#define I2C_DRV_REG_ENC_FLD_OFFSET 7// Device info#define I2C_DRV_REG_DEVICE_ID 39#define I2C_DRV_REG_FIRMWARE_VER 32#define I2C_DRV_REG_MCU_ID 33#define I2C_DRV_MCU_ID_SIZE 6#define I2C_DRV_REG_I2CS_ERR_CNTR 43// Misc. functions#define I2C_DRV_REG_RESET_MODE 8/********************************************************/// Types of supported encoders#define I2C_DRV_ENC_TYPE_AS5048A 1#define I2C_DRV_ENC_TYPE_AS5048B 2#define I2C_DRV_ENC_TYPE_AMT203 3#define I2C_DRV_ENC_TYPE_MA3_10BIT 4#define I2C_DRV_ENC_TYPE_MA3_12BIT 5#define I2C_DRV_ENC_TYPE_ANALOG 6#define I2C_DRV_ENC_TYPE_AS5600 7#define I2C_DRV_ENC_TYPE_AS5050A 8#define I2C_DRV_ENC_TYPE_AS5055A 9#endif/* I2C_DRV_H_ */Example of using I2C_Drvuint8_t OutputI2CDrv::init(uint8_t _out_port, uint8_t _axis){addr = (I2C_DRV_START_ADDR - 3) + _out_port;cur_power = 0;// Check if I2C board is connected (wait 2 sec)i2c::select_line(I2C_LINE_A);for(uint8_t i=0; i<100; i++) {if(i2c::read_reg_byte(addr, I2C_DRV_REG_DEVICE_ID) == I2C_DRV_DEVICE_ID) { // check device IDreturn 1;}}return 0;}void OutputI2CDrv::write_reg_byte(uint8_t reg, uint8_t val) {i2c::select_line(I2C_LINE_A);i2c::write_reg_byte(addr, reg, val);}void OutputI2CDrv::powerOn() {write_reg_byte(I2C_DRV_REG_SET_ENABLE, 1);}void OutputI2CDrv::powerOff() {write_reg_byte(I2C_DRV_REG_SET_ENABLE, 0);}void OutputI2CDrv::output16(uint16_t el_angle) {i2c::select_line(I2C_LINE_A);uint16_t buf[2] = { cur_power, el_angle };i2c::write_reg_buf(addr, I2C_DRV_REG_SET_POWER_ANGLE, (void*)buf, sizeof(buf));// TODO: We can write force power, if encoder fld.offset is calibrated// (not yet implemented in the I2C_DRV firmware)}// Search for the I2C_Drv-connected encodervoid Encoder::_init_i2c_drv(uint8_t type) {i2c.addr = (I2C_DRV_START_ADDR - ENC_TYPE_I2C_DRV1) + type;i2c::select_line(I2C_LINE_A);if(i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_DEVICE_ID) == I2C_DRV_DEVICE_ID) { // Get firmware version, if required//uint16_t frw_ver;//i2c::read_reg_buf(addr, I2C_DRV_REG_FIRMWARE_VER, &frw_ver, 2);// Configure the type of internal encoderif(i2c::write_reg_byte(i2c.addr, I2C_DRV_REG_ENC_TYPE, cfg)) {// Read it back to confirm activation. Wait max. 50msfor(uint8_t i=0; i<50 && !encoder_type; i++) {Time::delay_us(1000);if(i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_ENC_TYPE) == cfg) {encoder_type = type;// configure field calibration//i2c::write_reg_buf(addr, I2C_DRV_REG_ENC_FLD_OFFSET,&(params.encoder_fld_offset[axis]), 2);// Configure encoder// bits 0..3: LPF factor// bit 4: I2C fast modeuint16_t conf = 5;i2c::write_reg_buf(i2c.addr, I2C_DRV_REG_ENC_CONF, &conf, sizeof(conf));}}}}i2c::errors_count = 0;}uint16_t Encoder::_read_i2c_drv() {uint16_t angle;i2c::select_line(I2C_LINE_A);if (i2c::read_reg_buf(i2c.addr, I2C_DRV_REG_ENC_ANGLE, &angle, 2)) {read_error = 0;return angle;}return 0;}void Encoder::_request_info_i2c_drv(uint8_t info[4]) {// info[0] - encoder error counter// info[1] - I2C slave error counter// Sub-type AS5048A, AS5048B:// info[2] - magnitude// info[3] - diagnostic registeri2c::select_line(I2C_LINE_A);info[0] = i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_ENC_ERR_CNTR);info[1] = i2c::read_reg_byte(i2c.addr, I2C_DRV_REG_I2CS_ERR_CNTR);// Write any data to ENC_INFO reg to queue information from encoderif(i2c::write_reg_byte(i2c.addr, I2C_DRV_REG_ENC_INFO, 0)) {Time::delay_ms(50); // wait a bit to let device to read informationi2c::read_reg_buf(i2c.addr, I2C_DRV_REG_ENC_INFO, &info[2], 2);}}© Basecamelectronics® 2018。
C连接MYSQL数据库的3种方法及示例连接MYSQL数据库有多种方法,下面介绍其中三种常用的方法。
1.使用CAPI连接MYSQL数据库CAPI是官方提供的一套用于连接和操作MYSQL数据库的函数库。
使用该API,可以在C程序中直接连接MYSQL数据库,并执行各种SQL语句。
以下是一个连接MYSQL数据库的示例:```c#include <mysql.h>int maiMYSQL *conn;MYSQL_RES *res;MYSQL_ROW row;conn = mysql_init(NULL);if (conn == NULL)fprintf(stderr, "mysql_init failed\n");return 1;}if (mysql_real_connect(conn, "localhost", "user", "password", "database", 0, NULL, 0) == NULL)fprintf(stderr, "mysql_real_connect failed: %s\n", mysql_error(conn));mysql_close(conn);return 1;}if (mysql_query(conn, "SELECT * FROM table"))fprintf(stderr, "mysql_query failed: %s\n",mysql_error(conn));mysql_close(conn);return 1;}res = mysql_use_result(conn);while ((row = mysql_fetch_row(res)) != NULL)printf("%s %s %s\n", row[0], row[1], row[2]);}mysql_free_result(res);mysql_close(conn);return 0;```上述代码首先初始化MYSQL对象,然后使用mysql_real_connect函数连接MYSQL数据库。
MySQL提⽰“toomanyconnections”的解决办法今天⽣产服务器上的MySQL出现了⼀个不算太陌⽣的错误“Too many connections”。
平常碰到这个问题,我基本上是修改/etc/f的max_connections参数,然后重启数据库。
但是⽣产服务器上数据库⼜不能随便重启。
没办法,只好想办法⼿动去释放⼀些没⽤的连接。
登陆到MySQL的提⽰符下,数据show processlist这个命令,可以得到所以连接到这个服务器上的MySQL连接:mysql> show processlist;+---------+------+---------------------+---------+---------+------+-------+-------------------+| Id | User | Host | db | Command | Time | State | Info |+---------+------+---------------------+---------+---------+------+-------+-------------------+| 1180421 | ur | 202.103.96.68:49754 | test1 | Sleep | 1 | | NULL || 1180427 | ur | 202.103.96.68:55079 | test2 | Sleep | 1 | | NULL || 1180429 | ur | 202.103.96.68:55187 | testdba | Sleep | 0 | | NULL || 1180431 | ur | 202.103.96.68:55704 | testdba | Sleep | 0 | | NULL || 1180437 | ur | 202.103.96.68:32825 | test1 | Sleep | 1 | | NULL || 1180469 | ur | 202.103.96.68:58073 | testdba | Sleep | 0 | | NULL || 1180472 | ur | 83.136.93.131:47613 | test2 | Sleep | 8 | | NULL || 1180475 | root | localhost | NULL | Query | 0 | NULL | show PROCESSLIST |+---------+------+---------------------+---------+---------+------+-------+-------------------+8 rows in set (0.00 sec)mysql>然后,你可以看到像上⾯这样的MySQL数据连接列表,⽽且每⼀个都会有⼀个进程ID号(在上表的第⼀列)。
Scripting Language ReferenceSimpleBGC 32bitActual firmware version: 2.70b5 and aboveUpdated: 17. Oct. 2021OverviewScripting language is intended to control a gimbal by user-written program. This program is uploaded to controller and executed there without a connection to PC. Program can be started by a command from remote controller (RC), menu button or GUI button.There is a simple editor in the SimpleBGC GUI with the syntax checking and tracing of the execution process, but you can use any text editors you like to edit scripts.General rules•Each line can contain only one command•Command may have up to 10 named parameters separated by space.•All values must be in decimal notation with a fractional part separated by a dot. Fractional part can be omitted.•You can add comments starting line with the # character, but comments are not saved to the board. Command notation:ANGLE RA(10) PA(10) ...command parameter name value other parametersSome commands may have one-letter abbreviation, for example “ANGLE” has a shortcut “A”.Parameters controlled in real-time (frw. ver. 2.60b3)Values of parameters in any command can be dynamically updated during the execution of a program by linking them to any of RC signal sources. Just specify the signal source name and the desired range of the parameter's value, and RC signal will be captured and mapped to this range at the start of the command. Note that the value is not updated during the command execution.All available RC signal source names are listed in the Appendix 3.Usage:<PARAMETER_NAME>(<RC_SOURCE_NAME>[<min_value>,<max_value>])The advanced scripting version supports also variables as parameter values. Variables may be set by the command SET_ADJ_VAR.Usage:<PARAMETER_NAME>(<VARIABLE_NAME>[<offset>,<scale>]), where parameter value is calculated as “<variable_value>*<scale> + <offset>”Examples:ANGLE RA(ADC1[-50,50]) PA(RC_VIRT_CH_1[0,90])SPEED YS(TMP_VAR_1[0,1])Advanced functionsSome versions of SBGC32 controller having big FLASH and RAM memory size, support advanced functions which do not present in the basic version of script processor:•Temporarily variables can be set by SET_ADJ_VAR command and used as a signal source in other commands;•Basic arithmetic operations;•IF .. GOTO command to implement control flow of the script (loops, conditional forks);•Motion synchronization option to synchronize trajectory between axes in commands ANGLE, INC.Advanced script functions are supported in the following controllers:•“Extended” series: “Extended”, “Extended long”, “Pro”, “CAN_MCU”, “OEM”•“Plus” series: “Regular+”, “Tiny+”Command referenceA, ANGLE — rotation to the absolute angle with a given speedCommand stops the program and waits until the angle reaches a given value. Rotation is done by the shortest path. If you want to turn the camera on the relative angle greater than ± 180 degrees, use the INC command instead. You can set the speed for each axis. If speed is not set, will be used the current value defined in the settings or command “CONFIG”.Parameters:RA(10.0) — target angle by the ROLL axis, in degreesPA(10.0) - target angle by the PITCH axisYA(10.0) - target angle by the YAW axisRS(10.0) — speed by the ROLL axis, degree/sec. in range 0..2000, special value 0 is used to synchronize motion with other axis.PS(10.0) - speed by the PITCH axisYS(10.0) - speed by the YAW axisTIMEOUT(60.0) – wait timeout. If not specified, it is 60 seconds by default.(supported in firmware ver.2.59+)Example:A RA(0) PA(0) YA(0)# go to home position by all axesA YA(70) YS(1)# rotate YAW to 70 degree with the speed 1 degree/sec.Motion synchronizationThe advanced scripting version in firmware 2.70b5 and above provides an option to synchronize a motion of any axis with the motion of another axis by specifying its speed parameter = 0. The last axis with the 'angle' parameter preceding the zero 'speed' parameter in the parameter string is selected as a sample for synchronization. Target angles should be specified for both axes and should differ from current angles. Example:A RA(0) PA(0) YA(0)# move to the initial positionA PA(20) PS(50) YA(90) YS(0)# YAW axis is asked to be synchronized with the PITCH axis. YAW travels 90°, but it takes exactly the same time as PITCH traveling 20°. Both axes have perfectly matched acceleration / deacceleration ramps.Wrong examples:A YA(90) YS(0)# error: sync sample is not definedA PA(0) YA(90) YS(0)# error: target angle in the sample should differ from its current angleI, INC - rotation by the relative angle with a given speedCommand stops the program and waits until the angle rotates by a given value. Angle should not exceed two full turns. The motion synchronization option is supported.Parameters:RA(10.0) — target angle by the ROLL axis, in degrees. Range -720..720PA(10.0) - target angle by the PITCH axisYA(10.0) - target angle by the YAW axisRS(10.0) — speed by the ROLL axis, degree/sec. in range 0..2000, special value 0 is used to synchronize motion with other axis.PS(10.0) - speed by the PITCH axisYS(10.0) - speed by the YAW axisTIMEOUT(60.0) – wait timeout. If not specified, it is 60 seconds by default.(supported in firmware ver.2.59+)Example:I YA(270)# rotate by YAW by 270 degree from current positionS, SPEED - turn with a given speed until it encounters another command SPEED, ANGLE, INC or the end of the program.The camera starts moving and program execution continues without delay.Parameters:RS(10.0) — speed by ROLL axis, degree/sec. Range -2000..2000.PS(10.0) - speed by PITCH axisYS(10.0) - speed by YAW axisExample:S YS(5.5)# panning by YAW with the speed 5.5 degree/secS RS(0) PS(0) YS(0)# full stopR, RESET — set the YAW angle = 0 for the current positionParameters:noT, TRIGGER — trigger the state of the output pinsParameters:1(0) — pin ID * and its state:0 – LOW (GND)1 — HIGH (+3.3V)2 – FLOATING (frw.ver. 2.66+)3 – FLOATING + PULLUP 3.3V (frw.ver. 2.66+)TIMEOUT(0.01) (optional) – if specified, program execution is delayed by a given time, in seconds.** At the end of the timeout the specified pins will be inverted (HIGH → LOW, LOW → HIGH). Don't set this parameter if you need to keep pin'sstate after triggering. A necessary delay may be created by the separate 'DELAY' command.* Mapping between Pin ID and physical port can be found in the Appendix 1. The pin should be free of otherfunctions (for example, not be used as an input in the RC settings tab).** Accuracy is ±1 millisecond. Specifying a timeout can be useful for example, to manually set the shutterspeed when shooting HDR images.Example:T 1(1) 2(1)# switch outputs ID=1,2 to a HIGH stateT 1(1) TIMEOUT(0.020)# switch output ID=1 to a HIGH state and return back to LOW after 20ms SERVO — set PWM signal pulse width on the specified pinThis command is used to control the servos connected to the special pins that supports output of PWM signal. PWM rate can be changed in the GUI (RC - PWM Output - PWM Rate, Hz).Parameters:1(1500) — Servo ID* and pulse duration, microseconds. For regular servo values are in the range 900-2100. Special value -1 frees pin and makes it high-impedance input.TIME(3)** — travel time to target position, in secondsTIMEOUT(1) — when target is reached, program execution is delayed by a giventime, in seconds.* Mapping between Servo ID and physical port can be found in the Appendix 1. The pin should be free of other functions (for example, not be used as an input in the RC settings tab).**Firmware ver. 2.5x and aboveExample:SERVO 1(1500) 2(1500)# move two servos to a middle positionSERVO 1(1000) TIME(3)# slowly move from 1500 to 1000 in 3 secondsSERVO 1(2000) TIMEOUT(1)# set new value and wait 1 secondSERVO 1(-1) 2(-1)# free two outputsD, DELA Y - delay of program executionParameters:TIMEOUT(10) — delay, in seconds. Accuracy ±1 milliseconds.Example:D TIMEOUT(0.300)# delay for 300 millisecondsW, WAIT – waiting for the specified angle or speedProgram execution is delayed until all specified conditions will be satisfied, or a given timeout will be expired. Parameters:RA(10.0) — angle by the ROLL axis, in degreesPA(10.0) — angle by the PITCH axisYA(10.0) — angle by the YAW axisRS(0) - speed by the ROLL axis, in degrees/sec.PS(0) - speed by the PITCH axisYS(0) - speed by the YAW axisTIMEOUT(10) – max. time of waiting, in seconds. Default is 60 sec.Example:W YA(30)# wait for YAW angle=30 degreeW RA(0) PA(0) YA(0)# wait for angle=0 for all axesW YS(0) TIMEOUT(1)# wait to stop motion by YAW axis, but not more than 1 second. CONFIG — configure some parameters used in program executionParameters:ACC_LIMIT_R(100), ACC_LIMIT_P(100), ACC_LIMIT_Y(100) — acceleration limit for the ROLL, PITCH, YAW axes, degrees/sec²SPEED_R(10), SPEED_P(10), SPEED_Y(10) — speed for the ROLL, PITCH, YAW axes, degree/sec. Range is 0..2000. Initial value is taken from the “RC SPEED” parameters INIT_SYSTEM_ON_FINISH(1) (ver. 2.60b3+) – if set to 1 (default), system will be re-initialized when script finishes (all parameters and modes of operation will be returned to default). If set to 0, system will be left in it's current state.JERK_SLOPE_R(50), JERK_SLOPE_P(50), JERK_SLOPE_Y(50) (ver. 2.66+) — jerk limiter for the ROLL, PITCH, YAW axis, the rise/fall time in msThe changed parameters are not saved to the persistent memory and will be reset to their original values when program is finished.Example:С ACC_LIMIT_R(100) SPEED_Y(5) # set an acceleration limit for the ROLL axis to 100 degree/sec² and a speed for YAW axis to 5 degree/sec.MENU_CMD — execute a menu command(frw. ver. 2.60b3+)Parameters:CMD_ID(10) – command ID to run. Full list of commands is listed in the Appendix 2. In case of any command is missed there, it can be found in the Serial API documentation. Script parser does not wait for command to be finished!TIMEOUT(1) – program execution is delayed by a given time, in seconds.SET_ADJ_VAR — set the value of adjustable variable (frw. ver. 2.61)Parameters:NAME(GYRO_TRUST) – name of variable. All names are provided in the SBGC32 User Manual, "Adjustable variables" section.VALUE(100) – new value to set.You can specify up to 5 pairs NAME - VALUE in a single commandExample:SET_ADJ_VAR NAME(RC_SPEED_PITCH) VALUE(60) NAME(RC_SPEED_ROLL) VALUE(50)The advanced scripting version supports temporarily variables and arithmetic operations on them. Variables can be used as parameters in other commands, can be sent for external logging, or used for flow control (see IF .. GOTO command definition). System keeps their values between script executions, so you need to reset values at the start of the script, if needed.Variables:•TMP_VAR_1 .. TMP_VAR_10 (floating point type) – may be used in a script only•API_VIRT_CH_1 .. API_VIRT_CH_32 (int16 type) – may be used as a source ofcontrol signal in all places where RC channels are assigned, value ±16384encodes the full RC range.Operations:OPERATOR(=+-*/%) – do arithmetic operation on two values, where 1st value isresult of all previous calculations and 2nd value is a value of the nextparameter in sequence. If OPERATOR goes next to the NAME parameter, the current value of the variable is used.Examples:SET_ADJ_VAR NAME(TMP_VAR_1) VALUE(1) NAME(TMP_VAR_2) VALUE(1)Result: TMP_VAR_1 = 1, TMP_VAR_2 = 1SET_ADJ_VAR NAME(TMP_VAR_1) OPERATOR(+) VALUE(10)Result: TMP_VAR_1 = 11SET_ADJ_VAR NAME(TMP_VAR_3) VALUE(TMP_VAR_1[0,1]) OPERATOR(+) VALUE(TMP_VAR_2[-5,4])OPERATOR(*) VALUE(10)Result: TMP_VAR_3 = (11 + (1*4 - 5))*10 = 100PLA Y_SOUND — plays standard sound and blinks LED (frw. ver. 2.68)Parameters:CMD_ID(1) – sound to play:•1 – calibration•2 – confirmation•4 – error•8 – alarm•16 – single click•32 – action complete•64 – startup melodyModifiers (can be combined with the ID by OR operator):•16384 – silent mode: do not emit sound, just blink LEDTIMEOUT(1) – program execution is delayed by a given time, in seconds. If notimeout is specified, program goes to a next command, playing sound in thebackground.IF — conditional flow control of the script (frw. ver. 2.69b7)The advanced scripting version supports a flow control using IF .. GOTO command together with theSET_ADJ_VAR command and temporarily variables.Parameters:NAME(<VARIABLE_NAME>) – name of the variable to compare, one of the:•TMP_VAR_1..TMP_VAR_10 – floating point type•API_VIRT_CH_1..API_VIRT_CH_32 – int16 type•all adjustable variables listed in “User Manual”VALUE(<value | RC source[min,max] | variable[offset,scale]>) – value to compare.It may be a regular decimal value or RC signal source/variable.COND(<condition>) – condition to be used in a comparison of variable and thefollowing VALUE parameter. Both values are rounded to integers before comparing, excepting >> and << operations.•= - equal•!= - not equal•> - greater•>= - greater or equal•< - less•<= - less or equal•>> - greater, not rounded•<< - less, not roundedGOTO(<line number | label_name>) – line number in script to jump if condition is true. It's recommended to use labels instead. You can place label before anycommand or on empty line, in a form of “LABEL_NAME: mand..”Command expects two values, provided by the NAME or VALUE parameters, one COND parameter and one GOTO parameter. In case of (NAME|VALUE)x2 and COND parameters are missed, GOTO will do unconditional jump.Example: repeat INC command 10 times to rotate YAW axis by 10-degree steps, sending a short pulse to pin AUX1 after each step.SET_ADJ_VAR NAME(TMP_VAR_1) VALUE(0)LOOP1: SET_ADJ_VAR NAME(TMP_VAR_1) OPERATOR(+) VALUE(1)INC YA(10)TRIGGER 16(1) TIMEOUT(0.5)IF NAME(TMP_VAR_1) COND(<) VALUE(10) GOTO(LOOP1)Appendix 1. Mapping between pin IDs and physical ports Labeling on the board Trigger pin ID Servo ID RC_ROLL1-RC_PITCH23 RC_YAW5-EXT_FC_ROLL31 EXT_FC_PITCH42 AUX1164 AUX217-AXU318-BUZZER32-Appendix 2: Menu commands MENU_CMD_PROFILE1 = 1MENU_CMD_PROFILE2 = 2MENU_CMD_PROFILE3 = 3MENU_CMD_SWAP_PITCH_ROLL = 4MENU_CMD_SWAP_YAW_ROLL = 5MENU_CMD_CALIB_ACC = 6MENU_CMD_RESET = 7MENU_CMD_SET_ANGLE = 8MENU_CMD_CALIB_GYRO = 9MENU_CMD_MOTOR_TOGGLE = 10MENU_CMD_MOTOR_ON = 11MENU_CMD_MOTOR_OFF = 12MENU_CMD_FRAME_UPSIDE_DOWN = 13 MENU_CMD_PROFILE4 = 14MENU_CMD_PROFILE5 = 15MENU_CMD_AUTO_PID = 16MENU_CMD_LOOK_DOWN = 17MENU_CMD_HOME_POSITION = 18MENU_CMD_RC_BIND = 19MENU_CMD_CALIB_GYRO_TEMP = 20 MENU_CMD_CALIB_ACC_TEMP = 21MENU_CMD_BUTTON_PRESS = 22MENU_CMD_RUN_SCRIPT1 = 23MENU_CMD_RUN_SCRIPT2 = 24MENU_CMD_RUN_SCRIPT3 = 25MENU_CMD_RUN_SCRIPT4 = 26MENU_CMD_RUN_SCRIPT5 = 27MENU_CMD_CALIB_MAG = 33MENU_CMD_LEVEL_ROLL_PITCH = 34 MENU_CMD_CENTER_YAW = 35MENU_CMD_UNTWIST_CABLES = 36MENU_CMD_SET_ANGLE_NO_SAVE = 37 MENU_HOME_POSITION_SHORTEST = 38 MENU_CENTER_YAW_SHORTEST = 39 MENU_ROTATE_YAW_180 = 40MENU_ROTATE_YAW_180_FRAME_REL = 41 MENU_SWITCH_YAW_180_FRAME_REL = 42 MENU_SWITCH_POS_ROLL_90 = 43MENU_START_TIMELAPSE = 44MENU_CALIB_MOMENTUM = 45MENU_LEVEL_ROLL = 46MENU_LOAD_PROFILE_SET1 = 48MENU_LOAD_PROFILE_SET2 = 49MENU_LOAD_PROFILE_SET3 = 50MENU_LOAD_PROFILE_SET4 = 51MENU_LOAD_PROFILE_SET5 = 52MENU_LOAD_PROFILE_SET_BACKUP = 53 MENU_INVERT_RC_ROLL = 54MENU_INVERT_RC_PITCH = 55MENU_INVERT_RC_YAW = 56MENU_SNAP_TO_FIXED_POSITION = 57 MENU_CAMERA_REC_PHOTO_EVENT = 58 MENU_CAMERA_PHOTO_EVENT = 59 MENU_MOTORS_SAFE_STOP = 60 MENU_CALIB_ACC_AUTO = 61Appendix 3: RC signal source namesHardware inputs for PWM format:RC_ROLL_PWMRC_PITCH_PWMRC_YAW_PWMFC_ROLL_PWMFC_PITCH_PWMRC input should be enabled (i.e. assigned to control of any axis or CMD channel in the RC settings).Analog inputs (joystick connection):ADC1ADC2ADC3Sum-PPM or serial protocols (Spektrum, s-bus):RC_VIRT_CH_1RC_VIRT_CH_2..RC_VIRT_CH_31Desired serial protocol should be selected in the RC settings;Channels 20..31 have special meaning: they are linked to the sin, cos of the angles of motors.Serial API virtual channels (can be set by the external devices or mobile applications connected by SBGC Serial API protocol):API_VIRT_CH_1API_VIRT_CH_2..API_VIRT_CH_31Example 1: Shooting 3-row spherical panorama with increment of 60 degrees in 20 seconds, AUX1 controls the shutter.# Setup a high speed for a quick completion of the panoramaCONFIG SPEED_R(200) SPEED_P(200) SPEED_Y(200) ACC_LIMIT_R(500) ACC_LIMIT_P(1000) ACC_LIMIT_Y(500) # Reset the origin of the YAW: Start recording with the current azimuthR# Turn off the shutter pinT 16(0)# Make 1st shot in the zenith position: raise the camera verticallyA RA(0) PA(-90) YA(0)# Make a shotT 16(1) TIMEOUT(0.100)# Tilt 45 degrees up to make the 1st rowA RA(0) PA(-45) YA(0)T 16(1) TIMEOUT(0.100)# Panning with increment of 60 degrees clockwiseA YA(60)T 16(1) TIMEOUT(0.100)A YA(120)T 16(1) TIMEOUT(0.100)A YA(180)T 16(1) TIMEOUT(0.100)A YA(240)T 16(1) TIMEOUT(0.100)A YA(300)T 16(1) TIMEOUT(0.100)# Camera is tilted 0 degrees to make 2nd rowA RA(0) PA(0) YA(0)T 16(1) TIMEOUT(0.100)# Panning with increment of 60 degrees counterclockwise (avoid double-twisting of the wires)A YA(-60)T 16(1) TIMEOUT(0.100)A YA(-120)T 16(1) TIMEOUT(0.100)A YA(-180)T 16(1) TIMEOUT(0.100)A YA(-240)T 16(1) TIMEOUT(0.100)A YA(-300)T 16(1) TIMEOUT(0.100)# Tilt 45 degrees down to make the 3rd rowA RA(0) PA(45) YA(0)T 16(1) TIMEOUT(0.100)# Panning with increment of 60 degrees clockwiseA YA(60)T 16(1) TIMEOUT(0.100)A YA(120)T 16(1) TIMEOUT(0.100)A YA(180)T 16(1) TIMEOUT(0.100)A YA(240)T 16(1) TIMEOUT(0.100)A YA(300)T 16(1) TIMEOUT(0.100)# Shoot in the nadir positionA YA(0) PA(90)T 16(1) TIMEOUT(0.100)# Returns the camera to its original position (untwist wires) A RA(0) PA(0)I YA(-360)### End of program ###Example 2: Pan at 5 deg/sec by 90 degrees. AUX1 operates recording # Reset the origin of the YAW: Start recording with the current azimuthR# Tilt the camera 30 degrees down and level itA RA(0) PA(30) YA(0)# Start recordingT 16(1)# Writing freeze for 3 seconds.D TIMEOUT(3)# Setup low acceleration for smooth start and stop of the motionCONFIG ACC_LIMIT_Y(5)# Panning with a speed of 5 degree/sec. clockwiseS YS(5)# Wait until turned by 90 degrees.W YA(90)# Stop panning (de-acceleration starts here)S YS(0)# Wait until de-acceleration is finishedW YS(0)# Writing freeze for 3 seconds.D TIMEOUT(3)# Stop recordingT 16(0)### End of program ###Example 3: Time-lapse shooting with minimized gyroscope drift# Let system to know that the frame is still, to compensate a drift of gyroscope;SET_ADJ_VAR NAME(FRAME_HEADING_ANGLE) VALUE(0)# Set the 'gyro trust' parameter low enough to better compensate drift of gyroscopeSET_ADJ_VAR NAME(GYRO_TRUST) VALUE(60)# (Optional) move camera to the desired initial position. Skip this command to start from the current position#ANGLE PA(0) RA(0)# Pan left with the speed 0.1 degrees/sec and tilt up with the speed half slower.SPEED YS(0.1) PS(-0.05)# Wait 10 minutesDELAY TIMEOUT(600)。
linux cascadeclassifier路径-回复Linux CascadeClassifier 路径是指在Linux操作系统中使用CascadeClassifier进行目标检测时,需要配置的CascadeClassifier模型的路径。
CascadeClassifier是一种基于Haar特征的级联分类器,特别适用于人脸检测。
本文将一步一步回答如何设置Linux CascadeClassifier路径。
一、什么是CascadeClassifier?CascadeClassifier是OpenCV库中提供的一种级联分类器,它基于Haar特征并通过Adaboost算法进行级联训练。
CascadeClassifier可以用于目标检测,特别是人脸检测。
它的分类器模型文件(.xml)描述了训练好的级联分类器的特征。
二、在Linux中安装OpenCV在Linux上使用CascadeClassifier之前,首先需要在Linux系统上安装OpenCV库。
1. 打开终端,并使用以下命令安装OpenCV库:sudo apt-get updatesudo apt-get install libopencv-dev2. 等待安装过程完成,检查OpenCV是否安装成功:pkg-config modversion opencv如果成功安装,终端将显示OpenCV的版本号。
三、获取CascadeClassifier文件在Linux操作系统中,CascadeClassifier的路径指向训练好的级联分类器模型文件(.xml)。
你可以选择从OpenCV官方仓库中下载现成的CascadeClassifier模型文件,也可以自己训练一个。
1. 下载现成的CascadeClassifier模型文件:wget上述命令将在当前目录下载一个名为"haarcascade_frontalface_default.xml"的级联分类器模型文件。
目录1Multipath概要说明 (2)2multipath程序流程: (3)2.1multipath版本 (3)2.2multipath用户态程序依赖库 (3)2.3生成多路径信息 (4)2.3.1命令执行概要 (4)2.3.2核心数据结构 (4)2.3.3主函数调用流程 (4)2.4清除所有多路径信息 (9)2.4.1命令执行概要 (9)3multipathd程序流程 (10)1.1.checkloop线程 (12)2.2. ueventloop线程 (14)2.3.uxlsnrloop线程 (16)4device_mapper用户库接口 (17)5dm_mod、dm_multipath内核模块 (18)1Multipath概要说明Multipath用户程序有两个,包括multipath和multipathd,其中multipath程序主要用来做查询多路径状态,multipathd程序主要用来响应硬件事件,并执行相应动作。
从网上找的一张描述multipath整体调用流程的图片,从用户态到内核态2multipath程序流程:首先调用sysfs_get_mnt_path,得到sysfs文件系统的挂载目录,一般情况下为/sys;然后调用configure,这个函数执行了剩下的所有事情:1)首先通过path_discovery从/sys下找到所有当前磁盘路径,放到结构体中pathvec中2)然后调用coalesce_paths,计算pathvec中每一条路径的wwid值,如果相同就聚合成一条mpp3)最后调用domap(mpp),执行多路径动作(例如:路径创建、路径删除、路径切换等等)2.1multipath版本device-mapper-multipath-0.4.7-23.el52.2multipath用户态程序依赖库(一)libsysfs.so从sysfs子系统内提取/sys/block/{sda,sdb...} 磁盘信息对应源码包:sysfsutils-2.0.0-6.src.rpm(二)libdevmapper.so重新封装ioctl接口,供libmultipath.so库以及kpartx调用主要提供函数接口如:dm_task_create dm_task_run dm_task_destroy等对应源码包:device-mapper-1.02.28-2.el5.src.rpm(三)libmultipath.so供multipath、multipathd等程序调用主要提供函数接口如:coalesce_paths、add_map_without_path、add_map_with_path、remove_map、remove_maps等对应源码包:device-mapper-multipath-0.4.7-23.el5.src.rpm以命令执行为入口,一步步分析代码流程:2.3生成多路径信息>>>multipath -v32.3.1命令执行概要扫描sysfs下所有磁盘,得到所有块设备,包括本机硬盘,U盘,所有scsi存储,过滤掉黑名单(blacklist)中的设备,通过scsi_id命令得到磁盘的scsi-id,并将相同scsi-id的磁盘归类为一个多路径,最后调用ioctl发往内核2.3.2核心数据结构struct vectors vecs {struct vector *pathvec; # 存储单独的一条磁盘信息,如sda、sdb等struct vector *mpvec; # 存储聚合后的多路径信息,如dm-0、dm-1等}2.3.3主函数调用流程执行main -> configure -> path_discovery、coalesce_paths2.3.3.1path_discovery函数流程从sysfs子系统提取所有路径,如sda,sdb... 遍历这些路径,依次调用path_discover,在path_discover中,过滤掉黑名单(blacklist)中的磁盘设备,再调用pathinfo获得与磁盘有关的信息:wwid、vendor_id、product_id、sg_id.{host_no,channel,scsi_id,lun}等,最终将所有单条路径信息填入vecs->pathvec结构中其中获得wwid的函数为get_uid,主要就是调用程序/sbin/scsi_id -g -u -s /block/%n 获得磁盘wwid信息2.3.3.2coalesce_paths(聚合路径)函数流程仍然是遍历vecs->pathvec中所有路径,将path.size 和path.wwid相同的路径聚合为一条多路径,最终调用domap(ACT_CREATE)创建一条多路径,并填充到结构体vecs->mpvec中2.3.3.3domap函数流程domap 参数主要有创建ACT_CREATE、重新生成多路径ACT_RELOAD、切换路径ACT_SWITCHPG、多路径重命名ACT_RENAME根据参数不同,调用如下函数:domap(ACT_CREATE) -> dm_addmap -> dm_task_run (在libdevmapper.so.1.02库中) ->2.3.3.4dm_addmap函数流程1)创建一个struct dm_task *dmt = dm_task_create(DM_DEVICE_CREATE)2)dm_task_set_name(多路径别名)3)dm_task_add_target() : 将多路径参数按格式填入4)dm_task_run() : 最终调用ioctl发往内核5)dm_task_destroy()注:上面以dm_task开头的函数都是libdevmapper.so库提供的2.3.3.5dm_task_run函数流程内核ioctl接口一共提供如下几种类型的命令# lib/libdevmapper.henum {DM_DEVICE_CREATE,DM_DEVICE_RELOAD,DM_DEVICE_REMOVE,DM_DEVICE_REMOVE_ALL,DM_DEVICE_SUSPEND,DM_DEVICE_RESUME,DM_DEVICE_INFO,DM_DEVICE_DEPS,DM_DEVICE_RENAME,DM_DEVICE_VERSION,DM_DEVICE_STATUS,DM_DEVICE_TABLE,DM_DEVICE_WAITEVENT,DM_DEVICE_LIST,DM_DEVICE_CLEAR,DM_DEVICE_MKNODES,DM_DEVICE_LIST_VERSIONS,DM_DEVICE_TARGET_MSG,DM_DEVICE_SET_GEOMETRY};# lib/ioctl/libdm-iface.cstatic struct cmd_data _cmd_data_v4[] = {{"create", DM_DEV_CREATE, {4, 0, 0}},{"reload", DM_TABLE_LOAD, {4, 0, 0}},{"remove", DM_DEV_REMOVE, {4, 0, 0}},{"remove_all", DM_REMOVE_ALL, {4, 0, 0}},{"suspend", DM_DEV_SUSPEND, {4, 0, 0}},{"resume", DM_DEV_SUSPEND, {4, 0, 0}},{"info", DM_DEV_STATUS, {4, 0, 0}},{"deps", DM_TABLE_DEPS, {4, 0, 0}},{"rename", DM_DEV_RENAME, {4, 0, 0}},{"version", DM_VERSION, {4, 0, 0}},{"status", DM_TABLE_STATUS, {4, 0, 0}},{"table", DM_TABLE_STATUS, {4, 0, 0}},{"waitevent", DM_DEV_WAIT, {4, 0, 0}},{"names", DM_LIST_DEVICES, {4, 0, 0}},{"clear", DM_TABLE_CLEAR, {4, 0, 0}},{"mknodes", DM_DEV_STATUS, {4, 0, 0}},{"versions", DM_LIST_VERSIONS, {4, 1, 0}},{"message", DM_TARGET_MSG, {4, 2, 0}},{"setgeometry", DM_DEV_SET_GEOMETRY, {4, 6, 0}},};通过将dmt.type 在枚举项和_create_and_load_v4中找到命令,如create、reload、remove等等,最终调用_do_dm_ioctl但是创建一条多路径的情况比较特殊(dmt.type==DM_DEVICE_CREATE的情况下) 直接调用_create_and_load_v42.3.3.6_create_and_load_v4函数流程调用两遍dm_task_run(dmt...)1)先要创建mpath0 :dmt.type == DM_DEVICE_CREATE 、command ==DM_DEV_CREATE2)再将sda,sdb写到table表中:dmt.type == DM_DEVICE_RELOAD 、command== DM_DEV_LOAD,2.3.3.7_do_dm_ioctl 函数流程1)首先调用_flatten函数将struct dm_task *dmt展开,将信息填入struct dm_ioctl*dmi 中,struct dm_ioctl结构体看起来很小,其实结构体后面还有很大的一块规定格式的大空间,_flatten函数是个格式编码函数2)调用ioctl,发送dmi到内核,内核将dmi反向解码,最终执行相应命令2.3.3.8内核层面<drivers/md/dm-ioctl.c> dm_ctl_ioctl 通过调用lookup_ioctl 查找调用dev_create还是table_load,然后调用copy_params将用户层参数struct dm_ioctl __user *user转换为内核结构struct dm_ioctl *param,其实就是_flatten函数的逆过程创建多路径设备:dev_create -> alloc_dev 最终调用alloc_disk创建真实的磁盘,得到struct mapped_device *md加载设备下的多路径信息:table_load函数:1)首先调用find_device查找到上面创建的md2)然后调用dm_table_create 创建dm_target3)最后调用populate_table -> dm_table_add_target 关联dm_table 和dm_target2.4清除所有多路径信息>>>multipath -F2.4.1命令执行概要获得所有多路径列表,然后依次删掉这些多路径2.4.1.1主函数执行流程main -> dm_flush_maps2.4.1.2dm_flush_maps函数流程1)创建一个struct dm_task *dmt = dm_task_create(DM_DEVICE_LIST)2)dm_task_set_name(多路径别名)3)dm_task_add_target() : 将多路径参数按格式填入4)dm_task_run() : 最终调用ioctl发往内核5)dm_task_get_names() : 获得从内核返回的多路径列表6)依次调用dm_flush_map删掉这些多路径7)dm_task_destroy()2.4.1.3dm_flush_map函数流程1)dm_map_present :检测多路径是否存在2)dm_type3)dm_remove_partmaps4)dm_get_opencount :如果多路径正在使用,则报错mpath0:map in use5)dm_simplecmd(DM_DEVICE_REMOVE) : 真正删掉一条多路径注:这些函数的实现都dm_task_create 、dm_task_set_name 、dm_task_run 、dm_task_destroy3multipathd程序流程multipathd可以有两种执行方式:前台调试、后台服务1)前台调试:multipathd–d –v 6(其中-v为日志等级,6为最高,即打印所有日志)2)后台服务:multipathd或者/etc/init.d/multipathd start这种执行方式,最终都会调用一个名为child的函数,main主流程如下:1.1.checkloop线程2.1.1. 路径状态checkloop线程主要是个while (1) 无限循环函数,根据checker模块提供的路径变动信息,向内核通知路径状态,路径状态有如下几种:PATH_UNCHECKED: checker方法获取失败,或checker_init调用失败返回PATH_WILD:sysfs接口查询设备及状态失败时返回PATH_PENDING:从sysfs获取的设备状态是blockedPATH_DOWN:从sysfs获取的设备状态是offline,或通过checker方法检查返回。