void IMPF_Packet_Header::read_from(const unsigned char *buf) { gp_packet_header.HeaderVersionNo = *buf; gp_packet_header.PacketType = *(buf+1); gp_packet_header.SubHeaderType = *(buf+2); gp_packet_header.SourceFacilityId = *(buf+3); gp_packet_header.SourceEnvId = *(buf+4); gp_packet_header.SourceInstanceId = *(buf+5); gp_packet_header.SourceSUId = get_ui4((const unsigned char *) buf+6); gp_packet_header.SourceCPUId[0] = *(buf+10); gp_packet_header.SourceCPUId[1] = *(buf+11); gp_packet_header.SourceCPUId[2] = *(buf+12); gp_packet_header.SourceCPUId[3] = *(buf+13); gp_packet_header.DestFacilityId = *(buf+14); gp_packet_header.DestEnvId = *(buf+15); gp_packet_header.SequenceCount = get_ui2((const unsigned char *) buf+16); gp_packet_header.PacketLength = get_ui4((const unsigned char *) buf+18); gp_packet_subheader.SubHeaderVersionNo = *(buf+22); gp_packet_subheader.ChecksumFlag = *(buf+23); gp_packet_subheader.Acknowledgement[0] = *(buf+24); gp_packet_subheader.Acknowledgement[1] = *(buf+25); gp_packet_subheader.Acknowledgement[2] = *(buf+26); gp_packet_subheader.Acknowledgement[3] = *(buf+27); gp_packet_subheader.ServiceType = *(buf+28); gp_packet_subheader.ServiceSubtype = *(buf+29); gp_packet_subheader.PacketTime.read_from((const unsigned char *) buf+30); gp_packet_subheader.SpacecraftId = get_ui2((const unsigned char *) buf+36); return; }
void MSG_header_segment_id::read_from( unsigned const char_1 *buff ) { spacecraft_id = (t_enum_MSG_spacecraft) get_ui2(buff+3); spectral_channel_id = *(buff+5); sequence_number = get_ui2(buff+6); planned_start_segment_sequence_number = get_ui2(buff+8); planned_end_segment_sequence_number = get_ui2(buff+10); data_field_format = (t_enum_MSG_data_format) *(buff+12); return; }
void MSG_header_image_struct::read_from( unsigned const char_1 *buff ) { number_of_bits_per_pixel = buff[3]; number_of_columns = get_ui2(buff+4); number_of_lines = get_ui2(buff+6); compression_flag = (t_enum_MSG_image_compression) buff[8]; image_pixels = number_of_columns * number_of_lines; image_size = (image_pixels*number_of_bits_per_pixel) / 8; if ((image_pixels*number_of_bits_per_pixel) % 8) image_size ++; return; }
size_t MSG_data_ImageProdStats::read_from( unsigned const char_1 *buff ) { size_t position = 0; SatelliteId = (t_enum_MSG_spacecraft) get_ui2(buff); position += 2; position += ActualScanningSummary.read_from(buff+position); position += RadiometerBehaviour.read_from(buff+position); position += ReceptionSummaryStats.read_from(buff+position); for (int i = 0; i < 12; i ++) position += L15ImageValidity[i].read_from(buff+position); position += ActualL15CoverageVIS_IR.read_from(buff+position); position += ActualL15CoverageHRV.read_from(buff+position); return position; }
void MSG_header_ancillary_text::read_from( unsigned const char_1 *buff ) { size_t h_length = (size_t) get_ui2(buff+1) - 3; if (h_length <= 0) { std::cerr << "Error: Data Function Header length invalid." << std::endl; std::cerr << "Header Length : " << h_length << std::endl; throw; } ancillary_text = new char_1[h_length]; if (!ancillary_text) { std::cerr << "Memory error in MSG_header_ancillary_text." << std::endl; std::cerr << "Header Length : " << h_length << std::endl; throw; } memcpy(ancillary_text, buff+3, h_length); return; }
void MSG_header::read_from( std::ifstream &in ) { unsigned char_1 primary_header[MSG_HEADER_PRIMARY_LEN]; unsigned char_1 *hbuff; check_endianess( ); in.read((char_1 *) primary_header, MSG_HEADER_PRIMARY_LEN); if (in.fail( )) { std::cerr << "Read error from HRIT file: Primary Header." << std::endl; throw; } if (primary_header[0] != MSG_HEADER_PRIMARY) { std::cerr << "Error: First header type value is not primary." << std::endl; throw; } if (get_ui2(primary_header+1) != MSG_HEADER_PRIMARY_LEN) { std::cerr << "Error: Primary Header Length mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(primary_header+1) << std::endl; throw; } f_typecode = (t_enum_MSG_filetype) *(primary_header+3); total_header_length = get_ui4(primary_header+4); data_field_length = get_ui8(primary_header+8); filesize = data_field_length/8+total_header_length; size_t hsize = total_header_length-MSG_HEADER_PRIMARY_LEN; hbuff = new unsigned char_1[hsize]; if (!hbuff) { std::cerr << "Memory allocation error in MSG_header." << std::endl << "Requested allocation of " << hsize << " bytes." << std::endl; throw; } in.read((char_1 *) hbuff, hsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Header body" << std::endl; throw; } unsigned char_1 *pnt = hbuff; size_t left = hsize; size_t hunk_size = 0; size_t hqlen = 0; while (left) { switch(*pnt) { case MSG_HEADER_IMAGE_STRUCTURE: if (get_ui2(pnt+1) != MSG_IMAGE_STRUCTURE_LEN) { std::cerr << "Error: Image Structure Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } image_structure = new MSG_header_image_struct; image_structure->read_from(pnt); pnt = pnt + MSG_IMAGE_STRUCTURE_LEN; left = left - MSG_IMAGE_STRUCTURE_LEN; break; case MSG_HEADER_IMAGE_NAVIGATION: if (get_ui2(pnt+1) != MSG_IMAGE_NAVIGATION_LEN) { std::cerr << "Error: Image Navigation Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } image_navigation = new MSG_header_image_navig; image_navigation->read_from(pnt); pnt = pnt + MSG_IMAGE_NAVIGATION_LEN; left = left - MSG_IMAGE_NAVIGATION_LEN; break; case MSG_HEADER_IMAGE_DATA_FUNCTION: hunk_size = (size_t) get_ui2(pnt+1); image_data_function = new MSG_header_image_datafunc; image_data_function->read_from(pnt); pnt = pnt + hunk_size; left = left - hunk_size; break; case MSG_HEADER_ANNOTATION: if (get_ui2(pnt+1) != MSG_ANNOTATION_LEN) { std::cerr << "Error: Annotation Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } annotation = new MSG_header_annotation; annotation->read_from(pnt); pnt = pnt + MSG_ANNOTATION_LEN; left = left - MSG_ANNOTATION_LEN; break; case MSG_HEADER_TIMESTAMP: if (get_ui2(pnt+1) != MSG_TIMESTAMP_LEN) { std::cerr << "Error: Timestamp Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } timestamp = new MSG_header_timestamp; timestamp->read_from(pnt); pnt = pnt + MSG_TIMESTAMP_LEN; left = left - MSG_TIMESTAMP_LEN; break; case MSG_HEADER_ANCILLARY_TEXT: hunk_size = (size_t) get_ui2(pnt+1); ancillary_text = new MSG_header_ancillary_text; ancillary_text->read_from(pnt); pnt = pnt + hunk_size; left = left - hunk_size; break; case MSG_HEADER_KEY: if (get_ui2(pnt+1) != MSG_KEY_LEN) { std::cerr << "Error: Key Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } key = new MSG_header_key; key->read_from(pnt); pnt = pnt + MSG_KEY_LEN; left = left - MSG_KEY_LEN; break; case MSG_HEADER_SEGMENT_IDENTIFICATION: if (get_ui2(pnt+1) != MSG_SEGMENT_ID_LEN) { std::cerr << "Error: Segment Id Header mismatch." << std::endl; std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl; throw; } segment_id = new MSG_header_segment_id; segment_id->read_from(pnt); pnt = pnt + MSG_SEGMENT_ID_LEN; left = left - MSG_SEGMENT_ID_LEN; break; case MSG_HEADER_IMAGE_SEGMENT_LINE_QUALITY: segment_quality = new MSG_header_segment_quality; segment_quality->read_from(pnt, image_structure->number_of_lines); hqlen = get_ui2(pnt+1); pnt = pnt + hqlen; left = left - hqlen; break; default: std::cerr << "Unknown header type: " << (uint_2) *pnt << std::endl; std::cerr << "Unparsed " << left << " bytes." << std::endl; throw; break; } } delete [ ] hbuff; return; }