コード例 #1
0
ファイル: src-tcpss.c プロジェクト: Manu-31/ndes
/**
 * @brief Build a segment and notify the destination
 * @param src is a pointer to the source
 */
void srcTCPss_sendSegment(struct srcTCPSS_t * src)
{
   int segmentSize; 
   struct PDU_t * segment;

   // Send no more than available and MSS
   segmentSize = min(src->backlog, src->MSS);

   if (segmentSize > 0) {
      printf_debug(DEBUG_SRC, "Will send a segment of %d bytes (out of %d remaining)\n", segmentSize, src->backlog);

      src->backlog -= segmentSize;

      // We need to build this new segment
      segment = PDU_create(segmentSize, NULL);

      // We insert it in the outputQueue 
      filePDU_insert(src->outputQueue, segment);

      printf_debug(DEBUG_SRC, "Segment in the queue, notifying the destination\n");

      // Now we notify the destination 
      src->destProcessPDU(src->destination, srcTCPss_getPDU, src);
   }
}
コード例 #2
0
ファイル: opcode_table.cpp プロジェクト: Eltamih/uvudec
void UVDDisasmOpcodeLookupTable::usedStats(void)
{
	int i = 0;
	int used = 0;
	int unused = 0;
	
	for( i = 0; i < 256; ++i )
	{
		std::string sOp = "non-encoding";
		if( m_lookupTable[i] )
		{
			sOp = m_lookupTable[i]->getHumanReadableUsage();
		}
		
		printf_debug("hits[0x%.2X] (%s): %d\n", i, sOp.c_str(), m_lookupTableHits[i]);
		if( m_lookupTableHits[i] )
		{
			++used;
		}
		else
		{
			++unused;
		}
	}
	printf_debug("Used opcodes: %d, unused opcodes: %d\n", used, unused);
}
コード例 #3
0
ファイル: srv-gen.c プロジェクト: Manu-31/ndes
/*
 * Fin de traitement d'une PDU
 */
void srvGen_terminateProcess(struct srvGen_t * srv)
{
   struct PDU_t * pdu;

   srv->srvState = srvStateIdle;

   printf_debug(DEBUG_SRV, " end of service\n");

   if (srv->serviceProbe) {
      probe_sample(srv->serviceProbe, motSim_getCurrentTime() - srv->serviceStartTime);
   }

   // On propose la PDU à la destination
   (void)srv->destProcessPDU(srv->destination, srvGen_getPDU, srv);

   // On va chercher la prochaine s'il y en a une
   // WARNING : et s'il y en a deux ?
   if (srv->source) {
      printf_debug(DEBUG_SRV, " looking for a new PDU\n");
      pdu = srv->getPDU(srv->source);
      // Est-elle encore prete ?
      if (pdu) {
         ndesLog_logLineF(PDU_getObject(pdu), "IN %d", srvGen_getObjectId(srv));
         srvGen_startService(srv, pdu);
      } else { // Si elle ne l'est plus, inutile d'y revenir pour le moment
         srv->source = NULL; 
      }
   }
}
コード例 #4
0
ファイル: opcode_table.cpp プロジェクト: Eltamih/uvudec
/*
Opcodes are not allowed here as opposed to uvd_parse_syntax
This function also recursivly calls itself to handle function arguments
*/
uv_err_t UVDDisasmOpcodeLookupTable::uvd_parse_syntax_operand(UVDDisasmOperandShared **op_shared_in, const std::string cur)
{
	uv_err_t rc = UV_ERR_GENERAL;
	UVDConfigValue parsed_type;


	if( !op_shared_in )
	{
		UV_ERR(rc);
		goto error;
	}
	
	/* The bulk of the work is done here as data is identified */
	printf_debug("Parse syntax operand, parsing type: %s\n", cur.c_str());
	if( UV_FAILED(UVDConfigValue::parseType(cur, &parsed_type)) )
	{
		UV_ERR(rc);
		goto error;
	}
	
	printf_debug("Parse syntax operand, converting to operand struct: %s\n", cur.c_str());
	if( UV_FAILED(UVDDisasmOperandShared::uvd_parsed2opshared(&parsed_type, op_shared_in)) )
	{
		UV_ERR(rc);
		goto error;
	}
	rc = UV_ERR_OK;
	
error:
	return UV_DEBUG(rc);
}
コード例 #5
0
ファイル: src-tcpss.c プロジェクト: Manu-31/ndes
/**
 * @brief get a PDU from a source
 * @param s is a pointer to the source
 * @result A PDU if available or NULL
 */
struct PDU_t * srcTCPss_getPDU(void * s)
{
   struct srcTCPSS_t * src = (struct srcTCPSS_t *) s;
   struct PDU_t * result = NULL;

   printf_debug(DEBUG_SRC, "IN\n");

