示例#1
0
TEST(misc, testGpsParser) {
	print("******************************************* testGpsParser\r\n");

	strcpy(nmeaMessage, "");
	gps_location(&GPSdata, nmeaMessage);

	// we need to pass a mutable string, not a constant because the parser would be modifying the string
	strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
	gps_location(&GPSdata, nmeaMessage);
	ASSERT_EQ( 4,  GPSdata.quality) << "1 valid";
	assertEqualsM("1 latitude", 3349.896, GPSdata.latitude);
	assertEqualsM("1 longitude", 11808.521, GPSdata.longitude);
	ASSERT_EQ( 0,  GPSdata.speed) << "1 speed";
// 	ASSERT_EQ( 0,  GPSdata.altitude) << "1 altitude";	// GPRMC not overwrite altitude
	ASSERT_EQ( 360,  GPSdata.course) << "1 course";

	strcpy(nmeaMessage, "$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70");
	gps_location(&GPSdata, nmeaMessage);
	ASSERT_EQ( 3,  GPSdata.quality) << "2 valid";		// see field details
	assertEqualsM("2 latitude", 50.0212, GPSdata.latitude);
	assertEqualsM("2 longitude", 36.2177, GPSdata.longitude);
	ASSERT_EQ( 0,  GPSdata.speed) << "2 speed";
	assertEqualsM("2 altitude", 10.2, GPSdata.altitude);
//	ASSERT_EQ( 0,  GPSdata.course) << "2 course";  // GPGGA not overwrite course

	strcpy(nmeaMessage, "$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50");
	gps_location(&GPSdata, nmeaMessage);
	ASSERT_EQ( 4,  GPSdata.quality) << "3 valid";
	assertEqualsM("3 latitude", 5001.27, GPSdata.latitude);
	assertEqualsM("3 longitude", 3613.06, GPSdata.longitude);
	assertEqualsM("3 speed", 11.2, GPSdata.speed);
//	ASSERT_EQ( 0,  GPSdata.altitude) << "3 altitude";  // GPRMC not overwrite altitude
	ASSERT_EQ( 0,  GPSdata.course) << "3 course";
	ASSERT_EQ( 2006,  GPSdata.GPStm.tm_year + 1900) << "3 GPS yy";
	ASSERT_EQ( 12,  GPSdata.GPStm.tm_mon) << "3 GPS mm";
	ASSERT_EQ( 26,  GPSdata.GPStm.tm_mday) << "3 GPS yy";
	ASSERT_EQ( 11,  GPSdata.GPStm.tm_hour) << "3 GPS hh";
	ASSERT_EQ( 16,  GPSdata.GPStm.tm_min) << "3 GPS mm";
	ASSERT_EQ( 9,  GPSdata.GPStm.tm_sec) << "3 GPS ss";

	// check again first one
	// we need to pass a mutable string, not a constant because the parser would be modifying the string
	strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
	gps_location(&GPSdata, nmeaMessage);
	ASSERT_EQ( 4,  GPSdata.quality) << "4 valid";
	assertEqualsM("4 latitude", 3349.896, GPSdata.latitude);
	assertEqualsM("4 longitude", 11808.521, GPSdata.longitude);
	ASSERT_EQ( 0,  GPSdata.speed) << "4 speed";
	ASSERT_EQ( 360,  GPSdata.course) << "4 course";
}
示例#2
0
static void onGpsMessage(char *buffer) {

    gps_location(&GPSdata, buffer);
    date_get_tm(&curTm);

    if (GPSdata.quality == 4 && GPSdata.GPStm.tm_year > 0 && GPSdata.GPStm.tm_sec != curTm.tm_sec) {
        // quality =4 (valis GxRMC), year > 0, and difference more then second
        date_set_tm(&GPSdata.GPStm);					// set GPS time
        //}
    }
    gpsMesagesCount++;
}
示例#3
0
void test_collection (void)
{
  std::cerr <<
    "************* COLLECTION: Testing container collections*************\n";

  knowledge::KnowledgeBase knowledge;
  knowledge::ThreadSafeContext & context (knowledge.get_context ());

  unsigned char buffer1[1024];
  unsigned char buffer2[2048];

  std::cerr << "  Creating containers...\n";

  containers::Integer age ("age", knowledge);
  containers::String name ("name", knowledge);
  containers::Double salary ("salary", knowledge);
  containers::NativeDoubleVector gps_location ("location.gps", knowledge, 3);
  containers::NativeIntegerVector years_employed ("employment.years", knowledge);
  containers::Map jobs ("jobs", knowledge);
  containers::BufferVector images ("images", knowledge);
  containers::StringVector movies ("movies.favorite", knowledge);
  containers::IntegerVector years ("years.favorite", knowledge);
  containers::IntegerVector sensors_ready ("sensors_ready", knowledge, 3);
  containers::DoubleVector coolfactor ("coolfactor.by.year", knowledge, 35);

  std::cerr << "  Testing modifieds.size == 2 after container creation... ";

  if (context.get_modifieds ().size () != 2)
  {
    std::cerr << "FAIL\n";
    std::cerr << "    Printing modified elements in context\n\n";
    std::cerr << context.debug_modifieds () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "  Assigning values to containers...\n";

  age = 40;
  name = "Jack Franklin";
  salary = 45000.0;
  gps_location.set (2, 1000.0);
  gps_location.set (0, 72.0);
  gps_location.set (1, 40.0);
  years_employed.set (0, 1998);
  years_employed.push_back (1999);
  years_employed.push_back (2005);
  years_employed.push_back (2007);
  years_employed.push_back (2010);
  years_employed.push_back (2011);
  years_employed.push_back (2012);
  years_employed.push_back (2013);
  years_employed.push_back (2014);
  years_employed.push_back (2015);
  jobs.set ("Albert's", "Courtesy Clerk");
  jobs.set ("Nursery House", "Plant Care Technician");
  jobs.set ("Johnson's", "Landscaping Expert");
  images.push_back (buffer1, sizeof (buffer1));
  images.push_back (buffer2, sizeof (buffer2));
  movies.push_back ("Edge of Tomorrow");
  movies.push_back ("Fight Club");
  movies.push_back ("Seven");
  movies.push_back ("Serenity");
  years.push_back (2000);
  years.push_back (2012);
  coolfactor.set (0, 10.0);
  coolfactor.set (1, 12.0);
  coolfactor.set (2, 10.5);
  coolfactor.set (3, 9);
  coolfactor.set (4, 8);
  coolfactor.set (5, 8.5);
  coolfactor.set (6, 8.5);
  coolfactor.set (7, 8.5);
  coolfactor.set (8, 8);
  coolfactor.set (9, 9);
  coolfactor.set (10, 10);
  coolfactor.set (11, 10);
  coolfactor.set (12, 11);
  coolfactor.set (13, 11);
  coolfactor.set (14, 6);
  coolfactor.set (15, 7);
  coolfactor.set (16, 20);
  coolfactor.set (17, 30);
  coolfactor.set (18, 35);
  coolfactor.set (19, 25);
  coolfactor.set (20, 20);
  coolfactor.set (21, 35);
  coolfactor.set (22, 30);
  coolfactor.set (23, 22);
  coolfactor.set (24, 18);
  coolfactor.set (25, 14);
  coolfactor.set (26, 11);
  coolfactor.set (27, 10);
  coolfactor.set (28, 9);
  coolfactor.set (29, 9);
  coolfactor.set (30, 5);
  coolfactor.set (31, 5);
  coolfactor.set (32, 4);
  coolfactor.set (33, 3);
  coolfactor.set (34, 3);
  sensors_ready.set (0, 1);
  sensors_ready.set (2, 1);

  containers::Collection collection;

  std::cerr << "\n  Adding 10 containers to collection container\n";

  collection.add (age);
  collection.add (name);
  collection.add (salary);
  collection.add (gps_location);
  collection.add (years_employed);
  collection.add (jobs);
  collection.add (images);
  collection.add (movies);
  collection.add (years);
  collection.add (coolfactor);

  std::cerr << "  Testing collection.size == 10 after adding containers... ";

  if (collection.size () != 10)
  {
    std::cerr << "FAIL. Size returned " << collection.size () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "\n  Printing Collection contents\n\n";
  std::cerr << collection.get_debug_info () << "\n";

  std::cerr << "  Printing modified elements in context\n\n";
  std::cerr << context.debug_modifieds () << "\n";

  std::cerr << "  Clearing modified elements in context\n\n";
  knowledge.clear_modifieds ();

  std::cerr << "  Testing modifieds.size == 0 after clearing modified... ";

  if (context.get_modifieds ().size () != 0)
  {
    std::cerr << "FAIL\n";
    std::cerr << "    Printing modified elements in context\n\n";
    std::cerr << context.debug_modifieds () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "  Calling modify on collection\n";
  collection.modify ();

  std::cerr << "  Testing modifieds.size == 55 after modifying containers... ";

  if (context.get_modifieds ().size () != 55)
  {
    std::cerr << "FAIL\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "  Printing modified elements in context\n\n";
  std::cerr << context.debug_modifieds () << "\n";

  std::cerr << "  Clearing modified elements in context\n\n";
  knowledge.clear_modifieds ();

  std::cerr << "  Clearing collection\n\n";
  collection.clear ();

  std::cerr << "  Testing collection.size == 0 after clearing containers... ";

  if (collection.size () != 0)
  {
    std::cerr << "FAIL. Size returned " << collection.size () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "\nAdding 3 containers to collection container\n";

  collection.add (age);
  collection.add (name);
  collection.add (salary);

  std::cerr << "  Testing collection.size == 3 after adding containers... ";

  if (collection.size () != 3)
  {
    std::cerr << "FAIL. Size returned " << collection.size () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "\nPrinting Collection contents\n\n";
  std::cerr << collection.get_debug_info () << "\n";

  std::cerr << "  Calling modify on collection\n";
  collection.modify ();

  std::cerr << "  Testing modifieds.size == 3... ";

  if (context.get_modifieds ().size () != 3)
  {
    std::cerr << "FAIL\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "  Printing modified elements in context\n\n";
  std::cerr << context.debug_modifieds () << "\n";

  std::cerr << "  Clearing modified elements in context\n\n";
  knowledge.clear_modifieds ();


  std::cerr << "  Calling modify_if_true on collection\n";
  collection.modify_if_true (sensors_ready);

  std::cerr << "  Testing modifieds.size == 0... ";

  if (context.get_modifieds ().size () != 0)
  {
    std::cerr << "FAIL\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

  std::cerr << "  Updating final sensors ready to true\n";
  sensors_ready.set (1, 1);

  std::cerr << "  Calling modify_if_true on collection\n";
  collection.modify_if_true (sensors_ready);

  std::cerr << "  Testing modifieds.size == 4... ";

  if (context.get_modifieds ().size () != 4)
  {
    std::cerr << "FAIL\n";
    std::cerr << "    Printing modified elements in context\n\n";
    std::cerr << context.debug_modifieds () << "\n";
  }
  else
  {
    std::cerr << "SUCCESS\n";
  }

}