100 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#include "app_main.h"
 | 
						|
#include "app_config.h"
 | 
						|
#include "app_common.h"
 | 
						|
#include "app_cus_task.h"
 | 
						|
#include "app_bypass_proc.h"
 | 
						|
#include "app_atcmd_proc.h"
 | 
						|
#include "app_atcmd_handle.h"
 | 
						|
 | 
						|
static uint16_t g_at_send_len = 0;
 | 
						|
static uint8_t g_dest_mac[6] = {0};
 | 
						|
static uint8_t g_at_send_flag = 0;
 | 
						|
 | 
						|
void app_bypass_set_param(uint8_t len, uint8_t * mac, uint8_t flag )
 | 
						|
{
 | 
						|
    g_at_send_len = len;
 | 
						|
    os_mem_cpy(g_dest_mac, mac, IOT_MAC_ADDR_LEN);
 | 
						|
 | 
						|
    g_at_send_flag = flag;
 | 
						|
    if (g_at_send_flag == 1)
 | 
						|
        app_set_work_mode(APP_WORK_MODE_BYPASS);
 | 
						|
    else
 | 
						|
        app_set_work_mode(APP_WORK_MODE_AT);
 | 
						|
}
 | 
						|
 | 
						|
uint16_t app_bypass_data_parse(uint8_t * buffer, uint32_t buffer_len)
 | 
						|
{
 | 
						|
    uint8_t dst_addr[IOT_MAC_ADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 | 
						|
 | 
						|
    if (g_at_send_flag == 1) {
 | 
						|
        if (ERR_OK == app_plc_tx(buffer, buffer_len, g_dest_mac,
 | 
						|
            ID_PLC_DATA_BYPASS, NULL)) {
 | 
						|
            ATCMD_PRINT("send data to plc...\n");
 | 
						|
            AT_RESP_OK();
 | 
						|
        } else {
 | 
						|
            ATCMD_PRINT("send data failed\n");
 | 
						|
            AT_RESP_ERROR();
 | 
						|
            return ERR_FAIL;
 | 
						|
        }
 | 
						|
    } else {
 | 
						|
        if (iot_plc_is_client_mode()) {
 | 
						|
            if (iot_mac_addr_valid(app_get_cco_mac_addr())) {
 | 
						|
                iot_mac_addr_cpy(dst_addr, app_get_cco_mac_addr());
 | 
						|
            } else {
 | 
						|
        /* in bypass mode, we provide two ways to handle sta connectionless
 | 
						|
         * broadcast. if support ieee 1901 protocol, sta connectionless
 | 
						|
         * broadcast is allowed. otherwise, it will be dropped.
 | 
						|
         */
 | 
						|
#if (SUPPORT_IEEE_1901 == 0)
 | 
						|
                APP_PRINTF("[INF] %s STA Not Ready, CCO MAC Invalid",
 | 
						|
                    __FUNCTION__);
 | 
						|
                return ERR_NOT_READY;
 | 
						|
#endif
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        if (ERR_OK != app_plc_tx(buffer, buffer_len, dst_addr,
 | 
						|
            ID_PLC_DATA_BYPASS, NULL)) {
 | 
						|
            APP_PRINTF("[ERR] %s Send Data Failed !!", __FUNCTION__);
 | 
						|
            return ERR_FAIL;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
void app_bypass_data_handle(uint16_t data_id, app_source_e data_src,
 | 
						|
    uint8_t *data, uint32_t data_len, void *info)
 | 
						|
{
 | 
						|
    (void)info;
 | 
						|
 | 
						|
    if (data_id == ID_PLC_DATA_BYPASS) {
 | 
						|
        app_tx_to_cus_uart_msg(data, data_len);
 | 
						|
    } else if (data_id == ID_PLC_REMOTE_AT) {
 | 
						|
        if (iot_plc_is_client_mode()) {
 | 
						|
            app_atcmd_data_parse(data, data_len, data_src);
 | 
						|
        } else {
 | 
						|
            APP_PRINTF("send at remote to cco");
 | 
						|
            app_tx_to_cus_uart_msg(data, data_len);
 | 
						|
        }
 | 
						|
    } else {
 | 
						|
        APP_PRINTF("mode not support data");
 | 
						|
    }
 | 
						|
 | 
						|
    return;
 | 
						|
} |