分类 Linux软件开发 下的文章



一、字符串分割


static     std::vector<std::string> getWords(const std::string  &s, const std::string  &delim)
{
    std::vector<std::string> res;
    //std::string delim = ",";
    std::string token = "";
    for (int i = 0; i < s.size(); i++) {
        bool flag = true;
        for (int j = 0; j < delim.size(); j++) {
            if (s[i + j] != delim[j]) flag = false;
        }
        if (flag) {
            if (token.size() > 0) {
                res.push_back(token);
                token = "";
                i += delim.size() - 1;
            }
        } else {
            token += s[i];
        }
    }
    res.push_back(token);
    return res;
}



二、读取CSV格式文件


static  void    Load_Full_IMU_Data(const std::string  &csv, std::vector<Eigen::Vector3d>  &gyro, \
                                   std::vector<Eigen::Vector3d>  &acce, std::vector<Eigen::Vector3d>  &magn)
{
    FILE  *fp = fopen(csv.c_str(), "r");
    if(nullptr == fp)
        return;
    char  buf[2048] = "";
    while(fgets(buf, sizeof(buf), fp)){
        std::vector<std::string> all_str = getWords(std::string(buf), ",");
        if(all_str.size()>=9){
            Eigen::Vector3d   acc;
            Eigen::Vector3d   gyr;
            Eigen::Vector3d   mag;
            double  t = strtod(all_str[0].c_str(), nullptr);

            double  gyrox = strtod(all_str[1].c_str(), nullptr);
            double  gyroy = strtod(all_str[2].c_str(), nullptr);
            double  gyroz = strtod(all_str[3].c_str(), nullptr);
            gyr[0] = gyrox;
            gyr[1] = gyroy;
            gyr[2] = gyroz;
            gyro.push_back(gyr);

            double  accex = strtod(all_str[4].c_str(), nullptr);
            double  accey = strtod(all_str[5].c_str(), nullptr);
            double  accez = strtod(all_str[6].c_str(), nullptr);
            acc[0] = accex;
            acc[1] = accey;
            acc[2] = accez;
            acce.push_back(acc);

            double  magnx = strtod(all_str[7].c_str(), nullptr);
            double  magny = strtod(all_str[8].c_str(), nullptr);
            double  magnz = strtod(all_str[9].c_str(), nullptr);
            mag[0] = magnx;
            mag[1] = magny;
            mag[2] = magnz;
            magn.push_back(mag);
        }
        memset(buf, 0x00, sizeof(buf));
    }
    fclose(fp);
    return;
}







#include <ctime>
#include <iostream>
#include <chrono>
#include <time.h>






int main(int argc, const char *argv[])
{
    unsigned short    gps_week = 2322;
    double    gps_seconds = 112576.3;   //数值来自GPS设备

    double  gps_total_seconds = gps_week*7*24*60*60 + gps_seconds;

    // GPS 参考时间起点: 1980-01-06 00:00:00
    int  gps_year = 1980;
    int  gps_month = 1;
    int  gps_day = 6;

    std::tm tm{};
    tm.tm_year = gps_year - 1900;//1980;   //年从 1900年开始
    tm.tm_mon  = gps_month - 1;//1;     // 月从0开始: 0~11
    tm.tm_mday = gps_day;//6;
    tm.tm_hour = 0;
    tm.tm_min  = 0;
    tm.tm_sec  = 0;
    tm.tm_isdst = 0;
    std::time_t t = std::mktime(&tm) + 8*60*60;

    double  total_seconds = static_cast<double>(t) + gps_total_seconds;
    total_seconds -= 18;    //计算 GPS秒对应的时间差,GPS时间与UTC时间在秒上相差18秒

    std::cout<<"t:"<<t<<std::endl;
    printf("T:%f\n\n\n", total_seconds);

    time_t  tnow = static_cast<time_t>(total_seconds);
    std::tm * dt = gmtime(&tnow);

    //printf ( "The current date/time is: %s", asctime(dt) );
    printf("%d-%02d-%02d %02d:%02d:%02d\n", dt->tm_year+1900, \
            dt->tm_mon+1, dt->tm_mday, dt->tm_hour, dt->tm_min, dt->tm_sec);



    double  utc_time = 0.0;     // GPS UTC time: hhmmss.ss
    double ms = gps_seconds - static_cast<int64_t>(gps_seconds)*1.0;
    utc_time = dt->tm_hour*10000.0 + dt->tm_min*100.0 + dt->tm_sec + ms;


    return  0;
}


























void loop() {
myIMU.readSensor();
xyzFloat gValue = myIMU.getGValues();
xyzFloat gyr = myIMU.getGyrValues();
xyzFloat magValue = myIMU.getMagValues();
float temp = myIMU.getTemperature();
float resultantG = myIMU.getResultantG(gValue);

Serial.print("{gyro}");
Serial.print(gyr.x);
Serial.print(",");
Serial.print(gyr.y);
Serial.print(",");
Serial.print(gyr.z);
Serial.print("\n");
Serial.print("{acce}");
Serial.print(gValue.x);
Serial.print(",");
Serial.print(gValue.y);
Serial.print(",");
Serial.print(gValue.z);
Serial.print("\n");

Serial.print("{magn}");
Serial.print(magValue.x);
Serial.print(",");
Serial.print(magValue.y);
Serial.print(",");
Serial.print(magValue.z);
Serial.print("\n");
delay(10);

}





1、git status 中文出现乱码

  配置core.quotepath为false,即

 

$ git config --global core.quotepath false


如果上面这句依然不能解决问题,则需要如下设置:


在使用git log出现乱码上面一个设置不能解决问题需要再做以下设置

git config --global gui.encoding utf-8

git config --global i18n.commit.encoding utf-8

git config --global i18n.logoutputencoding utf-8


export LESSCHARSET=utf-8 # 添加到环境变量