Subversion Repositories HomeAutomation

Rev

Rev 1026 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /***************************************************************************
  2.  *   Copyright (C) December 27, 2008 by Mattias Runge                             *
  3.  *   mattias@runge.se                                                      *
  4.  *   candebug.cpp                                            *
  5.  *                                                                         *
  6.  *   This program is free software; you can redistribute it and/or modify  *
  7.  *   it under the terms of the GNU General Public License as published by  *
  8.  *   the Free Software Foundation; either version 2 of the License, or     *
  9.  *   (at your option) any later version.                                   *
  10.  *                                                                         *
  11.  *   This program is distributed in the hope that it will be useful,       *
  12.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  13.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  14.  *   GNU General Public License for more details.                          *
  15.  *                                                                         *
  16.  *   You should have received a copy of the GNU General Public License     *
  17.  *   along with this program; if not, write to the                         *
  18.  *   Free Software Foundation, Inc.,                                       *
  19.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  20.  ***************************************************************************/
  21.  
  22. #include "candebug.h"
  23.  
  24. CanDebug* CanDebug::myInstance = NULL;
  25.  
  26. CanDebug& CanDebug::getInstance()
  27. {
  28.     if (myInstance == NULL)
  29.     {
  30.         myInstance = new CanDebug();
  31.     }
  32.  
  33.     return *myInstance;
  34. }
  35.  
  36. void CanDebug::deleteInstance()
  37. {
  38.     if (myInstance != NULL)
  39.     {
  40.         delete myInstance;
  41.         myInstance = NULL;
  42.     }
  43. }
  44.  
  45. CanDebug::CanDebug()
  46. {
  47. }
  48.  
  49. CanDebug::~CanDebug()
  50. {
  51. }
  52.  
  53. void CanDebug::sendCanMessageToAll(CanMessage canMessage)
  54. {
  55.     if (myClientSockets.size() > 0)
  56.     {
  57.         string debugData = "";
  58.  
  59.         if (canMessage.getClassName() == "nmt")
  60.         {
  61.             debugData += "NMT";
  62.         }
  63.         else
  64.         {
  65.             if (canMessage.getDirectionFlag() == "To_Owner")
  66.             {
  67.                 debugData += "RX";
  68.             }
  69.             else if (canMessage.getDirectionFlag() == "From_Owner")
  70.             {
  71.                 debugData += "TX";
  72.             }
  73.             else
  74.             {
  75.                 debugData += "??";
  76.             }
  77.  
  78.             debugData += " " + canMessage.getClassName();
  79.             debugData += "_" + canMessage.getModuleName();
  80.             debugData += ":" + itos(canMessage.getModuleId());
  81.         }
  82.  
  83.         debugData += " CMD=" + canMessage.getCommandName() + " ";
  84.  
  85.         map<string, CanVariable> vars = canMessage.getData();
  86.         map<int, string> sortMap;
  87.  
  88.         for (map<string, CanVariable>::iterator iter = vars.begin(); iter != vars.end(); iter++)
  89.         {
  90.             sortMap[iter->second.getStartBit()] = " " + iter->second.getName() + "=" + iter->second.getValue();
  91.         }
  92.  
  93.         for (map<int, string>::iterator iter = sortMap.begin(); iter != sortMap.end(); iter++)
  94.         {
  95.             debugData += iter->second;
  96.         }
  97.  
  98.         sendToAll("[" + niceTime() + "] " + debugData + "\r\n");
  99.     }
  100. }
  101.  
  102. void CanDebug::handleClientData(int id, string data)
  103. {
  104.  
  105. }
  106.