将MicroChip的无效操作数编译为二进制=='时出错

时间:2014-05-29 13:25:02

标签: c struct

static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt,coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{

 if (inpkt->payload.len == 0)
    return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, COAP_RSPCODE_BAD_REQUEST, COAP_CONTENTTYPE_TEXT_PLAIN);

 if (inpkt->payload.p[0] == '1')
 {
    light = '1';


    UARTWrite(1,"ON\n");


    return coap_make_response(scratch, outpkt, (const UINT8_VAL *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN);
 }
 else
 {
    light = '0';

    UARTWrite(1,"OFF\n");

    return coap_make_response(scratch, outpkt, (const UINT8_VAL *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN);
 }
}

这是我的代码,我在第5行收到错误。结构定义为

typedef struct
{
    coap_header_t hdr;
    coap_buffer_t tok;
    uint8_t numopts;
    coap_option_t opts[MAXOPT];
    coap_buffer_t payload;
} coap_packet_t;

    typedef struct
{
    const UINT8_VAL *p;
    size_t len;
} coap_buffer_t;

当我尝试使用主要是C编译器的Microchip c30编译器进行编译时,我收到以下错误。

  

错误: - 错误:二进制的操作数无效==

请嘻嘻!!

1 个答案:

答案 0 :(得分:0)

尝试使用UINT8_VAL的Val成员进行比较:

inpkt->payloadp[0].Val == '1'