-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageITA5.cpp
204 lines (168 loc) · 4.74 KB
/
MessageITA5.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* File: MessageITA5.cpp
* Author: kavlar
*
* Created on 20140821
*/
#include "MessageITA5.h"
#include "ITA.h"
MetCode::MessageITA5::MessageITA5()
{
tagBEGIN = std::string(1, SOH);
tagEND = std::string(1, ETX);
}
MetCode::MessageITA5::MessageITA5(const MessageITA5& orig)
{
}
MetCode::MessageITA5::~MessageITA5()
{
}
bool MetCode::MessageITA5::canIdentify(const std::string& headFragment) const throw ()
{
if (headFragment.find(tagBEGIN) != std::string::npos)
return true;
else
return false;
}
bool is_digits(const std::string& s);
bool MetCode::MessageITA5::onHEAD(std::string& head) const throw ()
{
if (head.size() > 8 + 2)
{
log("W", i_line, i_group, "ITA5 size+type is incorrect format; use rightmost 10 bytes.", head);
head = head.substr(head.size() - 10);
}
if (head.size() < 8)
{
log("W", i_line, i_group, "ITA5 size+type is incorrect format; reset to 0000000000", head);
head = "0000000000";
}
if (head.size() == 8)
{
log("W", i_line, i_group, "ITA5 size+type is incorrect format; appending 00.", head);
head += "00";
}
if (head.size() == 9)
{
log("W", i_line, i_group, "ITA5 size+type is incorrect format; appending 0.", head);
head += "0";
}
std::string size = head.substr(0, 8);
std::string type = head.substr(8, 2);
if (::is_digits(size))
{
}
else
{
log("W", i_line, i_group, "ITA5 size is incorrect format; reset to 00000000.", size);
size = "00000000";
}
if (::is_digits(type))
{
}
else
{
log("W", i_line, i_group, "ITA5 size is incorrect format; reset to 00000000.", type);
type = "00";
}
head = size + type;
//std::cerr << "MessageITA5 - onHEAD : " << head << std::endl;
return true;
}
bool MetCode::MessageITA5::onHEAD(std::string& head, StreamWriter& streamwriter) throw ()
{
// delayed to StreamWriter::flush
return true;
}
bool MetCode::MessageITA5::onBEGIN(std::string& begin) const throw ()
{
//std::cerr << "MessageITA5 - onBEGIN : " << begin << std::endl;
return true;
}
bool MetCode::MessageITA5::onBEGIN(std::string& begin, StreamWriter& streamwriter) throw ()
{
begin = tagBEGIN;
return streamwriter.put(begin, o_group, o_line, false, false);
}
bool MetCode::MessageITA5::onSEQ(std::string& seq) const throw ()
{
if (seq.size() > 5)
{
log("W", i_line, i_group, "ITA5 sequence number is incorrect format; use rightmost 5 bytes.", seq);
seq = seq.substr(seq.size() - 5);
}
if (seq.size() == 4)
{
log("W", i_line, i_group, "ITA5 sequence number is incorrect format; appending 0.", seq);
seq += "0";
}
if (seq.size() == 2)
{
log("W", i_line, i_group, "ITA5 sequence number is incorrect format; appending 0.", seq);
seq += "0";
}
if (seq.size() == 1)
{
log("W", i_line, i_group, "ITA5 sequence number is incorrect format; appending 00.", seq);
seq += "00";
}
if (seq.size() == 0)
{
log("W", i_line, i_group, "ITA5 size+type is incorrect format; reset to 001", seq);
seq = "001";
}
if (::is_digits(seq))
{
}
else
{
if (seq.size() == 5)
{
log("W", i_line, i_group, "ITA5 size is incorrect format; reset to 00001.", seq);
seq = "00001";
}
else
{
log("W", i_line, i_group, "ITA5 size is incorrect format; reset to 001.", seq);
seq = "001";
}
}
//std::cerr << "MessageITA5 - onSEQ : " << seq << std::endl;
return true;
}
bool MetCode::MessageITA5::onSEQ(std::string& seq, StreamWriter& streamwriter) throw ()
{
static unsigned long seqnum = 0;
char buf[10];
char fmt[10];
seqnum++;
if (seqnum > seqmax)
seqnum = seqmin;
::sprintf(fmt, "%%0%dd\0", seqlength);
::sprintf(buf, fmt, seqnum);
seq = buf;
return streamwriter.put(seq, o_group, o_line, false, true);
}
bool MetCode::MessageITA5::onBulletin(std::string& bulletinFragment) const throw ()
{
//std::cerr << "MessageITA5 - onBulletin : " << bulletinFragment << std::endl;
return true;
}
bool MetCode::MessageITA5::onBulletin(std::string& bulletinFragment, StreamWriter& streamwriter) throw ()
{
return true;
}
bool MetCode::MessageITA5::onEND(std::string& end) const throw ()
{
//std::cerr << "MessageITA5 - onEND : " << end << std::endl;
return true;
}
bool MetCode::MessageITA5::onEND(std::string& end, StreamWriter& streamwriter) throw ()
{
bool result = false;
end = tagEND;
result = streamwriter.put(end, o_group, o_line, false, false);
if (!result)
return result;
return streamwriter.flush(true, "00");
}