예제 #1
0
TEST(FilePersistence, SaveMultipleUnits)
{
	QString testDir = QDir::tempPath() + QDir::toNativeSeparators("/Envision/FilePersistence/tests");
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root, "set title");
	root->name()->set("Root");
	TestNodes::BinaryNode* left = root->setLeft<TestNodes::BinaryNodePersistenceUnit>();
	TestNodes::BinaryNode* right = root->setRight<TestNodes::BinaryNode>();

	left->name()->set("Left child");
	TestNodes::BinaryNode* leftleft = left->setLeft<TestNodes::BinaryNode>();
	leftleft->name()->set("in a new unit");
	right->name()->set("Right child");
	model.endModification();

	model.setName("units");
	model.save(&store);
	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/units", testDir + "/units/units");
	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/2", testDir + "/units/2");
}
예제 #2
0
TEST(FilePersistence, LoadMultipleUnits)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "units");
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root());

	CHECK_STR_EQUAL("BinaryNode", root->typeName() );
	CHECK_STR_EQUAL("Root", root->name()->get() );
	CHECK_CONDITION(root->left() != nullptr);
	CHECK_CONDITION(root->right() != nullptr);
	CHECK_STR_EQUAL("BinaryNodePersistenceUnit", root->left()->typeName() );
	CHECK_STR_EQUAL("Left child", root->left()->name()->get() );
	CHECK_CONDITION(root->left()->left() != nullptr);
	CHECK_CONDITION(root->left()->right() == nullptr);
	CHECK_STR_EQUAL("BinaryNode", root->left()->left()->typeName() );
	CHECK_STR_EQUAL("in a new unit", root->left()->left()->name()->get() );
	CHECK_CONDITION(root->left()->left()->left() == nullptr);
	CHECK_CONDITION(root->left()->left()->right() == nullptr);
	CHECK_STR_EQUAL("BinaryNode", root->right()->typeName() );
	CHECK_STR_EQUAL("Right child", root->right()->name()->get() );
	CHECK_CONDITION(root->right()->left() == nullptr);
	CHECK_CONDITION(root->right()->right() == nullptr);
}
예제 #3
0
TEST(FilePersistence, SaveList)
{
	QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.createRoot("PartialList"));

	model.beginModification(root, "create ");
	Model::Text* one = new Model::Text();
	one->set("one");
	root->list()->append(one);
	Model::Text* two = new Model::Text();
	two->set("two");
	root->list()->append(two);
	Model::Text* three = new Model::Text();
	three->set("three");
	root->list()->append(three);
	Model::Text* four = new Model::Text();
	four->set("four");
	root->list()->append(four);
	model.endModification();

	model.setName("partial");
	model.save(&store);

	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/partial/partial", testDir + "/partial/partial");
}
예제 #4
0
 /// Dump information about the clock store to an ostream.
 /// @param[in] os ostream to receive the output; defaults to std::cout
 /// @param[in] detail integer level of detail to provide; allowed values are
 ///    0: number of satellites, time step and time limits
 ///    1: above plus flags, gap and interval values, and number of data/sat
 ///    2: above plus all the data tables
 void dumpClock(std::ostream& os = std::cout, short detail = 0)
    const throw()
 {
    if(useSP3clock)
       SP3Files.dump(os, detail);
    else
       clkFiles.dump(os, detail);
    clkStore.dump(os, detail);
 }
