示例#1
0
int main()
{
    char s[100];
    double a, b;
    struct complex C1, C2;
    printf("Введите комплексное число в формате a, b: ");
    scanf("%lf%lf", &a, &b);
    C1 = cRead(a, b);
    cPrint(C1);
    printf("Введите комплексное число в формате a,b: ");
    scanf("%lf%lf", &a, &b);
    C2 = cRead(a,b);
    cPrint(C2);
    printf("РЎСѓРјРјР°: ");
    cPrint(cAdd(C1, C2));
    printf("Разность: ");
    cPrint(cSub(C1, C2));
    printf("Произведение: ");
    cPrint(cMul(C1, C2));
    printf("Частное: ");
    cPrint(cDiv(C1, C2));
    printf("Модуль 1-ого: %f: \n", cAbs(C1));
    printf("Аргумент 1-ого: %f: \n", cArg(C1)); 
    printf("Сопряжённое 1-ого: "); cPrint(cConj(C1));
    printf("Re 1-РѕРіРѕ: %f: \n", cReal(C1));
    printf("Im 1-РѕРіРѕ: %f: \n", cImag(C1));
    return 0;
}
示例#2
0
int main(){
	Complex C1, C2, CADD;
	C1 = cRead();
	C2 = cRead();
	Complex_Output(C1);
	Complex_Output(C2);
	CADD = cAdd(C1, C2);
	Complex_Output(CADD);
	Complex_Output(cMul(C1,C2));
	printf("\nArg(C1) = %lf", Arg(C1));
	printf("\nMODUL(C2) = %lf", Modul(C1));
	return 0;
}
示例#3
0
uint16_t checkHeader(Client &client, uint16_t *contentLength) {
    char buf[70];
    uint8_t p = 0;
    int c = 0;
    bool done = false;  // when we read the blank line or error
    uint16_t ret = 401;  // not found

    if (contentLength) *contentLength = 0;

    //Serial.print("__bss_end 0x");Serial.println(__bss_end,HEX);
    if (client == NULL) {
        Serial.println("Client NULL!!");
        return ret;
    }
    // read until \r\n\r\n then check header values
    while (!done) {
        // read a single line up to a newline \n
        p = cRead(&client, buf, sizeof(buf), '\n');
        // Serial.print("read "); Serial.println(p);
        // process the data in the line
        if (p && buf[p-1] == '\n')  {  // did we succeed in reading a line?
            buf[p] = 0;  // end the string
            //Serial.println(buf);
            ++c;
            if (c >= 20) {
                client.flush();
                return 402;
            }
            //Serial.print("read line of length "); Serial.print(p); Serial.println(": ");
            //Serial.println(buf);
            char *h;
            if ((h = strstr(buf, "HTTP")) != NULL) {
                char *q = strchr(h, ' ') ;
                if (q != NULL) {
                    ret = atoi(q+1);
                    //Serial.print("status "); Serial.println(buf);
                    if (ret != 200) {
                        client.flush();
                        return ret;
                    }
                }
            } else if (contentLength != NULL && !strncasecmp_P(buf, PSTR("Content-Length:"), 15)) {
                char *q = strchr(buf, ' ') ;
                if (q != NULL) {
                    *contentLength = atoi(q+1);
                }
            } else if (p == 2) {  // blank line, done with header
                done = true;
            }
        } else {
            Serial.println("failed");
            // somthing went wrong, didn't read a full line
            ret = 403;  // indicate we're not successful
            client.flush();
            done = true;
        }
    }
    //Serial.print("status "); Serial.println(ret);
    return ret;
}
示例#4
0
void CScreenJoin::ReadCurServerList()
{
	m_nSelectedServer = 0;

	IServerDirectory *pServerDir = g_pClientMultiplayerMgr->GetServerDir();
	IServerDirectory::TPeerList cPeers = pServerDir->GetPeerList();
	m_cServerList.resize(cPeers.size());
	IServerDirectory::TPeerList::const_iterator iCurPeer = cPeers.begin();
	TServerList::iterator iCurServer = m_cServerList.begin();
	for (; iCurPeer != cPeers.end(); ++iCurPeer, ++iCurServer)
	{
		// Indicate that the server's an invalid entry until we get everything..
		iCurServer->m_sAddress.clear();

		char aStringBuffer[256];
	
		// Point at this server
		if (!pServerDir->SetActivePeer(iCurPeer->c_str()))
			continue;

		// Read the name
		CAutoMessage cMsg;
		if (!pServerDir->GetActivePeerInfo(IServerDirectory::ePeerInfo_Name, cMsg))
			continue;
		{
			CLTMsgRef_Read cRead(cMsg.Read());
			cRead->ReadString(aStringBuffer, sizeof(aStringBuffer));
		}
		iCurServer->m_sName = aStringBuffer;

		// Read the summary
		if (!pServerDir->GetActivePeerInfo(IServerDirectory::ePeerInfo_Summary, cMsg))
			continue;
		{
			CLTMsgRef_Read cRead(cMsg.Read());
			cRead->ReadString(aStringBuffer, sizeof(aStringBuffer));
			iCurServer->m_sMap = aStringBuffer;
			iCurServer->m_nNumPlayers = cRead->Readuint8();
			iCurServer->m_nMaxPlayers = cRead->Readuint8();
		}

		// Ok, this one's valid
		iCurServer->m_sAddress = *iCurPeer;
	}
}
示例#5
0
int cameraComm::cWrite (int query, int pos)
{

    // Read(clean) Buffer
    char cmd[10];
    cRead(NONE);
    //sleep(1);
    switch ( query )
    {

    case STC  :
        write( fd, "stc\n", 4);
        break;

    case ITF  :
        write( fd, "itf\n", 4);
        break;

    case SSP  :
        sprintf(cmd,"ssp %d\n",pos);
        write( fd, cmd, strlen(cmd));
        break;

    case RTI  :
        write( fd, "rti\n", 4);
        break;

    case NET  :
        write( fd, "net\n", 4);
        break;

    case ESC  :
        write( fd, "esc\n", 4);
        break;
        //default   : printf( "???" );
    }
}
示例#6
0
static void vTest9Dof()
{
    static char str[40];
    char cBuf[6] = {0, 0, 0, 0, 0, 0};
    unsigned char* ucBuf = (unsigned char*) cBuf;
    int x = 0,
        y = 0,
        z = 0;

    if( !is9DofInit )
    {
        vInit9Dof();
        return;
    }

    cBuf[0] = 0x32;
    cWrite( BUS_9DOF, WRITE_9DOF, cBuf, 1 );
    cBuf[0] = 0;
    cRead( BUS_9DOF, READ_9DOF, cBuf, 6 );
//    x = (unsigned) ucBuf[0] | ((unsigned) ucBuf[1] << 8);
//    y = (unsigned) ucBuf[2] | ((unsigned) ucBuf[3] << 8);
//    z = (unsigned) ucBuf[4] | ((unsigned) ucBuf[5] << 8);
    x = *((int*) &ucBuf[0]);
    y = *((int*) &ucBuf[2]);
    z = *((int*) &ucBuf[4]);

    /* Read bytes as signed! */
//    sprintf(str, "[ADXL345] x=0x%04x, y=0x%04x, z=0x%04x", x, y, z);
    sprintf(str, "[ADXL345] %04x%04x%04x -> x=%4d, y=%4d, z=%4d",
//            *((unsigned*) &ucBuf[0]), *((unsigned*) &ucBuf[2]), *((unsigned*) &ucBuf[4]),
//            *((unsigned*) &ucBuf[0]), *((unsigned*) &ucBuf[2]), *((unsigned*) &ucBuf[4]));
            ucBuf[0]<<8 | ucBuf[1], ucBuf[2]<<8 | ucBuf[3], ucBuf[4]<<8 | ucBuf[5], /* force endianness */
            x, y, z);
//    sprintf(str, "[ADXL345] x=%+03d, y=%+03d, z=%+03d", x, y, z);
    vConsolePuts(str);
}
示例#7
0
int cameraComm::stateFunction(int actualState)
{
    int nextState = 0;
    int i =0;
    int r;

    switch (actualState)
    {
    case 1:
        printf("CAMERA   : Sending STC\n");
        cWrite(STC);
        cameraPosition = 134;
        numAsk = MAX_NUM_ASK;
        nextState = 2;
        break;

    case 2:
        printf("CAMERA   : Is there a Feature?... ");
        usleep (500000);
        r=cRead(ITF);// free buffer
        cWrite(ITF);

        r = 1;
        //r = cRead(ITF);
        while (r == 1 &&  i < 5)
        {
            usleep (500000);
            r=cRead(ITF);
            i++;
            //printf("    i = %d ; r = %d\n", i, r);
        }
        if (r != 1)
        {
            if (value[0] == 0)
            {
                printf("No");
                if (numAsk < MAX_NUM_ASK)
                {
                    numAsk++;;
                    nextState = 2;
                    usleep(1000000);
                    printf("( %d/15)", numAsk);
                }
                else
                    nextState = 3;

                printf("\n");
            }
            else if (value[0]==1)
            {
                printf("Yes\n");
                nextState = 4;
            }
        }
        else
        {
            printf("CAMERA   : No answer from CMUcam\n");
            nextState = 1;
        }
        break;

    case 3:
        //Other Processor Movement
        nextState = 2;
        break;

    case 4:
        //printf("x =%d\n", cmuCam.getValue(2));

        numAsk = 0;
        if (value[1] >= 82 && value[1] <= 92)
        {
            printf("CAMERA   : Is feature is in the horizontal range (82 - 92)? Yes (%d)\n", value[1]);
            nextState = 6;
        }
        else
        {
            printf("CAMERA   : Is feature is in the horizontal range (82 - 92)? No (%d)\n", value[1]);
            nextState = 5;
        }
        break;

    case 5:

        speed = 0.5;
        if (value[1] > 92)
        {
            if (cameraPosition < 50)
                steering = 0.55;
            else
                steering = 0.6;
            printf("CAMERA   : Turning to the right (steering=%f)\n", steering);

        }
        else if (value[1] < 82)
        {
            if (cameraPosition < 50)
                steering = 0.43;
            else
                steering = 0.4;
            printf("CAMERA   : Turning to the left (steering=%f)\n", steering);
        }

        //GIRAR
        nextState = 2;

        break;

    case 6:

        if (value[2] >= 138 && value[2] <= 148)
        {
            printf("CAMERA   : Is the feature in the vertical range (138 - 148): Yes (%d)\n", value[2]);
            nextState = 8;
        }
        else
        {
            printf("CAMERA   : Is the feature in the vertical range (138 - 148): No (%d)\n", value[2]);
            nextState = 7;
        }
        break;

    case 7:

        int newCameraPosition;
        newCameraPosition = cameraPosition + (int)(0.3*(float)(143-value[2]));
        if (newCameraPosition < 15)
        {
            newCameraPosition = 0;
        }
        if (newCameraPosition > 134)
        {
            newCameraPosition = 134;
        }

        if (newCameraPosition < cameraPosition + 20 && newCameraPosition > cameraPosition - 20 && newCameraPosition != 0 )//newCameraPosition == cameraPosition)
        {
            printf("CAMERA   : CMUcam is in optimal position: %d\n", cameraPosition);
            nextState = 8;
        }
        else
        {
            printf("CAMERA   : CMUcam is not in optimal position: %d\n", cameraPosition);
            cameraPosition = newCameraPosition;
            nextState = 9;
        }

        break;

    case 8:

        speed = 0.6 + 0.5*((float)cameraPosition/134);//old Value: 0.4 (now 0.5)
        if (speed > 0.8)
            speed = 0.8;
        steering = 0.5;
        printf("CAMERA   : Moving forward: speed = %f\n", speed);
        //AVANZAR
        nextState = 2;
        break;

    case 9:

        printf("CAMERA   : Setting new camera position: %d. \n", cameraPosition);
        cWrite(SSP,cameraPosition);

        if (cameraPosition == 0)
        {
            numAsk = 0;
            nextState = 10;
        }
        else
            nextState = 2;
        break;

    case 10:

        printf("CAMERA   : Is the camera ready to identify the feature?\n");
        cWrite(ITF);

        r = cRead(ITF);
        while (r == 1 &&  i < 3)
        {
            usleep (500000);
            r=cRead(ITF);
            i++;
            //printf("    i = %d ; r = %d\n", i, r);
        }
        if (r != 1)
        {
            if (value[0] == 0)
            {
                printf("\tNo\n");
                nextState = 2;
            }
            else if (value[0]==1)
            {
                printf("\t(%d,%d) ", value[1], value[2]);
                nextState = 11;
            }
        }

        usleep(1000000);

        cWrite(RTI);

        r = 1;
        while (r == 1 &&  i < 6)
        {
            usleep (500000);
            r=cRead(RTI);
            i++;
            //printf("    i = %d ; r = %d\n", i, r);
        }
        if (r != 1)
        {
            if (value[0] == 0)
            {
                printf("\tNo\n");
                if (numAsk < MAX_NUM_ASK)
                {
                    numAsk++;;
                    nextState = 10;
                    printf("numAsk = %d", numAsk);
                }
                else
                    nextState = 2;
            }
            else if (value[0]==1)
            {
                printf("\tYes\n");
                nextState = 11;
            }
        }
        else
        {
            printf("CAMERA   : No answer from CMUcam\n");
            nextState = 1;
        }
        break;

    case 11:

        cWrite(NET);

        r = cRead(NET);
        while (r == 1 &&  i < 3)
        {
            usleep (500000);
            r=cRead(NET);
            i++;
            //printf("    i = %d ; r = %d\n", i, r);
        }
        if (r != 1)
        {

            recognizedFeature = value[0];
            featureColor = RED;
            printf("CAMERA   : Feature found: %d\n",recognizedFeature);
            nextState = 1;
            numAsk = MAX_NUM_ASK;
        }

        usleep (500000);
        break;
    }

    return nextState;
}