tool/globals.h
changeset 1142 59be91dfcbe1
parent 1141 7ffbca63fc72
child 1143 09ee878d7214
equal deleted inserted replaced
1141:7ffbca63fc72 1142:59be91dfcbe1
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <sys/types.h>
       
     8 
       
     9 #include <string>
       
    10 #include <sstream>
       
    11 #include <vector>
       
    12 using namespace std;
       
    13 
       
    14 #include "MasterDevice.h"
       
    15 
       
    16 /*****************************************************************************/
       
    17 
       
    18 enum Verbosity {
       
    19     Quiet,
       
    20     Normal,
       
    21     Verbose
       
    22 };
       
    23 
       
    24 extern string commandName;
       
    25 extern unsigned int masterIndex;
       
    26 extern int slavePosition;
       
    27 extern int domainIndex;
       
    28 extern vector<string> commandArgs;
       
    29 extern Verbosity verbosity;
       
    30 extern string dataTypeStr;
       
    31 extern bool force;
       
    32 
       
    33 extern MasterDevice masterDev;
       
    34 
       
    35 /****************************************************************************/
       
    36 
       
    37 class InvalidUsageException:
       
    38     public runtime_error
       
    39 {
       
    40     public:
       
    41         /** Constructor with std::string parameter. */
       
    42         InvalidUsageException(
       
    43                 const stringstream &s /**< Message. */
       
    44                 ): runtime_error(s.str()) {}
       
    45 };
       
    46 
       
    47 /****************************************************************************/
       
    48 
       
    49 class CommandException:
       
    50     public runtime_error
       
    51 {
       
    52     public:
       
    53         /** Constructor with std::string parameter. */
       
    54         CommandException(
       
    55                 const stringstream &s /**< Message. */
       
    56                 ): runtime_error(s.str()) {}
       
    57 };
       
    58 
       
    59 /*****************************************************************************/
       
    60 
       
    61 #define swap16(x) \
       
    62         ((uint16_t)( \
       
    63         (((uint16_t)(x) & 0x00ffU) << 8) | \
       
    64         (((uint16_t)(x) & 0xff00U) >> 8) ))
       
    65 #define swap32(x) \
       
    66         ((uint32_t)( \
       
    67         (((uint32_t)(x) & 0x000000ffUL) << 24) | \
       
    68         (((uint32_t)(x) & 0x0000ff00UL) <<  8) | \
       
    69         (((uint32_t)(x) & 0x00ff0000UL) >>  8) | \
       
    70         (((uint32_t)(x) & 0xff000000UL) >> 24) ))
       
    71 
       
    72 #if __BYTE_ORDER == __LITTLE_ENDIAN
       
    73 
       
    74 #define le16tocpu(x) x
       
    75 #define le32tocpu(x) x
       
    76 
       
    77 #define cputole16(x) x
       
    78 #define cputole32(x) x
       
    79 
       
    80 #elif __BYTE_ORDER == __BIG_ENDIAN
       
    81 
       
    82 #define le16tocpu(x) swap16(x)
       
    83 #define le32tocpu(x) swap32(x)
       
    84 
       
    85 #define cputole16(x) swap16(x)
       
    86 #define cputole32(x) swap32(x)
       
    87 
       
    88 #endif
       
    89 
       
    90 /****************************************************************************/
       
    91 
       
    92 enum {BreakAfterBytes = 16};
       
    93 enum {DefaultBufferSize = 1024};
       
    94 
       
    95 void printRawData(const uint8_t *, unsigned int);
       
    96 
       
    97 /****************************************************************************/