예제 #5
0
TEST(FilePersistence, LoadRootOnly)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "rootOnly");
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root());

	CHECK_CONDITION(root);
	CHECK_STR_EQUAL("BinaryNode", root->typeName() );
	CHECK_STR_EQUAL("Title", root->name()->get() );
	CHECK_CONDITION(root->left() == nullptr);
	CHECK_CONDITION(root->right() == nullptr);
}
예제 #6
0
TEST(FilePersistence, LoadingList)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "partial");
	TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.root());
	CHECK_CONDITION(root != nullptr);

	Model::List* list = root->list();

	CHECK_CONDITION(list != nullptr);
	CHECK_STR_EQUAL("List", list->typeName() );
	CHECK_CONDITION(list->isFullyLoaded() == false);
	CHECK_INT_EQUAL(1, list->id());

	list->loadFully(store);

	CHECK_CONDITION(list->isFullyLoaded());
	CHECK_INT_EQUAL(4, list->size());

	Model::Text* one = list->at<Model::Text>(0);
	Model::Text* two = list->at<Model::Text>(1);
	Model::Text* three = list->at<Model::Text>(2);
	Model::Text* four = list->at<Model::Text>(3);

	CHECK_CONDITION(one != nullptr);
	CHECK_STR_EQUAL("one", one->get());
	CHECK_INT_EQUAL(2, one->id());

	CHECK_CONDITION(two != nullptr);
	CHECK_STR_EQUAL("two", two->get());
	CHECK_INT_EQUAL(3, two->id())

	CHECK_CONDITION(three != nullptr);
	CHECK_STR_EQUAL("three", three->get());
	CHECK_INT_EQUAL(4, three->id())

	CHECK_CONDITION(four != nullptr);
	CHECK_STR_EQUAL("four", four->get());
	CHECK_INT_EQUAL(5, four->id());

}
예제 #7
0
void Webserver::ProcessGcode(const char* gc)
{
	if (StringStartsWith(gc, "M30 "))		// delete SD card file
	{
		reprap.GetGCodes()->DeleteFile(&gc[4]);
	}
	else if (StringStartsWith(gc, "M23 "))	// select SD card file to print next
	{
		reprap.GetGCodes()->QueueFileToPrint(&gc[4]);
	}
	else if (StringStartsWith(gc, "M112") && !isdigit(gc[4]))	// emergency stop
	{
		reprap.EmergencyStop();
		gcodeReadIndex = gcodeWriteIndex;		// clear the buffer
		reprap.GetGCodes()->Reset();
	}
	else if (StringStartsWith(gc, "M503") && !isdigit(gc[4]))	// echo config.g file
	{
		FileStore *configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false);
		if (configFile == NULL)
		{
			HandleReply("Configuration file not found", true);
		}
		else
		{
			char c;
			size_t i = 0;
			while (i < ARRAY_UPB(gcodeReply) && configFile->Read(c))
			{
				gcodeReply[i++] = c;
			}
			configFile->Close();
			gcodeReply[i] = 0;
			++seq;
		}
	}
	else if (StringStartsWith(gc, "M25") && !isDigit(gc[3]))	// pause SD card print
	{
		reprap.GetGCodes()->PauseSDPrint();
	}
	else
	{
		StoreGcodeData(gc, strlen(gc) + 1);
	}
}
예제 #8
0
TEST(FilePersistence, SaveRootOnly)
{
	QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root->name(), "set title");
	root->name()->set("Title");
	model.endModification();

	model.setName("rootOnly");
	model.save(&store);

	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/rootOnly/rootOnly", testDir + "/rootOnly/rootOnly");
}
예제 #9
0
 /// Clear the dataset, meaning remove all data
 virtual void clear(void) throw()
 {
    NavFiles.clear();
    GPSstore.clear();
    GLOstore.clear();
    GALstore.clear();
    //GEOstore.clear();
    //COMstore.clear();
 }
