Subversion Repositories DashDisplay

Rev

Rev 42 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <map>
  4. #include <vector>
  5.  
  6. #include "../plx_lib/plx.h"
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  14.  
  15.  
  16.  
  17. int main(int argc, char** argv) {
  18.        
  19.         int nextcol = 1;
  20.         int row = 0;
  21.         std::map<int,int> mapping;
  22.         std::vector<std::vector<double> *> store;
  23.         std::vector<std::string> headings;
  24.         size_t constexpr size_step = 10000;
  25.        
  26.         FILE  * f;
  27.         if(argc > 1) {
  28.        
  29.            f=fopen(argv[1],"r");
  30.            if(f){
  31.                   while (!feof(f))
  32.                                 {
  33.                                 int key;
  34.                                 int index;
  35.                           int value;
  36.                                                  
  37.                                
  38.                                 int c = fscanf(f,"%d,%d,%d\n",&key,&index,&value);
  39.                                 if(c)
  40.                                 {
  41.                                 int search = key * 10 + index;
  42.                                
  43.                                 int & col = mapping[search];
  44.                                
  45.                                 if(col == 0)
  46.                                 {
  47.                                         col = nextcol++;
  48.                                         mapping[search] = col;
  49.                                 }
  50.                                
  51.        if (col > store.size())
  52.         {
  53.                                   if(key <=  PLX_X_CHT )
  54.                                   {
  55.                                        
  56.                 std::string st = PLX_Obs_Names[key];
  57.                                   char c_code = '1'+ index;
  58.                                         st += c_code;
  59.           headings.push_back( st ); // save column heading
  60.                 std::vector<double> * new_vec = new std::vector<double>;
  61.                         //              new_vec->reserve(size_step);  // reserve a big chunk of store
  62.                                 store.push_back(new_vec); // save value
  63.                             }
  64.                                 }
  65.                                
  66.               std::vector<double> * vec = store[col-1];
  67.                                 if(vec)
  68.                                 {
  69.                                
  70.                                 if(vec->capacity() <= row )
  71.                                 {
  72.                                         vec->reserve(vec->capacity() + size_step);
  73.                                 }      
  74.                                
  75.                                 // decode scaling
  76.                                 double res = 0;
  77.                                 switch (key)
  78.                                 {
  79.                                         case PLX_Volts:
  80.                                                  vec->push_back(ConveriMFDRaw2Data(key ,0, value)) ;
  81.                                                  break;
  82.                                         case PLX_AFR:
  83.                                  vec->push_back(ConveriMFDRaw2Data(key , AFR_Gasoline, value)) ;
  84.                                                  break;
  85.                                   case PLX_RPM:
  86.                                                  vec->push_back( ConveriMFDRaw2Data(key ,0, value)) ;
  87.                          break;
  88.                                   case PLX_MAP:
  89.                                           vec->push_back(ConveriMFDRaw2Data(key ,PRESSURE_kPa, value)) ;
  90.               break;
  91.           case PLX_X_CHT:
  92.              vec->push_back(ConveriMFDRaw2Data(key ,TEMP_Celsius, value));
  93.                                                  break;
  94.                                         case PLX_FluidPressure:
  95.                                             vec->push_back(ConveriMFDRaw2Data(key ,PRESSURE_PSI_Oil, value));  
  96.                                                         break;                                   
  97.                                         default:
  98.                                                 break;
  99.                                 }
  100.                                
  101.                                 if(col == 1)
  102.                                 {
  103.                                         row++;
  104.                                 }
  105.  
  106. }
  107.                         //      printf("%3d %3d %10d\n", key,index,value);
  108.                                        
  109.                                 }}
  110.                                
  111.                         }
  112.                
  113. }
  114.        
  115.         // having gathered all the data print it
  116.        
  117.         for(auto it = headings.begin(); it != headings.end() ;it++)
  118.         {
  119.                 printf("%s,",(*it).c_str());
  120.         }
  121.                 printf("\n");
  122.        
  123.         for(size_t print = 0; print < row ; print++)
  124.         {
  125.        
  126.  
  127.         for(auto it = store.begin(); it != store.end() ;it++)
  128.                  
  129.                  
  130.                   {
  131.  
  132.                                double val = 0.0;
  133.                                 if(*it != nullptr)
  134.                                                   {
  135.                                                   std::vector<double> * vec =  *it;
  136.                                                   if(vec && (print < vec->size()))
  137.                               val =  vec->at(print);
  138.                                                         }
  139.                                 printf("%0.2f," ,val);
  140.                              }
  141.                
  142.                 printf("\n");
  143.                
  144.         }
  145.        
  146.        
  147.         return 0;
  148. }
  149.  
  150.