/*******************************************
 *   Copyright (C) 2008 by Mauro Rodrigues *
 *******************************************/
#include <iostream>
#include "mytime.h"
#include "rs232.h"

FILE *rs232log;

using namespace std;

int createRSlog()
{
	char buffer[25], slog[35];

	getdate(buffer);
	strcpy(slog, "rs232_");
	strcat(buffer, ".txt");
	strcat(slog, buffer);
	if((rs232log = fopen(slog, "w")) == NULL)
		return -1;

	return 0;
}

//---------------------------------------------------
// Função auxiliar de escrita num ficheiro de registo
//---------------------------------------------------
void rslog(char *pstr)
{
	char str[100], hour[10];

	if(rs232log == NULL){
		cout << "RSLOG: Null file pointer!\n";
		return;}
	if(pstr == NULL){
		cout << "RSLOG: Null string!\n";
		return;}
	gethour(hour);
	sprintf(str, "%s -\t%s", hour, pstr);
	fprintf(rs232log, str);
}

int closeRSlog()
{
	if(fclose(rs232log) == -1)
		return -1;

	return 0;
}