  // If a PDU is available, we send it and (slow start) schedule 2 new
  // PDUs, if available
  if (filePDU_length(src->outputQueue) > 0) {
     printf_debug(DEBUG_SRC, "scheduling two more segments\n");
     motSim_scheduleNewEvent(srcTCPss_send2Segments, src, motSim_getCurrentTime() + src->RTT);
     result = filePDU_extract(src->outputQueue);
     src->nbSentSegments++;
     printf_debug(DEBUG_SRC, "returning a segment (nb %d)\n", src->nbSentSegments);
     if (srcTCPss_isEmpty(src)) {
        printf_debug(DEBUG_SRC, "(last for now)\n");
        // This is the end of the transmission, we need to save window
        // size for the next transmission, if any
        src->windowSize += src->nbSentSegments;
        src->nbSentSegments = 0;

        // Run any event in the list, if any.
        // WARNING : this this the EOT, not the end of reception !
        // You may need to wait for an extra RTT ...
        eventList_runList(src->EOTEventList);
     }
     return result; 
  } else { // Should not occur ...
     printf_debug(DEBUG_SRC, "OUT\n");
     return NULL;
  }
}
コード例 #6
0
ファイル: data.cpp プロジェクト: Eltamih/uvudec
void UVDData::hexdump()
{
	uint32_t dataSize = 0;
	char *buffer = NULL;
	
	if( UV_FAILED(size(&dataSize)) )
	{
		printf_debug("Could not read data size\n"); 
		return;
	}
	
	if( UV_FAILED(readData(&buffer) ) )
	{
		printf_debug("Could not read data\n"); 
		return;
	}
	
	if( !buffer )
	{
		printf_debug("No data");
		return;
	}
	
	//::hexdump(buffer, dataSize);
	free(buffer);
}
コード例 #7
0
/*
 * Try to load CA certificates from supplied files and/or directories.
 */
int X509_store_add_certs_from_files_and_dirs(SSL_CTX *ssl_ctx,
    const char **fname_p, const char **dirname_p)
{
	struct stat s;
	unsigned long err;
	int ret = -1;

	assert(ssl_ctx != NULL);

	if (fname_p != NULL) {
		while (*fname_p != NULL) {
			if ((stat(*fname_p, &s) == 0) &&
			   (s.st_mode & S_IFREG)) {
				/* Is file. */
				if (SSL_CTX_load_verify_locations(ssl_ctx,
				        *fname_p, NULL) == 0) {
					err = ERR_get_error();
					printf_debug(DEBUG_PREFIX_CERT,
					    "Cannot load certificate file "
					    "'%s'. Error: %s.\n", *fname_p,
					    ERR_error_string(err, NULL));
				}
				ret = 0; /* At least one success. */
			} else {
				printf_debug(DEBUG_PREFIX_CERT,
				    "'%s' is not a file.\n", *fname_p);
			}

			++fname_p;
		}
	}

	if (dirname_p != NULL) {
		while (*dirname_p != NULL) {
			if ((stat(*dirname_p, &s) == 0) &&
			   (s.st_mode & S_IFDIR)) {
				/* Is directory. */
				if (SSL_CTX_load_verify_locations(ssl_ctx,
				        NULL, *dirname_p) == 0) {
					err = ERR_get_error();
					printf_debug(DEBUG_PREFIX_CERT,
					    "Cannot load certificate "
					    "directory '%s'. Error: %s.\n",
					    *dirname_p,
					    ERR_error_string(err, NULL));
				}
				ret = 0; /* At least one success. */
			} else {
				printf_debug(DEBUG_PREFIX_CERT,
				    "'%s' is not a directory.\n", *dirname_p);
			}

			++dirname_p;
		}
	}

	return ret;
}
コード例 #8
0
ファイル: opcode_table.cpp プロジェクト: Eltamih/uvudec
/* 
Syntax
How the instruction looks during assembly
-Should not 
	-imply anything about how much actual space they use
	-Have opcodes
-Should
	-Have immediates
		-Must have name matching USAGE, as such will have size implied
		-Does not imply size because it is possible for examle to have ADD 0x10 be a single opcode
	-Have registers
	-Have memory usage
	-Not have to be in the same order as the USAGE
	-Setup operand structures as all of them appear during syntax
SYNTAX=RAM_INT(u8_0),u8_1
*/
uv_err_t UVDDisasmOpcodeLookupTable::uvd_parse_syntax(UVDDisasmInstructionShared *inst_shared, const std::string value_syntax)
{
	uv_err_t rc = UV_ERR_GENERAL;
	std::vector<std::string> syntaxParts;
	
	
	if( !inst_shared )
	{
		UV_ERR(rc);
		goto error;
	}
	
	/* Occasionally we may have no syntax */
	if( value_syntax.empty() )
	{
		inst_shared->m_operands.clear();
		rc = UV_ERR_OK;
		goto error;	
	}

	uv_assert_err_ret(getArguments(value_syntax, syntaxParts));
						
	/* Collect immediates and operands */
	for( std::vector<std::string>::size_type syntaxPartsIndex = 0; syntaxPartsIndex < syntaxParts.size(); ++syntaxPartsIndex )
	{
		UVDConfigValue parsed_type;
		std::string cur;

		cur = syntaxParts[syntaxPartsIndex];
		printf_debug("Current syntax part: %s\n", cur.c_str());
		if( UV_FAILED(UVDConfigValue::parseType(cur, &parsed_type)) )
		{
			UV_ERR(rc);
			goto error;
		} 
		//uv_assert(parsed_type);
		printf_debug("Current syntax part, post parse: %s\n", cur.c_str());

		UVDDisasmOperandShared *op_shared = NULL;

		if( UV_FAILED(uvd_parse_syntax_operand(&op_shared, cur)) )
		{
			UV_ERR(rc);
			goto error;
		}

		//Why would it be okay for this to be null?
		//Are there some non-encoding syntax parts?
		//Why not error instead?
		uv_assert(op_shared);
		inst_shared->m_operands.push_back(op_shared);
	}
	rc = UV_ERR_OK;
	
error:
	return UV_DEBUG(rc);
}
コード例 #9
0
ファイル: cpap.c プロジェクト: hawkhsieh/sigbox
int openCPAPDevice( void )
{
    int uartIndex;
    int io_descriptor;
    pthread_t threadTestUART[TEST_UART_NUMBER];

    if ( cpap_global.uart_fd != -1 )
    {
        printf_debug("close uart set fd:%d to -1\n" , cpap_global.uart_fd );
        close( cpap_global.uart_fd );
    }

    cpap_global.uart_fd=-1;

    for ( uartIndex=0 ; uartIndex<TEST_UART_NUMBER ; uartIndex++ )
    {
        threadTestUART[uartIndex] = -1;
        char *deviceName = cpap_global.uart_id[uartIndex].deviceName;

        bzero( deviceName , sizeof(deviceName) );
        sprintf( deviceName , "/dev/ttyUSB%d" , uartIndex );
        io_descriptor = rs232_open( deviceName , 9600 );

        if ( io_descriptor > 0 )
        {
            printf_debug( "open %s ok\n" , deviceName );
            cpap_global.uart_id[uartIndex].descriptor=io_descriptor;
            pthread_create( &threadTestUART[uartIndex] , 0 , functionTestUART , (void *)uartIndex );
            continue;
        }
        else
        {
            cpap_global.uart_id[uartIndex].descriptor = -1;
            printf_debug( "open %s error\n" , deviceName );
        }
    }

    for ( uartIndex=0 ; uartIndex<TEST_UART_NUMBER ; uartIndex++ )
    {
        if ( threadTestUART[uartIndex] != -1 )
            pthread_join( threadTestUART[uartIndex] , 0 );
    }

    int use_descriptor=GetCPAPDescriptor();

    if ( use_descriptor > 0 )
    {
        printf_debug( "use descriptor:%d\n" , use_descriptor );
        SetLed( 1 );
    }else{
        printf_debug("cant find any cpap device\n" );
        SetLed( 0 );
    }
    return use_descriptor;
}
コード例 #10
0
ファイル: motsim.c プロジェクト: Manu-31/ndes
/*
 * Création d'une instance du simulateur au sein de laquelle on pourra
 * lancer plusieurs simulations consécutives
 */