예제 #10
0
TEST(FilePersistence, ReSaveList)
{
	QString srcDir(":/FilePersistence/test/persisted");
	QString destDir(QDir::tempPath() + "/Envision/FilePersistence/tests");

	QFile src(srcDir + "/partial/partial");
	QFile dest(destDir + "/partialResave/partialResave");

	if (dest.exists())
	{
		bool removed = dest.remove();
		CHECK_CONDITION(removed);
	}

	if (!QDir(destDir + "/partialResave").exists())
	{
		bool createdDir = QDir().mkpath(destDir + "/partialResave");
		CHECK_CONDITION(createdDir);
	}
	bool copied = src.copy(dest.fileName());
	CHECK_CONDITION(copied);

	bool permissionOk = dest.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
	CHECK_CONDITION(permissionOk);

	Model::Model model;
	FileStore store;
	store.setBaseFolder(destDir);

	model.load(&store, "partialResave");
	TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.root());

	CHECK_CONDITION(root->list()->isFullyLoaded() == false);

	model.beginModification(root->list(), "fake modification ");
	model.endModification();

	CHECK_CONDITION(root->list()->isFullyLoaded() == false);
	model.setName("partialResave");
	model.save(&store);
	CHECK_CONDITION(root->list()->isFullyLoaded() == false);

	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/partialResave/partialResave", destDir + "/partialResave/partialResave");
}
예제 #11
0
      /// Dump information about the store to an ostream.
      /// @param[in] os ostream to receive the output; defaults to std::cout
      /// @param[in] detail integer level of detail to provide; allowed values are
      ///    0: number of satellites, time step and time limits
      ///    1: above plus flags, gap and interval values, and number of data/sat
      ///    2: above plus all the data tables
      virtual void dump(std::ostream& os = std::cout, short detail = 0)
         const throw()
      {
         // may have to re-write this...
         os << "Dump SP3EphemerisStore:" << std::endl;
         // 'reject' flags
         os << (rejectBadPosFlag ? " Reject":" Do not reject") << " bad positions."
            << std::endl;
         os << (rejectBadClockFlag ? " Reject":" Do not reject") << " bad clocks."
            << std::endl;
         os << (rejectPredPosFlag ? " Reject":" Do not reject")
            << " predicted positions." << std::endl;
         os << (rejectPredClockFlag ? " Reject":" Do not reject")
            << " predicted clocks." << std::endl;

         SP3Files.dump(os, detail);
         posStore.dump(os, detail);
         if(!useSP3clock) clkFiles.dump(os, detail);
         clkStore.dump(os, detail);

         os << "End dump SP3EphemerisStore." << std::endl;
      }
예제 #12
0
TEST(FilePersistence, SavingTypedList)
{
	QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	Model::TypedList<Model::Text>* list = dynamic_cast<Model::TypedList<Model::Text>*> (model.createRoot("TypedListOfText"));

	model.beginModification(list, "create");
	Model::Text* one = new Model::Text();
	one->set("one");
	list->append(one);
	Model::Text* two = new Model::Text();
	two->set("two");
	list->append(two);
	model.endModification();

	model.setName("typedList");
	model.save(&store);

	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/typedList/typedList", testDir + "/typedList/typedList");
}
예제 #13
0
TEST(FilePersistence, LoadingTypedList)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "typedList");
	Model::TypedList<Model::Text>* list = dynamic_cast<Model::TypedList<Model::Text>*> (model.root());
	CHECK_CONDITION(list != nullptr);

	CHECK_STR_EQUAL("TypedListOfText", list->typeName() );
	CHECK_INT_EQUAL(2, list->size());

	Model::Text* one = list->at(0);
	Model::Text* two = list->at(1);

	CHECK_CONDITION(one != nullptr);
	CHECK_STR_EQUAL("one", one->get());

	CHECK_CONDITION(two != nullptr);
	CHECK_STR_EQUAL("two", two->get());
}
예제 #14
0
int SCShell_cat::execute(SCCommand *command, SCStream *in, SCStream *out){

  // if no params, do nothing
  if(command->getArgCount() != 1){
    out->println("Must specify file to output");
    return -1;
  }

  // only get first parameter
  String pwd = fUtils.getPWD();
  String target = command->getArg(0);
  String *path = fUtils.combineName(pwd, target);

  // check if file exists
  int ret = 0;
  if(SD.FileExists(path->c_str())){
    FileStore fs = FileStore();
    fs.Init();
    if(fs.Open(NULL, path->c_str(), FILE_READ)){
      unsigned long fileLength = fs.Length();
      char buf[READ_CHUNK_SIZE];
      while(fileLength > 0){
        int bytesToRead = min(fileLength, READ_CHUNK_SIZE); 
        int bytesRead = fs.Read(buf, bytesToRead);
        out->write((const uint8_t *)buf, bytesRead);
        fileLength -= bytesRead;
      }
      fs.Close();
    } else {
      out->println("Cannot open file");
      ret = -2;
    }
  } else {
    out->println(target + " does not exist");
    ret = -1;
  }
  delete path;
  
  return ret;
}
예제 #15
0
      /// Dump information about the store to an ostream.
      /// @param[in] os ostream to receive the output; defaults to std::cout
      /// @param[in] detail integer level of detail to provide; allowed values are
      ///    0: number of satellites, time step and time limits
      ///    1: above plus flags, gap and interval values, and number of data/sat
      ///    2: above plus all the data tables
      virtual void dump(std::ostream& os=std::cout, short detail=0)
         const throw()
      {
         // may have to re-write this...
         os << "Dump Rinex3EphemerisStore:" << std::endl;
         // dump the time system corrections
         std::map<std::string,TimeSystemCorrection>::const_iterator tcit;
         for(tcit=mapTimeCorr.begin(); tcit != mapTimeCorr.end(); ++tcit) {
            os << "Time correction for " << tcit->second.asString4() << " : "
               << tcit->second.asString() << " " << std::scientific << std::setprecision(12);
            switch(tcit->second.type) {
               case TimeSystemCorrection::GPUT:
                    os << ", A0 = " << tcit->second.A0
                        << ", A1 = " << tcit->second.A1
                        << ", RefTime = week/sow " << tcit->second.refWeek
                        << "/" << tcit->second.refSOW;
                  break;
               case TimeSystemCorrection::GAUT:
                    os << ", A0 = " << tcit->second.A0
                        << ", A1 = " << tcit->second.A1
                        << ", RefTime = week/sow " << tcit->second.refWeek
                        << "/" << tcit->second.refSOW;
                  break;
               case TimeSystemCorrection::SBUT:
                    os << ", A0 = " << tcit->second.A0
                        << ", A1 = " << tcit->second.A1
                        << ", RefTime = week/sow " << tcit->second.refWeek
                        << "/" << tcit->second.refSOW
                        << ", provider " << tcit->second.geoProvider
                        << ", UTC ID = " << tcit->second.geoUTCid;
                  break;
               case TimeSystemCorrection::GLUT:
                    os << ", -TauC = " << tcit->second.A0;
                  break;
               case TimeSystemCorrection::GPGA:
                    os << ", A0G = " << tcit->second.A0
                        << ", A1G = " << tcit->second.A1
                        << ", RefTime = week/sow " << tcit->second.refWeek
                        << "/" << tcit->second.refSOW;
                  break;
               case TimeSystemCorrection::GLGP:
                    os << ", TauGPS = " << tcit->second.A0
                        << " = " << tcit->second.A0 * C_MPS
                        << " m, RefTime = yr/mon/day "
                        << tcit->second.refYr
                        << "/" << tcit->second.refMon
                        << "/" << tcit->second.refDay;
                  break;
            }
            os << std::endl;
         }

         NavFiles.dump(os, detail);

         GPSstore.dump(os, detail);
         GLOstore.dump(os, detail);
         GALstore.dump(os, detail);
         //if(GEOstore.size()) GEOstore.dump(os, detail);
         //if(COMstore.size()) COMstore.dump(os, detail);
         os << "End dump Rinex3EphemerisStore." << std::endl;
      }
