blob: 2e21e927b7cd557501835a9c554b94b8e15417b2 (
plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/*
Copyright (C) 2014 BARRATERO Laurent
AeroUp is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Aeroup 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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* Filename: Symlink.cpp
*
* Description: Return a beautiful Symlink for udev
*
* Version: 0.3.0.1
* Created: 19/01/2014 14:51:05
* Revision: none
* Compiler: gcc
*
* Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
* Organization: La rue Luberlu
*/
#include "symlink.hpp"
static uint32_t serialNumber;
static uint8_t id_prob;
static uint8_t num;
static std::stringstream ss;
const uint8_t BALL = 0x62; // 'b'
const uint8_t STAFF = 0x73; // 's'
const uint8_t CLUB = 0x63; // 'c'
const uint8_t POI = 0x70; // 'p'
const uint32_t PROB_MASK = 0x0000ff00;
const uint32_t NUM_MASK = 0x000000ff;
/*
* Name: Symlink::getSym
* Description: return Symlink
*/
std::string
Symlink::getSym(std::string serial_str)
{
/* test entry */
if(EOF == sscanf(serial_str.c_str(), "%d", &serialNumber))
{
throw Symlink::Bad_Symlink();
}
//if (serialNumber > 0xffffffff)
if (serialNumber > 0x0)
{
throw Symlink::Bad_Symlink();
}
ss << std::hex << serial_str ;
ss >> serialNumber;
// comment
//std::cout << serial_str;
//std::cout << serialNumber;
if((serialNumber & 0xffff0000) != 0)
Symlink::badSerNum();
id_prob = ((PROB_MASK & serialNumber) >> 8 );
num = (NUM_MASK & serialNumber);
ss << num;
std::string x;
ss >> x;
std::cout << x;
// now we use serial_str for output
serial_str = Symlink::whatProp(id_prob);
serial_str += std::to_string(num);
//std::cout << serial_str;
return serial_str;
}
/*
* Name: Symlink::whatProp
* Description: send error ( for future)
*/
void
Symlink::badSerNum()
{
throw Symlink::Bad_Symlink();
}
/*
* Name: Symlink::whatProp
* Description: addr to symlink
*/
std::string
Symlink::whatProp(uint8_t id)
{
switch (id)
{
case BALL:
return "Ball";
break;
case STAFF:
return "Staff";
break;
case CLUB:
return "Club";
break;
case POI:
return "Poi";
break;
default:
//UdevLink::badSerNum();
return "AeroProb";
break;
} /* ----- end switch ----- */
}
|