-
Notifications
You must be signed in to change notification settings - Fork 0
/
oap.cc
58 lines (45 loc) · 1.3 KB
/
oap.cc
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
// Helper functions.
#include "OAP.h"
#include "portable.h"
/* -------------------------------------------------------------------- */
void OAP::swapPMS2D(OAP::P2d_rec *buff)
{
// Perform byte swapping on whole [data] record if required.
if (1 != ntohs(1))
{
unsigned short *sp = (unsigned short *)buff;
for (int i = 1; i < 10; ++i)
sp[i] = ntohs(sp[i]);
if (OAP::probeType((unsigned char *)buff) == OAP::TWODS_T ||
OAP::probeType((unsigned char *)buff) == OAP::HVPS_T)
{
unsigned char tmp[16], *cp = (unsigned char *)buff->data;
// 256 slices at 16 bytes each.
for (size_t i = 0; i < OAP::nSlices_128bit; ++i, cp += 16)
{
for (size_t j = 0; j < 16; ++j)
tmp[j] = cp[15-j];
memcpy(cp, tmp, 16);
}
}
}
}
/* -------------------------------------------------------------------- */
OAP::ProbeType OAP::probeType(const unsigned char *id)
{
if (id[0] == 'C' || id[0] == 'P')
{
if (id[1] >= '4' && id[1] <= '7')
return OAP::FAST2D_T;
if (id[1] == '8')
return OAP::CIP_T;
return OAP::PMS2D_T;
}
if (id[0] == '2' || id[0] == '3' || id[0] == 'S')
return OAP::TWODS_T;
if (id[0] == 'H')
return OAP::HVPS_T;
if (id[0] == 'G')
return OAP::GREYSCALE_T;
return OAP::UNKNOWN_T;
}