次のコードに小さな問題があります。ステートマシン内からクラスで呼び出しますthis->write_file(this->d_filename);。ループ内のケースは数回ヒットしますが、作成したいCSVファイルには1行のエントリしかありません。
なぜなのかわかりません。this->open(filename)書き込み関数でファイルを開きます。ファイル記述子を返します。ファイルはO_TRUNK、およびで開かれますif ((d_new_fp = fdopen(fd, d_is_binary ? "wba" : "w")) == NULL)。abaは書き込み、バイナリ、追加を指します。したがって、私は複数の行を期待しています。
fprintfステートメントは私のデータを書き込みます。また、があり\nます。
 fprintf(d_new_fp, "%s, %d %d\n", this->d_packet, this->d_lqi, this->d_lqi_sample_count);
ファイルが大きくならない理由がわかりません。
最高、マリウス
 inline bool
    cogra_ieee_802_15_4_sink::open(const char *filename)
    {
      gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function
      // we use the open system call to get access to the O_LARGEFILE flag.
      int fd;
      if ((fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE,
          0664)) < 0)
        {
          perror(filename);
          return false;
        }
      if (d_new_fp)
        { // if we've already got a new one open, close it
          fclose(d_new_fp);
          d_new_fp = 0;
        }
      if ((d_new_fp = fdopen(fd, d_is_binary ? "wba" : "w")) == NULL)
        {
          perror(filename);
          ::close(fd);
        }
      d_updated = true;
      return d_new_fp != 0;
    }
    inline void
    cogra_ieee_802_15_4_sink::close()
    {
      gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function
      if (d_new_fp)
        {
          fclose(d_new_fp);
          d_new_fp = 0;
        }
      d_updated = true;
    }
    inline void
    cogra_ieee_802_15_4_sink::write_file(const char* filename)
    {
      if (this->open(filename))
        {
          fprintf(d_new_fp, "%s, %d %d\n", this->d_packet, this->d_lqi,
              this->d_lqi_sample_count);
          if (true)
            {
              fprintf(stderr, "Writing file %x\n", this->d_packet);
            }
        }
    }