@@ -34,12 +34,14 @@ const std::string ShippingClassNames[] = {
3434 " Search and Rescue Transponder EPIRB" // CLASS_SARTEPIRB
3535};
3636
37- PromotheusCounter::PromotheusCounter () {
37+ PromotheusCounter::PromotheusCounter ()
38+ {
3839 Reset ();
3940 Clear ();
4041}
4142
42- void PromotheusCounter::Clear () {
43+ void PromotheusCounter::Clear ()
44+ {
4345
4446 m.lock ();
4547 std::memset (_msg, 0 , sizeof (_msg));
@@ -51,10 +53,13 @@ void PromotheusCounter::Clear() {
5153 m.unlock ();
5254}
5355
54- void PromotheusCounter::Add (const AIS::Message& m, const TAG& tag, bool new_vessel) {
56+ void PromotheusCounter::Add (const AIS::Message &m, const TAG &tag, bool new_vessel)
57+ {
5558
56- if (m.type () > 27 || m.type () < 1 ) return ;
57- if (tag.shipclass < 0 || tag.shipclass > 13 ) return ;
59+ if (m.type () > 27 || m.type () < 1 )
60+ return ;
61+ if (tag.shipclass < 0 || tag.shipclass > 13 )
62+ return ;
5863
5964 std::string speed = tag.speed < 0 ? " Unknown" : (tag.speed > 0.5 ? " Moving" : " Stationary" );
6065
@@ -67,19 +72,21 @@ void PromotheusCounter::Add(const AIS::Message& m, const TAG& tag, bool new_vess
6772 _count++;
6873 _msg[m.type () - 1 ]++;
6974
70-
71- if (m.getChannel () >= ' A' || m.getChannel () <= ' D' )
75+ if (m.getChannel () >= ' A' && m.getChannel () <= ' D' )
7276 _channel[m.getChannel () - ' A' ]++;
7377
74- if (tag.distance > _distance) {
78+ if (tag.distance > _distance)
79+ {
7580 _distance = tag.distance ;
7681 }
7782}
7883
79- void PromotheusCounter::Receive (const JSON::JSON* json, int len, TAG& tag) {
80- AIS::Message& data = *((AIS::Message*)json[0 ].binary );
84+ void PromotheusCounter::Receive (const JSON::JSON *json, int len, TAG &tag)
85+ {
86+ AIS::Message &data = *((AIS::Message *)json[0 ].binary );
8187
82- if (ppm.size () > 32768 || level.size () > 32768 ) {
88+ if (ppm.size () > 32768 || level.size () > 32768 )
89+ {
8390 return ;
8491 }
8592
@@ -90,14 +97,16 @@ void PromotheusCounter::Receive(const JSON::JSON* json, int len, TAG& tag) {
9097 m.unlock ();
9198}
9299
93- void PromotheusCounter::Reset () {
100+ void PromotheusCounter::Reset ()
101+ {
94102 m.lock ();
95103 ppm = " # HELP ais_msg_ppm\n # TYPE ais_msg_ppm gauge\n " ;
96104 level = " # HELP ais_msg_level\n # TYPE ais_msg_level gauge\n " ;
97105 m.unlock ();
98106}
99107
100- std::string PromotheusCounter::toPrometheus () {
108+ std::string PromotheusCounter::toPrometheus ()
109+ {
101110 m.lock ();
102111 std::string element;
103112
@@ -109,14 +118,16 @@ std::string PromotheusCounter::toPrometheus() {
109118 element += " # TYPE ais_stat_distance gauge\n " ;
110119 element += " ais_stat_distance " + std::to_string (_distance) + " \n " ;
111120
112- for (int i = 0 ; i < 4 ; i++) {
121+ for (int i = 0 ; i < 4 ; i++)
122+ {
113123 std::string ch (1 , i + ' A' );
114124 element += " # HELP ais_stat_count_channel_" + ch + " Total number of messages on channel " + ch + " \n " ;
115125 element += " # TYPE ais_stat_count_channel_" + ch + " counter\n " ;
116126 element += " ais_stat_count_channel_" + ch + " " + std::to_string (_channel[i]) + " \n " ;
117127 }
118128
119- for (int i = 0 ; i < 27 ; i++) {
129+ for (int i = 0 ; i < 27 ; i++)
130+ {
120131 std::string type = std::to_string (i + 1 );
121132 element += " # HELP ais_stat_count_type_" + type + " Total number of messages of type " + type + " \n " ;
122133 element += " # TYPE ais_stat_count_type_" + type + " counter\n " ;
0 commit comments