コード例 #1
0
char *pando_protocol_get_uri(struct pando_buffer *pdbuf)
{
	if (pdbuf == NULL)
	{
		return NULL;
	}

	struct sub_device_buffer device_buffer;
	device_buffer.buffer_length = pdbuf->buff_len - pdbuf->offset;
	device_buffer.buffer = pdbuf->buffer + pdbuf->offset;

	struct pando_command cmd_body;
	struct TLV *cmd_param = get_sub_device_command(&device_buffer, &cmd_body);
	
	int i = 0;
	uint16_t tlv_type, tlv_length;
	for (i = 0; i < cmd_body.params->count; i++)
	{
		pd_memcpy(&tlv_type, &(cmd_param->type), sizeof(tlv_type));
		tlv_type = net16_to_host(tlv_type);

		pd_memcpy(&tlv_length, &(cmd_param->length), sizeof(tlv_length));
		tlv_length = net16_to_host(tlv_length);

		if (tlv_type == TLV_TYPE_URI)
		{
			return (char *)cmd_param->value;
		}

		cmd_param = (struct TLV *)((uint8_t *)cmd_param + sizeof(struct TLV) + tlv_length);
	}

	return NULL;
}
コード例 #2
0
static void ICACHE_FLASH_ATTR
decode_command(struct sub_device_buffer *device_buffer)
{
	struct pando_command cmd_body;
	PARAMS *cmd_param = get_sub_device_command(device_buffer, &cmd_body);
	if(CMD_QUERY_STATUS == cmd_body.command_id)
	{
		PRINTF("receive a get request\n");
		send_current_status();
	}
}
コード例 #3
0
ファイル: stdoutsub.c プロジェクト: DenisZheng/pando-protocol
/* event exactly the same as command */
void FUNCTION_ATTRIBUTE decode_command(struct pando_buffer *buf, uint16_t payload_type)
{
	// 网关解包
	pando_protocol_decode(buf, payload_type);

    // 网关向子设备传递数据包,如果是向子设备发包,请用对应的设备send函数
    struct sub_device_buffer *device_buffer = pd_malloc(sizeof(struct sub_device_buffer));
    device_buffer->buffer_length = pando_get_package_length(buf);
    device_buffer->buffer = pd_malloc(device_buffer->buffer_length);

 
    // 从网关数据包中获取子设备数据包
    pd_memcpy(device_buffer->buffer, pando_get_package_begin(buf), device_buffer->buffer_length);
 
    // 获取数据完成,释放网关缓冲区
    pando_buffer_delete(buf);




	/* 以下是子设备解析代码 */
	struct pando_command cmd_body;
	// 1.子设备解命令包, 返回参数区的起始位置 
	struct TLVs *cmd_params_block = get_sub_device_command(device_buffer, &cmd_body);
	pd_printf("sub id %02x, cmd num %02x, pri %02x, count: %d\n", 
        cmd_body.sub_device_id, cmd_body.command_num,
        cmd_body.priority, cmd_body.params->count);
	
	// 2.子设备获取命令参数
	uint16_t tlv_length;
    uint8_t *value = pd_malloc(100);

    uint8_t param1 = get_next_uint8(cmd_params_block);
    show_package(&param1, sizeof(param1));
    uint32_t param2 = get_next_uint32(cmd_params_block);
    show_package(&param2, sizeof(param2));
    char *param_bytes = get_next_bytes(cmd_params_block, &tlv_length);
    pd_memcpy(value, param_bytes, tlv_length);
    show_package(value, tlv_length);

    pd_free(value);
	// 3. 删除子设备缓冲区
	delete_device_package(device_buffer);
}
コード例 #4
0
/******************************************************************************
 * FunctionName : zero_device_data_process.
 * Description  : process the received data of zero device(zero device is the gateway itself).
 * Parameters   : uint.
 * Returns      : none.
*******************************************************************************/
static void FUNCTION_ATTRIBUTE
zero_device_data_process(uint8_t * buffer, uint16_t length)
{
    struct pando_command cmd_body;
    uint16_t type = 0;
    uint16_t len = 0;
    struct sub_device_buffer * device_buffer = (struct sub_device_buffer *)pd_malloc(sizeof(struct sub_device_buffer));
    if(device_buffer == NULL)
    {
    	pd_printf("%s:malloc error!\n", __func__);
        return;
    }
    device_buffer->buffer = (uint8_t*)pd_malloc(length);
    if(device_buffer->buffer == NULL)
    {
    	pd_printf("%s:malloc error!\n", __func__);
    	pd_free(device_buffer);
        return;
    }
    pd_memcpy(device_buffer->buffer, buffer, length);
    device_buffer->buffer_length = length;
    struct TLVs *cmd_param = get_sub_device_command(device_buffer, &cmd_body);
    if(COMMON_COMMAND_SYN_TIME == cmd_body.command_num )
    {
    	pd_printf("PANDO: synchronize time\n");
        uint64_t time = get_next_uint64(cmd_param);
        show_package((uint8_t*)(&time), sizeof(time));
       // pando_set_system_time(time);
    }

    if( device_buffer->buffer != NULL)
    {
    	pd_free( device_buffer->buffer);
    	device_buffer->buffer = NULL;
    }

    if(device_buffer != NULL)
    {
    	pd_free(device_buffer);
    	device_buffer = NULL;
    }
}