Beispiel #1
0
void main_bridge(void)
{
    GLOBAL(daytrig)=10;
    GLOBAL(lcdbacklight)=10;
    GLOBAL(privacy) = 3;
    char input[64];
    char led1=0;
    char led2=0;

    usbCDCInit();
    delayms(500);
    nrf_init();
    nrf_config_set(&config);
    
    nrf_rcv_pkt_start(R_CONFIG_EN_CRC);
    while(1){
        int l, i, status;
        CDC_OutBufAvailChar (&l);
        if(l>0){
            gpioSetValue (RB_LED0, led1);led1=1-led1;
            CDC_RdOutBuf (input, &l);
            for(i=0; i<l; i++){
                uint8_t cmd = serialmsg_put(input[i]);
                if( cmd != SERIAL_NONE ){
                    switch( cmd ){
                        case '1':
                            // can we loose packets here?
                            nrf_rcv_pkt_end();
                            status=snd_pkt_no_crc(serialmsg_len, serialmsg_message);
                            //status=nrf_snd_pkt_crc(serialmsg_len, serialmsg_message);
                            nrf_rcv_pkt_start(R_CONFIG_EN_CRC);
                        break;
                        case '3':
                            memcpy(config.txmac, serialmsg_message, 5);
                            nrf_write_long(C_W_REGISTER|R_TX_ADDR,5,config.txmac);
                        break;
                        case '4':
                            memcpy(config.mac0, serialmsg_message, 5);
                            nrf_write_long(C_W_REGISTER|R_RX_ADDR_P0,5,config.mac0);
                            nrf_write_reg(R_EN_RXADDR,1);
                        break;
                        case '5':
                            config.channel=serialmsg_message[0];
                            nrf_set_channel(config.channel);
                            nrf_cmd(C_FLUSH_RX);
                        break;
                        case '6':
                            config.maclen[0]=serialmsg_message[0];
                            nrf_write_reg(R_RX_PW_P0,config.maclen[0]);
                        break;
                        case '7':
                            puts("\\7");
                            char s[sizeof(uint32_t)+1];
                            *((uint32_t*)s) =GetUUID32();
                            s[sizeof(uint32_t)]=0;
                            puts(s);
                            puts("\\0");
                        break;
                        case '8': /* set mac width */
                            nrf_write_reg(R_SETUP_AW,serialmsg_message[0]);
                        break;
                        case '9': // Dis/Enable CRC
                            nrf_write_reg(R_CONFIG, R_CONFIG_PRIM_RX|R_CONFIG_PWR_UP|
                                    ((serialmsg_message[0]&1)?R_CONFIG_EN_CRC :0)|
                                    ((serialmsg_message[0]&2)?R_CONFIG_CRCO :0)
                                    
                                    );
                            /* maybe add enhanced shockburst stuff here */
                            nrf_cmd(C_FLUSH_RX);
                            nrf_write_reg(R_STATUS,0);
                        break;

                    };
                    puts("\\2\\0");
                }
            }
        }
        int len;
        uint8_t buf[32];
        len=nrf_rcv_pkt_poll(sizeof(buf),buf);
        if( len > 0 ){
            gpioSetValue (RB_LED2, led2);led2=1-led2;
            puts("\\1");
            dump_encoded(len, buf);
            puts("\\0");
        }
    }
}
Beispiel #2
0
void main_bridge(void)
{
    GLOBAL(daytrig)=10;
    GLOBAL(lcdbacklight)=10;
    GLOBAL(privacy) = 3;
    char input[64];
    char led1=0;
    char led2=0;

    usbCDCInit();
    delayms(500);
    nrf_init();
    nrf_config_set(&config);
    
    nrf_rcv_pkt_start();
    while(1){
        int l, i, status;
        CDC_OutBufAvailChar (&l);
        if(l>0){
            gpioSetValue (RB_LED0, led1);led1=1-led1;
            CDC_RdOutBuf (input, &l);
            for(i=0; i<l; i++){
                uint8_t cmd = serialmsg_put(input[i]);
                if( cmd != SERIAL_NONE ){
                    switch( cmd ){
                        case '1':
                            // can we loose packets here?
                            nrf_rcv_pkt_end();
                            status=snd_pkt_no_crc(serialmsg_len, serialmsg_message);
                            //status=nrf_snd_pkt_crc(serialmsg_len, serialmsg_message);
                            nrf_rcv_pkt_start();
                        break;
                        case '3':
                            memcpy(config.txmac, serialmsg_message, 5);
                            nrf_config_set(&config);
                        break;
                        case '4':
                            memcpy(config.mac0, serialmsg_message, 5);
                            nrf_config_set(&config);
                        break;
                        case '5':
                            config.channel=serialmsg_message[0];
                            nrf_config_set(&config);
                        break;
                        case '6':
                            config.maclen[0]=serialmsg_message[0];
                            nrf_config_set(&config);
                        break;
                        case '7':
                            puts("\\7");
                            char s[sizeof(uint32_t)+1];
                            *((uint32_t*)s) =GetUUID32();
                            s[sizeof(uint32_t)]=0;
                            puts(s);
                            puts("\\0");
                        break;
                    };
                    puts("\\2\\0");
                }
            }
        }
        int len;
        uint8_t buf[32];
        len=nrf_rcv_pkt_poll(sizeof(buf),buf);
        if( len > 0 ){
            gpioSetValue (RB_LED2, led2);led2=1-led2;
            puts("\\1");
            dump_encoded(len, buf);
            puts("\\0");
        }
    }
}