Esempio n. 1
0
////////////////////////////////////////////////////////////
/// Initialize the application
////////////////////////////////////////////////////////////
bool ApplicationInitialize()
{
	// Initialize mutex
	MutexInitialize(&AppMutex);

	// Start it
	AppSetRun(false);

	// Platform Initialize
	#ifdef SYSTEM_MACOS
		InitializeWorkingDirectory(); // Specific in MacOS
	#endif

	if (!UsersInitialize())
		return false;

	// Initialize database
	if (!DataBaseInitialize())
		return false;

	// Initialize protocol
	if (!ProtocolInitialize(12993))
		return false;

	// Initialize console
	if (!ConsoleInitialize())
		return false;

	// Run it
	AppSetRun(true);

	return true;
}
Esempio n. 2
0
//-------------------------------------------------------------------------------------------------
// Entry point
//-------------------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
	char *String_Serial_Port_File, *String_Command, *String_Hex_File;
		
	// Check parameters
	if (argc < 3)
	{
		printf("Usage : %s Serial_Port Command [Parameters]\n"
			"Available commands :\n"
			"   -d : get the sonar distance from the nearest object\n"
			"   -v : get the battery voltage\n"
			"   -u Hex_File : update the robot firmware from an Intel Hex file\n"
			"How to update the robot firmware :\n"
			"   1) Turn the robot off\n"
			"   2) Start this program in update mode\n"
			"   3) Turn the robot on\n", argv[0]);
		return EXIT_FAILURE;
	}
	String_Serial_Port_File = argv[1];
	String_Command = argv[2];
	
	// Try to open the serial port
	if (ProtocolInitialize(String_Serial_Port_File) != 0)
	{
		printf("Error : failed to open the serial port '%s'.\n", String_Serial_Port_File);
		return EXIT_FAILURE;
	}
	
	// Select the right command
	if (strcmp(String_Command, "-d") == 0) printf("Distance to the nearest object : %d cm\n", ProtocolGetSonarDistance());
	else if (strcmp(String_Command, "-v") == 0) printf("Battery voltage : %0.3f V\n", ProtocolGetBatteryVoltage());
	else if (strcmp(String_Command, "-u") == 0)
	{
		// Get the Hex file parameter
		if (argc < 4)
		{
			printf("Error : you must provide an Hex file path with the -u command.\n");
			return EXIT_FAILURE;
		}
		String_Hex_File = argv[3];
		
		// Try to update the firmware
		if (ProtocolUpdateFirmware(String_Hex_File) != 0) return EXIT_FAILURE;
	}
	else
	{
		printf("Error : unknown command.\n");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}