예제 #16
0
파일: FileStore_T.cpp 프로젝트: PPNav/GPSTk
//---------------------------------------------------------------------------
int FileStore_T :: testEverything()
{
   TestUtil  initTester(   "FileStore", "initialization", __FILE__, __LINE__ );
   TestUtil  sizeTester(   "FileStore", "size",           __FILE__, __LINE__ );
   TestUtil  nfilesTester( "FileStore", "nfiles",         __FILE__, __LINE__ );
   TestUtil  clearTester(  "FileStore", "clear",          __FILE__, __LINE__ );
   TestUtil  getTester(    "FileStore", "getFilenames",   __FILE__, __LINE__ );
   TestUtil  addTester(    "FileStore", "addFile",        __FILE__, __LINE__ );
   TestUtil  headerTester( "FileStore", "getHeader",      __FILE__, __LINE__ );

   try   // default initialization
   {
      FileStore<TestHeaderType>  store;
      initTester.assert( true, "unexpected exception", __LINE__ );
   }
   catch (...)
   {
      initTester.assert( false, "unexpected exception", __LINE__ );
   }

   FileStore<TestHeaderType>  store;  // Use this for the remaining tests

   try   // empty store (size)
   {      
      sizeTester.assert( (0 == store.size() ), "empty store expected", __LINE__ );
   }
   catch (...)
   {
      sizeTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // empty store (nfiles)
   {
      nfilesTester.assert( (0 == store.nfiles() ), "empty store expected", __LINE__ );
   }
   catch (...)
   {
      nfilesTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // empty store (getFilenames)
   {
      getTester.assert( (0 == store.getFileNames().size() ), "empty store expected", __LINE__ );
   }
   catch (...)
   {
      getTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // empty store (clear)
   {
      store.clear();
      clearTester.assert( true, "unexpected exception", __LINE__ );
   }
   catch (...)
   {
      clearTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // empty store (getHeader)
   {
      const TestHeaderType&  header = store.getHeader("filename");
      headerTester.assert( false, "expected exception", __LINE__ );
   }
   catch (InvalidRequest& ire)
   {
      headerTester.assert( true, "expected exception", __LINE__ );
   }
   catch (...)
   {
      headerTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // empty store (addFile)
   {
      TestHeaderType  header(1);
      store.addFile("testfile1", header);

      addTester.assert( true, "unexpected exception", __LINE__ );
      sizeTester.assert( (1 == store.size() ), "single file expected", __LINE__ );
      nfilesTester.assert( (1 == store.nfiles() ), "single file expected", __LINE__ );

      std::vector<std::string>  filenames = store.getFileNames();
      getTester.assert( (1 == filenames.size() ), "single file expected", __LINE__ );
      if (filenames.size() > 0)
      {
         getTester.assert( (0 == filenames[0].compare("testfile1") ), "unexpected filename", __LINE__ );
      }
   }
   catch (...)
   {
      addTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // non-empty store (getHeader, present)
   {
      const TestHeaderType&  header = store.getHeader("testfile1");
      headerTester.assert( true, "unexpected exception", __LINE__ );
      headerTester.assert( (1 == header.value), "unexpected header", __LINE__ );
   }
   catch (...)
   {
      headerTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // non-empty store (getHeader, absent)
   {
      const TestHeaderType&  header = store.getHeader("foo");
      headerTester.assert( false, "expected exception", __LINE__ );
   }
   catch (InvalidRequest& ire)
   {
      headerTester.assert( true, "expected exception", __LINE__ );
   }
   catch (...)
   {
      headerTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // non-empty store (addFile)
   {
      TestHeaderType  header(2);
      store.addFile("testfile2", header);

      addTester.assert( true, "unexpected exception", __LINE__ );
      sizeTester.assert( (2 == store.size() ), "two files expected", __LINE__ );
      nfilesTester.assert( (2 == store.nfiles() ), "two files expected", __LINE__ );

      std::vector<std::string>  filenames = store.getFileNames();
      getTester.assert( (2 == filenames.size() ), "two files expected", __LINE__ );
   }
   catch (...)
   {
      addTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // non-empty store (getHeader, present)
   {
      const TestHeaderType&  header = store.getHeader("testfile2");
      headerTester.assert( true, "unexpected exception", __LINE__ );
      headerTester.assert( (2 == header.value), "unexpected header", __LINE__ );
   }
   catch (...)
   {
      headerTester.assert( false, "unexpected exception", __LINE__ );
   }

   try   // non-empty store (clear)
   {
      store.clear();
      clearTester.assert( true, "unexpected exception", __LINE__ );      
      sizeTester.assert( (0 == store.size() ), "empty store expected", __LINE__ );
      nfilesTester.assert( (0 == store.nfiles() ), "empty store expected", __LINE__ );
      getTester.assert( (0 == store.getFileNames().size() ), "empty store expected", __LINE__ );
   }
   catch (...)
   {
      clearTester.assert( false, "unexpected exception", __LINE__ );
   }

   return initTester.countFails() +
          sizeTester.countFails() +
          nfilesTester.countFails() +
          clearTester.countFails() +
          getTester.countFails() +
          addTester.countFails() +
          headerTester.countFails();
}
예제 #17
0
// Start sending a file or a JSON response.
void Webserver::SendFile(const char* nameOfFileToSend)
{
	if (StringEquals(nameOfFileToSend, "/"))
	{
		nameOfFileToSend = INDEX_PAGE;
	}
	FileStore *fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
	if (fileToSend == NULL)
	{
		nameOfFileToSend = FOUR04_FILE;
		fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
		if (fileToSend == NULL)
		{
			RejectMessage("not found", 404);
			return;
		}
	}

	Network *net = reprap.GetNetwork();
	RequestState *req = net->GetRequest(NULL);
	req->Write("HTTP/1.1 200 OK\n");

	const char* contentType;
	bool zip = false;
	if (StringEndsWith(nameOfFileToSend, ".png"))
	{
		contentType = "image/png";
	}
	else if (StringEndsWith(nameOfFileToSend, ".ico"))
	{
		contentType = "image/x-icon";
	}
	else if (StringEndsWith(nameOfFileToSend, ".js"))
	{
		contentType = "application/javascript";
	}
	else if (StringEndsWith(nameOfFileToSend, ".css"))
	{
		contentType = "text/css";
	}
	else if (StringEndsWith(nameOfFileToSend, ".htm") || StringEndsWith(nameOfFileToSend, ".html"))
	{
		contentType = "text/html";
	}
	else if (StringEndsWith(nameOfFileToSend, ".zip"))
	{
		contentType = "application/zip";
		zip = true;
	}
	else
	{
		contentType = "application/octet-stream";
	}
	req->Printf("Content-Type: %s\n", contentType);

	if (zip && fileToSend != NULL)
	{
		req->Write("Content-Encoding: gzip\n");
		req->Printf("Content-Length: %lu", fileToSend->Length());
	}

	req->Write("Connection: close\n\n");
	net->SendAndClose(fileToSend);
}
예제 #18
0
 /// Get number of files (all types) in FileStore.
 int nfiles(void) throw()
    { return (SP3Files.size() + (useSP3clock ? 0 : clkFiles.size())); }
예제 #19
0
TEST(FilePersistence, LoadDataMultipleUnits)
{
	QString testDir = ":/FilePersistence/test/persisted";
	FileStore store;
	store.setBaseFolder(testDir);

	typedef PersistedValue< QString >* String;
	typedef PersistedValue< QList<PersistedNode*> >* Composite;

	// Root Node
	Composite root = dynamic_cast<Composite> (store.loadCompleteNodeSubtree("units", nullptr));
	CHECK_CONDITION(root);
	CHECK_STR_EQUAL("BinaryNode", root->type() );
	CHECK_STR_EQUAL("units", root->name());
	CHECK_INT_EQUAL(0, root->id());
	CHECK_CONDITION(!root->partialHint());
	CHECK_CONDITION(!root->isNewPersistenceUnit());
	CHECK_INT_EQUAL(3, root->value().size());

	// Root Node children
	String rootName = dynamic_cast<String> (root->value().at(0));
	CHECK_CONDITION(rootName);
	CHECK_STR_EQUAL("Text", rootName->type() );
	CHECK_STR_EQUAL("name", rootName->name());
	CHECK_INT_EQUAL(1, rootName->id());
	CHECK_CONDITION(!rootName->partialHint());
	CHECK_CONDITION(!rootName->isNewPersistenceUnit());
	CHECK_STR_EQUAL("Root", rootName->value());

	Composite left = dynamic_cast<Composite> (root->value().at(1));
	CHECK_CONDITION(left);
	CHECK_STR_EQUAL("BinaryNodePersistenceUnit", left->type() );
	CHECK_STR_EQUAL("left", left->name());
	CHECK_INT_EQUAL(2, left->id());
	CHECK_CONDITION(!left->partialHint());
	CHECK_CONDITION(left->isNewPersistenceUnit());
	CHECK_INT_EQUAL(2, left->value().size());

	Composite right = dynamic_cast<Composite> (root->value().at(2));
	CHECK_CONDITION(right);
	CHECK_STR_EQUAL("BinaryNode", right->type() );
	CHECK_STR_EQUAL("right", right->name());
	CHECK_INT_EQUAL(6, right->id());
	CHECK_CONDITION(!right->partialHint());
	CHECK_CONDITION(!right->isNewPersistenceUnit());
	CHECK_INT_EQUAL(1, right->value().size());

	// Left Node children
	String leftName = dynamic_cast<String> (left->value().at(0));
	CHECK_CONDITION(leftName);
	CHECK_STR_EQUAL("Text", leftName->type() );
	CHECK_STR_EQUAL("name", leftName->name());
	CHECK_INT_EQUAL(3, leftName->id());
	CHECK_CONDITION(!leftName->partialHint());
	CHECK_CONDITION(!leftName->isNewPersistenceUnit());
	CHECK_STR_EQUAL("Left child", leftName->value());

	Composite leftleft = dynamic_cast<Composite> (left->value().at(1));
	CHECK_CONDITION(leftleft);
	CHECK_STR_EQUAL("BinaryNode", leftleft->type() );
	CHECK_STR_EQUAL("left", leftleft->name());
	CHECK_INT_EQUAL(4, leftleft->id());
	CHECK_CONDITION(!leftleft->partialHint());
	CHECK_CONDITION(!leftleft->isNewPersistenceUnit());
	CHECK_INT_EQUAL(1, leftleft->value().size());

	String leftleftName = dynamic_cast<String> (leftleft->value().at(0));
	CHECK_CONDITION(leftleftName);
	CHECK_STR_EQUAL("Text", leftleftName->type() );
	CHECK_STR_EQUAL("name", leftleftName->name());
	CHECK_INT_EQUAL(5, leftleftName->id());
	CHECK_CONDITION(!leftleftName->partialHint());
	CHECK_CONDITION(!leftleftName->isNewPersistenceUnit());
	CHECK_STR_EQUAL("in a new unit", leftleftName->value());

	// Right Node children
	String rightName = dynamic_cast<String> (right->value().at(0));
	CHECK_CONDITION(rightName);
	CHECK_STR_EQUAL("Text", rightName->type() );
	CHECK_STR_EQUAL("name", rightName->name());
	CHECK_INT_EQUAL(7, rightName->id());
	CHECK_CONDITION(!rightName->partialHint());
	CHECK_CONDITION(!rightName->isNewPersistenceUnit());
	CHECK_STR_EQUAL("Right child", rightName->value());
}
예제 #20
0
 /// Get number of clock files in FileStore.
 int nClockfiles(void) throw()
    { return (useSP3clock ? SP3Files.size() : clkFiles.size()); }
예제 #21
0
 /// Get number of SP3 files in FileStore.
 int nSP3files(void) throw()
    { return SP3Files.size(); }
예제 #22
0
 /// add filename and header to FileStore
 /// @param string filename file name to be added
 /// @param Rinex3NavHeader Rhead header to be added
 void addFile(const std::string& filename, Rinex3NavHeader& head) throw()
 { NavFiles.addFile(filename,head); }
예제 #23
0
OutputBuffer *RepRap::GetConfigResponse()
{
	// We need some resources to return a valid config response...
	OutputBuffer *response;
	if (!OutputBuffer::Allocate(response))
	{
		return nullptr;
	}

	// Axis minima
	response->copy("{\"axisMins\":");
	char ch = '[';
	for (size_t axis = 0; axis < AXES; axis++)
	{
		response->catf("%c%.2f", ch, platform->AxisMinimum(axis));
		ch = ',';
	}

	// Axis maxima
	response->cat("],\"axisMaxes\":");
	ch = '[';
	for (size_t axis = 0; axis < AXES; axis++)
	{
		response->catf("%c%.2f", ch, platform->AxisMaximum(axis));
		ch = ',';
	}

	// Accelerations
	response->cat("],\"accelerations\":");
	ch = '[';
	for (size_t drive = 0; drive < DRIVES; drive++)
	{
		response->catf("%c%.2f", ch, platform->Acceleration(drive));
		ch = ',';
	}

	// Motor currents
	response->cat("],\"currents\":");
	ch = '[';
	for (size_t drive = 0; drive < DRIVES; drive++)
	{
		response->catf("%c%.2f", ch, platform->MotorCurrent(drive));
		ch = ',';
	}

	// Firmware details
	response->catf("],\"firmwareElectronics\":\"%s\"", ELECTRONICS);
	response->catf(",\"firmwareName\":\"%s\"", NAME);
	response->catf(",\"firmwareVersion\":\"%s\"", VERSION);
	response->catf(",\"firmwareDate\":\"%s\"", DATE);

	// Motor idle parameters
	response->catf(",\"idleCurrentFactor\":%.1f", platform->GetIdleCurrentFactor() * 100.0);
	response->catf(",\"idleTimeout\":%.1f", move->IdleTimeout());

	// Minimum feedrates
	response->cat(",\"minFeedrates\":");
	ch = '[';
	for (size_t drive = 0; drive < DRIVES; drive++)
	{
		response->catf("%c%.2f", ch, platform->ConfiguredInstantDv(drive));
		ch = ',';
	}

	// Maximum feedrates
	response->cat("],\"maxFeedrates\":");
	ch = '[';
	for (size_t drive = 0; drive < DRIVES; drive++)
	{
		response->catf("%c%.2f", ch, platform->MaxFeedrate(drive));
		ch = ',';
	}

	// Configuration File (whitespaces are skipped, otherwise we easily risk overflowing the response buffer)
	response->cat("],\"configFile\":\"");
	FileStore *configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false);
	if (configFile == nullptr)
	{
		response->cat("not found");
	}
	else
	{
		char c, esc;
		bool readingWhitespace = false;
		size_t bytesWritten = 0, bytesLeft = OutputBuffer::GetBytesLeft(response);
		while (configFile->Read(c) && bytesWritten + 4 < bytesLeft)		// need 4 bytes to finish this response
		{
			if (!readingWhitespace || (c != ' ' && c != '\t'))
			{
				switch (c)
				{
					case '\r':
						esc = 'r';
						break;
					case '\n':
						esc = 'n';
						break;
					case '\t':
						esc = 't';
						break;
					case '"':
						esc = '"';
						break;
					case '\\':
						esc = '\\';
						break;
					default:
						esc = 0;
						break;
				}

				if (esc)
				{
					response->catf("\\%c", esc);
					bytesWritten += 2;
				}
				else
				{
					response->cat(c);
					bytesWritten++;
				}
			}
			readingWhitespace = (c == ' ' || c == '\t');
		}
		configFile->Close();
	}
	response->cat("\"}");

	return response;
}
예제 #24
0
void Webserver::ProcessGcode(const char* gc)
{
  int8_t specialAction = 0;
  if(StringStartsWith(gc, "M30 "))
  {
	  specialAction = 1;
  }
  else if(StringStartsWith(gc, "M23 "))
  {
	  specialAction = 2;
  }
  else if(StringStartsWith(gc, "M112") && !isdigit(gc[4]))
  {
	  specialAction = 3;
  }
  else if(StringStartsWith(gc, "M503") && !isdigit(gc[4]))
  {
	  specialAction = 4;
  }
  
  if(specialAction != 0) // Delete or print a file?
  { 
    switch (specialAction)
    {
    case 1: // Delete
      reprap.GetGCodes()->DeleteFile(&gc[4]);
      break;

    case 2:	// print
      reprap.GetGCodes()->QueueFileToPrint(&gc[4]);
      break;

    case 3:
      reprap.EmergencyStop();
      break;

    case 4:
	  {
		FileStore *configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false);
		if(configFile == NULL)
		{
		  HandleReply("Configuration file not found", true);
		}
		else
		{
		  char c;
		  size_t i = 0;
		  while(i < STRING_LENGTH && configFile->Read(c))
		  {
			gcodeReply[i++] = c;
		  }
		  configFile->Close();
		  gcodeReply[i] = 0;
		  ++seq;
		}
	  }
	  break;
    }
  }
  else
  {
	  // Copy the gcode to the buffer
	  size_t len = strlen(gc) + 1;		// number of characters to copy
	  if (len > GetGcodeBufferSpace())
	  {
		  platform->Message(HOST_MESSAGE, "Webserver: GCode buffer overflow.\n");
		  HandleReply("Webserver: GCode buffer overflow", true);
	  }
	  else
	  {
		  size_t remaining = gcodeBufLength - gcodeWriteIndex;
		  if (len <= remaining)
		  {
			  memcpy(&gcodeBuffer[gcodeWriteIndex], gc, len);
		  }
		  else
		  {
			  memcpy(&gcodeBuffer[gcodeWriteIndex], gc, remaining);
			  memcpy(gcodeBuffer, gc + remaining, len - remaining);
		  }
		  gcodeWriteIndex = (gcodeWriteIndex + len) % gcodeBufLength;
	  }
  }
}
예제 #25
0
 /// Dump information about the position store to an ostream.
 /// @param[in] os ostream to receive the output; defaults to std::cout
 /// @param[in] detail integer level of detail to provide; allowed values are
 ///    0: number of satellites, time step and time limits
 ///    1: above plus flags, gap and interval values, and number of data/sat
 ///    2: above plus all the data tables
 void dumpPosition(std::ostream& os = std::cout, short detail = 0)
    const throw()
 {
    SP3Files.dump(os, detail);
    posStore.dump(os, detail);
 }