SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
goes_headers.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "utils/string.h"
9#include <cstdint>
10#include <cstring>
11#include <map>
12#include <vector>
13
14namespace satdump
15{
16 namespace xrit
17 {
18 namespace goes
19 {
20 const int ID_HIMAWARI = 43;
21
22 struct NOAALRITHeader
23 {
24 static constexpr int TYPE = 129;
25
26 uint8_t type;
27 uint16_t record_length;
28 char agency_signature[4];
29 uint16_t product_id;
30 uint16_t product_subid;
31 uint16_t parameter;
32 uint8_t noaa_specific_compression;
33
34 NOAALRITHeader(uint8_t *data)
35 {
36 type = data[0];
37 record_length = data[1] << 8 | data[2];
38 std::memcpy(agency_signature, &data[3], 4);
39 product_id = data[7] << 8 | data[8];
40 product_subid = data[9] << 8 | data[10];
41 parameter = data[11] << 8 | data[12];
42 noaa_specific_compression = data[13];
43 }
44 };
45
46 struct RiceCompressionHeader
47 {
48 static constexpr int TYPE = 131;
49
50 uint8_t type;
51 uint16_t record_length;
52 uint16_t flags;
53 uint8_t pixels_per_block;
54 uint8_t scanlines_per_packet;
55
56 RiceCompressionHeader(uint8_t *data)
57 {
58 type = data[0];
59 record_length = data[1] << 8 | data[2];
60 flags = data[3] << 8 | data[4];
61 pixels_per_block = data[5];
62 scanlines_per_packet = data[6];
63 }
64 };
65
66 struct AncillaryTextRecord
67 {
68 static constexpr int TYPE = 6;
69
70 uint8_t type;
71 uint16_t record_length;
72 std::string ancillary_text;
73
74 std::map<std::string, std::string> meta;
75
76 AncillaryTextRecord(uint8_t *data)
77 {
78 type = data[0];
79 record_length = data[1] << 8 | data[2];
80 ancillary_text.insert(ancillary_text.end(), &data[3], &data[record_length]);
81
82 // I will admit I needed to peek in goestools to figure that one out
83 // A bit hard without having live data...
84 std::vector<std::string> fields = splitString(ancillary_text, ';');
85
86 for (std::string &field : fields)
87 {
88 std::vector<std::string> values = splitString(field, '=');
89 if (values.size() == 2)
90 {
91 values[0] = values[0].substr(0, values[0].find_last_not_of(' ') + 1);
92 values[1] = values[1].substr(values[1].find_first_not_of(' '));
93 meta.insert({values[0], values[1]});
94 }
95 }
96 }
97 };
98
99 struct AnnotationRecord
100 {
101 static constexpr int TYPE = 4;
102
103 uint8_t type;
104 uint16_t record_length;
105 std::string annotation_text;
106
107 AnnotationRecord(uint8_t *data)
108 {
109 type = data[0];
110 record_length = data[1] << 8 | data[2];
111 annotation_text.insert(annotation_text.end(), &data[3], &data[record_length]);
112 }
113 };
114
115 struct SegmentIdentificationHeader
116 {
117 static constexpr int TYPE = 128;
118
119 uint8_t type;
120 uint16_t record_length;
121 uint16_t image_identifier;
122 uint16_t segment_sequence_number;
123 uint16_t start_column_of_segment;
124 uint16_t start_line_of_segment;
125 uint16_t max_segment;
126 uint16_t max_column;
127 uint16_t max_row;
128
129 SegmentIdentificationHeader(uint8_t *data)
130 {
131 type = data[0];
132 record_length = data[1] << 8 | data[2];
133 image_identifier = data[3] << 8 | data[4];
134 segment_sequence_number = data[5] << 8 | data[6];
135 start_column_of_segment = data[7] << 8 | data[8];
136 start_line_of_segment = data[9] << 8 | data[10];
137 max_segment = data[11] << 8 | data[12];
138 max_column = data[13] << 8 | data[14];
139 max_row = data[15] << 8 | data[16];
140 }
141 };
142 } // namespace goes
143 } // namespace xrit
144} // namespace satdump
A collection of string-related utility functions.