Beispiel #1
0
static PyObject*
decode_json(JSONData *jsondata)
{
    PyObject *object;

    skipSpaces(jsondata);
    switch(*jsondata->ptr) {
    case 0:
        PyErr_SetString(JSON_DecodeError, "empty JSON description");
        return NULL;
    case '{':
        object = decode_object(jsondata);
        break;
    case '[':
        object = decode_array(jsondata);
        break;
    case '"':
        object = decode_string(jsondata);
        break;
    case 't':
    case 'f':
        object = decode_bool(jsondata);
        break;
    case 'n':
        object = decode_null(jsondata);
        break;
    case 'N':
        object = decode_nan(jsondata);
        break;
    case 'I':
        object = decode_inf(jsondata);
        break;
    case '+':
    case '-':
        if (*(jsondata->ptr+1) == 'I') {
            object = decode_inf(jsondata);
        } else {
            object = decode_number(jsondata);
        }
        break;
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        object = decode_number(jsondata);
        break;
    default:
        PyErr_SetString(JSON_DecodeError, "cannot parse JSON description");
        return NULL;
    }

    return object;
}
Beispiel #2
0
void decode_cdma_sms(char *pdu, char *from, char *message, int *is_vm) {
    unsigned int i=1;
    int code,length;
    strcpy(from,"000000"); // in case something fails
    strcpy(message,"UNKNOWN"); 
    
    if (is_vm)
        *is_vm = 0;

    while(i*2<strlen(pdu)) {
        get_code_and_length(pdu+i*2,&code,&length);
        if(code==2) // from
            decode_number(pdu+i*2+4,length,from);
        if(code==8) // bearer_data
            decode_bearer_data(pdu+i*2+4,length,message,is_vm);
        i+=length+2;
    }
}
Beispiel #3
0
owerror_t osens_val_receive(
    OpenQueueEntry_t* msg,
    coap_header_iht*  coap_header,
    coap_option_iht*  coap_options
) {
    owerror_t outcome = E_FAIL;
    uint8_t n;
    static uint8_t buf[128];
    uint8_t *pbuf = &buf[0];
    uint8_t index;

    switch (coap_header->Code) {
    case COAP_CODE_REQ_GET:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;
        // /s
        if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) ||
                (coap_options[1].type != COAP_OPTION_NUM_URIPATH))
        {
        } // /s/1 or /s/12
        else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH))
        {

            osens_point_t pt;
#if (MYLINKXS_LIGHT_CONTROL == 0)
            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;


            if(osens_get_point(index,&pt))
            {
                pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0);
                pbuf = insert_point_val(pbuf,&pt);
                pbuf = insert_str(pbuf,(uint8_t*)"}",1,0);


#if (ENABLE_DEBUG_RFF == 1) && (DBG_APP_1 == 1)
                uint8_t pos=0;
                uint8_t *paux;

                rffbuf[pos++]= 0x85;
                rffbuf[pos++]= index;
                paux  = (uint8_t*) &pt.value.fp32;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                paux = (uint8_t*) &pbuf[0];
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;

                openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos);
#endif
            }
            else
                pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0);
#else
            //QUANDO TRABALHANDO COM A LAMPADA ESTAVA ESTE OUTRO CODIGO
            //TODO!!! DEIXAR O CODIGO UNICO
            pt.type = OSENS_DT_U8;
            pt.value.u8 = light_get_value();

            pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0);
            pbuf = insert_point_val(pbuf,&pt);
            pbuf = insert_str(pbuf,(uint8_t*)"}",1,0);


#endif
            outcome = E_SUCCESS;

        }

        if(outcome == E_SUCCESS)
        {
            n = ((uint32_t)pbuf - (uint32_t)buf);
            packetfunctions_reserveHeaderSize(msg, 1 + n);
            msg->payload[0] = COAP_PAYLOAD_MARKER;
            memcpy(&msg->payload[1], buf, n);
            coap_header->Code = COAP_CODE_RESP_CONTENT;
        }

        break;

    case COAP_CODE_REQ_PUT:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;

#if (DEBUG_LOG_RIT  == 1)
        {
            uint8_t   pos=0;

            rffbuf[pos++]= RFF_COMPONENT_STORMCOAP_TX;
            rffbuf[pos++]= 0x01;
            rffbuf[pos++]= coap_options[1].length;
            rffbuf[pos++]= coap_options[2].length;
            rffbuf[pos++]= coap_options[1].type;
            rffbuf[pos++]= coap_options[2].type;
            //rffbuf[pos++]= sensor_points.points[0].value.value.u8;

            openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos);
        }
