This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

getting feedback from dk using switch case in function nus_data_handler

Hi,

I'm trying to write a program that i can get a different feedback from my development kit using ble_uart_app example, the idea is using switch case so i send different character or string from smartphone here is what i do:

static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    uint32_t err_code;
    uint64_t counter = 0;
    uint16_t length1 = 0;
    char PrintBuffer[256] = {0};  
//    p_evt->type == BLE_NUS_EVT_RX_DATA;

    for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    {
        switch (p_evt->params.rx_data.p_data[i])
       {
        case 'M':
            memset(PrintBuffer,128,sizeof(PrintBuffer));                                       //clear PrintBuffer buffer
            sprintf(PrintBuffer, "Good Morning,%d\r\n", counter++);                             //prepare data 
            length1 = strlen(PrintBuffer);                                                      //get data length
            err_code = ble_nus_data_send(&m_nus, PrintBuffer, &length1 ,m_conn_handle);          //output data via ble
//            nrf_delay_ms(100); 
            break;
        case 'W':
            memset(PrintBuffer,128,sizeof(PrintBuffer));                                       //clear PrintBuffer buffer
            sprintf(PrintBuffer, "Hello World,%d\r\n", counter++);                              //prepare data 
            length1 = strlen(PrintBuffer);                                                      //get data length
            err_code = ble_nus_data_send(&m_nus, PrintBuffer, &length1 ,m_conn_handle);          //output data via ble
 //           nrf_delay_ms(100); 
            break;
        case 'Andhika':   
            memset(PrintBuffer,128,sizeof(PrintBuffer));                                       //clear PrintBuffer buffer
            sprintf(PrintBuffer, "huebsch,%d\r\n", counter++);                                  //prepare data 
            length1 = strlen(PrintBuffer);                                                      //get data length
            err_code = ble_nus_data_send(&m_nus, PrintBuffer, &length1 ,m_conn_handle);          //output data via ble
 //           nrf_delay_ms(100); 
            break;
        default:
            err_code=app_uart_put(p_evt->params.rx_data.p_data[i]);
            break;
       }
     }

}

my problem is in my switch case there is an error if i put a string as my requirment in 'case' the error says 'charakter constant toolong for its type' and 'warning case label value exceeds maximum value for type' i tried to play with ram but it didn't work. is there any configuration to solve it so i can send more character and getting feedback from the board?

thank you in advance and happy new year

best regards.

Andhika

Related