void motSim_create()
{
   struct sigaction act;

   __motSim = (struct motsim_t * )sim_malloc(sizeof(struct motsim_t));
   __motSim->currentTime = 0.0;

   printf_debug(DEBUG_MOTSIM, "Initialisation du simulateur ...\n");
   __motSim->events = eventList_create();
   __motSim->nbInsertedEvents = 0;
   __motSim->nbRanEvents = 0;
   __motSim->resetClient = NULL;

   printf_debug(DEBUG_MOTSIM, "gestion des signaux \n");
   // We want to close files on exit, even with ^c
   bzero(&act, sizeof(struct sigaction));
   act.sa_handler = mainHandler;
   act.sa_flags = SA_NOCLDWAIT;

   sigaction(SIGHUP, &act,NULL);
   sigaction(SIGINT, &act,NULL);
   sigaction(SIGQUIT, &act,NULL);
   sigaction(SIGCHLD, &act,NULL);

   // For periodic ping
   act.sa_handler = periodicHandler;
   sigaction(SIGALRM, &act,NULL);

   printf_debug(DEBUG_MOTSIM, "creation des sondes systeme\n");
   // Calcul de la durée moyenne des simulations
   __motSim->dureeSimulation = probe_createExhaustive();
   probe_setPersistent(__motSim->dureeSimulation);

   // Les sondes systeme
   PDU_createProbe = probe_createMean();
   probe_setName(PDU_createProbe, "created PDUs");

   PDU_reuseProbe = probe_createMean();
   probe_setName(PDU_reuseProbe, "reused PDUs");

   PDU_mallocProbe = probe_createMean();
   probe_setName(PDU_mallocProbe, "mallocd PDUs");

   PDU_releaseProbe = probe_createMean();
   probe_setName(PDU_releaseProbe, "released PDUs");

   // Intialisation des log
   printf_debug(DEBUG_MOTSIM, "Initialisation des log ...\n");
   ndesLog_init();

   printf_debug(DEBUG_MOTSIM, "Simulateur pret ...\n");
}
コード例 #11
0
FILE * received_file(const char *buffer, int len, char *filename)
{
    int iret = 0;
    char path[4096] = {'\0'};

    if (buffer[1] == '1')  //filename 
    {
        //if (fd != NULL) 
        //fclose(fd);
        strcpy(path, filename);
        iret = access(path, W_OK);
        if(iret != 0)
        {
            iret = mkdir(path, 0777);
            if(iret != 0)
            {
                printf("can not create dir");
                exit(1);
            }
        }
        strcat(path, "/");
        strcat(path, (buffer + 4));
        fd_now = fopen(path, "w+");
        if(fd_now == NULL)
        {
            printf("can not open file\n");
            printf("Maybe have not enough space\n");
            exit(1);
        }
        if (flag == 0) 
        {
            flag = 1;
            fd_before = fd_now;
        }
        if (fd_before != fd_now) 
        {
            fclose(fd_before);
            fd_before = fd_now;
        }
        printf("\nReceiving: %s ...\n",(buffer + 4));
    }
    if (buffer[1] == '0')  //file data
    {
        printf_debug("Received byte = %d\n",len);
        len = fwrite(buffer + 4, 1, len-4, fd_now);
        //printf_debug("write byte = %d\n",len);
        printf_debug("write byte = %d\n",len + 4);
    }

    return fd_now;
}
コード例 #12
0
ファイル: event.c プロジェクト: Manu-31/ndes
/**
 * @brief Run the destroy an event, whatever the date
 * @param event an event to run
 *
 * If the event is periodic, it is rescheduled an not destroyed.
 */