#endif

        // /s/2/-12.45 or /s/12/12.45
        if((coap_options[1].length == 1 || coap_options[1].length == 2) &&
                (coap_options[2].length > 0) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH) &&
                (coap_options[2].type == COAP_OPTION_NUM_URIPATH))
        {
#if 0
            uint8_t index;
            double number;
            osens_point_t pt;

            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;

            number = decode_number(coap_options[2].pValue,coap_options[2].length);
            pt.type = osens_get_ptype(index);

            if(pt.type >= 0)
            {
                set_point_val(&pt,number);
                if(osens_set_pvalue(index,&pt))
                {
                    // set the CoAP header
                    coap_header->Code = COAP_CODE_RESP_CHANGED;
                    outcome = E_SUCCESS;
                }
            }
#else
            // switch on the light pulse (50 ms)
            light_on();

            opentimers_start(1000,TIMER_ONESHOT,TIME_MS,light_timer);
#endif

        }
        break;

    default:
        outcome = E_FAIL;
        break;
    }

    return outcome;
}
Beispiel #4
0
owerror_t osens_val_receive(
    OpenQueueEntry_t* msg,
    coap_header_iht*  coap_header,
    coap_option_iht*  coap_options
) {
    owerror_t outcome = E_FAIL;
    uint8_t n;
    static uint8_t buf[128];
    uint8_t *pbuf = &buf[0];

    switch (coap_header->Code) {
    case COAP_CODE_REQ_GET:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;
        // /s
        if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) ||
                (coap_options[1].type != COAP_OPTION_NUM_URIPATH))
        {
            // WE DO NOT HAVE SPACE FOR A FULL FRAME WITH ALL PARAMETERS
            // at ~80 bytes we have a overflow
            /*
            uint8_t m;
            osens_point_t pt;
            uint8_t num_points = osens_get_num_points();

            pbuf = insert_str(pbuf,(uint8_t*)"[",1,0);
            if(num_points == 0)
            {
            	pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0);
            }
            else
            {
            	for(m = 0 ; m < num_points ; m++)
            	{
            		if(osens_get_point(m,&pt))
            		{
            			pbuf = insert_str(pbuf, (uint8_t*)"{\"idx\":", 7,0);
            			pbuf = insert_uint(pbuf, m);
            			pbuf = insert_str(pbuf, (uint8_t*)",\"v\":", 5,0);
            			pbuf = insert_point_val(pbuf, &pt);
            			if (m < (num_points - 1))
            				pbuf = insert_str(pbuf, (uint8_t*)"},", 2,0);
            			else
            				pbuf = insert_str(pbuf, (uint8_t*)"}", 1,0);
            		}
            	}
            }
            pbuf = insert_str(pbuf,(uint8_t*)"]",1,0);

            outcome = E_SUCCESS;
            */
        } // /s/1 or /s/12
        else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH))
        {

            uint8_t index;
            osens_point_t pt;

            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;

            if(osens_get_point(index,&pt))
            {
                pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0);
                pbuf = insert_point_val(pbuf,&pt);
                pbuf = insert_str(pbuf,(uint8_t*)"}",1,0);
            }
            else
                pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0);

            outcome = E_SUCCESS;

        }

        if(outcome == E_SUCCESS)
        {
            n = ((uint32_t)pbuf - (uint32_t)buf);
            packetfunctions_reserveHeaderSize(msg, 1 + n);
            msg->payload[0] = COAP_PAYLOAD_MARKER;
            memcpy(&msg->payload[1], buf, n);
            coap_header->Code = COAP_CODE_RESP_CONTENT;
        }

        break;

    case COAP_CODE_REQ_PUT:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;

        // /s/2/-12.45 or /s/12/12.45
        if((coap_options[1].length == 1 || coap_options[1].length == 2) &&
                (coap_options[2].length > 0) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH) &&
                (coap_options[2].type == COAP_OPTION_NUM_URIPATH))
        {
            uint8_t index;
            double number;
            osens_point_t pt;

            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;

            number = decode_number(coap_options[2].pValue,coap_options[2].length);
            pt.type = osens_get_ptype(index);

            //DBG_LOG(0,("App I:%x P:%x L:%x T:%x \n",index,coap_options[2].pValue[0],coap_options[2].length,pt.type));

            if(pt.type >= 0)
            {

                set_point_val(&pt,number);

                //DBG_LOG(1,("WrApp=I:%x T:%x V:%x\n",index,pt.type,pt.value.u16));

#if (MYLINKXS_SENSORS == 1) && (MYLINKXS_REMOTE_CONTROL == 1)
                simula_envio_cmd(&pt);
#endif
                if(osens_set_pvalue(index,&pt))
                {
                    // set the CoAP header
                    coap_header->Code = COAP_CODE_RESP_CHANGED;
                    outcome = E_SUCCESS;
                }
            }
        }
        break;

    default:
        outcome = E_FAIL;
        break;
    }

    return outcome;
}