-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
logging.h
71 lines (63 loc) · 2.3 KB
/
logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* This file is part of cannelloni, a SocketCAN over ethernet tunnel.
*
* Copyright (C) 2014-2017 Maximilian Güntner <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#pragma once
#include <iostream>
#include <iomanip>
#include <string>
#include "cannelloni.h"
using namespace cannelloni;
inline std::string splitFilename(const std::string &path) {
size_t pos = path.find_last_of("/\\");
if (pos == std::string::npos)
return path;
else
return path.substr(pos+1);
}
#define FUNCTION_STRING splitFilename(__FILE__) << "[" << std::dec << __LINE__ << "]:" << __FUNCTION__ << ":"
#define INFO_STRING "INFO:"
#define ERROR_STRING "ERROR:"
#define WARNING_STRING "WARNING:"
#define linfo std::cout << INFO_STRING << FUNCTION_STRING
#define lwarn std::cerr << WARNING_STRING << FUNCTION_STRING
#define lerror std::cerr << ERROR_STRING << FUNCTION_STRING
inline void printCANInfo(const canfd_frame *frame) {
if (frame->len & CANFD_FRAME) {
std::cout << "FD|";
} else {
std::cout << "LC|";
}
if (frame->can_id & CAN_EFF_FLAG) {
std::cout << "EFF Frame ID[" << std::setw(5) << std::dec << (frame->can_id & CAN_EFF_MASK) << "]";
} else {
std::cout << "SFF Frame ID[" << std::setw(5) << std::dec << (frame->can_id & CAN_SFF_MASK) << "]";
}
if (frame->can_id & CAN_ERR_FLAG)
std::cout << "\t ERROR\t";
else
std::cout << "\t Length:" << std::dec << (int) canfd_len(frame) << "\t";
if (frame->can_id & CAN_RTR_FLAG) {
std::cout << "\tREMOTE";
} else {
/* This will also contain the error information */
for (uint8_t i=0; i < canfd_len(frame); i++)
std::cout << std::setbase(16) << " " << int(frame->data[i]);
}
std::cout << std::endl;
};