void event_run(struct event_t * event)
{
   printf_debug(DEBUG_EVENT, " running ev %p at %f\n", event, event->date);
 
   event->run(event->data);

   if (event->type &EVENT_PERIODIC) {
      event->date += event->period;
      motSim_scheduleEvent(event, event->date);
   } else {
      free_event(event);
   }

   printf_debug(DEBUG_EVENT, " end of ev %p at %f\n", event, event->date);
}
コード例 #13
0
ファイル: Parser.cpp プロジェクト: pope88/Servers
inline void push(void * parser, SSUStruct * ssus)
{
	TokenAssign * assign;
	for(assign = tokenAssigns; assign->token != NULL; ++ assign)
	{
		if(strcmp(assign->token, ssus->word.c_str()) == 0)
		{
			printf_debug("%s %d\n", ssus->word.c_str(), assign->id);
			ssuParser(parser, assign->id, strdup(ssus->word.c_str()), ssus);
			return;
		}
	}
	printf_debug("%s\n", ssus->word.c_str());
	ssuParser(parser, TK_CUSTOM, strdup(ssus->word.c_str()), ssus);
}
コード例 #14
0
ファイル: srv-gen.c プロジェクト: Manu-31/ndes
/*
 * Début de traitement d'une PDU
 */
void srvGen_startService(struct srvGen_t * srv, struct PDU_t * pdu)
{
   struct event_t * event;
   double date ; 

   assert(pdu != NULL);

   // Si le destinataire n'a pas récupéré la précédente, trop tard !
   if (srv->currentPDU != NULL) {
      PDU_free(srv->currentPDU);
   }

   srv->srvState = srvStateBusy;
   srv->serviceStartTime = motSim_getCurrentTime();
   srv->currentPDU = pdu;

   //Déterminer une date de fin en fonction du temps de traitement
   if (srv->serviceTime == serviceTimeProp){
      date = motSim_getCurrentTime() + PDU_size(pdu) * srv->serviceTimeParameter;
   } else {
      assert(srv->dateGenerator);
      date = dateGenerator_nextDate(srv->dateGenerator);
   }

   printf_debug(DEBUG_SRV, " PDU %d from %6.3f to %6.3f\n", PDU_id(pdu), motSim_getCurrentTime(), date);

   // On crée un événement
   event = event_create((eventAction_t)srvGen_terminateProcess, srv);

   // On ajoute cet événement au simulateur pour cette date
   motSim_scheduleEvent(event, date);
}
コード例 #15
0
int ck2316_alarm_init(void)
{
    int i = 0;
    //15 01 02 03 04
    //打开存储门禁控制器一些参数的文件
    //一共存储5个参数,从上到下顺序为:
    //door_lock_relay_status_setup (1:常开, 0:常闭)   
    //door_contact_detection_mode_setup (1:开路,0:短路)
    //door_status (1:开门,0:关门)
    //client_set_door_hold_time (0-255s)
    //button_set_door_hold_time (0-255s)
    if ((fp_ck2316_config_file = fopen(CK2316_CONFIG_FILE, "a+")) == NULL)
    {
        printf("FUNC[%s] LINE[%d]\tOpen %s error!\n",__FUNCTION__, __LINE__, CK2316_CONFIG_FILE);
        return -1;
    }
    fseek(fp_ck2316_config_file, 0, SEEK_SET);
    if ((fscanf(fp_ck2316_config_file, "%02d ",&ck2316_alarm_data.ck2316_simulate_keyboard_address)) != 1)
    {
        ck2316_keyboard_address_code[0] = CK2316_KEYBOARD_ADDRESS;
        ck2316_actual_keyboard_address_code[0] = CK2316_ACTUAL_KEYBOARD_ADDRESS;
        ck2316_alarm_data.ck2316_simulate_keyboard_address = CK2316_ACTUAL_KEYBOARD_ADDRESS;
    }
    else
    {
        ck2316_actual_keyboard_address_code[0] = ck2316_alarm_data.ck2316_simulate_keyboard_address;
        ck2316_keyboard_address_code[0] = ck2316_actual_keyboard_address_code[0] - 1;
    }

    if ((fscanf(fp_ck2316_config_file, "%02d %02d %02d %02d",&ck2316_alarm_data.ck2316_user_password[0], &ck2316_alarm_data.ck2316_user_password[1], &ck2316_alarm_data.ck2316_user_password[2], &ck2316_alarm_data.ck2316_user_password[3])) != 4)
    {
        ck2316_alarm_data.ck2316_user_password[0] = CK2316_USER_PASSWORD_1;
        ck2316_alarm_data.ck2316_user_password[1] = CK2316_USER_PASSWORD_2;
        ck2316_alarm_data.ck2316_user_password[2] = CK2316_USER_PASSWORD_3;
        ck2316_alarm_data.ck2316_user_password[3] = CK2316_USER_PASSWORD_4;
    }
    else
    {
        //ck2316_user_password_setup(ck2316_alarm_data.ck2316_user_password);
        for (i = 0; i < 4; i++) 
        {
            system_defence_code[i][2] = (unsigned char)ck2316_alarm_data.ck2316_user_password[i];
            system_abandon_code[i][2] = (unsigned char)ck2316_alarm_data.ck2316_user_password[i];
            bypass_defence_area_code[i][2] = (unsigned char)ck2316_alarm_data.ck2316_user_password[i];
            alarm_host_reset_code[i][2] = (unsigned char)ck2316_alarm_data.ck2316_user_password[i];
        }
    }

    fclose(fp_ck2316_config_file);
    if ((fp_ck2316_config_file = fopen(CK2316_CONFIG_FILE, "w+")) == NULL)
    {
        printf("FUNC[%s] LINE[%d]\tOpen %s error!\n",__FUNCTION__, __LINE__, CK2316_CONFIG_FILE);
        return -1;
    }
    printf_debug("\n\nCK2316 initial status info: %02d %02d %02d %02d %02d\n\n",ck2316_alarm_data.ck2316_simulate_keyboard_address, ck2316_alarm_data.ck2316_user_password[0], ck2316_alarm_data.ck2316_user_password[1], ck2316_alarm_data.ck2316_user_password[2], ck2316_alarm_data.ck2316_user_password[3]);
    fprintf(fp_ck2316_config_file, "%02d %02d %02d %02d %02d",ck2316_alarm_data.ck2316_simulate_keyboard_address, ck2316_alarm_data.ck2316_user_password[0], ck2316_alarm_data.ck2316_user_password[1], ck2316_alarm_data.ck2316_user_password[2], ck2316_alarm_data.ck2316_user_password[3]);
    fflush(fp_ck2316_config_file);

    return 0;
}
コード例 #16
0
ファイル: dvb-s2-ll.c プロジェクト: Manu-31/ndes
/*
 * Création d'une entité DVB-S2 couche 2. Attention, elle ne contient
 * aucun MODCOD par défaut, il faut en ajouter.
 * 
 * Le débit est donnée en symboles/seconde
 */
