mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:00:04 +00:00 
			
		
		
		
	Updating test product messages to expose additional details
This commit is contained in:
		
							parent
							
								
									3692ef75f2
								
							
						
					
					
						commit
						612874f830
					
				
					 7 changed files with 80 additions and 2 deletions
				
			
		|  | @ -40,6 +40,21 @@ public: | |||
| TextEventManager::TextEventManager() : p(std::make_unique<Impl>(this)) {} | ||||
| TextEventManager::~TextEventManager() = default; | ||||
| 
 | ||||
| size_t TextEventManager::message_count(const types::TextEventKey& key) const | ||||
| { | ||||
|    size_t messageCount = 0u; | ||||
| 
 | ||||
|    std::shared_lock lock(p->textEventMutex_); | ||||
| 
 | ||||
|    auto it = p->textEventMap_.find(key); | ||||
|    if (it != p->textEventMap_.cend()) | ||||
|    { | ||||
|       messageCount = it->second.size(); | ||||
|    } | ||||
| 
 | ||||
|    return messageCount; | ||||
| } | ||||
| 
 | ||||
| std::vector<std::shared_ptr<awips::TextProductMessage>> | ||||
| TextEventManager::message_list(const types::TextEventKey& key) const | ||||
| { | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ public: | |||
|    explicit TextEventManager(); | ||||
|    ~TextEventManager(); | ||||
| 
 | ||||
|    size_t message_count(const types::TextEventKey& key) const; | ||||
|    std::vector<std::shared_ptr<awips::TextProductMessage>> | ||||
|    message_list(const types::TextEventKey& key) const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,9 +13,18 @@ namespace types | |||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::types::text_event_key"; | ||||
| 
 | ||||
| std::string TextEventKey::ToFullString() const | ||||
| { | ||||
|    return std::format("{} {} {} {:04}", | ||||
|                       officeId_, | ||||
|                       awips::GetPhenomenonText(phenomenon_), | ||||
|                       awips::GetSignificanceText(significance_), | ||||
|                       etn_); | ||||
| } | ||||
| 
 | ||||
| std::string TextEventKey::ToString() const | ||||
| { | ||||
|    return std::format("{}.{}.{}.{}", | ||||
|    return std::format("{}.{}.{}.{:04}", | ||||
|                       officeId_, | ||||
|                       awips::GetPhenomenonCode(phenomenon_), | ||||
|                       awips::GetSignificanceCode(significance_), | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ struct TextEventKey | |||
|    { | ||||
|    } | ||||
| 
 | ||||
|    std::string ToFullString() const; | ||||
|    std::string ToString() const; | ||||
|    bool        operator==(const TextEventKey& o) const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -87,6 +87,7 @@ public: | |||
|    TextProductMessage(TextProductMessage&&) noexcept; | ||||
|    TextProductMessage& operator=(TextProductMessage&&) noexcept; | ||||
| 
 | ||||
|    std::string                                 message_content() const; | ||||
|    std::shared_ptr<WmoHeader>                  wmo_header() const; | ||||
|    std::vector<std::string>                    mnd_header() const; | ||||
|    std::vector<std::string>                    overview_block() const; | ||||
|  |  | |||
|  | @ -12,6 +12,8 @@ namespace Characters | |||
| 
 | ||||
| constexpr char DEGREE = static_cast<char>(0xb0); | ||||
| constexpr char ETX    = static_cast<char>(0x03); | ||||
| constexpr char NUL    = static_cast<char>(0x00); | ||||
| constexpr char SOH    = static_cast<char>(0x01); | ||||
| 
 | ||||
| } // namespace Characters
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,6 +6,9 @@ | |||
| #include <regex> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <boost/algorithm/string/replace.hpp> | ||||
| #include <boost/algorithm/string/trim.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace awips | ||||
|  | @ -34,9 +37,17 @@ static std::optional<Vtec>          TryParseVtecString(std::istream& is); | |||
| class TextProductMessageImpl | ||||
| { | ||||
| public: | ||||
|    explicit TextProductMessageImpl() : wmoHeader_ {} {} | ||||
|    explicit TextProductMessageImpl() : | ||||
|        messageContent_ {}, | ||||
|        wmoHeader_ {}, | ||||
|        mndHeader_ {}, | ||||
|        overviewBlock_ {}, | ||||
|        segments_ {} | ||||
|    { | ||||
|    } | ||||
|    ~TextProductMessageImpl() = default; | ||||
| 
 | ||||
|    std::string                           messageContent_; | ||||
|    std::shared_ptr<WmoHeader>            wmoHeader_; | ||||
|    std::vector<std::string>              mndHeader_; | ||||
|    std::vector<std::string>              overviewBlock_; | ||||
|  | @ -53,6 +64,11 @@ TextProductMessage::TextProductMessage(TextProductMessage&&) noexcept = default; | |||
| TextProductMessage& | ||||
| TextProductMessage::operator=(TextProductMessage&&) noexcept = default; | ||||
| 
 | ||||
| std::string TextProductMessage::message_content() const | ||||
| { | ||||
|    return p->messageContent_; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<WmoHeader> TextProductMessage::wmo_header() const | ||||
| { | ||||
|    return p->wmoHeader_; | ||||
|  | @ -94,6 +110,8 @@ bool TextProductMessage::Parse(std::istream& is) | |||
| { | ||||
|    bool dataValid = true; | ||||
| 
 | ||||
|    std::streampos messageStart = is.tellg(); | ||||
| 
 | ||||
|    p->wmoHeader_ = std::make_shared<WmoHeader>(); | ||||
|    dataValid     = p->wmoHeader_->Parse(is); | ||||
| 
 | ||||
|  | @ -143,6 +161,37 @@ bool TextProductMessage::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (dataValid) | ||||
|    { | ||||
|       // Store raw message content
 | ||||
|       std::streampos  messageEnd  = is.tellg(); | ||||
|       std::streamsize messageSize = messageEnd - messageStart; | ||||
|       p->messageContent_.resize(messageEnd - messageStart); | ||||
|       is.seekg(messageStart); | ||||
|       if (is.peek() == common::Characters::SOH) | ||||
|       { | ||||
|          is.seekg(std::streamoff {1}, std::ios_base::cur); | ||||
|          messageSize--; | ||||
|       } | ||||
|       is.read(p->messageContent_.data(), messageSize); | ||||
| 
 | ||||
|       // Trim extra characters from raw message
 | ||||
|       while (p->messageContent_.size() > 0 && | ||||
|              (p->messageContent_.back() == common::Characters::NUL || | ||||
|               p->messageContent_.back() == common::Characters::ETX)) | ||||
|       { | ||||
|          p->messageContent_.resize(p->messageContent_.size() - 1); | ||||
|       } | ||||
|       boost::replace_all(p->messageContent_, "\r\r\n", "\n"); | ||||
|       boost::trim(p->messageContent_); | ||||
|       p->messageContent_.shrink_to_fit(); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       p->messageContent_.resize(0); | ||||
|       p->messageContent_.shrink_to_fit(); | ||||
|    } | ||||
| 
 | ||||
|    return dataValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat