Пример #1
0
int connect()
{
    unsigned char answer = 0;

    SerialTransmit(HELLO_HOST);
    Sleep(50);
    answer = SerialReceive();

    if(answer == HELLO_CLIENT) {
        return 1;
    }

    return 0;
}
Пример #2
0
int main(int argc,char**argv)
{
	int rtn;
	int Count = 0;
	unsigned char *send = "Hello Uart";
	unsigned char buf[1024] ={0};
	if(2 > argc)
	{
		printf("Input error\n");
		printf("Usage: %s <Device>\n",argv[0]);
		printf("Eample: %s /dev/ttyS0\n",argv[0]);
		return -1;
	}
	
	rtn = SerialOpen(argv[1]);
	if(0 > rtn)
		return -1;
	
	rtn = SerialConfig(115200,8,'n',1);
	if(0 > rtn)
		return -1;
	
	while(1)
	{
		rtn = SerialSend(send,strlen(send));
		if(0 < rtn)
		{
			printf("[Send]: %s\n",send);
		}
		sleep(1);
		rtn = SerialReceive(buf,sizeof(buf));
		if(0 < rtn)
		{
			printf("[Recv]: %s\n",buf);
		}
	}
	SerialClose();
}
Пример #3
0
int AddIn_main(int isAppli, unsigned short OptionNum)
{
    int collided = 0;
    unsigned char answer;

    Bdisp_AllClr_DDVRAM();

    Init_SerialPort();
    Start_SerialPort();

    if(connect() == 0) {
        isHost = 1;
    }

    while(1) {
        startScreen();

        memset(videoBuffer, 0, 1024);
        DrawBox(0, 0, 127, 63, videoBuffer, BLACK);
        DrawBox(48, 27, 79, 37, videoBuffer, BLACK);
        CoolText(51, 29, FONT_FIVE, "Ready?", videoBuffer);
        DrawAll(videoBuffer);

        Sleep(1000);

        SerialTransmit(READY);
        while(SerialReceive() != READY) {
            ;
        }

        reset();

        while(1) {
            answer = SerialReceive();

            if(answer == CRASH) {
                score++;
                wonLast = ME;
                break;
            }
            if(answer == EXIT) {
                Reset_Calc();
            }
            if(answer == COORDS) {
                receivedX = SerialReceive();
                receivedY = SerialReceive();

                setBit(videoBuffer, 128, receivedX, receivedY, 1);
            }

            checkKeys();
            move();

            collided = getBit(videoBuffer, 128, playerX, playerY);
            if(collided) {
                otherScore++;
                wonLast = OTHER;
                SerialTransmit(CRASH);
                break;
            }

            setBit(videoBuffer, 128, playerX, playerY, 1);

            SerialTransmit(COORDS);
            SerialTransmit(playerX);
            SerialTransmit(playerY);

            DrawAll(videoBuffer);

            Sleep(delays[speed]);
        }
    }

    return 1;
}
Пример #4
0
void startScreen()
{
    unsigned char answer;
    char scoreText[4], otherScoreText[4], statusText[22], speedText[22], levelText[22];
    int isReady = 0, is1Pressed = 0, is2Pressed = 0, is3Pressed = 0, isLeftPressed = 0, isRightPressed = 0;

    while(!isReady) {
        if(isHost) {
            if(isConnected) {
                strcpy(statusText, "Hosting");
            } else {
                strcpy(statusText, "Waiting");
            }
        } else {
            strcpy(statusText, "Connected");
        }

        sprintf(scoreText, "%d", score);
        sprintf(otherScoreText, "%d", otherScore);
        sprintf(speedText, "SPEED:  %d", speed + 1);
        sprintf(levelText, "LEVEL:  %d", level + 1);

        memset(videoBuffer, 0, 1024);

        DrawBox(0, 0, 127, 63, videoBuffer, BLACK);
        DrawLine(0, 8, 127, 8, videoBuffer, BLACK);
        DrawLine(0, 16, 127, 16, videoBuffer, BLACK);
        DrawLine(0, 24, 127, 24, videoBuffer, BLACK);
        DrawLine(64, 16, 64, 24, videoBuffer, BLACK);
        DrawLine(0, 32, 127, 32, videoBuffer, BLACK);
        DrawLine(0, 40, 127, 40, videoBuffer, BLACK);

        CoolText(32, 1, FONT_FIVE, "MTRON by rojet601", videoBuffer);
        CoolText(48, 9, FONT_FIVE, statusText, videoBuffer);
        CoolText(27, 17, FONT_FIVE, scoreText, videoBuffer);
        CoolText(91, 17, FONT_FIVE, otherScoreText, videoBuffer);
        if(wonLast == ME) {
            CoolText(48, 25, FONT_FIVE, "You won", videoBuffer);
        }
        if(wonLast == OTHER) {
            CoolText(48, 25, FONT_FIVE, "You lost", videoBuffer);   
        }
        if(isHost) {
            CoolText(2, 33, FONT_FIVE, speedText, videoBuffer);
            CoolText(65, 33, FONT_FIVE, levelText, videoBuffer);
            CoolText(2, 52, FONT_FIVE, "[1]-[3] SPEED", videoBuffer);
            CoolText(65, 52, FONT_FIVE, "         LEVEL", videoBuffer);
            DrawLine(65, 55, 71, 55, videoBuffer, BLACK);
            DrawLine(66, 55, 68, 53, videoBuffer, BLACK);
            DrawLine(66, 55, 68, 57, videoBuffer, BLACK);

            DrawLine(73, 55, 79, 55, videoBuffer, BLACK);
            DrawLine(79, 55, 77, 53, videoBuffer, BLACK);
            DrawLine(79, 55, 77, 57, videoBuffer, BLACK);
            if(isConnected) {
                CoolText(2, 43, FONT_FIVE, "[SHIFT] START", videoBuffer);
            }
        } else {
            CoolText(2, 43, FONT_FIVE, "Only the host can change", videoBuffer);
            CoolText(2, 52, FONT_FIVE, "the settings", videoBuffer);
        }

        DrawAll(videoBuffer);

        if(IsKeyDown(KEY_CTRL_EXIT) || IsKeyDown(KEY_CTRL_MENU)) {
            SerialTransmit(EXIT);
            Stop_SerialPort();
            Reset_Calc();
        }

        answer = SerialReceive();

        if(answer == EXIT) {
            Stop_SerialPort();
            Reset_Calc();
        }
        if(answer == START) {
            Sleep(50);
            speed = SerialReceive();
            level = SerialReceive();
            isReady = 1;
        }

        if(isHost) {
            if(!isConnected) {
                if(answer == HELLO_HOST) {
                    SerialTransmit(HELLO_CLIENT);
                    isConnected = 1;
                }
            } else {
                if(IsKeyDown(KEY_CTRL_SHIFT)) {
                    SerialTransmit(START);
                    SerialTransmit(speed);
                    SerialTransmit(level);
                    Sleep(50);
                    isReady = 1;
                }
            }
            if(!IsKeyDown(KEY_CHAR_1)) {
                is1Pressed = 0;
            }
            if(IsKeyDown(KEY_CHAR_1) && !is1Pressed) {
                is1Pressed = 1;
                speed = 0;
            }
            if(!IsKeyDown(KEY_CHAR_2)) {
                is2Pressed = 0;
            }
            if(IsKeyDown(KEY_CHAR_2) && !is2Pressed) {
                is2Pressed = 1;
                speed = 1;
            }
            if(!IsKeyDown(KEY_CHAR_3)) {
                is3Pressed = 0;
            }
            if(IsKeyDown(KEY_CHAR_3) && !is3Pressed) {
                is3Pressed = 1;
                speed = 2;
            }
            if(!IsKeyDown(KEY_CTRL_LEFT)) {
                isLeftPressed = 0;
            }
            if(IsKeyDown(KEY_CTRL_LEFT) && !isLeftPressed) {
                isLeftPressed = 1;
                level--;
                if(level == 255) {
                    level = levels - 1;
                }
            }
            if(!IsKeyDown(KEY_CTRL_RIGHT)) {
                isRightPressed = 0;
            }
            if(IsKeyDown(KEY_CTRL_RIGHT) && !isRightPressed) {
                isRightPressed = 1;
                level++;
                if(level > levels - 1) {
                    level = 0;
                }
            }
        }
    }
}
Пример #5
0
int  DwReceive(u8 *in, int inlen) {
  if (CurrentPortKind() == 's')
    return SerialReceive((struct SPort*)Ports[CurrentPort], in, inlen);
  else
    return DigisparkReceive((struct UPort*)Ports[CurrentPort], in, inlen);
}
Пример #6
0
int main(void)
{

    ind = 0;
	// Setup functions for operation
	CP0Init();
	INTInitialize();
	ADCSetup();
	SetupButtons();
	SetupIO();
	SetupT1CountINT();
	SetupTimer2_3PWM();
        //SetupUART(115200);
        NU32_EnableUART2Interrupt();


	// Wait until LCD screen comes up
	wait(1000);	wait(1000);	wait(1000); wait(1000);
	LCDConfig();
	LCDSetup();


        ClearLCDScreen();

        char msg[32];
        sprintf(msg,"UART demo. Press A to start");
	WriteLCD(1,msg);

        int button = 1;
        while(button == 1) {
            button = BUTTON_A;
        }
        wait(1000);
        while(button == 0)
        {
            button = BUTTON_A;
        }
        wait(1000);
        
        // send dollar signs to enter command mode
        char send1[] = "$$$";
        SerialTransmit(send1);

        wait(1000);wait(1000);wait(1000);
        // print message and wait for press
/*        ClearLCDScreen();
        wait(1000);wait(1000);wait(1000);
        sprintf(msg,"command mode. press A");
	WriteLCD(1,msg);
        wait(1000);wait(1000);wait(1000);
        button = 1;
        while(button == 1) {
            button = BUTTON_A;
        }
        wait(1000);
        while(button == 0)
        {
            button = BUTTON_A;
        }
        wait(1000);
        wait(1000);
*/
        while(next == 0);
        next = 0;

        char send2[] = "GB\n";
        SerialTransmit(send2);

        while(1)
        {
            ClearLCDScreen();
            WriteLCD(0,string);
            wait(10000);
            wait(10000);
            wait(10000);
        }

        // receive response from chip
        char temp[4];
        SerialReceive(temp, 4, CHAR_MODE);
        
//        // print response to lcd
//        ClearLCDScreen();
//        WriteLCD(1,temp);
        

        
        char temp2[32];
        SerialReceive(temp2, 32, HEX_MODE);

        ClearLCDScreen();
        WriteLCD(1,temp2);


 /*
  * Software State machine
  *     POR:
  *         Try to connect
  *
  *
  */

        return 0;
}
Пример #7
0
void SocketModbusMasterLoop( void )
{
	char AdrIP[ 30 ];
	int SizeQuestionToAsk;
	static char QuestionFrame[ 800 ];
	int ResponseSize;
	static char ResponseFrame[ 800 ];
        int SendResultStatus = 0;

#ifdef __XENO__
	pthread_set_name_np(pthread_self(), __FUNCTION__);
#endif

	while( ClientSocketRunning )
	{
// TODO: added for XENO... not found why required for now...
// (task suspended otherwise with the watchdog, seen with dmesg!)
// removing this next line for EMC- we don't use XENO

//		DoPauseMilliSecs( 10 );

		if (InfosGene->LadderState!=STATE_RUN)
		{
			DoPauseMilliSecs( ModbusTimeInterFrame );
		}
		else
		{
			SizeQuestionToAsk = ModbusMasterAsk( (unsigned char*)AdrIP, (unsigned char*)QuestionFrame );
			if ( SizeQuestionToAsk>0 )
			{
				if ( ModbusSerialPortNameUsed[ 0 ]=='\0' )
				{
					SendResultStatus = SendSocketModbusMaster( AdrIP, 502, QuestionFrame, SizeQuestionToAsk );
				}
				else
				{
					// before sending queston, set size of frame that will be to receive after! 
					SerialSetResponseSize( 1/*adr*/+GetModbusResponseLenghtToReceive()+2/*crc*/, ModbusTimeOutReceipt );
					SerialSend( QuestionFrame, SizeQuestionToAsk );
				}
                                if ( SendResultStatus==0 )
				{
				    if ( ModbusTimeAfterTransmit>0 )
				    {
				    	// useful for USB-RS485 dongle...
				    	if( ModbusDebugLevel>=3 )
						printf(_("INFO CLASSICLADDER- after transmit delay now...%i milliseconds\n"),ModbusTimeAfterTransmit);
					DoPauseMilliSecs( ModbusTimeAfterTransmit );
			    	    }
				
				    if ( ModbusSerialPortNameUsed[ 0 ]=='\0' )
					ResponseSize = WaitRespSocketModbusMaster( ResponseFrame, 800, ModbusTimeOutReceipt );
				    else
					ResponseSize = SerialReceive( ResponseFrame, 800, ModbusTimeOutReceipt );
				    NbrFrames++;
				    if ( ResponseSize==0 )
					printf(_("ERROR CLASSICLADDER-  MODBUS NO RESPONSE (Errs=%d/%d) !?\n"), ++CptErrors, NbrFrames);
				    if ( !TreatModbusMasterResponse( (unsigned char *)ResponseFrame, ResponseSize ) )
				    {
					// trouble? => flush all (perhaps we can receive now responses for old asks
					// and are shifted between ask/resp...)
					if ( ModbusSerialPortNameUsed[ 0 ]!='\0' )
						SerialFlush( );
				    }
                                }
				DoPauseMilliSecs( ModbusTimeInterFrame );
			}
			else
			{
//				sleep( 1 );
				DoPauseMilliSecs( 1000 );
			}
		}
	
	}
#ifndef __WIN32__
	pthread_exit(NULL);
#endif

}