struct DVBS2ll_t * DVBS2ll_create(void * destination,
				  processPDU_t destProcessPDU,
				  unsigned long symbolPerSecond,
				  unsigned int FECFrameBitLength)
{
   struct DVBS2ll_t * result = (struct DVBS2ll_t * )sim_malloc(sizeof(struct DVBS2ll_t));
 
   if (result) {
      result->nbModCods = 0;
      result->destination = destination;
      result->send = destProcessPDU;
      result->symbolPerSecond = symbolPerSecond;
      result->FECFrameBitLength = FECFrameBitLength;
      result->source = NULL;
      result->getPDU = NULL;
      result->dummyFecFrameProbe = NULL;
      result->available = 1;
 
      // Ajout à la liste des choses à réinitialiser avant une prochaine simu
      motsim_addToResetList(result, (void (*)(void *))DVBS2ll_reset);

      printf_debug(DEBUG_DVB, "%p created\n", result);
   }
   return result;
};
コード例 #17
0
ファイル: dvb-s2-ll.c プロジェクト: Manu-31/ndes
/*
 * Fonction invoquée pour fournir une nouvelle PDU
 */
int DVBS2ll_processPDU(struct DVBS2ll_t * dvbs2ll,
                        getPDU_t getPDU,
                        void * source)
{
   struct PDU_t * pdu;

   // Si c'est juste pour tester si je suis pret
   if ((getPDU == NULL) || (source == NULL)) {
      printf_debug(DEBUG_ALWAYS, "getPDU/source should not be NULL\n");
      return DVBS2ll_available(dvbs2ll); // WARNING il vaudrait mieux un DVBS2ll_processPDU
   }

   // Si on n'est pas dispo, on ne fait rien !
   // On reviendra voir plus tard (à la fin de la transmission) et
   // tant pis si on ne trouve plus rien !!!
   if (DVBS2ll_available(dvbs2ll)) {
      assert(getPDU != NULL);
      assert(source != NULL);

      pdu = getPDU(source);
  
      DVBS2ll_sendPDU(dvbs2ll, pdu);
   }
   return 1;
}
コード例 #18
0
ファイル: string.cpp プロジェクト: Eltamih/uvudec
uv_err_t uvd_parse_line(const char *line_in, char **key_in, char **value_in)
{
	uv_err_t rc = UV_ERR_GENERAL;
	char *key = NULL;
	char *value = NULL;
	char *line = strdup(line_in);

	uv_assert(key_in);
	uv_assert(value_in);
	/* Double check we aren't a section */
	uv_assert(line[0] != '.');

	/*
	Skip comments, empty 
	Must be at beginning, some assemblers require # chars
	*/
	if( line[0] == 0 || line[0] == '#' )
	{
		rc = UV_ERR_BLANK;
		goto error;	
	}

	/* Setup key/value pairing */
	value = strstr(line, "=");
	if( !value )
	{
		UV_ERR(rc);
		goto error;
	}
	//Make equals zero for key
	value[0] = 0;
	//Skip equals
	++value;
	key = strdup(line);
	if( !key )
	{
		UV_ERR(rc);
		goto error;
	}
	/* Skip the equals sign, make key comparisons easier */
	value = strdup(value);
	if( !value )
	{
		free(key);
		free(value);
		//printf_debug("ERROR: out of memory allocating value string\n");
		UV_ERR(rc);
		goto error;
	}
	free(line);
	line = NULL;
	*key_in = key;
	*value_in = value;

	printf_debug("key: %s, value: %s\n", key, value);
	rc = UV_ERR_OK;
	
error:
	return UV_DEBUG(rc);
}
コード例 #19
0
ファイル: motsim.c プロジェクト: Manu-31/ndes
void motSim_runUntil(motSimDate_t date)
{
   struct event_t * event;

   //event_periodicAdd(motSim_periodicMessage, NULL, 0.0, date/200.0);
   alarm(1);

   __motSim->finishTime=date;
   if (!__motSim->nbRanEvents) {
      __motSim->actualStartTime = time(NULL);
   }
   event = eventList_nextEvent(__motSim->events);

   while ((event) && (event_getDate(event) <= date)) {
      event = eventList_extractFirst(__motSim->events);

      printf_debug(DEBUG_EVENT, "next event at %f\n", event_getDate(event));
      assert(__motSim->currentTime <= event_getDate(event));
      __motSim->currentTime = event_getDate(event);
      event_run(event);
      __motSim->nbRanEvents ++;
      /*
afficher le message toutes les 
      n secondes de temps réel
 ou x % du temps simule passe

   Bof : moins on en rajoute à chaque event, mieux c'est !
      */
      event = eventList_nextEvent(__motSim->events);
   }
}
コード例 #20
0
ファイル: socket2uart.c プロジェクト: hawkhsieh/sigbox
int main( int argc , char **argv )
{
    socket_to_uart_standalone = malloc( sizeof( Socket2Uart ) );
    if ( access( "/etc/debug" , 0 ) == 0 )
        debug=1;

    if ( argc == 3)
    {
        socket_to_uart_standalone->port = atoi( argv[1] );
        strncpy( socket_to_uart_standalone->uart_name , argv[2] , sizeof( socket_to_uart_standalone->uart_name) );
    }
    else
    {
        printf("example:socket2uart 21 /dev/ttyUSB0\n");
        exit(1);
    }
    printf_debug("listen port:%d\n",port);
    /* Variable and structure definitions. */

    signal(SIGCHLD, handler);
    if (!fork())
    {
        return socket2uart( socket_to_uart_standalone->uart_name , socket_to_uart_standalone->port );
    }

    //father process sleep and wait SIGCHLD
    while(1) sleep(1);

}
コード例 #21
0
static void	graphic_receive(t_receiver *rec, char *msg)
{
  t_graphic	*graphic;

  printf_debug("graphic received: %s", msg);
  graphic = (t_graphic *)rec;
  graph_PI(graphic, msg);
}
コード例 #22
0
ファイル: command_option.c プロジェクト: oxiden/csvparse
int parse_command_option(int argc, char* argv[], COMMAND_OPTION* popt) {
	popt->options = OPTION_NONE;
	popt->target_file_no = 0;

  int double_hyphen = FALSE;
	int i;
	// parse comand line
	for(i = 1; i < argc; i++){
		printf_debug("[%d]: %s\n", i, argv[i]);
		if (!double_hyphen && strncmp(argv[i], "-", 1) == 0) {
			if (strncmp(argv[i] + 1, "-", 1) == 0) {
				// long option
				if (strcmp(argv[i] + 2, "filter") == 0) {
					popt->options |= OPTION_FILTER;
				}
				if (strcmp(argv[i] + 2, "help") == 0) {
					popt->options = OPTION_HELP;
					return 0;
				}
				if (strcmp(argv[i] + 2, "") == 0) {
					double_hyphen = TRUE;
					printf_debug("detect double-pyphen\n");
				}
			} else {
				// short option
				if (strcmp(argv[i] + 1, "f") == 0) {
					popt->options |= OPTION_FILTER;
				}
				if (strcmp(argv[i] + 1, "h") == 0) {
					popt->options = OPTION_HELP;
					return 0;
				}
			}
			if (!double_hyphen && popt->options == OPTION_NONE) {
				popt->options = OPTION_HELP;
				return 0;
			}
		} else {
			printf_debug("target=[%s]\n", argv[i]);
			if (popt->target_file_no == 0) {
				popt->target_file_no = i;
			}
		}
	}
	return 0;
}
コード例 #23
0
ファイル: main.cpp プロジェクト: Eltamih/uvudec
int main(int argc, char **argv)
{
	printf_debug("main: enter\n");

	//Simple translation to keep most stuff in the framework
	uv_err_t rc = uvmain(argc, argv);
	printf_debug("main: exit\n");
	if( UV_FAILED(rc) )
	{
		printf_error("failed\n");
		return 1;
	}
	else
	{
		return 0;
	}
}
コード例 #24
0
ファイル: natnet2ivy.c プロジェクト: CodeMining/paparazzi
int main(int argc, char **argv)
{
  // Set the default tracking system position and angle
  struct EcefCoor_d tracking_ecef;
  //alt 45 m because of ellipsoid altitude in Delft
  tracking_ecef.x = 3924331.5;
  tracking_ecef.y = 300361.7;
  tracking_ecef.z = 5002197.1;
  tracking_offset_angle = 33.0 / 57.6;
  ltp_def_from_ecef_d(&tracking_ltp, &tracking_ecef);

  // Parse the options from cmdline
  parse_options(argc, argv);
  printf_debug("Tracking system Latitude: %f Longitude: %f Offset to North: %f degrees\n", DegOfRad(tracking_ltp.lla.lat),
               DegOfRad(tracking_ltp.lla.lon), DegOfRad(tracking_offset_angle));

  // Create the network connections
  printf_debug("Starting NatNet listening (multicast address: %s, data port: %d, version: %d.%d)\n",
               natnet_multicast_addr, natnet_data_port, natnet_major, natnet_minor);
  udp_socket_create(&natnet_data, "", -1, natnet_data_port, 0); // Only receiving
  udp_socket_subscribe_multicast(&natnet_data, natnet_multicast_addr);
  udp_socket_set_recvbuf(&natnet_data, 0x100000); // 1MB

  printf_debug("Starting NatNet command socket (server address: %s, command port: %d)\n", natnet_addr, natnet_cmd_port);
  udp_socket_create(&natnet_cmd, natnet_addr, natnet_cmd_port, 0, 1);
  udp_socket_set_recvbuf(&natnet_cmd, 0x100000); // 1MB

  // Create the Ivy Client
  GMainLoop *ml =  g_main_loop_new(NULL, FALSE);
  IvyInit("natnet2ivy", "natnet2ivy READY", 0, 0, 0, 0);
  IvyStart(ivy_bus);

  // Create the main timers
  printf_debug("Starting transmitting and sampling timeouts (transmitting frequency: %dHz, minimum velocity samples: %d)\n",
               freq_transmit, min_velocity_samples);
  g_timeout_add(1000 / freq_transmit, timeout_transmit_callback, NULL);

  GIOChannel *sk = g_io_channel_unix_new(natnet_data.sockfd);
  g_io_add_watch(sk, G_IO_IN | G_IO_NVAL | G_IO_HUP,
                 sample_data, NULL);

  // Run the main loop
  g_main_loop_run(ml);

  return 0;
}
コード例 #25
0
/*
 * Store CA file into store.
 */
