Example #1
0
ptu32_t led_flash1(void)
{
    u32 my_para;
    while(1)
    {
        Djy_GetEventPara(&my_para,NULL);
        switch(my_para)
        {
            case 1:
                GPIO_SettoLow(CN_GPIO_C, (1<<4)|(1<<6)|(1<<8));
                GPIO_SettoHigh(CN_GPIO_C, (1<<9));
                break;
            case 2:
                GPIO_SettoLow(CN_GPIO_C, (1<<4)|(1<<6)|(1<<9));
                GPIO_SettoHigh(CN_GPIO_C, (1<<8));
               break;
            case 3:
                GPIO_SettoLow(CN_GPIO_C, (1<<6)|(1<<9)|(1<<8));
                GPIO_SettoHigh(CN_GPIO_C, (1<<4));
                break;
            case 4:
                GPIO_SettoLow(CN_GPIO_C, (1<<9)|(1<<4)|(1<<8));
                GPIO_SettoHigh(CN_GPIO_C, (1<<6));
                break;
            default:break;
        }
        Djy_ParaUsed(0);
        Djy_WaitEvttPop(Djy_MyEvttId(),NULL,CN_TIMEOUT_FOREVER);
    }
}
Example #2
0
File: telnet.c Project: djyos/djyos
static ptu32_t __TelnetClientMain(void)
{
    int sock;
    int chars;  //how many chars in the buf
    char ch;
    int  rcvlen;
    u8   buf[CN_CLIENT_BUFLEN];

    tagTelnetClient  *client;


    Djy_GetEventPara((ptu32_t *)&client,NULL);
    sock = client->sock;
    sendexact(sock,CN_CLIENT_WELCOM,strlen(CN_CLIENT_WELCOM));
    sendexact(sock,CN_CLIENT_PREFIX,strlen(CN_CLIENT_PREFIX));
    chars = 0;
    while(1)
    {
        rcvlen = recv(sock,&ch,sizeof(ch),0);
        if(rcvlen == sizeof(ch))
        {
            //now check each char to do something
            if ((ch == '\r') || (ch == '\n'))
            {
                buf[chars] = '\0';
                if(chars > 1)
                {
                    if(0 == strcmp((const char *)buf,"quit"))
                    {
                        break;
                    }
                    else
                    {
                        //exe the command
                        Sh_ExecCommand((char *)buf);
                        sendexact(sock,CN_CLIENT_PREFIX,strlen(CN_CLIENT_PREFIX));
                        //reset the buffer
                        chars =0;
                    }
                }
            }
            else  //put the char in the buffer or move from the buf
            {
                if (ch == 8)    // Backspace
                {
                    if(chars > 0)
                    {
                        chars --;
                    }
                }
                else
                {
                    if(chars < CN_CLIENT_BUFLEN-1) //the last one will be '\0'
                    {
                        buf[chars] = ch;
                        chars++;
                    }
                    else
                    {
                        //exceed the buffer part ,will be ignored
                    }
                }
            }
        }
        else if(rcvlen == 0)
        {
            break;//bye bye
        }
        else
        {
            //do nothing ,no data yet
        }
    }

    __TelnetClientRemove(client);
    free(client);
    closesocket(sock);
    return 0;
}