Ejemplo n.º 1
0
/*
 * Handle a message received from the widget
 */
void GenericUsbProWidget::HandleMessage(uint8_t label,
                                        const uint8_t *data,
                                        unsigned int length) {
  switch (label) {
    case REPROGRAM_FIRMWARE_LABEL:
      break;
    case PARAMETERS_LABEL:
      HandleParameters(data, length);
      break;
    case RECEIVED_DMX_LABEL:
      HandleDMX(data, length);
      break;
    case DMX_CHANGED_LABEL:
      HandleDMXDiff(data, length);
      break;
    case BaseUsbProWidget::SERIAL_LABEL:
      break;
    default:
      OLA_WARN << "Unknown message type " << ola::strings::ToHex(label)
               << ", length " << length;
  }
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	char *input_file = NULL;
	char *output_file = NULL;
	int initial_direction = 0;
	int initial_depth = 0;
	int initial_ammo = 0;
	Submarine *submarine = NULL;
	//$// AlreadySeenFriends **already_seen_friends = NULL;
	AlreadySeenFriends *already_seen_friends = NULL;
	TextFileReader reader;
	SubmarineOutputWriter *output_writer = NULL;
	BOOL simulation_result = FALSE;
	ErrorCode error_code = SUCCESS;

	if (!HandleParameters(
		argc,
		argv,
		&input_file,
		&output_file,
		&initial_direction,
		&initial_depth,
		&initial_ammo
	))
	{
		LOG_ERROR("Failed to parse the cmd parameters");
		error_code = WRONG_PARAMETERS;
		goto cleanup;
	};

	LOG_INFO("Started Submarine Run with the following parameters: \r\n \
			 Input File = %s \r\n \
			 Initial Direction = %d \r\n \
			 Initial Depth = %d \r\n \
			 Initial Ammo = %d \r\n \
			 Output File = %s",
			 input_file,
			 initial_direction,
			 initial_depth,
			 initial_ammo,
			 output_file
	);

	// Create the input file reader
	reader = CreateTextFileReader(input_file);
	if (reader.IsInitialized == FALSE)
	{
		LOG_ERROR("Failed to initialize the Text Reader");
		error_code = TEXT_READER_INITIALIZATION_FAILED;
		goto cleanup;
	}

	// Create the output file writer
	output_writer = InitializeSubmarineOutputWriter(output_file);
	if (output_writer == NULL)
	{
		LOG_ERROR("Failed to initialize the Submarine Output Writer");
		error_code = SUBMARINE_OUTPUT_WRITER_FAILED;
		goto cleanup;
	}
	//Intialize already seen friends structure
	already_seen_friends = InitializeAlreadySeenFriends();
	// Initialize the Submarine
	submarine = InitializeSubmarine(
		initial_depth, 
		initial_direction, 
		initial_ammo,
		output_writer
//$//		already_seen_friends..fds
	);
	if (submarine == NULL) 
	{
		LOG_ERROR("Failed to initialize the submarine");
		error_code = SUBMARINE_INITIALIZATION_FAILED;
		goto cleanup;
	}

	simulation_result = RunSimulation(submarine, reader, already_seen_friends);
	if (!simulation_result)
	{
		LOG_ERROR("Failed during the simulation");
		error_code = SIMULATION_FAILED;
	}

cleanup:
	// Cleanup
	if (submarine != NULL)
	{
		//$//FreeSubmarine(submarine,already_seen_friends);
		FreeSubmarine(submarine);
	}
	if (already_seen_friends != NULL)
	{
		FreeAlreadySeenFriends(already_seen_friends);
	}
	if (output_writer != NULL)
	{
		CloseSubmarineOutputWriter(output_writer);
	}
	if (reader.IsInitialized != FALSE)
	{
		DeleteTextFileReader(reader);
	}

	return SUCCESS;
}