mrfioc2  2.3.0
Public Member Functions | Public Attributes | List of all members
mrf::XilinxBitInfo Struct Reference

Attempt to read out the header of a Xilinx bitstream file. More...

#include <flash.h>

Public Member Functions

 XilinxBitInfo ()
 
bool read (std::istream &strm)
 

Public Attributes

std::string project
 
std::string part
 
std::string date
 

Detailed Description

Attempt to read out the header of a Xilinx bitstream file.

Definition at line 104 of file flash.h.

Constructor & Destructor Documentation

◆ XilinxBitInfo()

mrf::XilinxBitInfo::XilinxBitInfo ( )
inline

Definition at line 106 of file flash.h.

106 {}

Member Function Documentation

◆ read()

bool mrf::XilinxBitInfo::read ( std::istream &  strm)

Definition at line 405 of file flash.cpp.

406 {
407  static const char header[] = "\0\x09\x0f\xf0\x0f\xf0\x0f\xf0\x0f\xf0\0\0\1";
408 
409  std::vector<char> buf(sizeof(header)-1);
410 
411  if(strm.read(&buf[0], buf.size()).gcount()!=std::streamsize(buf.size()) || !std::equal(buf.begin(), buf.end(), header))
412  return false; // not a .bit file
413 
414  std::string project, part, date, time;
415 
416  bool eof = false;
417  while(!eof) {
418  epicsUInt8 id;
419  epicsUInt16 size;
420 
421  if(strm.read((char*)&id, 1).gcount()==0)
422  break;
423 
424  switch(id) {
425  case 0x61:
426  case 0x62:
427  case 0x63:
428  case 0x64:
429  if(strm.read((char*)&size, 2).gcount()!=2)
430  throw std::runtime_error("Truncated block header");
431  size = ntohs(size);
432  buf.resize(size);
433  if(strm.read(&buf[0], buf.size()).gcount()!=std::streamsize(buf.size()))
434  throw std::runtime_error("Truncated block payload");
435 
436  // there are all actually printable strings, so ensure they have a trailing nil.
437  buf.push_back('\0');
438 
439  break;
440  case 0x65:
441  // start of bit stream content, we treat this as end of "header" and stop here.
442  // in practice there is nothing after the bit stream anyway.
443  eof = true;
444  break;
445  default:
446  fprintf(stderr, "Warning: attempting to ignore unknown block 0x%02x\n", unsigned(id));
447  eof = true;
448  break;
449  }
450 
451  std::string str(&buf[0]);
452 
453  switch(id) {
454  case 0x61: project.swap(str); break;
455  case 0x62: part.swap(str); break;
456  case 0x63: date.swap(str); break;
457  case 0x64: time.swap(str); break;
458  }
459  }
460 
461  date += " ";
462  date += time;
463 
464  this->project.swap(project);
465  this->part.swap(part);
466  this->date.swap(date);
467  return true;
468 }
std::string date
Definition: flash.h:110
std::string part
Definition: flash.h:110
std::string project
Definition: flash.h:110

Member Data Documentation

◆ date

std::string mrf::XilinxBitInfo::date

Definition at line 110 of file flash.h.

◆ part

std::string mrf::XilinxBitInfo::part

Definition at line 110 of file flash.h.

◆ project

std::string mrf::XilinxBitInfo::project

Definition at line 110 of file flash.h.


The documentation for this struct was generated from the following files: