int transporter_C::connect_Socket()
{
    int err;
    int bytecount = 0;
    char data[1024];


    if( connect( hsock, (struct sockaddr*)&my_addr, sizeof(my_addr)) == -1 )
    {
        if((err = errno) != EINPROGRESS)
        {
            fprintf(stderr, "Error connecting socket %d\n", errno);
            exitClient(hsock);
            return -1;
        }
    }
    buffer_len = 1024;
    memset(buffer, '\0', buffer_len);
    strcpy(buffer, configuration[0].name.c_str());

    SetupCode(data);

    if( (bytecount=send(hsock, (const void*)data, 1024,0)) < 1)
    {
        fprintf(stderr, "send_Data Error sending data %d\n", errno);
        exitClient(hsock);
        return -1;
    }

    memset(buffer, '\0', buffer_len);

    if((bytecount = recv(hsock, buffer, buffer_len, 0)) < 1)
    {
        fprintf(stderr, "Error receiving data %d\n", errno);
        exitClient(hsock);
    }

    unsigned char magic;
    unsigned int ps2;
    char s2[96];

    unpack((unsigned char*)buffer, "CHs",   &magic,
                                            &ps2,
                                            &s2);

    printf("recv: '%c' %hhu %s\n",  magic,
                                    ps2,
                                    s2);

    if(magic == 69)
    {
        cout << "se cerro"<< endl;
        exitClient(hsock);
        return -1;
    }
    return 0;
}
Esempio n. 2
0
int main (void)
{
	unsigned char MoveDir=0;

	SetupCpu();
	SetupCode();
	rfPwrUp();
	rfRxMode();
	LED1ON;
	WaitForSwitch();
	LED1OFF;
//TimerAStart();


/*
while(1)
{
	if (CTS)
	{
		LED5TOGGLE;
	}
	if (!CTS) LED5OFF;
	if( TimerExpired || IfSwitch() )
	{
		CTS=0;
		TimerExpired=0;
		AssembleStartTimerPacket();
		rfStandbyMode();
		rfSendPacket2Module(&TxPacket[0],32);
		rfTxMode();
		softDelay(65535);
		rfStandbyMode();
		rfRxMode();
		LED1TOGGLE;
	}
}
*/






//	MAZE MAPPING CODE
	AddWall(SOUTH, GetMouseX(), GetMouseY() );
	ReserveCurrentCell();
	AnalyseCellLR();
	AnalyseCellFB();
	ReserveCellsAroundHere();
	IncrementCellVisits();
	SetThisCellMappedByThisMouse();
	TxCellInfo();

	while (1)
	{


		MoveDir = 0;

		while (!MoveDir) //If unable to get an exit, redo until can get exit
		{
			MoveDir=GetExitDir();
			LED7ON;
		}
		LED7OFF;

		ReserveCellsAround(MoveDir);

		Rotate( MoveDir );

		DriveToEndOfCurrentCellCorrecting();

		MoveToNewCellLogical(MoveDir);		// no walls in new cell, so will not correct until LR analysed

		DriveToStartOfNextCellNOTCorrecting();

		AnalyseCellLR();		// analysed, so if walls exist, mouse will correct itself

		DriveToMiddleOfNewCellCorrecting();

		AnalyseCellFB();

		IncrementCellCount();

		IncrementCellVisits();

		TxCellInfo();

		ReleaseOldCells(MoveDir);

		ReleaseWalledCells();

		DeadEndBlocking();

		if ( IsMazeMapped() ) break;


	}

	SetLedsLower(0x55);


		// count total visits in maze

	unsigned char x = 0;
	unsigned char y = 0;
	unsigned char count = 0;

	while (y < MAZEY)
	{
		while (x < MAZEX)
		{
			count += GetVisits(x,y);
			x++;
		}
		y++;
		x=0;
	}

//	SetLedsUpper (count);

	while (1)
	{
		WaitForSwitch();
//		SetLedsUpper(GetLargeErrors());

		WaitForSwitch();
//		SetLedsUpper(GetSmallErrors());
	}


	return 0;
}