Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Revision:
20:b0281e8a375a
Parent:
19:4b147d8f9164
Child:
39:13e66d087ae9
--- a/Payload.cpp	Thu Aug 30 08:48:19 2018 +0000
+++ b/Payload.cpp	Sun Sep 02 22:24:14 2018 +0000
@@ -1,68 +1,50 @@
-//#include <strstream>
-#include "Component.hpp"
 #include "Payload.hpp"
 
-Payload::Payload(Payload::PAYLOAD_ID id, std::vector<Component*> components) : _id(id), _components(components)  {
+
+using namespace misnet;
+
+
+Payload::Payload(Payload::PAYLOAD_ID id, std::vector<Component*> components, uint16_t base_period)
+: _id(id), _components(components), _basePeriod(base_period)  {
     for (std::vector<Component*>::iterator it = this->_components.begin(); it != this->_components.end(); it++) {
         Component* component = *it;
         for(std::vector<Service*>::iterator it = component->getServices().begin(); it != component->getServices().end(); it++) {
-            this->_channels.push_back(*it);
+            this->_services.push_back(*it);
         }
     }
-
-    /*
-    for (Component component : this->_components) {
-        for (Service* channel : component.getServices()) {
-            this->_channels.push_back(channel);
-        }
-    */
 }
 
 
-Service* Payload::getServiceByRank(short channelRank) {
-    /*
-    if (channelRank < 1 || channelRank > 6) {
-        throw ServiceException();
-    }
-    */
-    if (channelRank < 1 || channelRank > 6) {
+Service* Payload::getServiceByRank(short servicesRank) {
+    if (servicesRank < 1 || servicesRank > 6) {
         return (Service*) NULL;
     }
 
-    return this->_channels[channelRank - 1];
+    return this->_services[servicesRank - 1];
 }
 
 
-std::ostream& operator<<(std::ostream& out, const Payload& payload) {
-    out << "Payload id : " << payload._id << std::endl;
-    out << "It contains " << payload._components.size() << " components" << std::endl;
-    out << "List of components :\n------------------" << std::endl;
+std::string Payload::toString() {
+    std::ostringstream stringStream;
 
-    //std::vector<const Component>::iterator it;
-    std::vector< Component*>::iterator it;
-    //for (it = payload._components.begin(); it != payload._components.end(); it++) {
-    //  std::cout << **it << std::endl;
-    //}
+    stringStream << "Payload id : " << this->_id << std::endl;
+    stringStream << "It contains " << this->_components.size() << " components" << std::endl;
+    stringStream << "List of components :\n------------------" << std::endl;
 
-    std::vector<Service*> channels = payload._channels;
-
-    out << "There are " << channels.size() << " channels." << std::endl;
-    out << "List of channels :\n------------------" << std::endl;
-
-    for(std::vector<Service*>::iterator it = channels.begin(); it != channels.end(); it++) {
-        Service* channel = *it;
-        std::cout << *channel << std::endl;
+    std::vector<Component*>::iterator it;
+    for (it = this->_components.begin(); it != this->_components.end(); it++) {
+        stringStream << (*it)->toString() << std::endl;
     }
 
-    /*
-    for (Component* component : payload._components) {
-        out << " (component : " << *component << ")";
+    std::vector<Service*> services = this->_services;
+
+    stringStream << "There are " << services.size() << " services." << std::endl;
+    stringStream << "List of services :\n------------------" << std::endl;
+
+    for(std::vector<Service*>::iterator it = services.begin(); it != services.end(); it++) {
+        Service* service = *it;
+        stringStream << service->toString() << std::endl;
     }
 
-    for (Service* channel : payload._channels) {
-        out << " (channel : " << *channel << ")";
-    }
-    */
-
-    return out;
+    return stringStream.str();
 }