Beispiel #1
0
void On_simulation_begin()
//************************
// VMLAB informs you that the simulation is starting. Initialize pin values
// here Open files; allocate memory, etc.
// The first instance to enter this function is responsible for opening the
// single log file and initializing any global data. Although the log filename
// doesn't change with each simulation, it's better to open it here and close it
// in On_simulation_end(). This allows the user to delete or move the log file
// without having to close or rebuild the project.
{
   char strBuffer[MAXBUF];

   // Force the initial value of data input to be logged at time step 0
   VAR(Log_data) = -1;

   // Keep track of how many instances have already been created
   VAR(Instance_number) = Instance_count;
   Instance_count++;
   
   // Because the VCD file format uses a single ASCII character to identify each
   // signal, it limits the number of vcdlog instances that can be used in a
   // project
   if(VAR(Instance_number) + MIN_ID > MAX_ID) {
      snprintf(strBuffer, MAXBUF, "Too many instances (max %d)",
         MAX_ID - MIN_ID + 1);
      BREAK(strBuffer);
      Close_file();
   }

   // The first instance to have its On_simulation_begin() called is responsible
   // for opening the log file and initializing global variables.
   if(Instance_count == 1) {
      Total_time = 0;

      // Setting Log_time to -1 forces the first instance entering
      // On_time_step(), to finish writing the VCD header section.
      Log_time = -1;

      // Create or overwrite log file in current directory
      File = fopen(FILE_NAME, "w");

      // We can still run if the file won't open; we just can't log anything.
      if(!File) {
         snprintf(strBuffer, MAXBUF, "Could not create \"%s\" file: %s",
            FILE_NAME, strerror(errno));
         BREAK(strBuffer);
      }
      
      // Write out the global VCD file header
      Log_printf("$version VMLAB vcdlog component $end\n");
      Log_printf("$timescale 1 %s $end\n", TIME_UNITS);
      Log_printf("$scope module vmlab $end\n");
   }

   // Write out per instance part of the VCD header that contains the variable
   // name and the ASCII identifier.
   Log_printf("$var wire 1 %c %s $end\n",
      VAR(Instance_number) + MIN_ID, GET_INSTANCE());
}
Beispiel #2
0
void
CloseLog()
{
  Log_printf("----------------------------------------------------\n");
  Log_printf("The benchmark ended: %s", get_local_timedate());
  if (logfile)
    fclose(logfile);
}
Beispiel #3
0
static bool
OBD_sendPidRequest( OBD_Mode_t mode,
                    OBD_Pid_t  pid )
{
    bool success;
    const uint8_t size = 8;

    uint8_t sreg = CRITICAL_SECTION_ENTER();

    memset( g_OBD_txDataBuffer, 0, sizeof(g_OBD_txDataBuffer) );

    g_OBD_txDataBuffer[0] = (size << 4) | (OBD_FRAME_TYPE_SINGLE);
    g_OBD_txDataBuffer[1] = mode;
    g_OBD_txDataBuffer[2] = pid;

    Log_printf( "Sending OBD request mode %u PID %u\n", mode, pid );

    success = CAN_sendStandardDataFrame( OBD_11BIT_FUNC_BCAST_ADDR,
                                         g_OBD_txDataBuffer,
                                         sizeof(g_OBD_txDataBuffer) );

    CRITICAL_SECTION_EXIT( sreg );

    return success;
}
Beispiel #4
0
int PCB_ExecuteImpFinalMig(char *param) 
{/*Lo tuve que hacer para no romper el disenio que vienen llevando, esta solo difiere con el 
print comun en que lleva un nro neg, el pcb_id *-1*/
	/* MENSAJE PRINT!!!!! */
	tSocket *pSocket;
	tPaquete *pPaq;
	int		nSend;
	unsigned char szIP[4];
	int		n = (-1)*PCB.PPCB_ID;
	
	memset( szIP, 0, 4 );
	
	ReducirIP(PCB.m_IP,szIP);
	
	Log_printf( log_info, "Se imprime: %s", param);
	
	pPaq = paquetes_newPaqPrint(szIP, (unsigned char)_PPCB_, PCB.m_Port, PCB.SessionID, PCB.ProgName, param);
	memcpy( &(pPaq->id.UnUsed), &n, sizeof(n) );/*Esta es la diferencia*/
	Log_log( log_debug, "Mando PRINT al ADP" );
	nSend = conexiones_sendBuff( PCB.m_socketADP, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
	if ( nSend != PAQUETE_MAX_TAM )
	{
		Log_logLastError( "error enviando PRINT al ADP" );
	}	
	paquetes_destruir( pPaq );
	
	/*sleep(1);*/
		
	return (nSend == PAQUETE_MAX_TAM) ? OK: ERROR;

}
Beispiel #5
0
int PCB_ExecuteDev(char *param) {
	
	tRecurso recurso;
	tSocket *pSocket;
	tPaquete *pPaq;
	int		nSend;
	unsigned char szIP[4];
	
	memset( szIP, 0, 4 );
	
	ReducirIP(PCB.m_IP,szIP);
	
	if (PCB_RecursoFromFriendlyName(&recurso, param) == ERROR)
		return;
	
	pPaq = paquetes_newPaqDev(szIP, (unsigned char)_PPCB_, PCB.m_Port, PCB.PPCB_ID, recurso);
	
	Log_printf( log_info, "Ppcb_id:%i devuelve recurso: %s",PCB.PPCB_ID, param);
	
	nSend = conexiones_sendBuff( PCB.m_socketADP, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
	if ( nSend != PAQUETE_MAX_TAM )
	{
		Log_logLastError( "error enviando DEV al ADP" );
	}	
	paquetes_destruir( pPaq );
	
	/*sleep(1);*/
	
	return 0;
}
Beispiel #6
0
int PCB_ExecuteImp(char *param) {
	/* MENSAJE PRINT!!!!! */
	tSocket *pSocket;
	tPaquete *pPaq;
	int		nSend;
	unsigned char szIP[4];
	
	memset( szIP, 0, 4 );
	
	ReducirIP(PCB.m_IP,szIP);
	
	Log_printf( log_info, "Se imprime: %s", param);
	
	pPaq = paquetes_newPaqPrint(szIP, (unsigned char)_PPCB_, PCB.m_Port, PCB.SessionID, PCB.ProgName, param);
	
	Log_log( log_debug, "Mando PRINT al ADP" );
	nSend = conexiones_sendBuff( PCB.m_socketADP, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
	if ( nSend != PAQUETE_MAX_TAM )
	{
		Log_logLastError( "error enviando PRINT al ADP" );
	}	
	paquetes_destruir( pPaq );
	
	/*sleep(1);*/
		
	return (nSend == PAQUETE_MAX_TAM) ? OK: ERROR;

}
Beispiel #7
0
void
setup( void )
{
    NVM_ResetReason_t resetReason;

    /* Assume data is invalid to begin with */
    g_sampleDataValid = false;

    WDT_init();

    LED_init();

    /* Initialize serial UART drivers */
    Serial_init();

    /* Initialize sensors */
    GPS_init();
    OBD_init();

    /* Print or initialize the reset reason */
    if ( NVM_getResetReason( &resetReason ) ) {
        /* Valid reset reason */
        if ( NVM_RESET_REASON_NORMAL != resetReason ) {
            Log_printf( "Reset Reason: 0x%02X\n", resetReason );
        }
    } else {
        /* Invalid reset reason, initialize it */
        NVM_setResetReason( NVM_RESET_REASON_NORMAL );
    }

    /* Start the watchdog timer */
    WDT_enable( WDT_TIMEOUT_MAX );
}
Beispiel #8
0
int PCB_ExecutePop(char *param) {
	char value = pop(&PCB.stack);
	Log_printf( log_info, "Se poppea: %c", value);
	
	/*sleep(1);*/
	return 0;
}
Beispiel #9
0
int PCB_ExecuteOper(char *param) {
	int cantSeg = atoi( param);
	
	Log_printf( log_info, "Se ejecuta una operacion de: %s segundos", param);
	
	PCB.tiempoRestanteOper = cantSeg;
	return 0;
}
Beispiel #10
0
int PCB_ExecutePush(char *param) {
	char value = param[0];
	
	push(&PCB.stack, value);
	Log_printf( log_info, "Se inserta en la pila: %c", value);
	/*MyStackPrint(&PCB.stack);*/
	/*sleep(1);*/
	return 0;
}
Beispiel #11
0
void
LogResult(const char *comment, int iter, bm_time bmtime)
{
  int h, min;
  float s;
  bm_time avg_time;

  bm_time2hms(bmtime, &h, &min, &s);

  Log_printf("\n%s\n\tTotal time: %i:%i:%f\n", comment, h, min, s);

  if (iter > 0)
    {
      div_time(bmtime, iter, &avg_time);
      bm_time2hms(avg_time, &h, &min, &s);
      Log_printf("\tAverage time: %i:%i:%f (%i entities)\n", h, min, s, iter);
    }
}
Beispiel #12
0
int PCB_ExecuteInstruction(int line) {
	char sentence[50];
	char instruction[5];
	int (*executer)(char *);
	int paramStart;
	
	strncpy(sentence, PCB.Code[line], 50);
	
	strncpy(instruction, sentence, 4);
	instruction[4] = '\0';
	Log_printf( log_info, "Sentencia: %s", sentence );
	Log_printf( log_info, "Comando: %s", instruction );
	
	if ( !strcmp("MEM ", instruction) ) {
		executer = PCB_ExecuteMem;	
	} else if ( !strcmp("OPER", instruction) ) {
		executer = PCB_ExecuteOper;		
	} else if ( !strcmp("SOL ", instruction) ) {
		executer = PCB_ExecuteSol;	
	} else if ( !strcmp("DEV ", instruction) ) {
		executer = PCB_ExecuteDev;	
	} else if ( !strcmp("IMP ", instruction) ) {
		executer = PCB_ExecuteImp;	
	} else if ( !strcmp("PUSH", instruction) ) {
		executer = PCB_ExecutePush;	
	} else if ( !strncmp("POP", instruction, 3) ) {
		executer = PCB_ExecutePop;	
	}  else {
		Log_log( log_error, "Comando no reconocido, checkee el script");
	}
	
	if ( sentence[3] == ' ' ) {
		paramStart = 4;
	} else if ( sentence[4] == ' ') {
		paramStart = 5;
	}
	
	executer(sentence+paramStart);
	/*SetRemainingTime(PCB_RemainingTimeExecution());*/
	
	return 0;
}
Beispiel #13
0
void
OpenLog(char *filename, int quietmode, int append)
{
  char *systeminfo;

  if (!filename && quietmode)		       /* must have log for -q */
    bm_error("open_log",
     "Illegal combination of parameters: filename==NULL && quietmode==TRUE",
	     FALSE);

  qmode = quietmode;

  if (filename)
    {
      if (append)
	logfile = fopen(filename, "a");	       /* append */
      else
	logfile = fopen(filename, "w");	       /* write */

      if (!logfile)
	{
	  sprintf(err_msg_buf, "Could not open log file: %s", filename);
	  bm_error("open_log", err_msg_buf, TRUE);
	}
    }

  if (append)
    Log_printf("\n\n\n(append)\n\n\n");
  Log_printf("Software Engineering Database Benchmark (S E B)\n");
  Log_printf("====================================================\n");
  Log_printf("The benchmark was started: %s", get_local_timedate());
  Log_printf("----------------------------------------------------\n");
  Log_printf("System information:\n");
  systeminfo = get_system_info();
  if (!systeminfo)
    Log_printf("\t(not available)\n");
  else
    Log_printf(systeminfo);
  Log_printf("----------------------------------------------------\n");
}
Beispiel #14
0
void On_simulation_end()
//**********************
// Undo here the operations done at On_simulation_begin: free memory, close
// files, etc.
{
   // Write the total elapsed simulation time at the end of the VCD file,
   // making sure to convert it to nanoseconds. Without this final "delay"
   // in the VCD file, any bit value changes in the last time step might
   // not be visible in some waveform viewers like GTKWave.
   Log_printf("#%.0lf\n", Total_time * TIME_MULT);

   // Since there is nothing else left to do here, except for closing the
   // log file, we just let the first instance to enter On_simulation_end()
   // close the file and reset the global Instance_count in preparation for
   // another simulation.
   Close_file();
   Instance_count = 0;
}
Beispiel #15
0
void PCB_ConfirmarConexion( tSocket* sockIn )
{
	char* 			tmp; 
	int 			len; 
	char 			buffer[ PAQUETE_MAX_TAM ];
	tPaquete* 		paq = NULL;
	
	Log_printf( log_debug, "%s: %d confirma conexion!", 
			conexiones_getIpRemotaDeSocket( sockIn ), 
			(int) conexiones_getPuertoRemotoDeSocket( sockIn ) );
	
		
	len = conexiones_recvBuff( sockIn, buffer, PAQUETE_MAX_TAM );
	
	if ( ERROR == len || !len)
	{
		conexiones_CerrarSocket( PCB.m_ListaSockets, sockIn, &PCB.m_ultimoSocket );
		return;
	}
	
		
	paq = paquetes_CharToPaq( buffer );

	if ( IS_ACR_PAQ( paq ) &&  IS_PAQ_PONG ( paq ) )
	{/*Si el ACR me responde pong la conexion queda establecida!*/
		Log_log( log_debug, "Conexion establecida con el ACR!" );
		sockIn->callback = &PCB_AtenderACR;
	} else 	if ( IS_ADP_PAQ( paq ) &&  IS_PAQ_PONG ( paq ) )
	{/*Si el ADP me responde pong la conexion queda establecida!*/
		Log_log( log_debug, "Conexion establecida con el ADP!" );
		sockIn->callback = &PCB_AtenderADP;
	}
	
	if ( paq ) 
		paquetes_destruir( paq );
}
Beispiel #16
0
void On_time_step(double pTime)
//*****************************
// The analysis at the given time has finished. DO NOT place further actions
// on pins (unless they are delayed). Pins values are stable at this point.
{
   LOGIC newData;

   // Do nothing if the log file could not be opened by the first instance
   if(!File) {
      return;
   }

   // Record the total elapsed simulation time for use in On_simulation_end()
   Total_time = pTime;
   
   // Since we're expecting a digital input, the input voltage should be either
   // 0, POWER(), or POWER()/2 to designate logic 0, 1, and UNKNOWN. To allow
   // for round off-errors or perhaps input passed though an analog RC filter,
   // the 0 to POWER() voltage range is divided into 3 equal sections. Input
   // voltages in the lower third are considered to be logic 0, the upper third
   // to be logic 1, and the middle third to be UNKNOWN.
   double voltage = GET_VOLTAGE(DATA);
   if(voltage < (1.0/3.0) * POWER()) {
      newData = 0;
   } else if(voltage > (2.0/3.0) * POWER()) {
      newData = 1;
   } else {
      newData = UNKNOWN;
   }

   // The first component to enter On_time_step(0) at the beginning of the
   // simulation is responsible for finishing the VCD header section.
   if(Log_time == -1 && pTime == 0) {
      Log_printf("$upscope $end\n");
      Log_printf("$enddefinitions $end\n");
      Log_time = 0;
   }
   
   // If the current state of the input pin is different from the previous
   // state in the last time step, then the new state needs to be logged
   if(newData != VAR(Log_data)) {
      char id = VAR(Instance_number) + MIN_ID;

      // If this component instance is the first to log something at the
      // current "pTime" then also write the current elapsed time to the file
      if(pTime > Log_time) {
         // The elapsed time (in seconds) is logged as an integer number of
         // nanoseconds. To avoid any floating point round off errors, the
         // fprintf() is used to round up the result to the closest integer
         // instead of using an integer cast.
         Log_printf("#%.0lf\n", pTime * TIME_MULT);
         Log_time = pTime;
      }

      // Write the new changed pin state to the log file
      if(newData == 0) {
         Log_printf("0%c\n", id);
      } else if(newData == 1) {
         Log_printf("1%c\n", id);
      } else {
         Log_printf("x%c\n", id);
      }
      
      VAR(Log_data) = newData;
   } 
}
Beispiel #17
0
/*
 *  ======== VIDDEC2FRONT_process ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* video decoders (both high and low complexity
 *  decoders are envoked using this method).
 */
XDAS_Int32 VIDDEC2FRONT_process(VIDDEC2FRONT_Handle handle,
        VIDDEC2_InArgs *inArgs, XDM_Context *context,
        VIDDEC2FRONT_OutArgs *outArgs)
{
    XDAS_Int32 retVal = VIDDEC2_EFAIL;

    VIDDEC2_InArgs refInArgs;

    /*
     * Note, we do this because someday we may allow dynamically changing
     * the global 'VISA_isChecked()' value on the fly.  If we allow that,
     * we need to ensure the value stays consistent in the context of this call.
     */
    Bool checked = VISA_isChecked();

    GT_4trace(CURTRACE, GT_ENTER, "VIDDEC2FRONT_process> "
            "Enter (handle=0x%x, inArgs=0x%x, context=0x%x, outArgs=0x%x)\n",
            handle, inArgs, context, outArgs);

    if (handle) {
        IVIDDEC2FRONT_Fxns *fxns =
            (IVIDDEC2FRONT_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        IVIDDEC2FRONT_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if (fxns && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"VIDDEC2FRONT:process",
                (Arg)handle, (Arg)0);

            if (checked) {

                /* validate inArgs with ranges. */
                if (inArgs->inputID == 0) {

                    GT_2trace(CURTRACE, GT_7CLASS,
                            "ERROR> app provided codec (0x%x) with out of range"
                            " inArgs->inputID field (0x%x)\n",
                            alg, inArgs->inputID);
                }

                /*
                 * Validate inBufs and outBufs.
                 */
//                XdmUtils_validateSparseBufDesc1(inBufs, "inBufs");
//                XdmUtils_validateSparseBufDesc(outBufs, "outBufs");

                /*
                 * Make a reference copy of inArgs so we can check that
                 * the codec didn't modify them during process().
                 */
                refInArgs = *inArgs;

                /* inArgs->inputID == 0 is an application error */
                if (inArgs->inputID == 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                            "ERROR> codec (0x%x) received invalid "
                            "inArgs->inputID == 0!\n", handle);
                }
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->process(alg, inArgs, context, outArgs);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only inArgs */
                if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                            "ERROR> codec (0x%x) modified read-only inArgs "
                            "struct!\n", handle);
                }
            }

        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "VIDDEC2FRONT_process> "
            "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #18
0
int PCB_Migrar(char szIp[LEN_IP], unsigned short int nPuerto)
/*	Procedimiento de MIGRACION
 * El tercer parametro es la macro SOCK_ACR o SOCK_ADP, dependiendo el caso
 */
{
	tSocket 	*pSocket;
	tPaquete 	*pPaq;
	tPaqueteArch*pPaqLargo;
	int			nSend;
	unsigned char szIP[4] = {'0','0','0','0'};
	void		(*callback)(struct sSocket*);
	char* 		tmp; 
	int 		len, cantLeido, byteLeido; 
	char 		buffer[ PAQUETE_MAX_TAM ];
	char		parteArchivo[MAX_PAQ_ARCH];
	char		strBuff[50];
	FILE		*cfgFile=NULL;
	
	Log_log(log_info,"Inicia Procedimiento de migracion");
	
	createPCBConfig();
	Log_log(log_debug,"Cree el archivo de configuracion");
	
	/*[INI]	Conexion ----------------------------------------------*/
	Log_printf(log_debug,"Intento conectarme con ip:%s,puerto:%d",szIp,nPuerto);
	
	if( PCB.nIdProcesoPadre == _ID_ADP_ ){
		callback = PCB_AtenderACR;	/*si lo creo el ADP entonces se intentara conectar con el ACR al migrar*/
	}else{
		callback = PCB_AtenderADP;
	}

	if ( !( pSocket = conexiones_ConectarHost( szIp, nPuerto,callback ) ) )
		return ERROR;
	
	if( PCB.nIdProcesoPadre == _ID_ADP_ ){
		PCB.m_socketACR = pSocket;
	}else{
		PCB.m_socketADP = pSocket;
	}

	/*PCB.m_ListaSockets[ posSocket ] = pSocket;*/
	/*TODO: Pensar que asignarle al "ultimoSocket"*/
	/*PCB.m_ultimoSocket = SOCK_ADP; /*En todos los casos atiende a ambos sockets (creo)*/
	
	PCB.m_ListaSockets = realloc( PCB.m_ListaSockets,
			( ++PCB.m_ultimoSocket + MALLOC_SOCKS_INI ) * sizeof( tSocket* ) );

	PCB.m_ListaSockets[ PCB.m_ultimoSocket ] = pSocket;
	
	
	/*Mando el Ping*/
	Log_log( log_debug, "envio Ping para conectarme" );
	
	if ( !(pPaq  = paquetes_newPaqPing(szIP, _ID_PPCB_, conexiones_getPuertoLocalDeSocket(pSocket) )) )
		return ERROR;
	
	memcpy(pPaq->msg,&PCB.PPCB_ID, sizeof(long)); /* Se le agrega el ID del PCB al mensaje del ping hacia el ACR, no queremos hacer otro paquete */
	
	nSend = conexiones_sendBuff( pSocket, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
	
	if(pPaq)
		paquetes_destruir(pPaq);
	/*[FIN]	Conexion*/
	Log_log(log_debug,"Conexion exitosa");

	/*[INI] Confirmacion ----------------------------------------------*/
	len = conexiones_recvBuff( pSocket, buffer, PAQUETE_MAX_TAM );
	
	if ( ERROR == len || !len)
	{
		conexiones_CerrarSocket( PCB.m_ListaSockets, pSocket, &PCB.m_ultimoSocket );
		return ERROR;
	}
	
	pPaq = paquetes_CharToPaq( buffer );

	if ( IS_ACR_PAQ( pPaq ) &&  IS_PAQ_PONG ( pPaq ) )
	{/*Si el ACR me responde pong la conexion queda establecida!*/
		Log_log( log_debug, "Conexion establecida con el ACR!" );
		pSocket->callback = &PCB_AtenderACR;
	} else 	if ( IS_ADP_PAQ( pPaq ) &&  IS_PAQ_PONG ( pPaq ) )
	{/*Si el ADP me responde pong la conexion queda establecida!*/
		Log_log( log_debug, "Conexion establecida con el ADP!" );
		pSocket->callback = &PCB_AtenderADP;
	}
	
	if ( pPaq ) 
		paquetes_destruir( pPaq );
	/*[FIN] Confirmacion*/
	Log_log(log_debug,"Confirmacion exitosa");
	
	/*[INI] PAQ_MIGRAR ----------------------------------------------*/
	if ( !(pPaq  = paquetes_newPaqMigrar(szIP, _ID_PPCB_,
						conexiones_getPuertoLocalDeSocket(pSocket), PCB.PPCB_ID )) )
		return ERROR;
	
	nSend = conexiones_sendBuff( pSocket, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
	if(nSend == 0 || nSend == ERROR )
		Log_log(log_error,"Error al enviar PAQ_MIGRAR");
	
	if ( pPaq ) 
		paquetes_destruir( pPaq );
	/*[FIN] PAQ_MIGRAR*/
	Log_log(log_debug,"Aviso migracion exitosa");
	
	/*[INI] PAQ_ARCHIVO ----------------------------------------------*/
	
	sprintf(strBuff, "config.ppcb%ld", PCB.PPCB_ID);
	if( !(cfgFile = fopen(strBuff, "rb")) ){
		Log_logLastError("Abriendo archivo config");
		return ERROR;
	}
	cantLeido = 0;
	while( (byteLeido = fgetc(cfgFile)) != EOF ){
		
		if( byteLeido != '\r' )
			parteArchivo[cantLeido++] = (char)byteLeido;
		
		if( cantLeido % MAX_PAQ_ARCH == 0 ){
			
			if( PCB_EnviarArchivo(parteArchivo,pSocket) == ERROR ){
				fclose(cfgFile);
				return ERROR;
			}
			bzero(parteArchivo,sizeof(parteArchivo));
			cantLeido = 0;
		}
	}
	
	if( cantLeido > MAX_PAQ_ARCH ){
		Log_log(log_error,"Error se leyo mas del maximo");
	}else if( cantLeido > 0 ){
		while( cantLeido < MAX_PAQ_ARCH )
			parteArchivo[cantLeido++] = '\0';	/*Completo con NULL*/
	}
	
	if( PCB_EnviarArchivo(parteArchivo,pSocket) == ERROR ){
		fclose(cfgFile);
		return ERROR;
	}
	fclose(cfgFile);
	/*[FIN] PAQ_ARCHIVO*/
	Log_log(log_debug,"Envio archivo exitoso");
	
	/*[INI] PAQ_FIN_MIGRAR ----------------------------------------------*/
	if( PCB_EnviarFinMigrar(pSocket) == ERROR ){
		return ERROR;
	}
	/*[FIN] PAQ_FIN_MIGRAR*/
	Log_log(log_debug,"Envio fin migracion exitoso");
	
	return OK;
}
Beispiel #19
0
void main()
{
    INT8U i=0;
    INT8U search_temp = 0x06;							 // search_temp 可以增加到6 在search_temp小于3的时候 开始发送广播唤醒
    
    CpuInit();
    POWER_UP_RESET_CC1100();
    halRfWriteRfSettings();
    halSpiWriteBurstReg(CCxxx0_PATABLE, PaTabel, 8);
		CC1101_Setwor();
    G_IT_ON;															// 开启单片机全局中断

    Usart_printf(&g_module_id.Sn[0],1);
    Usart_printf(&g_module_id.Sn[1],1);
    Usart_printf(&g_gateway.Sn[0],1);
    Usart_printf(&g_gateway.Sn[1],1);
    Log_printf("   ");

		
		// 上电设置网关
    // 只有外部中断没有打开,现在进行设置网关字节 地址和网管不能为全0xFFFF
    while( ( 0xFFFF == g_gateway.Sn_temp ) || ( 0xFFFF == g_module_id.Sn_temp ) )
    {
    	LED_D4 = ~LED_D4;
    	delay(50000);
    	if( 0x55 == g_rx_flag )
    	{
  			g_rx_flag = 0x00;

				// 将网关数据写入
				IapProgramByte(GATEWAY_ADDRESS,TxBuf[1]);
				IapProgramByte(GATEWAY_ADDRESS+1,TxBuf[2]);
				//g_gateway.Sn_temp = IapReadByte(GATEWAY_ADDRESS);

				// 将地址数据写入
				IapProgramByte(MODEL_SN_ADDRESS,TxBuf[3]);
				IapProgramByte(MODEL_SN_ADDRESS+1,TxBuf[4]);
				//g_module_id.Sn_temp = IapReadByte(MODEL_SN_ADDRESS);
				Log_printf("GATEWAY OK\n");
				Log_printf("MODEL_SN OK\n");
				LED_D4 = 0;
				// 读取设置数据
    		IapReadModelSn(MODEL_SN_ADDRESS,&g_module_id);
    		IapReadModelSn(GATEWAY_ADDRESS,&g_gateway);
    	}
    }

    // g_module_rpl = IapReadByte(MODEL_RPL);
    // 默认模块id的路由等级1  模块ID 最高位为0 表示路由模块
    g_module_id.Sn[0] |= ( (g_module_rpl<<4) & 0x7F );
    g_pre_src = g_module_id.Sn_temp;
    Usart_printf(&g_module_id.Sn[0],1);
    Usart_printf(&g_module_id.Sn[1],1);
    Usart_printf(&g_gateway.Sn[0],1);
    Usart_printf(&g_gateway.Sn[1],1);
   	Log_printf(" initialization ok ");

    // 地址网关设置完成
    LED_D2 = ~LED_D2;
    // 读出搜索模式 首次上电为0xFF 则进行搜索
    g_search = IapReadByte(SEARCH_MODE);
		if( 0xFF == g_search )
		{
SearchMode:
	  	while( search_temp-- != 0 )
	  	{
	  		SearchData[2] = g_rid;
	  		// 网关地址
	  		SearchData[4] = g_gateway.Sn[0];
	  		SearchData[5] = g_gateway.Sn[1];
				// 源地址(模块ID)
	  		SearchData[9]  = g_module_id.Sn[0];
	  		SearchData[10] = g_module_id.Sn[1];
				// 目的地址(网关地址)
	   		SearchData[11] = g_gateway.Sn[0];
	  		SearchData[12] = g_gateway.Sn[1];   		
	  		
	  		for( i=0;i<13;i++)
	  		{
	  			SearchData[13] += SearchData[i];
	  		}    		
	  		// 进行唤醒时,只需要把路由标识滤除即可 将路由标识高字节分出一位代表是模块还是基站
	  		// 首先发送唤醒波,而后发送数据 进行路由搜索时,使用广播唤醒
	  		if( search_temp < 3 )
	  			CC1101_Wakeupcarry(WorCarry, 2,4);
	  		halRfSendPacket(SearchData, 14);
	  		g_rid++;															// 发送完成后g_rid自增
	  		//g_wor_flag = 0x55;
	  		timer = 0; 
				Timer0_Init(10);
				TIMER0_ON;	
				//g_search = 0x55;
				g_enter_rx = 0x55;
				// 存放校验和
				SearchData[13] = 0x00;
				goto EnterRx;
	  	}	
	  	g_search = 0x00;		
		}
//		else 
//		{
//			g_search = 0x00;
//		}

  	
    while (1)
    {
    	//Log_printf("Enter wor\n");
			if( 0x55 == g_wor_flag )
			{
				CC1101_Worwakeup();
				// 将接收的数据存储到RxBuf数组中
EnterRx:
				while(g_enter_rx)
					halRfRxPacket(RfRecBuf);

				// 此处进行rf数据处理
				if( 0x55 == g_rf_rx_flag )
				{
					g_rf_rx_flag = 0x00;	
					RfRouteManage(&rf_route_data);
				}
				if( 0xFF == g_search )									// 若没有搜索到路径,则跳转回搜索路径
					goto SearchMode;
			}
			
			halSpiStrobe(CCxxx0_SWORRST);					// 复位到 事件1
			halSpiStrobe(CCxxx0_SWOR);						// 启动WOR	
			INT1_ON;															// 开外部中断
			PCON |= PD_ON;												// 从掉电模式唤醒后,程序从这行开市			
			//Log_printf("Exit pd\n");
    }	
}
Beispiel #20
0
int PCB_LeerConfig()
{
	char    strConfig[20];
	char 	*tmp;
	int 	line=1, nStack=1, intValue;
	char 	strCode[10], strStack[10];
	tConfig *cfg;
	
	do
	{
		Log_printf(log_debug,"abriendo el archivo config");
		if ( !(cfg = config_Crear( "config", _ADP_ )) ) 
			break;	
	
		PCB.m_ADP_Port = config_GetVal_Int( cfg, _ADP_, "ADP_PORT" );
		
		if ( (tmp = config_GetVal( cfg, _ADP_ , "ADP_IP" ) ) )
		{
			strncpy( PCB.m_ADP_IP, tmp, LEN_IP );
		}
		config_Destroy(cfg);
		tmp = NULL;
	
		sprintf(strConfig, "config.ppcb%ld", PCB.PPCB_ID);
		
		Log_printf(log_debug,"abriendo el archivo %s",strConfig);
		if ( !(cfg = config_Crear( strConfig, _PPCB_ )) ) 
			break;
		
		
		
		if ( (tmp = config_GetVal( cfg, _PPCB_, "CREATORID" ) ) )
		{
			strncpy( PCB.User, tmp, LEN_USUARIO );
		}
		
		PCB.SessionID = config_GetVal_Int( cfg, _PPCB_, "SESIONID" );
		
		if ( (tmp = config_GetVal( cfg, _PPCB_, "COMANDO" ) ) )
		{
			strncpy( PCB.ProgName, tmp, LEN_COMANDO_EJEC );
		}
						
		sprintf(strCode, "CODE%d", line);
		
		while ( (tmp = config_GetVal( cfg, _PPCB_, strCode) ) ) {
			strncpy( PCB.Code[line-1], tmp, 50);
			
			line++;
			sprintf(strCode, "CODE%d", line);
			
		}
		PCB.ultimaSentencia = line-1;
		Log_printf(log_debug,"Config(LeerConfig): PCB.ultimaSentencia %d",PCB.ultimaSentencia);
		sscanf( PCB.Code[0], "MEM %d", &(PCB.Mem));	/*tomo la cantidad de memoria*/
		
		if ( (PCB.IP = config_GetVal_Int( cfg, _PPCB_, "IPOINTER" ) ) ){
					
		}
		
		if (!strcmp("PENDIENTE", config_GetVal( cfg, _PPCB_, "ESTADO")) ){
			PCB.State = PENDIENTE;
		} else if (!strcmp("BLOQUEADO", config_GetVal( cfg, _PPCB_, "ESTADO")) ) {
			PCB.State = BLOQUEADO;
		} else if (!strcmp("LISTO", config_GetVal( cfg, _PPCB_, "ESTADO")) ) {
			PCB.State = LISTO;
		} else if (!strcmp("EJECUTANDO", config_GetVal( cfg, _PPCB_, "ESTADO")) ) {
			PCB.State = EJECUTANDO;
		} 
		
		init(&PCB.stack);
		
		sprintf(strStack, "STACK%d", nStack);
			
		while ( (intValue = config_GetVal_Int( cfg, _PPCB_, strStack) ) ) {
			push( &PCB.stack, intValue );
				
			nStack++;
			sprintf(strStack, "STACK%d", nStack);
		
		}
		
				
		PCB.m_ACR_Port = config_GetVal_Int( cfg, _PPCB_, "PUERTO_ACR" );
		
		/*Levanto la configuracion*/
		/*if ( (tmp = config_GetVal( cfg, _MSHELL_, "PCB_IP" ) ) )
		{
			strncpy( PCB.m_IP, tmp, LEN_IP );
		}
		*/
		
		if ( (tmp = config_GetVal( cfg, _PPCB_ , "IP_ACR" ) ) )
		{
			strncpy( PCB.m_ACR_IP, tmp, LEN_IP );
		}
		
		PCB.tiempoRestanteOper = config_GetVal_Int( cfg, _PPCB_, "TMP_REST_OPER" );
		
		/*
		
		PCB.m_Port = config_GetVal_Int( cfg, _MSHELL_, "PCB_PORT" );
		*/
		/*PCB.m_nMemDisp = PCB.m_nMemMax = config_GetVal_Int( cfg, _PCB_, "MAX_MEM" );
		PCB.m_Q = config_GetVal_Int( cfg, _PCB_, "Q" );
		PCB.m_nLimite1 = config_GetVal_Int( cfg, _PCB_, "L1" );
		PCB.m_nLimite2 = config_GetVal_Int( cfg, _PCB_, "L2" );
		*/
		
		
		config_Destroy(cfg);
		
		/* PARA PRUEBA */
		/*PCB_ExecuteProgram();*/
		return OK;
		
	}while(0);
	
	return ERROR;
}
Beispiel #21
0
void PCB_AtenderADP ( tSocket *sockIn )
/**/
{
	int 			len; 
	tPaquete* 		paq ; 
	char 			*tmp;
	char			buffer [ PAQUETE_MAX_TAM ]; 
	tIDMensaje		idMsj;
	float 			fCargaProm = 0;
	int 			CantPCB = 0;
	char*			buffPaq;
	int				nSend;
	unsigned char	szIP[4] = {'\0','\0','\0','\0'};


	len = conexiones_recvBuff(sockIn, buffer, PAQUETE_MAX_TAM);
	
	if ( ERROR == len || !len)
	{
		Log_log( log_debug, "Se cae conexion con ADP" );
		PCB_CerrarConexion( sockIn );
		if( PCB.State == EJECUTANDO ) PCB.State = LISTO;  /*Evito que siga ejecutando en el ACR*/
		PCB_Migrar(PCB.m_ACR_IP,PCB.m_ACR_Port);	/*Migra al ACR*/
		return;
	}
	
	paq = paquetes_CharToPaq(buffer);

	if ( IS_PAQ_MIGRAR_OK( paq ) )
	{/*La migracion concluyo con exito*/
		
		Log_log( log_info, "el ADP me manda un PAQ_MIGRAR_OK" );
		paq->id.id_Proceso = _ID_PPCB_;
		nSend = conexiones_sendBuff( PCB.m_socketACR, 
					(const char*) paquetes_PaqToChar( paq ), PAQUETE_MAX_TAM );
		if(nSend == 0 || nSend == ERROR )
			Log_log(log_error,"Error al enviar PAQ_MIGRAR_OK");
			 
	} else if( IS_PAQ_MIGRAR_FAULT(paq) ){

		Log_log( log_info, "el ADP me manda un PAQ_MIGRAR_FAULT" );
		paq->id.id_Proceso = _ID_PPCB_;
		nSend = conexiones_sendBuff( PCB.m_socketACR, 
					(const char*) paquetes_PaqToChar( paq ), PAQUETE_MAX_TAM );
		if(nSend == 0 || nSend == ERROR )
			Log_log(log_error,"Error al enviar PAQ_MIGRAR_FAULT");		 
		
	} else  if( IS_PAQ_SUSPEND_PCB(paq) ){
		
		Log_log(log_info, "Se suspende la ejecucion del PPCB");
		PCB.State = LISTO;
		
	}else if ( IS_PAQ_EXEC_PCB(paq) ){
		if( PCB.State == LISTO ){
			Log_log(log_info, "Se reanuda la Ejecucion del PPCB");
			PCB.State = EJECUTANDO;
		}else{
			Log_log(log_info, "Se intento reanudar la Ejecucion del PPCB pero no tiene estado LISTO");
		}
	}else if (IS_PAQ_GET_REMAINING_TIME_EXECUTION(paq)){
		tPaquete *pPaq;
		int		nSend;
		unsigned char szIP[4];
		int tiempoRestante;
		
		memset( szIP, 0, 4 );
		
		if (ReducirIP(PCB.m_IP,szIP) == ERROR)
			return;
		if ((tiempoRestante = PCB_RemainingTimeExecution()) == ERROR)
			return;
		
		Log_log( log_info, "Enviando el tiempo restante de ejecucion al ADP");
		
		pPaq = paquetes_newPaqInfoRemainingTimeExecution(szIP, (unsigned char)_PPCB_, PCB.m_Port, PCB.PPCB_ID, tiempoRestante );
		nSend = conexiones_sendBuff( PCB.m_socketADP, (const char*) paquetes_PaqToChar( pPaq ), PAQUETE_MAX_TAM );
		if ( nSend != PAQUETE_MAX_TAM )
		{
			Log_logLastError( "Error enviando INFO_REMAINING_TIME_EXECUTION al ADP" );
		}	
		paquetes_destruir( pPaq );
	}else if (IS_PAQ_SOL_CONCEDIDO(paq)){
		int id;
		memcpy( &id, &(paq->msg[SOLDEV_POS_PPCBID]), sizeof( int ) );
		Log_printf(log_info, "se concedio la solicitud al ppcb_id %d",id);
		PCB.State = LISTO;
	} else {
		Log_log(log_warning,"recibo en atenderADP un mensaje que no reconozco");
	}
	if ( paq ) 
		paquetes_destruir( paq );
	
}
Beispiel #22
0
/*
 *  ======== SPHENC_process ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* speech encoders (both high and low complexity
 *  encoders are invoked using this method).
 */
XDAS_Int32 SPHENC_process(SPHENC_Handle handle, XDM_BufDesc *inBufs,
        XDM_BufDesc *outBufs, ISPHENC_InArgs *inArgs, ISPHENC_OutArgs *outArgs)
{
    XDAS_Int32 retVal = SPHENC_EFAIL;

    SPHENC_InArgs refInArgs;

    /*
     * Note, we assign "VISA_isChecked()" results to a local variable
     * rather than repeatedly query it throughout this fxn because
     * someday we may allow dynamically changing the global
     * 'VISA_isChecked()' value on the fly.  If we allow that, we need
     * to ensure the value stays consistent in the context of this
     * call.
     */
    Bool checked = VISA_isChecked();

    if (checked) {
        /* Ensure inArgs and outArgs are non-NULL, per the XDM spec */

        if ((!(XdmUtils_validateExtendedStruct(inArgs, sizeof(*inArgs),
                "inArgs"))) || (!(XdmUtils_validateExtendedStruct(outArgs,
                sizeof(*outArgs), "outArgs")))) {
            /* for safety, return here before dereferencing and crashing */
            return (retVal);
        }
    }

    GT_5trace(CURTRACE, GT_ENTER, "SPHENC_process> "
        "Enter (handle=0x%x, inBufs=0x%x, outBufs=0x%x, inArgs=0x%x, "
        "outArgs=0x%x)\n", handle, inBufs, outBufs, inArgs, outArgs);

    if (handle) {
        ISPHENC_Fxns *fxns =
            (ISPHENC_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        ISPHENC_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if ((fxns != NULL) && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"SPHENC:process",
                (Arg)handle, (Arg)0);

            if (checked) {
                /*
                 * Zero out the outArgs struct (except for .size field);
                 * it's write-only to the codec, so the app shouldn't pass
                 * values through it, nor should the codec expect to
                 * receive values through it.
                 */
                memset((void *)((XDAS_Int32)(outArgs) + sizeof(outArgs->size)),
                    0, (sizeof(*outArgs) - sizeof(outArgs->size)));

                /*
                 * Make a reference copy of inArgs so we can check that
                 * the codec didn't modify them during process().
                 */
                refInArgs = *inArgs;
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->process(alg, inBufs, outBufs, inArgs, outArgs);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only inArgs */
                if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only inArgs "
                        "struct!\n", handle);
                }
            }

        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "SPHENC_process> "
        "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #23
0
int createPCB(char *argv[]) {

	FILE *cfgCode;
	int line=0;
	char strBuff[200];
		
	do {
		/*
		%PPCB%
		<ID>=1
		<CREATORID>=Gonzalo
		<CODE1>=MEM 10
		<CODE2>SOL Impresora
		<CODE3>OPER 15
		<CODE4>DEV Impresora
		<CODE5>IMP Ya Imprimi!!!
		…
		
		<IPOINTER>=2
		<ESTADO>=PENDIENTE
		<STACK1>=A
		<STACK2>=b
		<STACK3>=15
		…
		<IP_ACR>=127.0.0.1
		<PUERTO_ACR>=9000
		
		*/
		
		strcpy( PCB.ProgramPath, argv[7] );
		
		sprintf(strBuff, "%s/%s", PCB.ProgramPath, argv[3] );
		cfgCode = fopen(strBuff, "r+");
		
		strcpy( PCB.User, argv[2] );
		
		strcpy( PCB.ProgName, argv[3] );
		
		PCB.SessionID = atoi (argv[4]);
		
		bzero(strBuff,sizeof(strBuff));
		while (!feof(cfgCode) && fgets(strBuff, 200, cfgCode)) {
			strncpy(PCB.Code[line], strBuff,49 );
			PCB.Code[line][49]='\0';
			line++;
		}
		PCB.ultimaSentencia = line;
		Log_printf(log_debug,"Config(createPPCB): PCB.ultimaSentencia %d",PCB.ultimaSentencia);
		sscanf( PCB.Code[0], "MEM %d", &(PCB.Mem));	/*tomo la cantidad de memoria requerida*/
		
		PCB.IP = 0;
		
		PCB.State = PENDIENTE;
		
		strncpy( PCB.m_ACR_IP, argv[5], LEN_IP );
		
		PCB.m_ACR_Port = atoi(argv[6]);
		
		fclose(cfgCode);
		/* PARA PRUEBA */
		/*PCB_ExecuteProgram();*/
		return OK;
		
	} while (0);
	
	return ERROR;
}
Beispiel #24
0
int PCB_ExecuteMem(char *param) {
	PCB.Mem = atoi(param);
	Log_printf( log_info, "Se solicita Memoria: %s", param);
	
	return 0;
}
Beispiel #25
0
/*
 *  ======== SPHENC_control ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* speech encoders (both high and low complexity
 *  encoders are envoked using this method).
 */
XDAS_Int32 SPHENC_control(SPHENC_Handle handle, ISPHENC_Cmd id,
        ISPHENC_DynamicParams *dynParams, ISPHENC_Status *status)
{
    XDAS_Int32 retVal = SPHENC_EFAIL;

    SPHENC_DynamicParams refDynParams;
    XDAS_Int32 refStatusSize;

    /*
     * Note, we assign "VISA_isChecked()" results to a local variable
     * rather than repeatedly query it throughout this fxn because
     * someday we may allow dynamically changing the global
     * 'VISA_isChecked()' value on the fly.  If we allow that, we need
     * to ensure the value stays consistent in the context of this
     * call.
     */
    Bool checked = VISA_isChecked();

    if (checked) {
        /* Ensure dynParams and status are non-NULL, per the XDM spec */

        if ((!(XdmUtils_validateExtendedStruct(dynParams, sizeof(*dynParams),
                "dynParams"))) || (!(XdmUtils_validateExtendedStruct(status,
                sizeof(*status), "status")))) {
            /* for safety, return here before dereferencing and crashing */
            return (retVal);
        }
    }

    GT_6trace(CURTRACE, GT_ENTER, "SPHENC_control> "
        "Enter (handle=0x%x, id=%d, dynParams=0x%x (size=0x%x), "
        "status=0x%x (size=0x%x)\n",
        handle, id, dynParams, dynParams->size, status, status->size);

    if (handle) {
        ISPHENC_Fxns *fxns =
            (ISPHENC_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        ISPHENC_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if ((fxns != NULL) && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"SPHENC:control",
                (Arg)handle, (Arg)0);

            if (checked) {

                /*
                 * Make a reference copy of dynParams, status->size, and
                 * status->data.bufSize so we can check that the codec
                 * didn't modify these read-only fields during control().
                 */
                refDynParams = *dynParams;
                refStatusSize = status->size;
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->control(alg, id, dynParams, status);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only dynParams */
                if (memcmp(&refDynParams, dynParams, sizeof(*dynParams)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only dynParams "
                        "struct!\n", handle);
                }

                /* ensure the codec didn't change status->size */
                if (status->size != refStatusSize) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only status->size "
                        "field!\n", handle);
                }
            }
        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "SPHENC_control> "
        "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #26
0
int createPCBConfig() {

	FILE *cfgFile;
	tConfig *cfg;
	int line=0;
	char strBuff[50];
	char strVal[10];
		
	do {
		/*
		%PPCB%
		<ID>=1
		<CREATORID>=Gonzalo
		<CODE1>=MEM 10
		<CODE2>SOL Impresora
		<CODE3>OPER 15
		<CODE4>DEV Impresora
		<CODE5>IMP Ya Imprimi!!!
		…
		
		<IPOINTER>=2
		<ESTADO>=PENDIENTE
		<STACK1>=A
		<STACK2>=b
		<STACK3>=15
		…
		<IP_ACR>=127.0.0.1
		<PUERTO_ACR>=9000
		
		*/
		
		sprintf(strBuff, "config.ppcb%ld", PCB.PPCB_ID);
		
		if( ExistPath(strBuff) != ERROR && PCB.argc == 3 )
		{	/*existe el archivo*/
		
			if ( !(cfg = config_Crear( strBuff, _PPCB_ )) ) 
				break;	
			
			bzero(strVal,sizeof(strVal));

			sprintf(strVal,"%d",PCB.IP);
			config_SetVal(cfg,_PPCB_,"IPOINTER",strVal);
			
			sprintf(strVal,"%d",PCB.tiempoRestanteOper);
			config_SetVal(cfg,_PPCB_,"TMP_REST_OPER",strVal);
			
			if( PCB.State == PENDIENTE ) 
				config_SetVal(cfg,_PPCB_,"ESTADO","PENDIENTE");
			else if( PCB.State == BLOQUEADO )
				config_SetVal(cfg,_PPCB_,"ESTADO","BLOQUEADO");
			else if( PCB.State == EJECUTANDO )
				config_SetVal(cfg,_PPCB_,"ESTADO","EJECUTANDO");
			else if( PCB.State == LISTO )
				config_SetVal(cfg,_PPCB_,"ESTADO","LISTO");
			
			sprintf(strVal,"%d",PCB_RemainingTimeExecution());
			config_SetVal(cfg,_PPCB_,"TMP_REST",strVal);
			
			config_Guardar(cfg,strBuff);
			
			config_Destroy(cfg);
			
		}else
		{	/*No existe el archivo*/
			cfgFile = fopen(strBuff, "w+");
			
			fprintf(cfgFile, "%PPCB%\n");
			fprintf(cfgFile, "<ID>=%ld\n", PCB.PPCB_ID);
			fprintf(cfgFile, "<CREATORID>=%s\n", PCB.User);
			fprintf(cfgFile, "<COMANDO>=%s\n",  PCB.ProgName);
			fprintf(cfgFile, "<SESIONID>=%d\n", PCB.SessionID);
			
			Log_printf(log_debug,"Config(createConfig): PCB.ultimaSentencia %d",PCB.ultimaSentencia);
			while( line < PCB.ultimaSentencia ) {
				fprintf(cfgFile, "<CODE%d>=%s", line+1, PCB.Code[line]);
				line++;
			}
			
			fprintf(cfgFile, "\n<IPOINTER>=%d\n", PCB.IP);
			
			if( PCB.State == PENDIENTE ) 
				fprintf(cfgFile, "<ESTADO>=%s\n", "PENDIENTE");
			else if( PCB.State == BLOQUEADO )
				fprintf(cfgFile, "<ESTADO>=%s\n", "BLOQUEADO");
			else if( PCB.State == EJECUTANDO )
				fprintf(cfgFile, "<ESTADO>=%s\n", "EJECUTANDO");		
			else if( PCB.State == LISTO )
				fprintf(cfgFile, "<ESTADO>=%s\n", "LISTO");		
			
			fprintf(cfgFile,"<IP_ACR>=%s\n",  PCB.m_ACR_IP);
			
			fprintf(cfgFile,"<PUERTO_ACR>=%d\n", PCB.m_ACR_Port);
			
			fprintf(cfgFile,"<TMP_REST_OPER>=%d\n", PCB.tiempoRestanteOper);
			
			fprintf(cfgFile, "<TMP_REST>=%d\n", PCB_RemainingTimeExecution());
			
			fclose(cfgFile);
		}
		
		return OK;
		
	} while (0);
	
	return ERROR;
}