-
Notifications
You must be signed in to change notification settings - Fork 2
/
idata.cpp
90 lines (84 loc) · 2.21 KB
/
idata.cpp
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
#include "common.h"
#include "idata.h"
#include <cassert>
#include "logger.h"
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("HAL.IDa");
using namespace spikey2;
namespace spikey2
{
// stream idata structs
ostream& operator<<(ostream& o, const SBData& d)
{
switch (d.payload()) {
case SBData::t_empty:
return o << "ID:--"
<< " ";
case SBData::t_fire:
return o << "ID:fi"
<< " ";
case SBData::t_dac:
return o << "ID:da v:" << dec << setw(4) << setfill(' ') << d.ADvalue() << " ";
case SBData::t_adc:
return o << "ID:ad v:" << dec << setw(4) << setfill(' ') << d.ADvalue() << " ";
default:
return o << "ID:illegal";
}
}
// stream sbdata structs
ostream& operator<<(ostream& o, const IData& d)
{
switch (d.payload()) {
case IData::t_empty:
return o << "ID:--";
case IData::t_ci:
return o << "ID:ci C:" << hex << setw(1) << setfill('0') << d.cmd() << " D:" << d.data()
<< " ";
case IData::t_event:
return o << "ID:ev A:" << hex << setw(3) << setfill('0') << d.neuronAdr()
<< " T:" << setw(3) << d.time() << " ";
case IData::t_control:
return o << "ID:dl r:" << d.reset() << " pr:" << d.pllreset() << " ci:" << d.cimode()
<< " vr:" << d.vrest_gnd() << " vm:" << d.vm_gnd() << " ib:" << d.ibtest_meas()
<< " pe:" << d.power_enable() << " r0:" << d.rx_clk0_phase()
<< " r1:" << d.rx_clk1_phase() << " ";
case IData::t_bustest:
return o << "ID:bt"
<< " ";
case IData::t_delay:
return o << "ID:ct"
<< " ";
default:
return o << "ID:illegal ";
}
}
istream& operator>>(istream& i, IData& d)
{
string type;
i.ignore(256, ':');
if (!(i >> type))
return i;
if (type == "ev") {
uint n, t;
i.ignore(256, ':');
i >> hex >> n;
i.ignore(256, ':');
i >> hex >> t;
d.setPayload(IData::t_event);
d.setNeuronAdr() = n;
d.setTime() = t;
} else {
LOG4CXX_ERROR(
logger, "De-serialization of non-event-type IData objects is currently not supported.");
LOG4CXX_ERROR(logger, "Got type " << type);
assert(false);
}
return i;
}
}
vector<bool>& SBData::emptyfire()
{
static vector<bool>* dummy = NULL;
if (!dummy)
dummy = new vector<bool>();
return *dummy;
}