static
int X509_store_add_cert_file(X509_STORE *store, const char *fname)
{
	FILE *fin = NULL;
	X509 *x509 = NULL;
	unsigned long err;

	assert(store != NULL);
	assert(fname != NULL);

	fin = fopen(fname, "r");
	if (fin == NULL) {
		printf_debug(DEBUG_PREFIX_CERT,
		    "Cannot open certificate '%s'.\n", fname);
		goto fail;
	}

	x509 = PEM_read_X509(fin, NULL, NULL, NULL);
	if (x509 == NULL) {
		printf_debug(DEBUG_PREFIX_CERT,
		    "Cannot parse certificate '%s'.\n", fname);
		goto fail;
	}

	if (X509_STORE_add_cert(store, x509) == 0) {
		err = ERR_get_error();
		printf_debug(DEBUG_PREFIX_CERT,
		    "Cannot store certificate '%s'. Error: %s.\n", fname,
		    ERR_error_string(err, NULL));
		goto fail;
	}

	X509_free(x509); x509 = NULL;
	fclose(fin); fin = NULL;

	return 0;

fail:
	if (fin != NULL) {
		fclose(fin);
	}
	if (x509 != NULL) {
		X509_free(x509);
	}
	return -1;
}
コード例 #26
0
ファイル: src-tcpss.c プロジェクト: Manu-31/ndes
/**
 * @brief Simulate transmission of nbBytes bytes
 * @param src is a pointer to the source
 * @param nbBytes is the number of bytes to transmit
 */
