/* Copyright (c) 2007-2008 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software and that appropriate acknowledgments are made to the research of the COSI group. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. Author : Alessandro Pinto University of California, Berkeley 545 Cory Hall, Berkeley, CA 94720 */ #include #include #include #include #include #include "io/bas/SvgBuildingParser.h" #include "networks/wiredbas/WiredBasSpecificaion.h" #include "platforms/wiredbas/BusPlatform.h" #include "platforms/wiredbas/NetworkPlatform.h" #include "libraries/wiredbas/node/ArcnetSensor.h" #include "libraries/wiredbas/node/ArcnetActuator.h" #include "libraries/wiredbas/node/ArcnetRouter.h" #include "libraries/wiredbas/node/ArcnetController.h" #include "libraries/wiredbas/node/ArcnetBus.h" #include "libraries/wiredbas/link/TwistedPair.h" #include "models/wiredbas/node/ArcnetNodeCost.h" #include "models/wiredbas/link/TwistedPairCost.h" #include "models/wiredbas/link/TwistedPairDelay.h" #include "libraries/wiredbas/node/EthernetCameraSensor.h" #include "libraries/wiredbas/node/EthernetSwitch.h" #include "libraries/wiredbas/node/EthernetController.h" #include "libraries/wiredbas/node/EthernetSubNetwork.h" #include "libraries/wiredbas/link/EthernetLink.h" #include "algorithms/wiredbas/ChainGenerator.h" #include "algorithms/wiredbas/HeuristicChainGenerator.h" #include "algorithms/wiredbas/PartitionGenerator.h" #include "algorithms/wiredbas/PbCoverGeneration.h" #include "algorithms/wiredbas/SecondLevelNetwork.h" #include "io/bas/InkScapeCodeGen.h" #include "io/bas/SynthesisReport.h" #include "environment/bas/InstSurface.h" #include "include/bas/CosiGlobal.h" std::ofstream CosiLog; cosi::io::ConfigParser* Configuration; //Bus platform setup cosi::platforms::wiredbas::BusPlatform* GenerateBusPlatform( cosi::io::bas::SvgBuildingParser* P, double BusSpeed, string SpecName) { cosi::platforms::wiredbas::BusPlatform * Plt = new cosi::platforms::wiredbas::BusPlatform; //Sensor cosi::library::wiredbas::ArcnetSensor * S = new cosi::library::wiredbas::ArcnetSensor; //Actuator cosi::library::wiredbas::ArcnetActuator * A = new cosi::library::wiredbas::ArcnetActuator; //Router cosi::library::wiredbas::ArcnetRouter * R = new cosi::library::wiredbas::ArcnetRouter; //Controller cosi::library::wiredbas::ArcnetController * Ctrl = new cosi::library::wiredbas::ArcnetController; Plt->AddNodeComponent("Sensor", S); Plt->AddNodeComponent("Actuator", A); Plt->AddNodeComponent("Router", R) ; Plt->AddNodeComponent("Controller", Ctrl) ; //Wires cosi::models::wiredbas::TwistedPairCost * Wcost = new cosi::models::wiredbas::TwistedPairCost; cosi::models::wiredbas::TwistedPairDelay * Wdelay = new cosi::models::wiredbas::TwistedPairDelay; cosi::library::wiredbas::TwistedPair * W = new cosi::library::wiredbas::TwistedPair(Wdelay,Wcost); Plt->AddWireComponent("Wire", W) ; cosi::rules::wiredbas::WiringRule * Wr = new cosi::rules::wiredbas::WiringRule(P->GetInstallationSurfaces(1)); Plt->SetWiringRule(Wr); cosi::rules::wiredbas::NodePosition * Np = new cosi::rules::wiredbas::NodePosition(P->GetRoutingPoints(SpecName)); Plt->SetNodePositions(Np) ; //Bus cosi::library::wiredbas::ArcnetBus * Bus = new cosi::library::wiredbas::ArcnetBus(BusSpeed,Wr,Wcost,Wdelay); Plt->AddBusComponent("Bus", Bus) ; return Plt ; } //Network platform setup cosi::platforms::wiredbas::NetworkPlatform* GenerateNetworkPlatform( cosi::io::bas::SvgBuildingParser* P, string SpecName) { cosi::platforms::wiredbas::NetworkPlatform * Plt = new cosi::platforms::wiredbas::NetworkPlatform; //Sensor cosi::library::wiredbas::EthernetCameraSensor * S = new cosi::library::wiredbas::EthernetCameraSensor; //Router cosi::library::wiredbas::EthernetSwitch * R = new cosi::library::wiredbas::EthernetSwitch(8,1,100e6); //Controller cosi::library::wiredbas::EthernetController * Ctrl = new cosi::library::wiredbas::EthernetController; Plt->AddNodeComponent("Sensor", S); Plt->AddNodeComponent("Router", R) ; Plt->AddNodeComponent("Controller", Ctrl) ; //Wires cosi::rules::wiredbas::WiringRule * Wr = new cosi::rules::wiredbas::WiringRule(P->GetInstallationSurfaces(1)); Plt->SetWiringRule(Wr); cosi::models::wiredbas::EthernetLinkCost * Wcost = new cosi::models::wiredbas::EthernetLinkCost; cosi::models::wiredbas::EthernetLinkDelay * Wdelay = new cosi::models::wiredbas::EthernetLinkDelay(100e6); cosi::library::wiredbas::EthernetLink * W = new cosi::library::wiredbas::EthernetLink(100e6); Plt->AddWireComponent("Wire", W) ; //Net cosi::rules::wiredbas::EthernetNetworkRule * Er = new cosi::rules::wiredbas::EthernetNetworkRule(100e6); cosi::models::wiredbas::EthernetNetworkCost * Nc = new cosi::models::wiredbas::EthernetNetworkCost(Wcost); cosi::models::wiredbas::EthernetNetworkDelay * Nd = new cosi::models::wiredbas::EthernetNetworkDelay(100e6); std::map N; N["Sensor"] = S ; N["Controller"] = Ctrl; N["Router"] = R ; std::map L; L["Wire"] = W ; cosi::library::wiredbas::EthernetSubNetwork * Net = new cosi::library::wiredbas::EthernetSubNetwork(Wr,Er,Wcost,Nc,Wdelay,Nd,N,L); Plt->AddNetComponent("Net", Net) ; cosi::rules::wiredbas::NodePosition * Np = new cosi::rules::wiredbas::NodePosition(P->GetRoutingPoints(SpecName)); Plt->SetNodePositions(Np) ; return Plt ; } // int main(int argc, char* argv[]) { if (argc < 5) { std::cout << "Use: CosiNes " << std::endl ; exit(1) ; } std::string SpecFile(argv[1]); std::string SpecName(argv[2]); double BusSpeed = atof(argv[4]); CosiLog.open("cosilog.txt") ; std::string CosiRoot = std::string(getenv("COSI_ROOT") ); //Parse configuration Configuration = new cosi::io::ConfigParser( CosiRoot + "/cosiconfig.xml" ); Configuration->Parse(); //Read the building spec cosi::io::bas::SvgBuildingParser* P = new cosi::io::bas::SvgBuildingParser(SpecFile); P->Parse() ; cosi::commstruct::wiredbas::Specification* Spec = P->GetSpecification(SpecName) ; cosi::platforms::wiredbas::NetworkPlatform * NetPlt = GenerateNetworkPlatform(P, SpecName) ; cosi::platforms::wiredbas::BusPlatform* Plt = GenerateBusPlatform(P, BusSpeed, SpecName) ; // cosi::algorithms::wiredbas::ChainGenerator // * C = new cosi::algorithms::wiredbas::ChainGenerator; // C->Initialize(Spec, Plt) ; // cosi::algorithms::wiredbas::HeuristicChainGenerator // * C = new cosi::algorithms::wiredbas::HeuristicChainGenerator(Spec, Plt); // // C->Run() ; std::list Chains; cosi::commstruct::wiredbas::Implementation* SlI; if (std::string(argv[3]) == "Arcnet") { cosi::algorithms::wiredbas::PartitionGenerator * C = new cosi::algorithms::wiredbas::PartitionGenerator(Spec, Plt); C->Run() ; cosi::algorithms::wiredbas::PbCoverGeneration * Cover = new cosi::algorithms::wiredbas::PbCoverGeneration(Spec,C->GetChains(),C->GetRouters(),Plt); Cover->Run() ; Chains = Cover->GetCover() ; // cosi::io::bas::SynthesisReport // * Report = new cosi::io::bas::SynthesisReport(Spec,Chains,Plt,"report_firstlevel.txt"); // Report->Run() ; // // delete Report; //second level network if (std::string(argv[5]) == "Arcnet") { //arcnet cosi::algorithms::wiredbas::SecondLevelNetwork * Sl = new cosi::algorithms::wiredbas::SecondLevelNetwork( Chains,Plt); Sl->Run() ; SlI = Sl->Get() ; } else { //ethernet cosi::algorithms::wiredbas::SecondLevelNetwork * Sl = new cosi::algorithms::wiredbas::SecondLevelNetwork( Chains,NetPlt); Sl->Run() ; SlI = Sl->Get() ; } if (std::string(argv[5]) == "Arcnet") { cosi::io::bas::SynthesisReport * Report = new cosi::io::bas::SynthesisReport(Spec,Chains,Plt,SlI,"report.txt"); Report->Run(); delete Report; } else { cosi::io::bas::SynthesisReport * Report = new cosi::io::bas::SynthesisReport(Spec,Chains,Plt,SlI,NetPlt,"report.txt"); Report->Run() ; delete Report; } } else if (std::string(argv[3]) == "Ethernet") { cosi::algorithms::wiredbas::PartitionGenerator * C = new cosi::algorithms::wiredbas::PartitionGenerator(Spec, NetPlt); C->Run(); cosi::algorithms::wiredbas::PbCoverGeneration * Cover = new cosi::algorithms::wiredbas::PbCoverGeneration(Spec,C->GetChains(),C->GetRouters(),NetPlt); Cover->Run(); Chains = Cover->GetCover(); cosi::algorithms::wiredbas::SecondLevelNetwork * Sl = new cosi::algorithms::wiredbas::SecondLevelNetwork( Chains,NetPlt); Sl->Run(); SlI = Sl->Get(); cosi::io::bas::SynthesisReport * Report = new cosi::io::bas::SynthesisReport(Spec,Chains,NetPlt,SlI,"report.txt"); Report->Run(); delete Report; } //std::list // Chains = Cover->GetCover() ; //std::list // Chains = C->GetChains() ; cosi::io::bas::InkScapeCodeGen* Ink = new cosi::io::bas::InkScapeCodeGen( "synth.svg" , 10,10); Ink->NewLayer(1, "Constraints"); Ink->Add(Spec); Ink->CloseLayer(); // Ink->NewLayer(2, "Implementation") ; // Ink->Add(Result) ; // Ink->CloseLayer(); // Ink->NewLayer(3, "Connectivity") ; // Ink->Add(Connectivity) ; // Ink->CloseLayer(); Ink->NewLayer(4, "InstSurfaces"); std::map< std::string , cosi::environment::bas::InstSurface > Surfaces; std::map< std::string , cosi::environment::bas::InstSurface >::iterator Is; Surfaces = P->GetInstallationSurfaces(1); for (Is = Surfaces.begin(); Is != Surfaces.end(); Is++) { Ink->Add(Is->second); } Ink->CloseLayer(); std::list::iterator Chain; int Layer = 5; for (Chain = Chains.begin(); Chain != Chains.end(); Chain++) { std::stringstream s; s << "Chain_"<< Layer; Ink->NewLayer(Layer, s.str()); //std::cout << (*Chain)->Print() << std::endl ; Ink->Add(*Chain); Ink->CloseLayer(); Layer++; } std::stringstream s; s << "SecondLevel"; Ink->NewLayer(Layer, s.str()); //std::cout << (*Chain)->Print() << std::endl ; Ink->Add(SlI); Ink->CloseLayer(); Layer++; Ink->Close(); return 0; }