void srcTCPss_sendFile(struct srcTCPSS_t * src,
                       int nbBytes)
{
   printf_debug(DEBUG_SRC, "Will send %d bytes (ws %d)\n", nbBytes, src->windowSize);

   if (srcTCPss_isEmpty(src)) {
      src->backlog = nbBytes;

      printf_debug(DEBUG_SRC, "First burst of %d segments\n",  min(src->windowSize, (nbBytes + src->MSS - 1)/src->MSS));
      // Send as many segments as possible
      srcTCPss_sendSegments(src, min(src->windowSize, (nbBytes + src->MSS - 1)/src->MSS));
   } else {
      printf_debug(DEBUG_SRC, "Persistent use\n");
      // If the source is already active, we just add these new bytes
      src->backlog += nbBytes;
   }
}
コード例 #27
0
ファイル: socket2uart.c プロジェクト: hawkhsieh/sigbox
void socket2uart_CloseClient(  Socket2Uart *socket_to_uart )
{
    usleep(10000);
    printf_debug( "close socket[%d]\n" , socket_to_uart->connect_fd );
    if ( socket_to_uart->connect_fd >= 0 )
        close ( socket_to_uart->connect_fd );
    socket_to_uart->connect_fd = -1;
}
コード例 #28
0
ファイル: relocation.cpp プロジェクト: Eltamih/uvudec
uv_err_t UVDElfRelocationSectionHeaderEntry::initRelocatableData()
{
	//So that we can construct the relocatable table in relocatable units
	m_fileRelocatableData = new UVDMultiRelocatableData();
	uv_assert_ret(m_fileRelocatableData);

	printf_debug("relocatable section file relocatable: 0x%.8X)\n", (unsigned int)m_fileRelocatableData);
	return UV_ERR_OK;
}
コード例 #29
0
int set_serial_dev_parameter(FILE *fp_dev_config_file)
{
    fseek(fp_dev_config_file, 0, SEEK_SET);
    printf_debug("\n\nEntrance guard attribution:\t%d %d %d %d %d %d\n\n",entrance_guard_data.entrance_guard_serial_pamater.byPathNo, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.dwBaudRate, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byDataBit, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byStopBit, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byParity, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byFlowcontrol);
    fprintf(fp_dev_config_file, "%d %d %d %d %d %d\n",entrance_guard_data.entrance_guard_serial_pamater.byPathNo, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.dwBaudRate, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byDataBit, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byStopBit, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byParity, entrance_guard_data.entrance_guard_serial_pamater.serialAttr.byFlowcontrol);

    printf_debug("Matrix control attribution:\t%d %d %d %d %d %d\n\n",matrix_control_data.matrix_control_serial_pamater.byPathNo, matrix_control_data.matrix_control_serial_pamater.serialAttr.dwBaudRate, matrix_control_data.matrix_control_serial_pamater.serialAttr.byDataBit, matrix_control_data.matrix_control_serial_pamater.serialAttr.byStopBit, matrix_control_data.matrix_control_serial_pamater.serialAttr.byParity, matrix_control_data.matrix_control_serial_pamater.serialAttr.byFlowcontrol);
    fprintf(fp_dev_config_file, "%d %d %d %d %d %d\n",matrix_control_data.matrix_control_serial_pamater.byPathNo, matrix_control_data.matrix_control_serial_pamater.serialAttr.dwBaudRate, matrix_control_data.matrix_control_serial_pamater.serialAttr.byDataBit, matrix_control_data.matrix_control_serial_pamater.serialAttr.byStopBit, matrix_control_data.matrix_control_serial_pamater.serialAttr.byParity, matrix_control_data.matrix_control_serial_pamater.serialAttr.byFlowcontrol);

    printf_debug("Cradle head attribution:\t%d %d %d %d %d %d\n\n",cradle_head_control_data.cradle_head_control_serial_pamater.byPathNo, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.dwBaudRate, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byDataBit, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byStopBit, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byParity, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byFlowcontrol);
    fprintf(fp_dev_config_file, "%d %d %d %d %d %d\n",cradle_head_control_data.cradle_head_control_serial_pamater.byPathNo, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.dwBaudRate, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byDataBit, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byStopBit, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byParity, cradle_head_control_data.cradle_head_control_serial_pamater.serialAttr.byFlowcontrol);

    printf_debug("Ck2316 alarm attribution:\t%d %d %d %d %d %d\n\n",ck2316_alarm_data.ck2316_alarm_serial_pamater.byPathNo, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.dwBaudRate, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byDataBit, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byStopBit, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byParity, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byFlowcontrol);
    fprintf(fp_dev_config_file, "%d %d %d %d %d %d",ck2316_alarm_data.ck2316_alarm_serial_pamater.byPathNo, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.dwBaudRate, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byDataBit, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byStopBit, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byParity, ck2316_alarm_data.ck2316_alarm_serial_pamater.serialAttr.byFlowcontrol);

    fflush(fp_dev_config_file);

    return 0;
}
コード例 #30
0
ファイル: src-tcpss.c プロジェクト: Manu-31/ndes
/**
 * @brief Delete and free a source
 * @param src an empty source
 * 
 * The caller MUST ensure this source is empty.
 */
void srcTCPss_free(struct srcTCPSS_t * src)
{
   assert(srcTCPss_isEmpty(src));

   // Delete the outputQueue
   printf_debug(DEBUG_TBD, "filePDU_free unavailable !");

   // Free the structure
   free(src);
}