A59 -V1.1版本提交

This commit is contained in:
2024-10-10 17:41:53 +08:00
parent 16b6433a98
commit 5f032cd320
903 changed files with 171909 additions and 22876 deletions

View File

@ -89,8 +89,35 @@ struct IAACallbacks
void* cb_ctx;
};
typedef struct __auto_cfg_info
{
short width;//pixel
short height;
short density;
short fps;
char* wifi_ssid;
char* wifi_passwd;
char wifi_channel;
bool disable_auto_audio;
bool video_auto_start;
} auto_cfg_info;
extern auto_cfg_info *g_auto_link_info;
int android_auto_init(struct IAACallbacks* cbs);
int android_auto_rfcomm_read_data_proc(char *buf, int len);
void android_auto_start();
void android_auto_set_rfcomm_info(const char * ssid, const char * passwd, const char * mac, int securityMode, const char * ip, int port);
void android_auto_set_BT_paring_status(bool paired, const char *pinCode, int status);
void android_auto_send_touch_event(unsigned int x, unsigned int y, int action);
void android_auto_send_key_event(unsigned int keycode, int press);
void android_auto_send_knob_event(unsigned int keycode, int delta);
void android_auto_set_night_mode(bool night);
void android_auto_get_video_focus(int mode);
void android_auto_release_video_focus(int mode);
void android_auto_get_audio_focus(int mode);
void android_auto_release_audio_focus(int mode);
#endif

Binary file not shown.

View File

@ -0,0 +1,302 @@
#include <stdio.h>
#include <stdint.h>
#include "carlink_video.h"
#include "carlink_common.h"
#include "AndroidAuto.h"
#include "board.h"
#if CARLINK_AA
struct AAHandle
{
struct ICalinkEventCallbacks carlinkEventCB;
struct IAACallbacks carlinkAACB;
bool mInitDone;
bool mBTConnected;
bool mRfcommReady;
char mLocalBTMac[6];
char mRemoteBTMac[6];
char mIp[32];
};
//extern int debug_buf_ref;
struct AAHandle gAACtx;
static bool g_aa_disable = false;
static void android_auto_notify_event(struct carlink_event *ev, enum CARLINK_EVENT_TYPE type, bool disable_filter)
{
ev->link_type = CARLINK_AUTO_WIRELESS;
ev->disable_filter = disable_filter;
ev->type = type;
carlink_notify_event(ev);
}
static void start_aa(struct AAHandle* pctx)
{
if (!pctx->mInitDone)
return;
//if (pctx->mBTConnected)
// return;
if (!pctx->mRfcommReady)
return;
if (g_aa_disable)
return;
printf("%s:%d\r\n", __func__, __LINE__);
g_auto_link_info->wifi_ssid = (char *)carlink_get_wifi_ssid();
g_auto_link_info->wifi_passwd = (char *)carlink_get_wifi_passwd;
android_auto_set_rfcomm_info((const char*)carlink_get_wifi_ssid(),
(const char*)carlink_get_wifi_passwd(), (const char*)carlink_get_wifi_mac(), 5, (const char*)pctx->mIp, 0);
android_auto_start();
}
static void onEventAA(void* ctx, const struct carlink_event *ev)
{
enum CARLINK_EVENT_TYPE type;
struct AAHandle* pctx = (struct AAHandle*)ctx;
if (NULL == ev)
return;
if (ev->link_type != CARLINK_AUTO_WIRELESS && !ev->disable_filter)// skip not aa event
return;
type = ev->type;
switch (type) {
case -1: {
break;
}
case CARLINK_EVENT_INIT_DONE:
pctx->mInitDone = true;
start_aa(pctx);
break;
case CARLINK_EVENT_BT_CONNECT: {
pctx->mBTConnected = true;
start_aa(pctx);
break;
}
case CARLINK_EVENT_BT_AA_RFCOMM_READY: {
pctx->mRfcommReady = true;
start_aa(pctx);
break;
}
case CARLINK_EVENT_BT_DISCONNECT: {
pctx->mBTConnected = false;
pctx->mRfcommReady = false;
break;
}
case CARLINK_EVENT_WIFI_CONNECT: {
break;
}
case CARLINK_EVENT_MSG_SESSION_CONNECT: {
break;
}
case CARLINK_EVENT_MSG_SESSION_STOP: {
printf("%s:%d\r\n", __func__, __LINE__);
start_aa(pctx);
break;
}
default:
break;
}
}
static void aa_rfcomm_data_read(void* ctx, const void* buf, int len)
{
struct AAHandle* pctx = (struct AAHandle*)ctx;
if (!pctx->mRfcommReady)
return;
android_auto_rfcomm_read_data_proc((char*)buf, len);
}
static int rf_write_transfer_cb(void* cb_ctx, char *buf, int len)
{
int ret = -1;
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
if (!pctx->mRfcommReady)
return -1;
ret = carlink_auto_rfcomm_data_write(buf, len);
return ret;
}
static void video_init_impl(void* cb_ctx, int w, int h, int x, int y)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
printf("x:%d y:%d w:%d h:%d\r\n", x, y, w, h);
set_carlink_active_video_info(x, y);
h264_dec_ctx_init();
set_carlink_display_state(1);
//debug_buf_ref = 1;
}
static void video_uninit_impl(void* cb_ctx)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
set_carlink_display_state(0);
set_carlink_active_video_info(0, 0);
}
int g_v_count;
static void video_play_impl(void* cb_ctx, char *buf, int len)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
video_frame_s* frame = NULL;
get_retry:
frame = get_h264_frame_buf();
if (NULL == frame) {
//printf("h264 frame is empty\r\n");
vTaskDelay(pdMS_TO_TICKS(10));
goto get_retry;
//continue;
}
memcpy(frame->cur, buf, len);
frame->len = len;
notify_h264_frame_ready(&frame);
if (g_v_count++ > 50) {
//android_auto_get_video_focus(0);
}
}
static void audio_init_callback_impl(void* cb_ctx, int type, int sample, int ch, int bits)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void audio_uninit_callback_impl(void* cb_ctx, int type)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void audio_play_impl(void* cb_ctx, int type, char *buf, int len)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void mic_init_callback_impl(void* cb_ctx, int sample, int ch, int bits)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void mic_uninit_callback_impl(void* cb_ctx)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void mic_capture_impl(void* cb_ctx, char *buf, int len)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void bt_paring_request_callback_impl(void* cb_ctx, const char *phoneAddr, int pairingMethod)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
static void status_notify_impl(void* cb_ctx, int status_type)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
struct carlink_event ev = {0};
if (status_type == LINK_REMOVED) {
printf("%s:%d\r\n", __func__, __LINE__);
android_auto_notify_event(&ev, CARLINK_EVENT_MSG_SESSION_STOP, 0);
}
}
static void json_msg_notify_impl(void* cb_ctx, char *buf, int len)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
}
int carlink_aa_init()
{
int ret = -1;
struct AAHandle* pctx = &gAACtx;
struct IAACallbacks* carlinkAACBPtr = NULL;
memset((void*)pctx, 0, sizeof(struct AAHandle));
g_auto_link_info->width = CARLINK_VIDEO_WIDTH;
g_auto_link_info->height = CARLINK_VIDEO_HEIGHT;
g_auto_link_info->fps = 30;
g_auto_link_info->density = 160;
g_auto_link_info->disable_auto_audio = 1;
g_auto_link_info->video_auto_start = 1;
set_carlink_display_info(0, 0, CARLINK_VIDEO_WIDTH, CARLINK_VIDEO_HEIGHT);
set_carlink_video_info(CARLINK_VIDEO_WIDTH, CARLINK_VIDEO_HEIGHT, 30);
ret = carlink_common_init();
pctx->carlinkEventCB.onEvent = onEventAA;
pctx->carlinkEventCB.rfcomm_data_read = aa_rfcomm_data_read;
pctx->carlinkEventCB.cb_ctx = (void*)pctx;
carlink_register_event_callbacks(&pctx->carlinkEventCB);
ret = carlink_bt_wifi_init();
carlinkAACBPtr = &pctx->carlinkAACB;
carlinkAACBPtr->video_init = video_init_impl;
carlinkAACBPtr->video_uninit = video_uninit_impl;
carlinkAACBPtr->video_play = video_play_impl;
carlinkAACBPtr->audio_init_callback = audio_init_callback_impl;
carlinkAACBPtr->audio_uninit_callback = audio_uninit_callback_impl;
carlinkAACBPtr->mic_init_callback = mic_init_callback_impl;
carlinkAACBPtr->mic_uninit_callback = mic_uninit_callback_impl;
carlinkAACBPtr->mic_capture = mic_capture_impl;
carlinkAACBPtr->bt_paring_request_callback = bt_paring_request_callback_impl;
carlinkAACBPtr->status_notify = status_notify_impl;
carlinkAACBPtr->json_msg_notify = json_msg_notify_impl;
carlinkAACBPtr->rf_read_transfer_cb = NULL;
carlinkAACBPtr->rf_write_transfer_cb = rf_write_transfer_cb;
carlinkAACBPtr->cb_ctx = (void*)pctx;
ret = android_auto_init(&pctx->carlinkAACB);
{
char ip[4] = {0};
carlink_get_ap_ip_addr(ip);
sprintf(pctx->mIp, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
}
{
struct carlink_event ev = {0};
android_auto_notify_event(&ev, CARLINK_EVENT_INIT_DONE, 0);
}
return 0;
}
void carlink_aa_enable(int enable)
{
if (enable) {
g_aa_disable = false;
} else {
g_aa_disable = true;
}
}
#else
int carlink_aa_init()
{
return 0;
}
void carlink_aa_enable(int enable)
{
(void)enable;
}
#endif

View File

@ -11,7 +11,6 @@ struct AAHandle
{
struct ICalinkEventCallbacks carlinkEventCB;
struct IAACallbacks carlinkAACB;
bool mInitDone;
bool mBTConnected;
@ -21,8 +20,11 @@ struct AAHandle
char mIp[32];
};
//extern int debug_buf_ref;
struct AAHandle gAACtx;
static bool g_aa_disable = false;
static void android_auto_notify_event(struct carlink_event *ev, enum CARLINK_EVENT_TYPE type, bool disable_filter)
{
@ -40,7 +42,12 @@ static void start_aa(struct AAHandle* pctx)
// return;
if (!pctx->mRfcommReady)
return;
if (g_aa_disable)
return;
printf("%s:%d\r\n", __func__, __LINE__);
g_auto_link_info->wifi_ssid = (char *)carlink_get_wifi_ssid();
g_auto_link_info->wifi_passwd = (char *)carlink_get_wifi_passwd;
android_auto_set_rfcomm_info((const char*)carlink_get_wifi_ssid(),
(const char*)carlink_get_wifi_passwd(), (const char*)carlink_get_wifi_mac(), 5, (const char*)pctx->mIp, 0);
android_auto_start();
@ -119,12 +126,17 @@ static int rf_write_transfer_cb(void* cb_ctx, char *buf, int len)
return ret;
}
int g_v_count;
static void video_init_impl(void* cb_ctx, int w, int h, int x, int y)
{
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
printf("x:%d y:%d w:%d h:%d\r\n", x, y, w, h);
set_carlink_active_video_info(x, y);
h264_dec_ctx_init();
set_carlink_display_state(1);
//carlink_bt_close();
g_v_count = 0;
//debug_buf_ref = 1;
}
static void video_uninit_impl(void* cb_ctx)
@ -132,6 +144,7 @@ static void video_uninit_impl(void* cb_ctx)
struct AAHandle* pctx = (struct AAHandle*)cb_ctx;
set_carlink_display_state(0);
set_carlink_active_video_info(0, 0);
}
static void video_play_impl(void* cb_ctx, char *buf, int len)
@ -153,6 +166,9 @@ get_retry:
frame->len = len;
notify_h264_frame_ready(&frame);
if (g_v_count++ > 50) {//enable_malloc_debug = 1;
//android_auto_get_video_focus(0);
}
}
static void audio_init_callback_impl(void* cb_ctx, int type, int sample, int ch, int bits)
@ -204,7 +220,7 @@ static void json_msg_notify_impl(void* cb_ctx, char *buf, int len)
int carlink_aa_init()
int _carlink_aa_init()
{
int ret = -1;
struct AAHandle* pctx = &gAACtx;
@ -212,6 +228,14 @@ int carlink_aa_init()
memset((void*)pctx, 0, sizeof(struct AAHandle));
g_auto_link_info->width = CARLINK_VIDEO_WIDTH;
g_auto_link_info->height = CARLINK_VIDEO_HEIGHT;
g_auto_link_info->fps = 30;
g_auto_link_info->density = 160;
g_auto_link_info->disable_auto_audio = 1;
g_auto_link_info->video_auto_start = 1;
set_carlink_display_info(0, 0, CARLINK_VIDEO_WIDTH, CARLINK_VIDEO_HEIGHT);
set_carlink_video_info(CARLINK_VIDEO_WIDTH, CARLINK_VIDEO_HEIGHT, 30);
@ -255,10 +279,41 @@ int carlink_aa_init()
}
return 0;
}
static void taskInitCarlinkAA(void* param)
{
_carlink_aa_init();
vTaskDelete(NULL);
}
int carlink_aa_init()
{
xTaskCreate(taskInitCarlinkAA, "initThread", 2048 * 4, NULL, 1, NULL);
return 0;
}
void carlink_aa_enable(int enable)
{
if (enable) {
g_aa_disable = false;
} else {
g_aa_disable = true;
}
}
#else
int carlink_aa_init()
{
return 0;
}
void carlink_aa_enable(int enable)
{
(void)enable;
}
#endif

View File

@ -0,0 +1,133 @@
#ifndef MYCOMMON_H_H
#define MYCOMMON_H_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#ifndef CAPLAY_LINK_TYPE
#define CAPLAY_LINK_TYPE
typedef enum
{
CARPLAY = 0x00,
CARLIFE,
ANDROID_CARLIFE,
ANDROID_MIRROR = 3,
IOS_CARLIFE,
ANDROID_AUTO = 5,
ECLINK = 0x06,
CARPLAY_WIRELESS
}Link_TYPE;
#endif
//general function
typedef enum __USB_MODE
{
UNDEFINED = 0,
HOST,
PERIPHERAL,
OTG
}USB_MODE;
#define LOGV(...) printf(__VA_ARGS__); printf("\r\n");
struct view_area
{
short w;
short h;
short x;
short y;
};
typedef struct __cfg_info
{
char *iap2_name;
char *iap2_modelIdentifier;
char *iap2_manfacturer;
char *iap2_serialnumber;
char *iap2_sw_ver;
char *iap2_hw_ver;
char *iap2_vehicleInfo_name;
char *iap2_product_uuid;
char *iap2_usb_serial_num;
char *manfacturer;
char *oem_icon_label;
char *oem_icon_path;
char *os_info;
char *iOSVersionMin;
char *limited_ui_elements;
char *guuid;
char *devid;
char link_type;
char btmac[6];
bool oem_icon_visible;
bool limited_ui;
bool right_hand_driver;
bool night_mode;
bool has_knob;
bool has_telbutton;
bool has_mediabutton;
bool has_proxsensor;
bool has_EnhancedReqCarUI;
bool has_ETCSupported;
bool HiFiTouch;
bool LoFiTouch;
unsigned short usb_country_code;
unsigned short tp_verndor_code;
unsigned short tp_product_code;
unsigned short tel_verndor_code;
unsigned short tel_product_code;
unsigned short knob_verndor_code;
unsigned short knob_product_code;
unsigned short proxsensor_verndor_code;
unsigned short proxsensor_product_code;
short width;//pixel
short height;
short fps;
short screen_width_phy;//mm
short screen_height_phy;
char encrypt_ic_i2c_bus_num;
char encrypt_ic_addr;
char usb_idx;
char need_sw_aec;
char aec_delay;
bool tvout_enable;
bool use_remote_audio;
char video_type;
short icurrent;
int duck_vol;
char enable_iap_carplay_sess;
char *keychain_path_dir;
char* wifi_ssid;
char* wifi_passwd;
char* public_key;
char* src_version;
char ip_v4_addr[4];
char wifi_channel;
short net_port;
char carplay_net_ready;
char disable_bonjour;
char iap_carplay_rej;
bool enable_enhanced_siri;
bool enable_single_ui;
bool is_old_carplay_ver;
struct view_area area[3];
char view_area_index;
}cfg_info;
extern cfg_info *g_link_info;
#ifdef __cplusplus
}
#endif
#endif

Binary file not shown.

View File

@ -36,6 +36,8 @@ struct carplay_ctx
};
struct carplay_ctx g_cp_handle;
static bool g_cp_disable = false;
static void carplay_init_parameter();
void start_mdnsd();
@ -56,9 +58,22 @@ static void iap2_link_status(void *ctx, IAP2_LINK_STATUS status){}
static int iap2_write_data(void *ctx, char *buf, int len)
{
(void)ctx;
printf("iap2_write_data --------------------------\r\n");
return carlink_iap_data_write((unsigned char *)buf, len);
}
static void iap2_msg_time_update(void *ctx, long long time, int zone_offset){}
extern uint32_t tire_front_time;
extern uint32_t tire_rear_time;
extern uint32_t fml_stamp_to_time(uint32_t timep , uint32_t time[]);
static void iap2_msg_time_update(void *ctx, long long time, int zone_offset){
(void)ctx;
printf("iap2_msg_time_update time ======================================== %lld , %d\r\n",time,zone_offset);
uint32_t time_transfer[6];
uint32_t sum = (uint32_t)time;
tire_rear_time = sum;
tire_front_time = sum;
fml_stamp_to_time(sum,time_transfer);
}
static void iap2_msg_gps(void *ctx, unsigned char session, int start){}
static void iap2_msg_gps_gprmc_data_status(void *ctx, int value_a, int value_v, int value_x){}
static void iap2_msg_identify(void *ctx, int type, int ok)
@ -163,6 +178,9 @@ static void start_cp(struct carplay_ctx* pctx)
if (pctx->mCarplayConnected)
return;
if (g_cp_disable)
return;
g_link_info->enable_iap_carplay_sess = 1;
g_link_info->is_old_carplay_ver = 0;
g_link_info->wifi_passwd = (char *)carlink_get_wifi_passwd();
@ -270,6 +288,7 @@ static void taskInitCarlinkCpProc(void* param)
(void)param;
iap2_callbacks iap2_cbs;
memset((void *)&iap2_cbs, 0, sizeof(iap2_cbs));
iap2_cbs.iap2_link_status_cb = iap2_link_status;
@ -388,8 +407,8 @@ static void carplay_init_parameter()
g_link_info->width = CARLINK_VIDEO_WIDTH;//pixel
g_link_info->height = CARLINK_VIDEO_HEIGHT;
g_link_info->fps = 30;
g_link_info->screen_width_phy = PHYSICAL_WIDTH;//mm
g_link_info->screen_height_phy = PHYSICAL_HEIGHT;
g_link_info->screen_width_phy = CARLINK_VIDEO_WIDTH;
g_link_info->screen_height_phy = CARLINK_VIDEO_HEIGHT;
g_link_info->icurrent = 1000;
g_link_info->enable_iap_carplay_sess = 1;
@ -424,6 +443,16 @@ int carlink_cp_init()
return 0;
}
void carlink_cp_enable(int enable)
{
if (enable) {
g_cp_disable = false;
} else {
g_cp_disable = true;
}
}
//int mdnsd_task();
static void taskMdnsdProc(void* param)
{
@ -442,5 +471,11 @@ int carlink_cp_init()
return 0;
}
void carlink_cp_enable(int enable)
{
(void)enable;
}
#endif

View File

@ -2,5 +2,6 @@
#define _CARLINK_CP_H_
int carlink_cp_init();
void carlink_cp_enable(int enable);
#endif

View File

@ -0,0 +1,393 @@
//#include "os_adapt.h"
#include <FreeRTOS_POSIX.h>
#include <task.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include "board.h"
#include "timer.h"
#include "iot_wifi.h"
#include "mmcsd_core.h"
#include "carlink_utils.h"
#include "console.h"
#include "fsc_bt.h"
#include "iap.h"
#if !defined(USE_LWIP) || !USE_LWIP
#error "Carplay need lwip!"
#endif
#include "ethernet.h"
#include "tcpip.h"
#include "lwip/apps/lwiperf.h"
#include "dhcp.h"
#include "carlink_video.h"
#include "mycommon.h"
#include "wifi_conf.h"
#include "carlink_cp_priv.h"
//#define USE_WLAN_STA
static char g_cp_bt_mac[13] = {0};
static bool g_cp_bt_mac_ready = false;
static uint8_t cp_ap_ssid[64] = {"ap63011"};
static uint8_t cp_ap_passwd[16] = {"88888888"};
extern int wps_connect_done;
static const uint8_t ucIPAddress[4] = {192, 168, 13, 1};
static const uint8_t ucNetMask[4] = {255, 255, 255, 0};
static const uint8_t ucGatewayAddress[4] = {0, 0, 0, 0};
static int lwip_tcpip_init_done_flag = 0;
//static int g_bt_iap_ready = 0;
//static int g_dhcp_client_cp_ready = 0;
static struct netif gnetif[4];
extern int wifi_add_custom_ie(void *cus_ie, int ie_num);
int mmcsd_wait_sdio_ready(int32_t timeout);
static void cp_reset_wifi_ap_info(const char *prefex);
static void cp_start_wlan();
extern err_t dhcp_server_start(struct netif *netif, ip4_addr_t *start, ip4_addr_t *end);
extern err_t wlan_ethernetif_init(struct netif *netif);
#define lwip_ipv4_addr(addr) ((addr[0]) | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24))
static void tcpip_init_done(void *arg)
{
(void)arg;
//lwip_tcpip_init_done_flag = 1;
}
void lwiperf_report_cb_impl(void *arg, enum lwiperf_report_type report_type,
const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
{
(void)arg;
printf("lwiperf_report_cb_impl bytes:%d %d ms \r\n", bytes_transferred, ms_duration);
}
int cp_wlan_tcp_ip_is_ready()
{
return lwip_tcpip_init_done_flag;
}
//dd3000a0400000020022020961726B6D6963726F0003064C696E75780004030102030606ffffffffffff070666fadde250c0
static u8 carplay_vendor_ie[] = {
0xdd, 0x30, 0x00, 0xa0, 0x40, 0x00, 0x00, 0x02, 0x00, 0x22, 0x02, 0x09, 0x61, 0x72, 0x6B, 0x6D,
0x69, 0x63, 0x72, 0x6F, 0x00, 0x03, 0x06, 0x4C, 0x69, 0x6E, 0x75, 0x78, 0x00, 0x04, 0x03, 0x01,
0x02, 0x03, 0x06, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x06, 0x66, 0xfa, 0xdd, 0xe2,
0x50, 0xc0
};
rtw_custom_ie_t carplay_ie[1] = {{carplay_vendor_ie, PROBE_RSP | BEACON}};
void carplay_add_vendor_ie()
{
wifi_add_custom_ie((void *)carplay_ie, 1);
}
void carplay_ie_replace_bt_mac(const char* btmac_str, int btmac_str_len)
{
char btmac[6] = {0};
string2hex((char *)btmac_str, btmac_str_len, btmac, 6);
memcpy((void*)g_link_info->btmac, (void*)btmac, 6);
//sscanf(btmac_str, "%02x%02x%02x%02x%02x%02x", btmac[0], btmac[1], btmac[2], btmac[3], btmac[4], btmac[5]);
carplay_vendor_ie[36] = btmac[0];
carplay_vendor_ie[37] = btmac[1];
carplay_vendor_ie[38] = btmac[2];
carplay_vendor_ie[39] = btmac[3];
carplay_vendor_ie[40] = btmac[4];
carplay_vendor_ie[41] = btmac[5];
//memcpy((void*)(carplay_vendor_ie + 36), (void*)btmac, 6);
{
int i;
for (i = 0; i < sizeof(carplay_vendor_ie); i++) {
printf("0x%02x, ", carplay_vendor_ie[i]);
}printf("\r\n");
}
}
#if defined(USE_WLAN_STA)
static void dump_ip_addr(const char *msg, const ip_addr_t *server_addr)
{
printf("%s %d.%d.%d.%d \r\n", msg,
ip4_addr1_16(ip_2_ip4(server_addr)), ip4_addr2_16(ip_2_ip4(server_addr)), ip4_addr3_16(ip_2_ip4(server_addr)), ip4_addr4_16(ip_2_ip4(server_addr)));
}
static void cp_dhcp_client_status_callback(struct netif *netif, int status, const ip_addr_t *server_addr)
{
if (&gnetif[0] == netif) {
dump_ip_addr("dhcp server ip :", (const ip_addr_t *)server_addr);
dump_ip_addr("dhcp client ip :", (const ip_addr_t *)&netif->ip_addr);
dump_ip_addr("dhcp client netmask:", (const ip_addr_t *)&netif->netmask);
dump_ip_addr("dhcp client gw :", (const ip_addr_t *)&netif->gw);
ip_addr_t *server_addr1 = (ip_addr_t *)&netif->ip_addr;
g_link_info->ip_v4_addr[0] = ip4_addr1_16(ip_2_ip4(server_addr1));
g_link_info->ip_v4_addr[1] = ip4_addr2_16(ip_2_ip4(server_addr1));
g_link_info->ip_v4_addr[2] = ip4_addr3_16(ip_2_ip4(server_addr1));
g_link_info->ip_v4_addr[3] = ip4_addr4_16(ip_2_ip4(server_addr1));
//g_dhcp_client_cp_ready = 1;
//if (g_bt_iap_ready)
//carplay_start();
}
}
#endif
void restart_bt_wifi()
{
cp_bt_close();
netif_set_down(&gnetif[0]);
WIFI_Off();
vTaskDelay(pdMS_TO_TICKS(2000));
cp_bt_open();
start_ap(36, (const char *)cp_ap_ssid, (const char *)cp_ap_passwd, 1);
carplay_add_vendor_ie();
netif_set_default(&gnetif[0]);
netif_set_up(&gnetif[0]);
}
static void cp_start_wlan()
{
char ap_prefix[5] = {0};
ip4_addr_t ip_addr;
ip4_addr_t netmask;
ip4_addr_t gw;
ip4_addr_t dhcp_addr_start;
ip4_addr_t dhcp_addr_end;
while(!g_cp_bt_mac_ready) {
vTaskDelay(pdMS_TO_TICKS(10));
}
memcpy(ap_prefix, g_cp_bt_mac + 8, 4);
cp_reset_wifi_ap_info(ap_prefix);
#if !defined(USE_WLAN_STA)
start_ap(36, (const char *)cp_ap_ssid, (const char *)cp_ap_passwd, 1);
#else
//start_sta((const char *)cp_ap_ssid, (const char *)cp_ap_passwd, 1);
dhcp_regisger_status_callback(cp_dhcp_client_status_callback);
#endif
ip_addr.addr = lwip_ipv4_addr(ucIPAddress);
netmask.addr = lwip_ipv4_addr(ucNetMask);
gw.addr = lwip_ipv4_addr(ucGatewayAddress);
tcpip_init(tcpip_init_done, NULL);
netif_add(&gnetif[0],
#if LWIP_IPV4
&ip_addr, &netmask, &gw,
#endif
NULL, wlan_ethernetif_init, tcpip_input);
netif_set_default(&gnetif[0]);
#if !defined(USE_WLAN_STA)
uint8_t addr_start[4] = {192, 168, 13, 20};
uint8_t addr_end[4] = {192, 168, 13, 30};
dhcp_addr_start.addr = lwip_ipv4_addr(addr_start);
dhcp_addr_end.addr = lwip_ipv4_addr(addr_end);
dhcp_server_start(&gnetif[0], &dhcp_addr_start, &dhcp_addr_end);
//g_dhcp_client_cp_ready = 1;
#endif
//netif_set_up(&gnetif[0]);
lwiperf_start_tcp_server_default(lwiperf_report_cb_impl, NULL);
lwip_tcpip_init_done_flag = 1;
carplay_add_vendor_ie();
}
void cp_wlan_start(void){
netif_set_up(&gnetif[0]);
}
static void cp_reset_wifi_ap_info(const char *prefex)
{
if (prefex) {
memset(cp_ap_ssid, 0, sizeof(cp_ap_ssid));
sprintf((char *)cp_ap_ssid, "AP630_CP_%s", prefex);
}
g_link_info->wifi_passwd = cp_ap_passwd;
g_link_info->wifi_ssid = cp_ap_ssid;
g_link_info->wifi_channel = 36;
g_link_info->ip_v4_addr[0] = ucIPAddress[0];
g_link_info->ip_v4_addr[1] = ucIPAddress[1];
g_link_info->ip_v4_addr[2] = ucIPAddress[2];
g_link_info->ip_v4_addr[3] = ucIPAddress[3];
}
static void cp_bt_callback(char * cAtStr)
{
char* cmd_para = NULL;
printf("\r\nfsc_bt_callback_ec %s %d\r\n", cAtStr, strlen(cAtStr));
struct cp_event ev;
memset((void*)&ev, 0, sizeof(ev));
ev.type = -1;
if (0) {
} else if (0 == strncmp(cAtStr, "+IAPDATA=", 9)) {
char ble_buf[256] = {0};
int data_len, i;
int data_str_len = (strlen(cAtStr) - 9);
cmd_para = cAtStr + 9;
data_len = data_str_len / 2;
string2hex(cmd_para, data_str_len, ble_buf, data_len);
for (i = 0; i < data_len; i++) {
printf("%02x ", ble_buf[i]);
}printf("\r\n");
iap2_read_data_proc(ble_buf, data_len);
} else if (0 == strncmp(cAtStr, "+GATTDATA=", 10)) {
} else if (0 == strncmp(cAtStr, "+GATTSTAT=1",11)) {
//ev.type = EC_EVENT_BT_DISCONNECT;
printf("TRACE[%s][%d]:EC_EVENT_BT_DISCONNECT\r\n",__func__ ,__LINE__);
ev.type = CP_EVENT_BT_DISCONNECT;
carlink_cp_notify_event(&ev);
} else if (0 == strncmp(cAtStr, "+GATTSTAT=3",11)) {
printf("TRACE[%s][%d]:EC_EVENT_BT_CONNECT\r\n",__func__ ,__LINE__);
ev.type = CP_EVENT_BT_CONNECT;
carlink_cp_notify_event(&ev);
} else if (0 == strncmp(cAtStr, "+ADDR=", 6)) {
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+NAME=AP630_CP_%s\r\n", (cAtStr + 6 + 8));
printf("ADDR:%s\r\n", cAtStr + 6);
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
memset(cmd_str, 0, sizeof(cmd_str));
sprintf(cmd_str, "AT+LENAME=AP630_CP_%s\r\n", (cAtStr + 6 + 8));
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
memcpy(g_cp_bt_mac, (cAtStr + 6), 12);
carplay_ie_replace_bt_mac(cAtStr + 6, 12);
g_cp_bt_mac_ready = true;
} else if (0 == strncmp(cAtStr, "+VER", 4)) {
char* cmd = "AT+ADDR\r\n";
console_send_atcmd(cmd, strlen(cmd));//get mac addr
} else if (0 == strncmp(cAtStr, "+NAME=", 6)) {
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+LEADDR\r\n");
console_send_atcmd(cmd_str, strlen(cmd_str));//get LE addr
} else if (0 == strncmp(cAtStr, "+LEADDR=", 6)) {
char hexMacAddr[6] = {0};
char m_tmp_buf[64] = {0};
string2hex(&cAtStr[8], 12, hexMacAddr, sizeof(hexMacAddr));
sprintf(m_tmp_buf, "AT+ADVDATA=%s\r\n", hexMacAddr);
console_send_atcmd(m_tmp_buf, 19);
} else if (0 == strncmp(cAtStr, "+GATTSENT=", 10)) {
return;
} else if (0 == strncmp(cAtStr, "+IAPSTAT=3", 10)) {
//g_bt_iap_ready = 1;
//if (g_dhcp_client_cp_ready)
//carplay_start();
ev.type = CP_EVENT_BT_IAP_READY;
carlink_cp_notify_event(&ev);
}
}
int iap_data_write(unsigned char *data, int len)
{
uint8_t *at_str = NULL, *at_str_ptr = NULL;
uint8_t *at_prefix = "AT+IAPSEND=";
int prefix_len = strlen((char *)at_prefix);
int cmd_len = (len * 2 + prefix_len + 2);
at_str = (uint8_t *)pvPortMalloc(cmd_len + 1);
memset(at_str, 0, cmd_len + 1);
if (NULL == at_str)
return -1;
at_str_ptr = at_str;
sprintf((char*)at_str_ptr, "%s", (char*)at_prefix);
at_str_ptr += prefix_len;
hex2str(data, len, (char *)at_str_ptr);
at_str_ptr += (len * 2);
*at_str_ptr++ = '\r';
*at_str_ptr++ = '\n';
console_send_atcmd((char *)at_str, cmd_len);
vPortFree(at_str);
return len;
}
void cp_bt_open()
{
char at_str[] = {"AT+BTEN=1\r\n"};
console_send_atcmd((char *)at_str, strlen(at_str));
}
void cp_bt_close()
{
char at_str[] = {"AT+BTEN=0\r\n"};
console_send_atcmd((char *)at_str, strlen(at_str));
}
static void cp_wifi_event_handler( WIFIEvent_t * xEvent )
{
WIFIEventType_t xEventType = xEvent->xEventType;
char mac_str[32] = {0};
char *mac = NULL;
if (xEvent) {
mac = xEvent->xInfo.xAPStationConnected.ucMac;
sprintf(mac_str, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
wps_connect_done = 0;
if (0) {
} else if (eWiFiEventConnected == xEventType) {// meter is sta
printf("\r\n The meter is connected to ap \r\n");
} else if (eWiFiEventDisconnected == xEventType) {// meter is sta
printf("\r\n The meter is disconnected from ap \r\n");
} else if (eWiFiEventAPStationConnected == xEventType) {// meter is ap
printf("\r\n The meter in AP is connected by sta %s \r\n", mac_str);
} else if (eWiFiEventAPStationDisconnected == xEventType) {// meter is ap
printf("\r\n The sta %s is disconnected from the meter \r\n", mac_str);
}
}
static BaseType_t cp_wifi_init()
{
int status;
WIFI_Context_init();
WIFI_RegisterEvent(eWiFiEventMax, cp_wifi_event_handler);
for (;;) {
status = mmcsd_wait_sdio_ready((int32_t)portMAX_DELAY);
if (status == MMCSD_HOST_PLUGED) {
printf("detect sdio device\r\n");
break;
}
}
return 0;
}
static void bt_set_support_carplay()
{
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+PROFILE=33962\r\n");
console_send_atcmd(cmd_str, strlen(cmd_str));
}
int carlink_cp_bt_wifi_init()
{
carlink_ey_video_init();
cp_wifi_init();
console_register_cb(NULL, cp_bt_callback);
fsc_bt_main();
bt_set_support_carplay();
cp_bt_open();
cp_start_wlan();
printf("bt wlan init is ok\r\n");
return 0;
}

View File

@ -0,0 +1,262 @@
#include "os_adapt.h"
#include <FreeRTOS_POSIX.h>
#include <task.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include "board.h"
#include "timer.h"
#include "iot_wifi.h"
#include "mmcsd_core.h"
#include "carlink_utils.h"
#include "console.h"
#include "fsc_bt.h"
#include "iap.h"
#if !defined(USE_LWIP) || !USE_LWIP
#error "Carplay in freertos must use lwip!"
#endif
#include "ethernet.h"
#include "tcpip.h"
#include "lwip/apps/lwiperf.h"
#include "dhcp.h"
#include "carlink_video.h"
#include "mycommon.h"
static char g_cp_bt_mac[13] = {0};
static bool g_cp_bt_mac_ready = false;
static uint8_t cp_ap_ssid[64] = {"ap63011"};
static uint8_t cp_ap_passwd[16] = {"88888888"};
extern int wps_connect_done;
static const uint8_t ucIPAddress[4] = {192, 168, 13, 1};
static const uint8_t ucNetMask[4] = {255, 255, 255, 0};
static const uint8_t ucGatewayAddress[4] = {0, 0, 0, 0};
static int lwip_tcpip_init_done_flag = 0;
static struct netif gnetif[4];
int mmcsd_wait_sdio_ready(int32_t timeout);
static void cp_reset_wifi_ap_info(const char *prefex);
static void cp_start_wlan();
extern err_t dhcp_server_start(struct netif *netif, ip4_addr_t *start, ip4_addr_t *end);
extern err_t wlan_ethernetif_init(struct netif *netif);
#define lwip_ipv4_addr(addr) ((addr[0]) | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24))
static void tcpip_init_done(void *arg)
{
(void)arg;
//lwip_tcpip_init_done_flag = 1;
}
void lwiperf_report_cb_impl(void *arg, enum lwiperf_report_type report_type,
const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
{
(void)arg;
printf("lwiperf_report_cb_impl bytes:%d %d ms \r\n", bytes_transferred, ms_duration);
}
int cp_wlan_tcp_ip_is_ready()
{
return lwip_tcpip_init_done_flag;
}
static void cp_start_wlan()
{
const char *customer = "ark630hv100";
char ap_prefix[5] = {0};
ip4_addr_t ip_addr;
ip4_addr_t netmask;
ip4_addr_t gw;
ip4_addr_t dhcp_addr_start;
ip4_addr_t dhcp_addr_end;
while(!g_cp_bt_mac_ready) {
vTaskDelay(pdMS_TO_TICKS(10));
}
memcpy(ap_prefix, g_cp_bt_mac + 8, 4);
cp_reset_wifi_ap_info(ap_prefix);
start_ap(36, (const char *)cp_ap_ssid, (const char *)cp_ap_passwd, 1);
ip_addr.addr = lwip_ipv4_addr(ucIPAddress);
netmask.addr = lwip_ipv4_addr(ucNetMask);
gw.addr = lwip_ipv4_addr(ucGatewayAddress);
tcpip_init(tcpip_init_done, NULL);
netif_add(&gnetif[0],
#if LWIP_IPV4
&ip_addr, &netmask, &gw,
#endif
NULL, wlan_ethernetif_init, tcpip_input);
netif_set_default(&gnetif[0]);
uint8_t addr_start[4] = {192, 168, 13, 20};
uint8_t addr_end[4] = {192, 168, 13, 30};
dhcp_addr_start.addr = lwip_ipv4_addr(addr_start);
dhcp_addr_end.addr = lwip_ipv4_addr(addr_end);
dhcp_server_start(&gnetif[0], &dhcp_addr_start, &dhcp_addr_end);
netif_set_up(&gnetif[0]);
lwiperf_start_tcp_server_default(lwiperf_report_cb_impl, NULL);
lwip_tcpip_init_done_flag = 1;
}
static void cp_reset_wifi_ap_info(const char *prefex)
{
memset(cp_ap_ssid, 0, sizeof(cp_ap_ssid));
sprintf((char *)cp_ap_ssid, "AP630_%s", prefex);
g_link_info->wifi_passwd = cp_ap_passwd;
g_link_info->wifi_ssid = cp_ap_ssid;
g_link_info->wifi_channel = 36;
g_link_info->ip_v4_addr[0] = ucIPAddress[0];
g_link_info->ip_v4_addr[1] = ucIPAddress[1];
g_link_info->ip_v4_addr[2] = ucIPAddress[2];
g_link_info->ip_v4_addr[3] = ucIPAddress[3];
}
static void cp_bt_callback(char * cAtStr)
{
char* cmd_para = NULL;
printf("\r\nfsc_bt_callback_ec %s %d\r\n", cAtStr, strlen(cAtStr));
if (0) {
} else if (0 == strncmp(cAtStr, "+IAPDATA=", 9)) {
char ble_buf[256] = {0};
int data_len, i;
int data_str_len = (strlen(cAtStr) - 9);
cmd_para = cAtStr + 9;
data_len = data_str_len / 2;
string2hex(cmd_para, data_str_len, ble_buf, data_len);
for (i = 0; i < data_len; i++) {
printf("%02x ", ble_buf[i]);
}printf("\r\n");
iap2_read_data_proc(ble_buf, data_len);
} else if (0 == strncmp(cAtStr, "+GATTDATA=", 10)) {
} else if (0 == strncmp(cAtStr, "+GATTSTAT=1",11)) {
//ev.type = EC_EVENT_BT_DISCONNECT;
printf("TRACE[%s][%d]:EC_EVENT_BT_DISCONNECT\r\n",__func__ ,__LINE__);
} else if (0 == strncmp(cAtStr, "+GATTSTAT=3",11)) {
printf("TRACE[%s][%d]:EC_EVENT_BT_CONNECT\r\n",__func__ ,__LINE__);
} else if (0 == strncmp(cAtStr, "+ADDR=", 6)) {
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+NAME=EC_%s\r\n", (cAtStr + 6));
printf("ADDR:%s\r\n", cAtStr + 6);
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
memset(cmd_str, 0, sizeof(cmd_str));
sprintf(cmd_str, "AT+LENAME=EC_%s\r\n", (cAtStr + 6));
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
g_cp_bt_mac_ready = true;
memcpy(g_cp_bt_mac, (cAtStr + 6), 12);
} else if (0 == strncmp(cAtStr, "+VER", 4)) {
char* cmd = "AT+ADDR\r\n";
console_send_atcmd(cmd, strlen(cmd));//get mac addr
} else if (0 == strncmp(cAtStr, "+NAME=", 6)) {
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+LEADDR\r\n");
console_send_atcmd(cmd_str, strlen(cmd_str));//get LE addr
} else if (0 == strncmp(cAtStr, "+LEADDR=", 6)) {
char hexMacAddr[6] = {0};
char m_tmp_buf[64] = {0};
string2hex(&cAtStr[8], 12, hexMacAddr, sizeof(hexMacAddr));
sprintf(m_tmp_buf, "AT+ADVDATA=%s\r\n", hexMacAddr);
console_send_atcmd(m_tmp_buf, 19);
} else if (0 == strncmp(cAtStr, "+GATTSENT=", 10)) {
return;
} else if (0 == strncmp(cAtStr, "+IAPSTAT=3", 10)) {
carplay_start();
}
}
int iap_data_write(unsigned char *data, int len)
{
uint8_t *at_str = NULL, *at_str_ptr = NULL;
uint8_t *at_prefix = "AT+IAPSEND=";
int prefix_len = strlen((char *)at_prefix);
int cmd_len = (len * 2 + prefix_len + 2);
at_str = (uint8_t *)pvPortMalloc(cmd_len + 1);
memset(at_str, 0, cmd_len + 1);
if (NULL == at_str)
return -1;
at_str_ptr = at_str;
sprintf((char*)at_str_ptr, "%s", (char*)at_prefix);
at_str_ptr += prefix_len;
hex2str(data, len, (char *)at_str_ptr);
at_str_ptr += (len * 2);
*at_str_ptr++ = '\r';
*at_str_ptr++ = '\n';
console_send_atcmd((char *)at_str, cmd_len);
vPortFree(at_str);
return len;
}
static void cp_wifi_event_handler( WIFIEvent_t * xEvent )
{
WIFIEventType_t xEventType = xEvent->xEventType;
wps_connect_done = 0;
if (0) {
} else if (eWiFiEventConnected == xEventType) {// meter is sta
printf("\r\n The meter is connected to ap \r\n");
} else if (eWiFiEventDisconnected == xEventType) {// meter is sta
printf("\r\n The meter is disconnected from ap \r\n");
} else if (eWiFiEventAPStationConnected == xEventType) {// meter is ap
printf("\r\n The meter in AP is connected by sta %s \r\n", xEvent->xInfo.xAPStationConnected.ucMac);
} else if (eWiFiEventAPStationDisconnected == xEventType) {// meter is ap
printf("\r\n The sta %s is disconnected from the meter \r\n", xEvent->xInfo.xAPStationDisconnected.ucMac);
}
}
static BaseType_t cp_wifi_init()
{
int status;
WIFI_Context_init();
WIFI_RegisterEvent(eWiFiEventMax, cp_wifi_event_handler);
for (;;) {
status = mmcsd_wait_sdio_ready((int32_t)portMAX_DELAY);
if (status == MMCSD_HOST_PLUGED) {
printf("detect sdio device\r\n");
break;
}
}
return 0;
}
static void bt_set_support_carplay()
{
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+PROFILE=33962\r\n");
console_send_atcmd(cmd_str, strlen(cmd_str));
}
int carlink_cp_bt_wifi_init()
{
carlink_ey_video_init();
cp_wifi_init();
console_register_cb(NULL, cp_bt_callback);
fsc_bt_main();
bt_set_support_carplay();
cp_start_wlan();
printf("bt wlan init is ok\r\n");
return 0;
}

View File

@ -632,7 +632,7 @@ int32_t ec_ble_write(void * data, uint32_t len);
int32_t ec_ble_read(void * data, uint32_t len);
int32_t ec_ble_open();
void ec_ble_close();
extern char strQrText[100];
extern char strQrText[200];
void* initECTiny(void* param)
{
char uuid[32] = {0};

View File

@ -3,288 +3,259 @@
#include "ECTypes.h"
#define ECSDK_VERSION "1.0.10"
#define ECSDK_VERSION "1.0.13.1"
typedef struct {
/**
* @brief 互联连接状态回调函数
* @param status 互联连接状态
* @param type 互联连接类型
* @note 此函数是非常重要的回调函数。它会返回整个互联的状态。
* 有部分互联功能接口比如EC_startMirror()/EC_enableDownloadPhoneAppHud()/EC_enableDownloadPhoneAppHud() 等,
* 都需要 status为 EC_CONNECT_STATUS_CONNECT_SUCCEED 时,调用才能生效。
* 因为这些接口都是在互联成功之后(ECTiny与手机app建立了通讯)才能发指令给手机app对应功能才能开启。
*/
void (*onECConnectStatus)(ECConnectedStatus status, ECConnectedType type);
void (*onMirrorStatus)(ECMirrorStatus status);
/**
* @brief Called when EasyConnected status changed.
*
* @param status The changed EasyConnected message.
* @brief 投屏状态
* @param status 互联投屏状态
*/
void (*onMirrorStatus)(ECMirrorStatus status);
/**
* @brief 互联状态变更通知
* @param status 变更的状态
*/
void (*onECStatusMessage)(ECStatusMessage status);
/**
* @brief Called when the phone app sends down HUD information.
*
* @param data HUD information.
* @brief 手机下发HUD信息时回调
* @param data HUD信息
*/
void (*onPhoneAppHUD)(const ECNavigationHudInfo *data);
/**
* @brief Called when the phone app sends down HUD Road Junction Picture.
* @brief 手机下发道路引导图时回调
* @param data
*/
void (*onPhoneAppHUDRoadJunctionPicture)(const ECHudRoadJunctionPictureInfo* data);
/*
* @brief Called when phone app tell the music info.
*
* @param data The information of music.
*/
/**
* @brief 手机音乐信息变化时回调
* @param data
*/
void (*onPhoneAppMusicInfo)(const ECAppMusicInfo *data);
/**
* @brief Called when the phone app sends down some information.
*
* @param data Buffer of app information.
*
* @param length Buffer length.
*
* @note data is json string, the fields includes os, osVersion and ip.
* Called when ECSDK::openTransport succeed.
* @brief 手机下发app信息时回调
* @param data app信息
* @param length app信息长度
* @note data 是json字符串, 包括手机类型、系统版本、ip地址等。
* ECTiny 与 手机app建立通讯后会回调此函数
*/
void (*onPhoneAppInfo)(const void *data, uint32_t length);
/**
* @brief Called when ECSDK wants car to do call operations(dial or hang up) via Bluetooth.
*
* @param type Operation type.
*
* @param name The person's name of corresponding number.
*
* @param number Phone numbers.
*
* @note Phone app is not able to dial or hang up automatically due to the latest system access limitation,
* however, car is able to do it via Bluetooth. Therefore, ECSDK moves the call operations
* to car, which can dial or hang up when this method is called.
* @brief 需要拨打或者挂断蓝牙电话时回调
* @param type 操作类型
* @param name 电话拨打的姓名
* @param number 电话号码
* @note 受限于Android/iOS系统的权限在车机上点击互联投屏的过来的拨打电话ECTiny无法完成电话的拨打和接听操作因此需要依赖于车机系统的蓝牙模块完成。
* 车机的投屏界面上点击拨打蓝牙电话时,此回调函数会把拨打的用户姓名和电话号码传到车机上,由车机蓝牙模块完成电话的拨打
* 1.需要车机端作为蓝牙免提设备Hand-Free-Device
* 2.亿连的蓝牙电话功能需要在车机和手机的HFP保持连接后才可以正常启用。
*/
void (*onCallAction)(ECCallType type, const char *name, const char *number);
/**
* @brief Called when bulk data is received.
*
* @brief 接收手机端发送的数据块
* @param data Buffer of bulk data.
*
* @param length Buffer length.
*
*/
void (*onBulkDataReceived)(const void *data, uint32_t length);
/**
* @brief onRealMirrorSizeChanged
* @param realWidth
* @param realHeight
*
* \note The actual size of the projection screen does not equal the size of the video stream in some cases.
* The surrounding area is filled with black. This message calls back the actual size of the projection screen
* @brief 投屏状态变更
* @param ECVideoInfo 视屏参数
* @note 投屏的实际宽高、横竖屏切换时回调此函数
*/
void (*onMirrorInfoChanged)(const ECVideoInfo *info);
/**
* @brief Called when the license authorization failed. After this interface was called,
* all connections would be forced closed.
*
* @param errCode Error code.
*
* @param errMsg Error message.
* @brief 鉴权失败时回调此函数。ECTiny功能全部不可用
* @param errCode 主要用于亿连后台进行排查的错误码,无需关心具体值。
* @param errMsg 错误信息。
* @note 此回调函数需要处理,当出现激活失败时给与提示。
* 该回调一般出现在互联建立过程中出现时ECTiny会在内部进行释放动作。
* ECTiny使用者需要保证合法的激活校验流程之后重新初始化ECSDK方可使用。
*/
void (*onLicenseAuthFail)(int32_t errCode, const char *errMsg);
/**
* @brief Called when the license authorization succeed.
*
* @param code success code. The code can gain specific meaning by ECAuthSuccessCode.
*
* @param msg success information.
*
* @param msg the description information.
*
* @brief 鉴权成时回调此函数
* @param code 正常错误码,无需关心具体值。
* @param msg 正常激活log信息。
* @note 该接口回调一般出现在互联建立过程中在首次进行激活手机IME号备案激活回调会包含剩余数量等信息SDK使用者可根据具体的使用场景进行相关展示。
*/
void (*onLicenseAuthSuccess)(int32_t code, const char *msg);
/**
* @brief Called when registered command was triggered by VR.
*
* @param carCmd The triggered command.
*
* @note Voice control can be implemented with this method by VR.
*
* @see ECSDK::registerCarCmds
* @brief 当注册的控车指令被vr激活时回调
* @param carCmd 触发的控车指令
* @see EC_registerCarCmds()
*/
void (*onCarCmdNotified)(const ECCarCmd *carCmd);
/**
* @brief Called when phone app request the HU to start input.
*
* @param info relevant parameters about the input.
* @brief 监听手机端文字输入
* @param info 当前需要输入的文字信息包括输入类型文字、数字、电话号码等最大输入长度默认的文字最大行数以及Enter键默认的显示效果及动作。
* @note 监听手机端输入法的开始输入状态,并传递此次输入文字的相关信息。
*/
void (*onInputStart)(const ECInputInfo *info);
/**
* @brief Called when phone app request the HU to cancel input.
* @note 监听手机端输入法的结束或者取消的状态,此时车机端键盘也需要取消。
*/
void (*onInputCancel)();
/**
* @brief Called when phone app tell the selection of input.
* @brief 监听手机端输入光标位置、选择状态信息
* @param start 光标开始的位置
* @param stop 光标结束的位置
* @note 监听手机端输入文字的选择状态,光标状态,车机端并做状态展示。仅对安卓手机有效,苹果手机互联无此回调。
*/
void (*onInputSelection)(int32_t start, int32_t stop);
/**
* @brief Called when phone app tell the text of input.
* @brief 同步当前手机端的文字信息到车机
* @param text 当前手机端输入的文字信息。
* @note 如在手机端也对输入框内的文字进行输入,需要同步至车机端,保持车机端和手机端的状态同步。
*/
void (*onInputText)(const char *text);
/**
* @brief Called when phone app send the text of VR or TTS.
* @brief 对识别内容进行展示
* @param info 手机端语音引擎识别后的文字内容信息。
*/
void (*onVRTextReceived)(const ECVRTextInfo *info);
/**
* @brief Called when phone app tell the page list.
*
* @param pages Array of the struct ECPageInfo.
*
* @param length The length of the array.
* @brief 获取快捷方式列表信息
* @param pages 返回快捷方式的数组,参考 ECTypes.h 的 ECPageInfo 定义主要包含图标的编号、名称、icon的唯一标识信息
* @param length pages数组长度
* @note ECPageInfo::page 字段标识了每一个快捷方式的唯一标识,通过该标识,可以实现两个主要的功能:
* 1. 通过page编号可以通过调用 ECSDK::queryPageIcon 获取快捷方式的图标资源。
* 2. 通过page编号可以通过调用 ECSDK::openAppPage 实现快捷打开对应指定手机APP页面
*/
void (*onPageListReceived)(const ECPageInfo *pages, int32_t length);
/**
* @brief Called when phone app tell the icons.
*
* @param icons Array of the struct ECIconInfo.
*
* @param length The length of the array.
* @brief 手机app回调图标信息
* @param icons 返回快捷方式图标资源的数组,参考 ECTypes.h 的 ECIconInfo 定义主要包含icon的编号、icon的格式、icon图像数据、icon的数据长度
* @param length icons的数组长度。
*/
void (*onPageIconReceived)(const ECIconInfo *icons, int32_t length);
/**
* @brief Called when phone app tell weather.
*
* @param data Buffer of weather information.
*
* @param length Buffer length.
*
* @note data pointed to a json string buffer.
* @brief 回调天气信息
* @param data 天气信息字符串
* @param length 字符串长度
* @note data 是一个固定格式的json字符串
*/
void (*onWeatherReceived)(const char *data, int32_t length);
/**
* @brief Called when phone app tell vr tips.
*
* @param data Buffer of tips information.
*
* @param length Buffer length.
*
* @note data pointed to a json string buffer.
* @brief 请求VR提醒文字
* @param data VR文字
* @param length data长度
* @note data是一个json字符串
* 在使用车机端本地语音助手时,一般需要有一些常驻提示类的使用帮助,这些文字主要通过手机端传输至车机端,由车机端系统完成展示。
*/
void (*onVRTipsReceived)(const char *data, int32_t length);
/**
* @brief Called when the app requests networking
*
* @param clientInfo Mobile phone related information
*
* @note
* @brief 手机app发送到车机的请求组网
* @param clientInfo 手机app的相关信息
* @note 此回调用于BLE组网
*/
void (*onRequestBuildNet)(const ECBTClientInfo *clientInfo);
/**
* @brief Called when canceling networking
*
* @note
* @brief 手机app取消组网时回调
* @note 此回调用于BLE组网
*/
void (*onRequestBuildNetCancel)();
/**
* @brief Called when networking is completed
*
* @note
* @brief 手机app组网完成时回调
* @note 此回调用于BLE组网
*/
void (*onPhoneBuildNetFinish)();
void (*onPhoneBuildNetFinish)(const char* ip);
/**
* @brief Called when app sends AP information
*
* @param netDeviceInfo AP information
*
* @note
* @brief 手机app通知车机手机创建的ap信息
* @param netDeviceInfo AP信息
* @note 此回调用于BLE组网
*/
void (*onPhoneAPInfo)(const ECBTNetInfo* netDeviceInfo);
/**
* @brief Called when mobile phone has a notification message.
* @param notification
* @brief 收到手机消息通知时回调
* @param notification 消息通知
* @note 允许下发手机消息通知功能开启后,当收到短信、微信等消息时,此函数会回调消息到车机
* @see EC_requestPhoneNotification()
*/
void (*onPhoneNotification)(const ECPhoneNotification* notification);
/**
* @brief Called when the phone app sends down HUD lane guidance Picture.
* @param notification
* @brief HUD道路引导图
* @param notification 引导图信息
* @note 下发HUD导航功能开启后导航时有道路引导图时此函数会回调
* @see EC_enableDownloadPhoneAppHud()
*/
void (*onPhoneAppHUDLaneGuidancePicture)(const ECHudLaneGuidancePictureInfo * data);
/**
* @brief Called when checkOTAUpdate was called, it will tell the result of checkOTAUpdate.
*
* @param downloadableSoftwares It pointer to a array of ECOTAUpdateSoftware, which is downloadable software.
*
* @param downloadableLength The length of the downloadable array, if downloadableLength < 0, means check occur error, downloadableLength is error value of ECOTAUpdateErrorCode.
*
* @param downloadedSoftwares It pointer to a array of ECOTAUpdateSoftware, which is downloaded software.
*
* @param downloadedLength The length of the downloaded array.
* @brief 检测更新函数 EC_checkOTAUpdate()调用后, 此回调函数返回结果
* @param downloadableSoftwares 可下载的软件包数组
* @param downloadableLength 可下载的软件包数组大小, 如果 downloadableLength < 0 标识出现错误, 错误码参考ECOTAUpdateErrorCode.
* @param downloadedSoftwares 已下载的软件包数组
* @param downloadedLength 已下载的软件包数组大小
*/
void (*onOTAUpdateCheckResult)(const ECOTAUpdateSoftware* downloadableSoftwares, const int32_t downloadableLength, const ECOTAUpdateSoftware* downloadedSoftwares, const uint32_t downloadedLength);
/**
* @brief Called when remote downloadable software has been downloaded to phone.
*
* @param downloadableSoftwares It pointer to a array of ECOTAUpdateSoftware, which has been in phone, can be downloaded from phone to HU.
*
* @param downloadableLength The length of the downloadable array.
* @brief 有软件包请求下载手机时回调
* @param downloadableSoftwares 可下载的软件包数组
* @param downloadableLength 可下载软件包数组大小
* @note 软件包已存在手机,请求下载到车机
*/
void (*onOTAUpdateRequestDownload)(const ECOTAUpdateSoftware* downloadableSoftwares, const uint32_t downloadableLength);
/**
* @brief Called when startOTAUpdate is called, it will notify the progress of downloading.
*
* @param downloadingSoftwareId The id of the downloading software.
*
* @param progress The progress of the downloading software,which is a percentage.
*
* @param softwareLeftTime The left time of the downloading software.
*
* @param otaLeftTime The left time of all the specified software by startOTAUpdate.
* @brief EC_startOTAUpdate()调用之后, 此回调函数会回调下载进度
* @param downloadingSoftwareId 下载的软件ID
* @param progress 下载的进度
* @param softwareLeftTime 剩余下载时间
* @param otaLeftTime OTA剩余时间
*/
void (*onOTAUpdateProgress)(const char* downloadingSoftwareId, float progress, uint32_t softwareLeftTime, uint32_t otaLeftTime);
/**
* @brief Called when startOTAUpdate is called, it will notify software is downloaded.
*
* @param downloadedSoftwareId The id of the downloaded software.
*
* @param md5Path The md5 file path.
*
* @param packagePath The software path.
*
* @param iconPath The icon path.
*
* @param leftSoftwareNum The amount of software remaining to be downloaded.
* @brief EC_startOTAUpdate()调用之后, 下载完成时回调此函数
* @param downloadedSoftwareId 下载的软件ID
* @param md5Path md5文件路径
* @param packagePath 升级包路径
* @param iconPath 图标路径
* @param leftSoftwareNum 剩余下载数量
*/
void (*onOTAUpdateCompleted)(const char* downloadedSoftwareId, const char* md5Path, const char* packagePath, const char* iconPath, uint32_t leftSoftwareNum);
/**
* @brief Called when checkOTAUpdate or startOTAUpdate failed.
*
* @param errCode error code, see ECOTAUpdateErrorCode.
*
* @param softwarId the id of software.
* @brief EC_checkOTAUpdate() 或者 EC_startOTAUpdate() 调用过程出错回调此函数
* @param errCode 错误码, 参考ECOTAUpdateErrorCode.
* @param softwarId 软件id
*/
void (*onOTAUpdateError)(int32_t errCode, const char* softwareId);
@ -350,67 +321,502 @@ ECConfigHandle EC_createECConfig();
void EC_destroyECConfig(ECConfigHandle config);
void EC_setBaseConfig(ECConfigHandle config,const char *uuid, const char *version,const char *writableDir);
void EC_setCommonConfig(ECConfigHandle config, const char *cfgName, const char *value);
/**
* @brief 设置 ECTiny 连接的app版本
* @param type 0:国内版; 1:海外版
*/
void EC_setLinkPhoneApp(ECConfigHandle config,int32_t type);
void EC_setCommonConfig1(ECConfigHandle config, const char *cfgName, int32_t value);
// This function must be called after the EC_start() function.
int32_t EC_resetECConfig(const char* config);
/**
* @brief ECTiny 初始化函数
* @param config 项目配置
* @param listener 回调接口
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口为互联必调用的接口。
* 1.除了调用 EC_setBaseConfig() 设置基本的运行配置之外config 一般不需要额外配置。
* 2.listener 的生命周期大于 ECTiny 生命周期。即 listener 在 EC_initialize() 调用前就需要初始化EC_release()之后才可以释放。
*/
int32_t EC_initialize(ECConfigHandle config, IECCallBack *listener);
int32_t EC_release();
int32_t EC_setLogInfo(const ECLogLevel level,const ECLogOutputType type,const char *logDirectory, int32_t module);
const char* EC_getVersion();
int32_t EC_getVersionCode();
int32_t EC_start();
int32_t EC_stop();
int32_t EC_bindAccessFile(IECAccessFile *handle);
int32_t EC_bindUSBDevice(ECTransportType type, IECAccessDevice *dev);
int32_t EC_bindWIFIDevice(ECTransportType type, const char *ip);
int32_t EC_unbindDevice(ECTransportType type);
int32_t EC_bindHidDevice(IECHidAccessDev* dev);
int32_t EC_unBindHidDevice();
int32_t EC_bindBTDevice( IECAccessDevice* ioHandle);
int32_t EC_unBindBTDevice();
int32_t EC_setMirrorConfig(const ECMirrorConfig *mirrorCfg);
int32_t EC_setVideoPlayer(IECVideoPlayer* video);
int32_t EC_setAudioPlayer(IECAudioPlayer* audio);
int32_t EC_setAudioRecorder(IECAudioRecorder* audioRecorde);
int32_t EC_notifyWifiStateChanged(ECWifiStateAction action, const ECNetWorkInfo* netInfo);
int32_t EC_setRequestBuildNetRly(const char *phoneID, const ECBTRequestBuildNetRly *rly);
int32_t EC_setNetInterfaceInfo(const ECNetInterfaceInfo *info,const int32_t num);
int32_t EC_startMirror();
void EC_stopMirror();
int32_t EC_pauseMirror();
int32_t EC_resumeMirror();
int32_t EC_sendTouchEvent(const ECTouchEventData *touch, ECTouchEventType type);
int32_t EC_sendBtnEvent(int32_t btnCode, int32_t type);
int32_t EC_stopPhoneNavigation();
int32_t EC_stopPhoneVR();
int32_t EC_uploadNightModeStatus(uint32_t isNightModeOn);
int32_t EC_uploadDrivingStatus(ECDrivingStatus status);
int32_t EC_enableDownloadPhoneAppAudio(uint32_t supportType, uint32_t autoChangeToBT);
void EC_disableDownloadPhoneAppAudio();
int32_t EC_enableDownloadPhoneAppHud(uint32_t supportFunction);
void EC_disableDownloadPhoneAppHud();
int32_t EC_setConnectedBTAddress(const char *carBtMac, const char *phoneBtMac);
int32_t EC_sendCarBluetooth(const char *name, const char *adddress, const char *pin);
int32_t EC_openAppPage(int32_t page);
int32_t EC_queryGPS(uint32_t* status, ECGPSInfo* gps);
int32_t EC_queryTime(uint64_t *gmtTime, uint64_t *localTime, char *timeZone, uint32_t len, char* dateTime, uint32_t dateTimeLen);
int32_t EC_sendCarStatus(ECCarStatusType carStatus, ECCarStatusValue value);
int32_t EC_registerCarCmds(const ECCarCmd *carCmds, uint32_t length);
int32_t EC_playCarTTS(const char *text, uint32_t level);
int32_t EC_registerSimilarSoundingWords(const char *data, uint32_t length);
int32_t EC_sendInputText(const char* text);
int32_t EC_sendInputAction(int32_t actionId, int32_t keyCode);
int32_t EC_sendInputSelection(int32_t start, int32_t stop);
int32_t EC_queryPageList();
int32_t EC_queryPageIcon(int32_t* pages, int32_t length);
int32_t EC_queryWeather();
int32_t EC_queryVRTips();
const char* EC_generateQRCodeUrl(ECQRInfo* info);
int32_t EC_requestPhoneNotification(int32_t enable);
/**
* @brief ECTiny 释放函数
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此函数调用后,后面声明的函数调用都会失效。
* 没有互联时ECTiny线程处于block或者waiting状态占用系统资源不多所以ECTiny的一般使用场景不需要调用此函数。
*/
int32_t EC_release();
/**
* @brief 设置ECTiny日志
* @param level 日志级别。调试时设置成EC_LOG_LEVEL_ALL生产时设置成EC_LOG_LEVEL_ERROR或者其他高级别
* @param type 日志输出类型,设置成 EC_LOG_OUT_STD标准输出。其余类型暂不支持。
* @param logDirectory 日志保存位置,暂不支持
* @param module 日志模块通常设置成EC_LOG_MODULE_SDK | EC_LOG_MODULE_APP
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口为互联必调用的接口。
*/
int32_t EC_setLogInfo(const ECLogLevel level,const ECLogOutputType type,const char *logDirectory, int32_t module);
/**
* @return 获取 ECTiny 版本号
*/
const char* EC_getVersion();
/**
* @return 获取 ECTiny 升级版本号
*/
int32_t EC_getVersionCode();
/**
* @brief 开启互联服务
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口为互联必调用的接口。
*/
int32_t EC_start();
/**
* @brief 停止互联服务
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 没有投屏的情况下, ECTiny线程出于阻塞状态占用的系统资源很少。
* 一般使用场景,调用 EC_start() 之后,不需要调用 EC_stop()。
*/
int32_t EC_stop();
/**
* @brief 绑定文件读写设备
* @param handle 文件操作接口
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 对于某些 RTOS 系统,没有标准的文件操作接口,因此需要实现此接口,把基本文件操作的接口传给 ECTiny。
* ECTiny会使用此接口读写license和OTA。
*/
int32_t EC_bindAccessFile(IECAccessFile *handle);
/**
* @brief 绑定usb设备
* @param type 互联类型
* @param dev usb设备操作接口
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 绑定usb设备读写操作用于实现usb互联。
* @see EC_unbindDevice()
*/
int32_t EC_bindUSBDevice(ECTransportType type, IECAccessDevice *dev);
/**
* @brief 绑定wifi互联ip
* @param type 互联类型
* @param ip 对端ip地址
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此函数调用之后, ECTiny会直接连接ip进行互联。
* @see EC_unbindDevice()
*/
int32_t EC_bindWIFIDevice(ECTransportType type, const char *ip);
/**
* @brief 释放绑定的设备
* @param type 互联类型
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此函数与 EC_bindUSBDevice()EC_bindWIFIDevice(),有绑定与解绑定关系。
*/
int32_t EC_unbindDevice(ECTransportType type);
/**
* @brief 绑定HID设备
* @param dev HID设备
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @see EC_unBindHidDevice()
*/
int32_t EC_bindHidDevice(IECHidAccessDev* dev);
/**
* @brief 解除HID设备绑定
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @see EC_bindHidDevice()
*/
int32_t EC_unBindHidDevice();
/**
* @brief 绑定蓝牙ble设备操作接口
* @param ioHandle 蓝牙ble设备操作接口
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口用于BLE组网方式的互联。
* @see EC_unBindBTDevice()
*/
int32_t EC_bindBTDevice( IECAccessDevice* ioHandle);
/**
* @brief 蓝牙ble设备解绑定
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @see EC_bindBTDevice()
*/
int32_t EC_unBindBTDevice();
/**
* @brief 设置投屏参数
* @param mirrorCfg 投屏参数
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口为互联必执行的接口。
*/
int32_t EC_setMirrorConfig(const ECMirrorConfig *mirrorCfg);
/**
* @brief 设置解码显示设备
* @param video 解码显示器
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 解码显示器 IECVideoPlayer 通过此接口注册给 ECTiny之后由 ECTiny主动调用解码器的开始和停止。
*/
int32_t EC_setVideoPlayer(IECVideoPlayer* video);
/**
* @brief 设置音频播放器
* @param audio 音频播放器
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 声音数据走usb或者wifi时才需要设置此接口。一般项目声音都是走蓝牙a2dp不需要设置此接口。
*/
int32_t EC_setAudioPlayer(IECAudioPlayer* audio);
/**
* @brief 设置录音设备
* @param audioRecorde 录音设备
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 需要手机app回声降噪的项目才需要设置此接口。
*/
int32_t EC_setAudioRecorder(IECAudioRecorder* audioRecorde);
/**
* @brief 仪表wifi状态通知接口
* @param action 仪表wifi模式ap/sta。 目前此值不做要求,填写此枚举任意值即可
* @param netInfo 网络状态。ECNetWorkInfo::state 必须填写,其余字段不需要填。
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 仪表/车机wifi发生变化时通过此接口通知给 ECTiny。wifi连接此接口必调用
*/
int32_t EC_notifyWifiStateChanged(ECWifiStateAction action, const ECNetWorkInfo* netInfo);
/**
* @brief 请求组网接口
* @param phoneID 手机id
* @param rly 组网信息
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 只有BLE组网的连接方式才用到此接口。
*/
int32_t EC_setRequestBuildNetRly(const char *phoneID, const ECBTRequestBuildNetRly *rly);
/**
* @brief 仪表ip地址上报给手机
* @param info 仪表网络信息
* @param num 仪表网络信息数量
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 只有BLE组网的连接方式才用到此接口。
*/
int32_t EC_setNetInterfaceInfo(const ECNetInterfaceInfo *info,const int32_t num);
/**
* @brief 开始投屏
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口为互联必执行的接口。
* 此接口调用后手机app会把 H264 数据发送给 ECTiny。 ECTiny会自动调用 IECVideoPlayer 解码器解码显示。
* onECConnectStatus 回调函数status==EC_CONNECT_STATUS_CONNECT_SUCCEED 时才可以调用此接口,否则无效。
* @see EC_stopMirror()
*/
int32_t EC_startMirror();
/**
* @brief 停止投屏
* @note 此接口为互联必执行的接口。
* @see EC_startMirror()
*/
void EC_stopMirror();
/**
* @brief 暂停/开启 投屏
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 目前不调用。调用 EC_startMirror()/EC_stopMirror()
*/
int32_t EC_pauseMirror();
int32_t EC_resumeMirror();
/**
* @brief 发送触控消息
* @param touch 触控数据
* @param type 触控类型
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 发送仪表/车机屏幕的触控消息给手机app互联程序会映射到手机的坐标让手机app做出响应。
*/
int32_t EC_sendTouchEvent(const ECTouchEventData *touch, ECTouchEventType type);
/**
* @brief 发送按键消息
* @param btnCode 按键键值取值于ECBtnCode
* @param type 按键类型取值与ECBtnEventType
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 发送按键消息给手机app让手机作出响应。
*/
int32_t EC_sendBtnEvent(int32_t btnCode, int32_t type);
/**
* @brief 结束手机导航
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
*/
int32_t EC_stopPhoneNavigation();
/**
* @brief 结束手机vr语音
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
*/
int32_t EC_stopPhoneVR();
/**
* @brief 上传汽车的夜间模式信息到手机
* @param isNightModeOn 1:夜间模式; 0: 非夜间模式
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 手机app的显示模式设置为自动时此接口才能让手机app响应
*/
int32_t EC_uploadNightModeStatus(uint32_t isNightModeOn);
/**
* @brief 上传汽车的驾驶信息到手机
* @param status 驾驶状态
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
*/
int32_t EC_uploadDrivingStatus(ECDrivingStatus status);
/**
* @brief 允许手机下发声音数据到仪表/车机
* @param supportType 下载的声音类型,取值于 ECAudioType 类型,可以通过或运算下载多种声音
* @param autoChangeToBT 是否启用蓝牙优先的策略,当蓝牙连接后,声音自动走蓝牙通道。
* 也可通过该接口控制手机端蓝牙连接提示框的弹出当该参数设置为false后手机端不再弹出连接蓝牙提示框。
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 只有在连接层成功建立后,接口调用才能成功。参考 onECConnectStatus()
* 该接口调用之后手机app才会下传相应声音停止音频下传接口为EC_disableDownloadPhoneAppAudio()
*/
int32_t EC_enableDownloadPhoneAppAudio(uint32_t supportType, uint32_t autoChangeToBT);
/**
* @brief 停止手机下发声音数据
*/
void EC_disableDownloadPhoneAppAudio();
/**
* @brief 允许手机下发HUD导航信息
* @param supportFunction hud导航功能取值于 ECAPPHUDSupportFunction 类型可以通过或运算开启多种hud功能
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 只有在连接层成功建立后,接口调用才能成功。参考 onECConnectStatus()
* 此接口调用一次即可生效
*/
int32_t EC_enableDownloadPhoneAppHud(uint32_t supportFunction);
/**
* @brief 停止手机下发HUD导航信息
*/
void EC_disableDownloadPhoneAppHud();
/**
* @brief 设置连接的蓝牙
* @param carBtMac 车机自己的蓝牙地址
* @param phoneBtMac 车机连接的蓝牙Mac地址
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
* @note 此接口的目的是用于对比手机和车机两者连接的蓝牙是不是对方。受限于手机系统限制,无法取得手机的蓝牙物理地址,目前此接口功能已经失效。
*/
int32_t EC_setConnectedBTAddress(const char *carBtMac, const char *phoneBtMac);
/**
* @brief 发送车机的蓝牙信息给手机
* @param name 蓝牙名称
* @param adddress 蓝牙地址
* @param pin 蓝牙pin码
* @return EC_OK 为成功,其余值为失败。此返回值一般不处理
*/
int32_t EC_sendCarBluetooth(const char *name, const char *adddress, const char *pin);
/**
* @brief 打开手机界面
* @param page 快速访问手机APP的相关界面或功能如导航、音乐、对讲等具体取值参考ECAppPage
* @return EC_OK 为成功,其余值为失败。
* @note 该接口主要用于如下场景,譬如车机端系统桌面集成快捷按钮,可直达互联的指定页面。
*/
int32_t EC_openAppPage(int32_t page);
/**
* @brief 查询GPS信息
* @param status 当前的请求结果是否有效0无效其余值有效
* @param gps GPS信息
* @return EC_OK 为成功,其余值为失败。
* @note 该接口主要用于车机需要使用到手机端GPS的场景请求网络当前位置。
*/
int32_t EC_queryGPS(uint32_t* status, ECGPSInfo* gps);
/**
* @brief 查询手机时间
* @param gmtTime 返回GMT(UTC)时间,单位毫秒。
* @param localTime 返回当前时区的时间,单位毫秒
* @param timeZone 返回当前的时区的字符串。
* @param len 当前时区字符串的长度
* @param dateTime 返回手机app当前时间字符串
* @param dateTimeLen 手机app当前时间字符串长度
* @return EC_OK 为成功,其余值为失败。
* @note 由于GMT时间涉及到系统函数和时区的计算建议直接使用后两个参数获取当前时间字符串然后解析字符串获取到时间
*/
int32_t EC_queryTime(uint64_t *gmtTime, uint64_t *localTime, char *timeZone, uint32_t len, char* dateTime, uint32_t dateTimeLen);
/**
* @brief 同步车机状态到手机
* @param carStatus 车机状态类型
* @param value 部分status需要携带状态值
* @return EC_OK 为成功,其余值为失败。
* @note 部分场景下需要将车机的部分状态信息通知到手机APP手机APP需要根据状态做互联的相关逻辑处理。
* 如手机APP可根据行车状态在不同的地区做不同的使用限制。该接口主要用于行车模式功能等功能。
*/
int32_t EC_sendCarStatus(ECCarStatusType carStatus, ECCarStatusValue value);
/**
* @brief 注册控车指令
* @param carCmds 控车指令
* .type : 指令类型,是一个全局指令或是一个和页面绑定的指令,见枚举 ECCarCmdEFFECTType 。
* .id : 指令id每个需要识别的指令都有一个唯一的标识。
* .cmd : 期望语音识别的指令,当时一个全局指令时,可以是正则表达式;如"(打开|开启)空调",等价于"打开空调" "开启空调";而当是一个和页面绑定的指令词,不支持正则表达式,仅支持明确的指令,如"放大地图"。
* .vrText : 当前成功匹配的语义,仅用于当 IECCallback::onCarCmdNotified 回调时,可根据匹配的内容处理相关的动作。
* .pauseMusic : 该参数仅用于 ECSDK::registerCarCmds ,告知手机如果触发语音识别时,是否需要暂停当前正在播放的音乐。
* .responser : 语音指令执行的结果是由车机端播报还是由手机端播报。0 车机端播报1手机端播报。
* .thresholdLevel : 可选项默认值为0由手机端指定默认的门限值 范围参考值 1~9999识别门限值值越大识别率越低误唤醒率越低开发者在使用语音识别功能时可在项目中调试设置合适的值。该参数仅在 type= EC_CAR_CMD_TYPE_EFFECTIVE_PAGE 生效;
* @param length 注册的指令列表的长度。
* @return EC_OK 为成功,其余值为失败。
* @note 当发起语音识别后通过手机端的VR引擎识别后会转化后具体的指令通过回调接口 IECCallback::onCarCmdNotified 响应,须在此进行相关处理。
*/
int32_t EC_registerCarCmds(const ECCarCmd *carCmds, uint32_t length);
/**
* @brief 播放指定的文字
* @param text 文字信息
* @param level 优先级0~10优先级越高被播放的优先级也越高。
* @return EC_OK 为成功,其余值为失败。
* @note 与手机的通讯建立成功后把需要播报的文字传输至手机APP。
* 如果车机端配置了 ECSDK::enableDownloadPhoneAppAudio 通过车机端播放手机APP音频此时音频将以TTS类型通过USB/wifi传输车机端。
*/
int32_t EC_playCarTTS(const char *text, uint32_t level);
/**
* @brief 注册近似指令
* @param data 需要注册的近音词组数据格式为JSON格式字符串
* {
* words:
* [
* ["词1", ..., "词m"], ///< 数据类型为string数组近音词集合数组中的第一个词为显示词。
* ...
* ["词a", ..., "词n"] ///< 数据类型为string数组近音词集合数组中的第一个词为显示词。
* ]
* }
* @param length 注册的指令Json字符串的长度。
* @return EC_OK 为成功,其余值为失败。
* @note 该接口主要是对 EC_registerCarCmds() 接口的补充,常见使用场景提高语音控车指令的准确度,如“上身车窗”、“上升车窗”可以正确的被识别为同一个含义。
*/
int32_t EC_registerSimilarSoundingWords(const char *data, uint32_t length);
/**
* @brief 发送给手机端当前已输入的文字
* @param text 当前输入的车机端文字
* @return EC_OK 为成功,其余值为失败。
* @note 此函数用于车机键盘输入功能
*/
int32_t EC_sendInputText(const char* text);
/**
* @brief 发送给手机端键盘按键事件
* @param actionId 当前输入的动作
* @param keyCode 键值
* @return EC_OK 为成功,其余值为失败。
* @note 如车机端输入法点击Enter键此时需把事件发送给手机端。所有keycode及ActionId对安卓手机都有效
* 苹果手机仅响应actionid=0 keycode=4苹果手机处理为隐藏手机端输入法并把输入状态置为inActive状态。
* 此函数用于车机键盘输入功能
*/
int32_t EC_sendInputAction(int32_t actionId, int32_t keyCode);
/**
* @brief 发送给手机端当前光标位置及选中状态
* @param start 光标开始的位置。
* @param stop 光标结束的位置。
* @return EC_OK 为成功,其余值为失败。
* @note 如果车机端的光标产生变化,需把对应状态发送至手机端同步。仅对安卓手机有效,苹果手机互联无此回调。
* 此函数用于车机键盘输入功能
*/
int32_t EC_sendInputSelection(int32_t start, int32_t stop);
/**
* @brief 获取快捷方式列表信息
* @return EC_OK 为成功,其余值为失败。
* @note ECTiny与手机app传输建立之后。通过 IECCallback::onPageListReceived 回调接口完快捷方式列表信息的接收。
*/
int32_t EC_queryPageList();
/**
* @brief 获取快捷方式图标资源
* @param pages 待请求的page编号的数组通过 EC_queryPageList 获取。
* @param length page编号的数组长度。
* @return EC_OK 为成功,其余值为失败。
* @note ECTiny与手机app传输建立之后。通过 IECCallback::onPageIconReceived 回调接口完快捷方式图标资源的的接收。
* 为了避免重复的请求占用带宽资源以及做到车机端的快捷方式快速显示车机端系统需要做好缓存策略对icon的资源信息做到增量更新
* 通过每次互联后 EC_queryPageList 获取最新的列表信息,然后比对车机端缓存的列表信息,仅对增量的资源进行请求更新;
*/
int32_t EC_queryPageIcon(int32_t* pages, int32_t length);
/**
* @brief 查询天气
* @return EC_OK 为成功,其余值为失败。
* @note 查询结果通过 IECCallback::onWeatherReceived 回调函数返回
*/
int32_t EC_queryWeather();
/**
* @brief 车机端语音提醒轮播
* @return EC_OK 为成功,其余值为失败。
* @note 在使用车机端本地语音助手时,一般需要有一些常驻提示类的使用帮助,这些文字主要通过手机端传输至车机端,由车机端系统完成展示。
*/
int32_t EC_queryVRTips();
/**
* @brief 生成二维码url
* @param info 二维码信息
* @return EC_OK 为成功,其余值为失败。
*/
const char* EC_generateQRCodeUrl(ECQRInfo* info);
/**
* @brief 允许手机下发手机消息
* @param enable 0禁止 1允许
* @return EC_OK 为成功,其余值为失败。
*/
int32_t EC_requestPhoneNotification(uint32_t enable);
/**
* @brief 检测OTA升级
* @param cfg ota配置
* @param language 语言
* @param mode ota升级模式
* @return EC_OK 为成功,其余值为失败。
*/
int32_t EC_checkOTAUpdate(const ECOTAConfig* cfg, const ECLanguage language, const ECOTAUpdateCheckMode mode);
/**
* @brief 开始OTA升级
* @param softwareIds 需要升级的软件id
* @param softwareNum 需要升级的软件id数量
* @return EC_OK 为成功,其余值为失败。
*/
int32_t EC_startOTAUpdate(const char** softwareIds, const int32_t softwareNum);
/**
* @brief 停止OTA升级
*/
void EC_stopOTAUpdate();
/**
* @brief 开启iperf服务端
* @param ip
* @param port
* @return
* @note 简单实现的iperf功能。车机/仪表进行iperf测试时建议使用标准iperf
*/
int32_t EC_startIperfTcpServer(const char* ip, int port);
void EC_stopIperfTcpServer();
#endif

View File

@ -194,6 +194,18 @@ enum ECProjectFlavor
};
typedef enum ECProjectFlavor ECProjectFlavor;
/**
* @enum ECAuthCheckMode
*
*/
enum ECAuthCheckMode {
EC_AUTH_CHECK_DEFAULT = 0, ///< default check auth on phone
EC_AUTH_CHECK_ON_CAR_NETWORK = 1, ///< check auth on car network
EC_AUTH_CHECK_SCAN_CODE_TO_ACTIVATE_FOR_SUDING = 2, ///< scan the code to activate the certificate for suding
EC_AUTH_CHECK_SCAN_CODE_TO_ACTIVATE = 4, ///< scan the code to activate the certificate
};
typedef enum ECAuthCheckMode ECAuthCheckMode;
/**
* @struct ECAuthentication
*
@ -205,7 +217,7 @@ struct ECAuthentication
char pwd[1024]; ///< the specific password for authentication powered by Carbit.
char versionName[1024]; ///< the version name of EasyConn.
uint32_t versionCode; ///< the version code of EasyConn.
uint32_t autoAuthViaCar; ///< specify whether make automatic authentication via car's network.
uint32_t authCheckMode; ///< the value of auth check model refer to ECAuthCheckMode.
ECProjectFlavor flavor; ///< specify the HU Project market for sale,SDK will carry a flavor by default.see enum ECProjectFlavor in ECTypes.h
char reserve[256]; ///< reserve
};
@ -373,11 +385,22 @@ struct ECOptions
ECMirrorMode mirrorMode; ///< tell the app of connected phone which mirror mode would be used.
uint32_t bluetoothPolicy; ///< the policy of A2DP message phone sent to the car.
uint32_t disableShowCallInfo; ///< true:Don't show call info
uint32_t disablePageInRVMap; ///< Block display of some page
uint32_t socketTimeoutPeriod; ///< socket timeout period in seconds
char reserve[256]; ///< reserve
};
typedef struct ECOptions ECOptions;
/**
* @enum ECDisablePageInRVMap
*
*/
enum ECDisablePageInRVMap {
EC_DISABLE_PAGEINRVMAP_CALLPHONE = 0x0001, ///< Block call display
EC_DISABLE_PAGEINRVMAP_MUSIC = 0x0002, ///< Block music display
EC_DISABLE_PAGEINRVMAP_MESSAGE = 0x0004, ///< Block message display
};
/**
* @enum ECTransportType
*

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,5 +2,7 @@
#define _CARLINK_EC_H_
int carlink_ec_init(int argc,char ** argv);
void carlink_ec_enable(int enable);
#endif

View File

@ -29,9 +29,12 @@
#include "wifi_conf.h"
#include "carlink_common.h"
#define DEV_NAME_PREFIX "AP630_CARLINK"
static char g_cp_bt_mac[13] = {0};
static bool g_cp_bt_mac_ready = false;
static uint8_t carlink_p2p_name[64] = {0};
static uint8_t carlink_ap_ssid[64] = {"ap63011"};
static uint8_t carlink_ap_passwd[16] = {"88888888"};
static uint8_t carlink_wifi_mac[32] = {0};
@ -65,6 +68,17 @@ extern err_t dhcp_server_start(struct netif *netif, ip4_addr_t *start, ip4_addr_
extern err_t wlan_ethernetif_init(struct netif *netif);
#define lwip_ipv4_addr(addr) ((addr[0]) | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24))
const char *carlink_get_bt_mac()
{
if (!g_cp_bt_mac_ready)
return NULL;
return (const char *)g_cp_bt_mac;
}
const char *carlink_get_wifi_p2p_name()
{
return (const char *)carlink_p2p_name;
}
const char *carlink_get_wifi_ssid()
{
@ -74,7 +88,7 @@ const char *carlink_get_wifi_ssid()
const char *carlink_get_wifi_mac()
{
wifi_get_mac_address(carlink_wifi_mac);
wifi_get_mac_address((char *)carlink_wifi_mac);
return (const char *)carlink_wifi_mac;
}
@ -173,7 +187,11 @@ static void carlink_start_wlan()
}
memcpy(ap_prefix, g_cp_bt_mac + 8, 4);
carlink_reset_wifi_ap_info(ap_prefix);
start_ap(36, (const char *)carlink_ap_ssid, (const char *)carlink_ap_passwd, 1);
#if (CARLINK_EC)
start_p2p((const char *)carlink_p2p_name, (const char *)carlink_ap_ssid, (const char *)carlink_ap_passwd);
#else
start_ap(36, (const char *)carlink_ap_ssid, (const char *)carlink_ap_passwd, 1);
#endif
ip_addr.addr = lwip_ipv4_addr(ucIPAddress);
netmask.addr = lwip_ipv4_addr(ucNetMask);
@ -194,18 +212,113 @@ static void carlink_start_wlan()
dhcp_server_start(&gnetif[0], &dhcp_addr_start, &dhcp_addr_end);
netif_set_up(&gnetif[0]);
//netif_set_up(&gnetif[0]);
lwiperf_start_tcp_server_default(carlink_lwiperf_report_cb_impl, NULL);
lwip_tcpip_init_done_flag = 1;
carlink_carplay_add_vendor_ie();
}
void cp_wlan_start(void){
netif_set_up(&gnetif[0]);
}
static void dump_ip_addr(const char *msg, const ip_addr_t *server_addr)
{
printf("%s %d.%d.%d.%d \r\n", msg,
ip4_addr1_16(ip_2_ip4(server_addr)), ip4_addr2_16(ip_2_ip4(server_addr)), ip4_addr3_16(ip_2_ip4(server_addr)), ip4_addr4_16(ip_2_ip4(server_addr)));
}
static void dhcp_client_status_callback(struct netif *netif, int status, const ip_addr_t *server_addr)
{
if (&gnetif[0] == netif) {
dump_ip_addr("dhcp server ip :", (const ip_addr_t *)server_addr);
dump_ip_addr("dhcp client ip :", (const ip_addr_t *)&netif->ip_addr);
dump_ip_addr("dhcp client netmask:", (const ip_addr_t *)&netif->netmask);
dump_ip_addr("dhcp client gw :", (const ip_addr_t *)&netif->gw);
}
}
int start_sta_ext(const char* ssid, const char* passwd, char need_passwd)
{
int ret = -1;
ip4_addr_t ip_addr;
ip4_addr_t netmask;
ip4_addr_t gw;
ret = start_sta(ssid, passwd, need_passwd);
if (ret != 0) {
printf("start wifi sta failed\r\n");
return ret;
}
if (lwip_tcpip_init_done_flag) {
netif_remove(&gnetif[0]);
netif_add(&gnetif[0],
#if LWIP_IPV4
&ip_addr, &netmask, &gw,
#endif
NULL, wlan_ethernetif_init, tcpip_input);
netif_set_default(&gnetif[0]);
dhcp_regisger_status_callback(dhcp_client_status_callback);
netif_set_up(&gnetif[0]);
dhcp_start(&gnetif[0]);
}
return ret;
}
int __restart_p2p(const char *dev_name, const char *ssid, const char *passwd)
{
int ret = -1;
ip4_addr_t ip_addr;
ip4_addr_t netmask;
ip4_addr_t gw;
ip_addr.addr = lwip_ipv4_addr(ucIPAddress);
netmask.addr = lwip_ipv4_addr(ucNetMask);
gw.addr = lwip_ipv4_addr(ucGatewayAddress);
ret = start_p2p(dev_name, ssid, passwd);
if (ret != 0) {
printf("restart wifi p2p failed\r\n");
return ret;
}
if (!lwip_tcpip_init_done_flag) {
printf("lwip tcpip is not inited\r\n");
return ret;
}
dhcp_stop(&gnetif[0]);
netif_remove(&gnetif[0]);
netif_add(&gnetif[0],
#if LWIP_IPV4
&ip_addr, &netmask, &gw,
#endif
NULL, wlan_ethernetif_init, tcpip_input);
netif_set_up(&gnetif[0]);
ret = 0;
return ret;
}
int restart_p2p()
{
if (!g_cp_bt_mac_ready) {
printf("bt is not ready at %s", __func__);
return -1;
}
return __restart_p2p((const char *)carlink_p2p_name, (const char *)carlink_ap_ssid, (const char *)carlink_ap_passwd);
}
static void carlink_reset_wifi_ap_info(const char *prefex)
{
if (prefex) {
memset(carlink_ap_ssid, 0, sizeof(carlink_ap_ssid));
sprintf((char *)carlink_ap_ssid, "AP630_CARLINK_%s", prefex);
sprintf((char *)carlink_ap_ssid, "%s_%s", DEV_NAME_PREFIX, prefex);
memset(carlink_p2p_name, 0, sizeof(carlink_p2p_name));
sprintf((char *)carlink_p2p_name, "DIRECT-%s_p2p_%s", DEV_NAME_PREFIX, prefex);//do not delete "DIRECT-" !!!
}
}
@ -256,11 +369,11 @@ static void carlink_bt_callback(char * cAtStr)
carlink_notify_event(&ev);
} else if (0 == strncmp(cAtStr, "+ADDR=", 6)) {
char cmd_str[64] = {0};
sprintf(cmd_str, "AT+NAME=AP630_CARLINK_%s\r\n", (cAtStr + 6 + 8));
sprintf(cmd_str, "AT+NAME=%s_%s\r\n", DEV_NAME_PREFIX, (cAtStr + 6 + 8));
printf("ADDR:%s\r\n", cAtStr + 6);
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
memset(cmd_str, 0, sizeof(cmd_str));
sprintf(cmd_str, "AT+LENAME=AP630_CARLINK_%s\r\n", (cAtStr + 6 + 8));
sprintf(cmd_str, "AT+LENAME=%s_%s\r\n", DEV_NAME_PREFIX, (cAtStr + 6 + 8));
console_send_atcmd(cmd_str, strlen(cmd_str));//get mac addr
memcpy(g_cp_bt_mac, (cAtStr + 6), 12);
carlink_carplay_ie_replace_bt_mac(cAtStr + 6, 12);
@ -396,7 +509,7 @@ static void carlink_wifi_event_handler( WIFIEvent_t * xEvent )
char *mac = NULL;
if (xEvent) {
mac = xEvent->xInfo.xAPStationConnected.ucMac;
mac = (char *)xEvent->xInfo.xAPStationConnected.ucMac;
sprintf(mac_str, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
@ -414,6 +527,40 @@ static void carlink_wifi_event_handler( WIFIEvent_t * xEvent )
}
}
#if ( ipconfigUSE_DHCP_HOOK != 0 )
eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
uint32_t ulIPAddress )
{
eDHCPCallbackAnswer_t eReturn;
char g_ip_str[32] = {0};
sprintf(g_ip_str, "%d.%d.%d.%d\r\n", (ulIPAddress >> 0) & 0xFF,
(ulIPAddress >> 8) & 0xFF, (ulIPAddress >> 16) & 0xFF, (ulIPAddress >> 24) & 0xFF);
printf("\r\n eDHCPPhase:%d ulIPAddress:%s state:%d \r\n", eDHCPPhase, g_ip_str, getDhcpClientState());
if (getDhcpClientState() == 0)
return eDHCPStopNoChanges;
switch( eDHCPPhase )
{
case eDHCPPhaseFinished:
eReturn = eDHCPContinue;
break;
case eDHCPPhasePreDiscover :
eReturn = eDHCPContinue;
break;
case eDHCPPhasePreRequest :
eReturn = eDHCPContinue;
break;
default :
eReturn = eDHCPContinue;
break;
}
return eReturn;
}
#endif
static BaseType_t carlink_wifi_init()
{
int status;

View File

@ -25,6 +25,7 @@ static pthread_mutex_t carlink_com_locker =
.xAttr = { .iType = 0 }
};
void pthread_key_system_init();
void carlink_rfcomm_data_read_hook(void* buf, int len)
{
@ -41,7 +42,7 @@ void carlink_rfcomm_data_read_hook(void* buf, int len)
void carlink_notify_event(struct carlink_event *ev)
{
if (-1 != ev->type && NULL != carlink_event_queue) {
if (CARLINK_EVENT_NONE != ev->type && NULL != carlink_event_queue) {
xQueueSend(carlink_event_queue, ev, 0);
}
}

View File

@ -16,13 +16,14 @@ typedef enum
CARLINK_ANDROID_AUTO = 5,
CARLINK_ECLINK = 0x06,
CARLINK_CARPLAY_WIRELESS,
CARLINK_AUTO_WIRELESS
CARLINK_AUTO_WIRELESS,
CARLINK_ECLINK_WIRELESS,
}CARLink_TYPE;
#define CARLINK_VIDEO_WIDTH 800
#define CARLINK_VIDEO_HEIGHT 480
#define CARLINK_VIDEO_HEIGHT 380
@ -72,6 +73,8 @@ int carlink_wlan_tcp_ip_is_ready();
void carlink_bt_open();
void carlink_bt_close();
void carlink_restart_bt_wifi();
const char *carlink_get_bt_mac();
const char *carlink_get_wifi_p2p_name();
const char *carlink_get_wifi_ssid();
const char *carlink_get_wifi_passwd();
const char *carlink_get_wifi_mac();

View File

@ -25,6 +25,15 @@ static int g_disp_x = 0, g_disp_y = 0, g_disp_width = LCD_WIDTH, g_disp_height =
static int g_video_width = LCD_WIDTH, g_video_height = LCD_HEIGHT, g_video_fps = 30;
static int g_hide_carlink_flag = 0;
static int g_active_video_x = 0, g_active_video_y = 0;
void set_carlink_active_video_info(int x, int y)//for android auto
{
g_active_video_x = x;
g_active_video_y = y;
}
void set_carlink_video_info(int w, int h, int fps)
{
g_video_width = w;
@ -145,7 +154,7 @@ void set_h264_frame_free(video_frame_s* frame)
}
xSemaphoreGive(frame_list_mutex);
}
uint8_t map_flag = 0;
static void h264_decode_proc(void *pvParameters)
{
MFCHandle *handle = NULL;
@ -197,6 +206,11 @@ static void h264_decode_proc(void *pvParameters)
}
if (g_hide_carlink_flag == 0) {
if(map_flag)
map_flag = 0;
printf("Exit navigation =========\r\n ");
Set_sys_wifi(0);
//printf("start carplay or andrord auto .\r\n");
ark_lcd_osd_enable(LCD_VIDEO_LAYER, 0);
ark_lcd_osd_enable(LCD_UI_LAYER, 1);
}
@ -236,15 +250,16 @@ static void h264_decode_proc(void *pvParameters)
//continue;
for(i = 0; i < outBuf.num; i++) {
int active_offset = 0;
align_width = outBuf.frameWidth;
align_height = outBuf.frameHeight;
if(!(align_width && align_height))
continue;
yaddr = outBuf.buffer[i].yBusAddress;
uaddr = yaddr + align_width * align_height;
vaddr = yaddr + align_width * align_height * 5/4;
active_offset = g_active_video_y * align_width;
yaddr = outBuf.buffer[i].yBusAddress + active_offset + g_active_video_x;
uaddr = outBuf.buffer[i].yBusAddress + align_width * align_height + active_offset / 2 + g_active_video_x;
vaddr = 0;//yaddr + align_width * align_height * 5/4;
if (carlink_lcd_take == 0) {
carlink_lcd_take = 1;
@ -295,6 +310,8 @@ static void h264_decode_proc(void *pvParameters)
info.y = g_disp_y;
info.width = g_disp_width;
info.height = g_disp_height;
if (g_active_video_x != 0)
info.stride = outBuf.frameWidth;
if (info.format == LCD_OSD_FORAMT_YUV420)
ark_lcd_set_osd_yuv420_mode(LCD_VIDEO_LAYER, LCD_OSD_Y_UV420);
@ -306,7 +323,8 @@ static void h264_decode_proc(void *pvParameters)
ark_lcd_set_osd_info_atomic(LCD_VIDEO_LAYER, &info);
ark_lcd_osd_enable(LCD_VIDEO_LAYER, 1);
ark_lcd_set_osd_sync(LCD_VIDEO_LAYER);
ark_lcd_osd_enable(LCD_UI_LAYER, 0);
Set_sys_wifi(1);
// ark_lcd_osd_enable(LCD_UI_LAYER, 0);
ark_lcd_set_osd_sync(LCD_UI_LAYER);
vVideoDisplayBufRender(dstaddr);
if (outBuf.num > 1) {// for apple h264
@ -317,6 +335,13 @@ static void h264_decode_proc(void *pvParameters)
if (delta_ts > 0)
vTaskDelay(pdMS_TO_TICKS(delta_ts));
}
if(!map_flag){
// printf("###############################################.\r\n");
request_UI("maps:");
map_flag = 1;
// printf("###############################################.\r\n");
}
}
}
//printf("all use:%d ms dec:%ld ms all ts:%ld ms\r\n", (get_timer(0) - ts) / 1000, dec_ts, (get_timer(0) - all_ts) / 1000);

View File

@ -29,7 +29,7 @@ int get_carlink_video_fps(void);
void set_carlink_video_info(int w, int h, int fps);//set h264 video stream info from phone
void set_carlink_display_info(int x, int y, int w, int h);//set carlink show area in lcd
void set_carlink_display_state(int on); // on: 1.display carlink; 0. display native ui
void set_carlink_active_video_info(int x, int y);//for android auto
#define WRITE_BE32(ptr, val) \
do { \

View File

@ -580,6 +580,33 @@ static void usb_read_thread(void *para)
status = usb_wait_stor_dev_pluged(portMAX_DELAY);
if (status == USB_DEV_PLUGED) {
printf("usb dev inserted.\n");
FF_FILE *fp = ff_fopen("/usb/update.bin", "rb");
if (fp) {
UpFileHeader header;
SysInfo *sysinfo = GetSysInfo();
if (ff_fread(&header, 1, sizeof(header), fp) == sizeof(header)) {
if (header.magic != MKTAG('U', 'P', 'D', 'F')) {
printf("Wrong update file, don't update.\n");
} else {
if (header.checksum != sysinfo->app_checksum) {
printf("found different update file(0x%x-0x%x), update...\n",
header.checksum, sysinfo->app_checksum);
sysinfo->update_media_type = UPDATE_MEDIA_USB;
sysinfo->update_status = UPDATE_STATUS_START;
SaveSysInfo();
hub_usb_dev_reset();
vTaskDelay(500);
wdt_cpu_reboot();
} else {
printf("the update file version is same, don't update.\n");
}
}
};
ff_fclose(fp);
} else {
printf("open update.bin fail.\n");
}
/*printf("usb dev inserted.\n");
#ifdef OTA_UPDATE_SUPPORT
FF_FILE *fp = ff_fopen("/usb/update.bin", "rb");
if (fp) {
@ -635,7 +662,7 @@ static void usb_read_thread(void *para)
} else {
printf("open update.bin fail.\n");
}
#endif
#endif*/
} else if (status == USB_DEV_UNPLUGED) {
printf("usb removed.\n");
}
@ -710,7 +737,7 @@ void awtk_thread(void *data)
/* can demo */
//can_demo();
can_demo();
/* read sd card demo */
#ifdef SDMMC_SUPPORT
@ -785,13 +812,15 @@ void awtk_thread(void *data)
extern int gui_app_start(int lcd_w, int lcd_h);
gui_app_start (OSD_WIDTH, OSD_HEIGHT);
#endif
// float cell = 0;
// static float cell_value = 0;
// static uint8_t cell_count = 0;
while(1) {
#ifdef TASK_STATUS_MONITOR
static uint32_t idletick = 0;
uint8_t CPU_RunInfo[1024];
if (xTaskGetTickCount() - idletick > configTICK_RATE_HZ * 10) {
memset(CPU_RunInfo,0,1024);
vTaskList((char *)&CPU_RunInfo); //获取任务运行时间信息
@ -807,6 +836,25 @@ void awtk_thread(void *data)
idletick = xTaskGetTickCount();
}
#endif
/*if ((xTaskGetTickCount() - idletick > configTICK_RATE_HZ*3) && (Get_sys_power_on_self_test() == 100)) {
adc_light = adc_get_channel_value(ADC_CH_AUX2);//光感
adc_voltage = adc_get_channel_value(ADC_CH_AUX3);//电压
// DEBUG_PRINT("adc_light = %d ,adc_voltage = %d . ",adc_light,adc_voltage);
idletick = xTaskGetTickCount();
cell = adc_voltage_calculation();
// DEBUG_PRINT("cell %lf .\r\n",cell);
// cell_value += cell;
// cell_count++;
// if(cell_count>=8){
// cell_value = cell_value/cell_count;
// Set_sys_voltage(cell_value);
// cell_value = 0;
// cell_count = 0;
// }
Set_sys_voltage(cell);
}*/
vTaskDelay(pdMS_TO_TICKS(10)); /*Just to let the system breath*/
}
}

View File

@ -0,0 +1,162 @@
#include "awtk.h"
#include "conversation_protocol.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "chip.h"
#include "board.h"
#include "serial.h"
#include "sysinfo.h"
#include "user_data.h"
#include "data_port.h"
#include "universal.h"
#define MAX_ENTRIES 100 // 假设最大条目数为100
// 定义电话本条目结构体
typedef struct {
char name[50];
char phone[20];
} PhoneBookEntry;
PhoneBookEntry phoneBook[MAX_ENTRIES]; // 存储电话本信息的数组
int numEntries = 0; // 当前电话本条目数量
void Phone_book_analysis(void){
/*int numEntries = 0; // 当前电话本条目数量
// 模拟收到的电话本信息字符串
char data[] = "+PBDATA=1<FF>JACK<FF>12345678911";
// 解析字符串并提取姓名和电话号码
char *token = strtok(data, "<FF>"); // 使用<FF>作为分隔符
if (token != NULL) {
token = strtok(NULL, "<FF>"); // 跳过第一个分隔符
if (token != NULL) {
strcpy(phoneBook[numEntries].name, token);
token = strtok(NULL, "<FF>");
if (token != NULL) {
strcpy(phoneBook[numEntries].phone, token);
numEntries++;
printf("Phone book entry stored successfully.\n");
}
}
}*/
// 打印存储的电话本信息
for (int i = 0; i < numEntries; i++) {
printf("Entry %d: Name - %s, Phone - %s\n", i+1, phoneBook[i].name, phoneBook[i].phone);
}
}
void Call_analysis(){
}
void parseBtATCommand(char* cAtCmd,int cATLen) {
uint8_t str[64];
static uint8_t flag = 0;
uint8_t j=0;
uint32_t num = 0;
printf(">>");
for(uint16_t i =0;i<cATLen;i++){
printf("%c",cAtCmd[i]);
}
if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+A2DPDEV",8))//蓝牙连接设备信息 远端设备信息 蓝牙连接
{
Set_sys_bt_connect_state(1);
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+A2DPDEV",8)){
}else if(strlen(cAtCmd) > 9 && !memcmp(cAtCmd,"+A2DPLOST",9)){//远距离断开 设备丢失
}else if(strlen(cAtCmd) > 12 && !memcmp(cAtCmd,"+AVRCPSTAT=1",12)){//AVRCP状态 1是配对状态 蓝牙断开
Set_sys_bt_connect_state(0);
}else if(strlen(cAtCmd) > 6 && !memcmp(cAtCmd,"+PBCNT",6)){//电话本数量
num = atoi(cAtCmd + 7); //从数字的起始位置开始转换为整数
printf("Extracted number from command: %d\n", num);
}else if(strlen(cAtCmd) > 7 && !memcmp(cAtCmd,"+PBDATA",7)){//电话号码
printf("----------------------------\r\n");
// 解析字符串并提取姓名和电话号码
// char *token = strtok(cAtCmd, "<FF>"); // 使用<FF>作为分隔符
/*char *token = strtok(cAtCmd, 0x3F); // 使用<FF>作为分隔符
printf("token1 > %s .\r\n",token);
if (token != NULL) {
// token = strtok(NULL, "<FF>"); // 跳过第一个分隔符
token = strtok(NULL, 0x3F); // 跳过第一个分隔符
printf("token2 > %s .\r\n",token);
if (token != NULL) {
strcpy(phoneBook[numEntries].name, token);
printf("token3 > %s .\r\n",token);
// token = strtok(NULL, "<FF>");
token = strtok(NULL, 0x3F); // 跳过第一个分隔符
if (token != NULL) {
strcpy(phoneBook[numEntries].phone, token);
printf("token4 > %s .\r\n",token);
numEntries++;
printf("Phone book entry stored successfully.\n");
}
}
}*/
printf(">>");
for(uint16_t i =0;i<cATLen;i++){
printf("%02X ",cAtCmd[i]);
}
char call_num[20];
char call_name[20];
uint16_t len1=0;
uint16_t len2=0;
for(uint16_t i=0;i<cATLen;i++){
if(cAtCmd[i] == 0xFF){
if(!len1)
len1 = i;
else
len2 = i;
}
}
printf("len1 = %d,len2 = %d.\r\n",len1,len2);
char *start;
char *start2;
char *start3;
char *start4 = cAtCmd + len2 +1;//call number
printf("start4 >%s.\r\n",start4);
strncpy(start2, (cAtCmd + len2), len2);//number
printf("start2 >%s.\r\n",start2);
strncpy(start, (cAtCmd + 10), len2-len1);//name
printf("start >%s, start2 >%s .\r\n",start,start2);
// char *start = cAtCmd + 10;
// char *start2;
// strncpy(start2, start, len1);
// char *start3 = start + len1;
// // char *end = strchr(start, 0x3F);
// // char *end2 = strchr(end, 0x3F);
// printf("start >%s, end >%s, end2 >%s .\r\n",start,start2,start3);
// if (end) {
// *end = '\0';
// strncpy(call_num, start, 19);
// call_num[19] = '\0'; // 确保字符串以null结尾
// printf("call_num > %s .\r\n",call_num);
// }
// if (end2) {
// *end2 = '\0';
// strncpy(call_name, end, 19);
// call_name[19] = '\0'; // 确保字符串以null结尾
// printf("call_name > %s .\r\n",call_name);
// }
}
}

View File

@ -0,0 +1,6 @@
#ifndef BT_INTERACTION_PROTOCOL_H
#define BT_INTERACTION_PROTOCOL_H
#endif

View File

@ -1,2 +1,69 @@
#include "awtk.h"
#include "can_protocol.h"
uint8_t tcs_twinkle = 0;
uint8_t tcs_switch = 0;
//37B
void tcsworking_event_handing(int *buf){
uint8_t data = 0;
*(buf++);
*(buf++);
data = *(buf++);
tcs_twinkle = getBitValue(data,7);//tcs闪烁控制指令 为1闪烁
}
//12B
void tcsswitch_event_handing(int *buf){
uint8_t data = 0;
uint8_t tcs_data = 0;
data = *(buf++);
tcs_data = getBit2Value(data,0);//tcs开关信号
if(tcs_data<=1)
tcs_switch = tcs_data;
}
//101
void speed_event_handing(int *buf){
uint16_t eng_temp = 0;
uint16_t data = 0;
double buf_value = 0;
*(buf++);
*(buf++);
*(buf++);
*(buf++);
data = *(buf++) &0xFF;
data = (*(buf++)&0xFF) | data<<8;
buf_value = data; //值为60-120
if(buf_value>5280)
buf_value = 255;
else if(buf_value>2730)
buf_value = ((buf_value*0.1)-273);
else
buf_value = 0;
eng_temp = (int)buf_value;
Set_sys_can_temp(eng_temp);
}
//0xA5
void abs_dtc_event_handing(int *buf){
char dtc[5] = {0};
dtc[4] = *(buf++)&0xFF;
dtc[3] = *(buf++)&0xFF;
dtc[2] = *(buf++)&0xFF;
dtc[1] = *(buf++)&0xFF;
dtc[0] = *(buf++)&0xFF;
Get_can_abs_dtc(dtc);
}
//0x402
void ecu_dtc_event_handing2(int *buf){
char dtc[5] = {0};
dtc[4] = *(buf++)&0xFF;
dtc[3] = *(buf++)&0xFF;
dtc[2] = *(buf++)&0xFF;
dtc[1] = *(buf++)&0xFF;
dtc[0] = *(buf++)&0xFF;
Get_can_abs_dtc(dtc);
}

View File

@ -70,29 +70,31 @@ void vbat_led_off(void){
void light_gpio_init(void){
// //灯光使能
// gpio_direction_output(GPIO_LIGHT, TRUE);
//灯光使能
gpio_direction_output(47, TRUE);
//R_LED
gpio_direction_output(GPIO_LIGHT_R_LED, TRUE);
//YG_LED
gpio_direction_output(GPIO_LIGHT_YG_LED, TRUE);
//ABS_LED
gpio_direction_output(GPIO_LIGHT_ABS, TRUE);
//OIL_LED
gpio_direction_output(GPIO_LIGHT_OIL, TRUE);
//L_LED
gpio_direction_output(GPIO_LIGHT_L_LED, TRUE);
//N_LED
gpio_direction_output(GPIO_LIGHT_N_LED, TRUE);
//ENG_LED
gpio_direction_output(GPIO_LIGHT_ENG_LED, TRUE);
// #if (MOTO_WARE_HOSE == MOTO_ICMX_A580A)
// //ABS_LED
// gpio_direction_output(GPIO_LIGHT_ABS, TRUE);
// //ENG_LED
// gpio_direction_output(GPIO_LIGHT_ENG_LED, TRUE);
// #endif
//VBAT_LED
gpio_direction_output(GPIO_LIGHT_VBAT_LED, TRUE);
gpio_direction_input(GPIO_LIGHT_SET);
gpio_direction_input(GPIO_LIGHT_MODE);
gpio_timer();
gpio_timer();//按键 //左右灯光
}
@ -101,16 +103,18 @@ void light_off(void){
gpio_direction_output(GPIO_LIGHT_R_LED, FALSE);
//YG_LED
gpio_direction_output(GPIO_LIGHT_YG_LED, FALSE);
//ABS_LED
gpio_direction_output(GPIO_LIGHT_ABS, FALSE);
//OIL_LED
gpio_direction_output(GPIO_LIGHT_OIL, FALSE);
//L_LED
gpio_direction_output(GPIO_LIGHT_L_LED, FALSE);
//N_LED
gpio_direction_output(GPIO_LIGHT_N_LED, FALSE);
//ENG_LED
gpio_direction_output(GPIO_LIGHT_ENG_LED, FALSE);
// #if (MOTO_WARE_HOSE == MOTO_ICMX_A580A)
// //ABS_LED
// gpio_direction_output(GPIO_LIGHT_ABS, FALSE);
// //ENG_LED
// gpio_direction_output(GPIO_LIGHT_ENG_LED, FALSE);
// #endif
//VBAT_LED
gpio_direction_output(GPIO_LIGHT_VBAT_LED, FALSE);

View File

@ -3,7 +3,7 @@
#include "tkc/types_def.h"
#define GPIO_LIGHT 47
#define GPIO_LIGHT_R_LED_FLAG 11
#define GPIO_LIGHT_L_LED_FLAG 10

View File

@ -10,9 +10,10 @@ KEY_DAT gs_keyDat[KEY_NUMBERS]={0};
bool key_readKeyPin(uint8_t keyx)
{
bool status;
if(keyx==0) status = gpio_get_value(GPIO_LIGHT_MODE);
else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_SET);
return status;
if(keyx==0) status = gpio_get_value(GPIO_LIGHT_SET);
else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_MODE);
// return (!status);//低有效
return (status);//高有效
}
void key_Scan(void)
@ -28,6 +29,9 @@ void key_Scan(void)
}
}
extern uint8_t map_flag;
static int step_about = 0;
static int step = 0;
void check_key(void)
{
@ -44,7 +48,7 @@ void check_key(void)
gs_keyDat[1].flag_Reset=1;
gs_keyDat[0].keyCnt=0;
gs_keyDat[1].keyCnt=0;
// printf("set mode key \r\n");
// printf("two long key ---------------------\r\n");
Key_Distinction(KEY_SHORT_ON,LV_KEY_OTHER1);
}
else if(gs_keyDat[i].keyCnt==KEY_LONGPRESS_COUNTER)
@ -55,14 +59,14 @@ void check_key(void)
{
gs_keyDat[i].flag_Reset=1;
gs_keyDat[i].keyCnt=0;
// printf("set key long key\r\n");
// printf("LV_KEY_OPTION key long key\r\n");
Key_Distinction(KEY_LONG_ON,LV_KEY_OPTION);
}
if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
{
gs_keyDat[i].flag_Reset=1;
gs_keyDat[i].keyCnt=0;
// printf("mode key long key\r\n");
// printf("LV_KEY_SELECT key long key\r\n");
Key_Distinction(KEY_LONG_ON,LV_KEY_SELECT);
}
@ -76,13 +80,37 @@ void check_key(void)
{
if(i==0 && gs_keyDat[1].flag_Pressed==KEY_OFF)
{
// printf("set key short key\r\n");
Key_Distinction(KEY_SHORT_ON,LV_KEY_OPTION);
// printf("LV_KEY_OPTION-------------------------.\r\n");
// if(map_flag){
// // KnobUpdate(0,0,0,0,0,1);
// request_UI("maps:");
// }else
// if(Get_sys_wifi()){
// printf("option DOWN .\r\n");
// android_auto_send_key_event(20,1);
// android_auto_send_key_event(20,0);
// // android_auto_send_knob_event(19,1);
// // android_auto_send_knob_event(19,0);
// }else
Key_Distinction(KEY_SHORT_ON,LV_KEY_OPTION);
}
else if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
{
// printf("mode key short key\r\n");
Key_Distinction(KEY_SHORT_ON,LV_KEY_SELECT);
// printf("LV_KEY_SELECT-------------------------.\r\n");
// if(map_flag){
// // KnobUpdate(0,0,0,0,0,-1);
// request_UI("maps:");
// }else
// if(Get_sys_wifi()){
// printf("select ENTER .\r\n");
// android_auto_send_key_event(66,1);
// android_auto_send_key_event(66,0);
// // android_auto_send_key_event(20,1);
// // android_auto_send_key_event(20,0);
// // android_auto_send_knob_event(20,1);
// // android_auto_send_knob_event(20,0);
// }else
Key_Distinction(KEY_SHORT_ON,LV_KEY_SELECT);
}
}
gs_keyDat[i].keyCnt=0;
@ -143,7 +171,7 @@ static void gpio_handler(void *param)
int gpio_timer(void){
// printf("gpio_timer .\r\n");
if (xTaskCreate(gpio_handler, "gpio_handler", configMINIMAL_STACK_SIZE, NULL,
configMAX_PRIORITIES / 3, NULL) != pdPASS) {
configMAX_PRIORITIES - 5, NULL) != pdPASS) {
printf("create uart rx demo task fail.\n");
return -1;
}

View File

@ -0,0 +1,539 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "FreeRTOS.h"
#include "chip.h"
#include "board.h"
#include "serial.h"
#include "sysinfo.h"
#include "conversation_protocol.h"
#include "sfud.h"
#include "ota_update.h"
#include "updatefile.h"
#include "romfile.h"
#include "animation.h"
#include "ff_stdio.h"
#include "awtk.h"
#include "ota_protocol.h"
int flash_copy_demo(void);
#if DEVICE_TYPE_SELECT != EMMC_FLASH
#include "ff_sfdisk.h"
#endif
typedef enum {
UART_FRAME_START,
UART_FRAME_FILEINFO,
UART_FRAME_FILEXFER,
UART_FRAME_FINISH,
} eUartFrameType;
typedef enum {
UUP_STATE_IDLE,
UUP_STATE_START,
UUP_STATE_GET_FILEINFO,
UUP_STATE_FILE_TFR,
UUP_STATE_END,
} eUartUpdateState;
#define UUP_ACK_OK 1
#define UUP_ACK_FAIL 0
#define UUP_MAX_FILE_SIZE 0x1000000
#define UUP_RX_FRAME_NUM 16
#define UUP_MAX_LOADER_SIZE STEPLDR_MAX_SIZE//0x10000
static int uup_status = UUP_STATE_IDLE;
static int uup_file_type = 0;
static int uup_file_size = 0;
static int uup_packet_num = 0;
static int uup_rev_packet = 0;
static int uup_rev_len = 0;
static char uup_filename[32];
static FF_FILE *uup_file = NULL;
#define UUP_PACKET_SIZE 128
#define UUP_MAX_FRAME_LEN (UUP_PACKET_SIZE + 16)
#define UUP_PACKET_A27_SIZE 4096
#define UUP_MAX_FRAME_A27_LEN (UUP_PACKET_A27_SIZE + 16)
#define UUP_RX_FRAME_NUM 16
#define BYTESPERPAGE 256
#define PAGESPERSECTORS 16
#define UUP_BUF_SIZE (BYTESPERPAGE * PAGESPERSECTORS)
#define IMAGE_RW_SIZE 0x10000
#define NEW_APPLDR_CHECKSUM_OFFSET 0x14
#define AMT630_BIN_OFFSET 0x41000
#define BOOTANIM_BIN_OFFSET 0x741000
#define ROM_BIN_OFFSET 0xb41000
#define NEW_APPFOOSET 0x17F0000
#define AMT630_BIN_MAX_SIZE 0x700000
/*
#define AMT630_BIN_OFFSET 0x41000
#define BOOTANIM_BIN_OFFSET 0x501000//0x341000
#define ROM_BIN_OFFSET 0x801000
#define NEW_APPFOOSET 0xb01000
#define AMT630_BIN_MAX_SIZE 0x4c0000
*/
static uint32_t uup_app_offset;
static uint32_t uup_burn_offset;
static unsigned char uup_buf[4096];
static unsigned int uup_buf_len = 0;
static unsigned int checksum = 0,calc_checksum = 0xffffffff;
static void uup_send_ack(UartPort_t *uap, int type, int ret)
{
/*unsigned char buf[7] = {0x55, 0x80, 0xc5, 0x02, 0x00, 0x00, 0x00};
int i;
buf[4] = type;
buf[5] = ret;
for (i = 1; i < 6; i++)
buf[6] ^= buf[i];
iUartWrite(uap, buf, 7, pdMS_TO_TICKS(100));*/
unsigned char buf[8] = {0x55, 0x80, 0xc5, 0x02, 0x00, 0x00, 0x00, 0x00};
int i;
buf[5] = type;
buf[6] = ret;
if(ret == 0){
Set_sys_power_on_self_test(100);
Set_sys_return_demo(2);
Set_sys_plan(0);
Set_sys_pace(0);
}
for (i = 1; i < 7; i++)
buf[7] ^= buf[i];
// printf("630->uart:");
// for(uint8_t j=0;j<8;j++){
// printf("%02x ",buf[j]);
// }
// printf("\n");
iUartWrite(uap, buf, 8, pdMS_TO_TICKS(100));
}
void uup_ota_update(UartPort_t *uap, uint8_t *framebuf, size_t len)
{
int frametype = framebuf[0];
uint8_t *buf = framebuf + 1;
unsigned int framelen;
unsigned int packetnum;
sfud_flash *sflash = sfud_get_device(0);
SysInfo *sysinfo = GetSysInfo();
//printf("uup_ota_update frametype =%d \n",frametype);
switch (frametype) {
case UART_FRAME_START:
printf("UART3_Modification_Type .\n");
UART3_Modification_Type();
vTaskDelay(10);
printf("start sfud erase flash .\n");
//擦除flash
uup_app_offset = NEW_APPFOOSET;
uup_burn_offset = uup_app_offset;
//uup_send_ack(uap, frametype, UUP_ACK_OK);
//Set_sys_power_on_self_test(150);
printf("erase add %X , size %X .\r\n",uup_app_offset,AMT630_BIN_MAX_SIZE);
if(sfud_erase(sflash, uup_app_offset, AMT630_BIN_MAX_SIZE)==SFUD_SUCCESS){
vTaskDelay(100);
printf("UART3_Type_regression .\n");
UART3_Type_regression();
vTaskDelay(100);
printf("UART_FRAME_START sfud erase ok.\n");
uup_send_ack(uap, frametype, UUP_ACK_OK);
}else{
vTaskDelay(100);
printf("UART3_Type_regression .\n");
UART3_Type_regression();
vTaskDelay(100);
printf("UART_FRAME_START sfud erase fail.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
}
uup_status = UUP_STATE_START;
break;
case UART_FRAME_FILEINFO:
if (uup_status != UUP_STATE_START && uup_status != UUP_STATE_GET_FILEINFO) {
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
uup_file_type = buf[0];
if (uup_file_type > UPFILE_TYPE_LNCHEMMC) {
printf("Rev wrong file type %d.\n", uup_file_type);
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
uup_packet_num = (buf[1] << 16) | (buf[2] << 8) | buf[3];
uup_file_size = 128 * uup_packet_num;
if (uup_file_size > AMT630_BIN_MAX_SIZE) {
printf("Rev wrong file size.\n");
printf("uup_file_size = 0x%x ,uup_packet_num = 0x%x .\n",uup_file_size,uup_packet_num);
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
printf("uup_file_size = 0x%x .\n",uup_file_size);
uup_packet_num = uup_packet_num/32;
Set_sys_plan(uup_packet_num);
uup_rev_packet = 0;
uup_send_ack(uap, frametype, UUP_ACK_OK);
uup_status = UUP_STATE_GET_FILEINFO;
calc_checksum = 0xffffffff;
break;
case UART_FRAME_FILEXFER:
if (uup_status != UUP_STATE_GET_FILEINFO && uup_status != UUP_STATE_FILE_TFR) {
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
packetnum = buf[0];
if ((uup_rev_packet & 0xff) != packetnum) {
printf("Wrong packet number.\n");
//printf("buf 0 - 4 : 0x%x ,0x%x ,0x%x ,0x%x ,0x%x \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
//printf("packetnum = 0x%x,uup_rev_packet = 0x%x \n",packetnum,uup_rev_packet);
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
//printf("uup_rev_packet==0 ---------TURE\n");
//printf("uup_rev_packet %d.\n", uup_rev_packet);
if (uup_rev_packet==0) { //第一条数据保存其crc校验码
/*if (uup_file_type == UPFILE_TYPE_WHOLE) {
UpFileHeader *header = (UpFileHeader*)&buf[1];
if (header->magic != MKTAG('U', 'P', 'D', 'F')) {
printf("Wrong whole file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
checksum = header->checksum;
sysinfo->app_size = header->files[0].size;
printf("sysinfo->appsize = 0x%x", sysinfo->app_size);
}else if (uup_file_type == UPFILE_TYPE_RESOURCE) {
RomHeader *header = (RomHeader *)&buf[1];
if (header->magic != MKTAG('R', 'O', 'M', 'A')) {
printf("Wrong resource file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
checksum = header->checksum;
} else if (uup_file_type == UPFILE_TYPE_ANIMATION) {
BANIHEADER *header = (BANIHEADER *)&buf[1];
if (header->magic != MKTAG('B', 'A', 'N', 'I')) {
printf("Wrong animation file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
checksum = header->checksum;
} else */
if (uup_file_type == UPFILE_TYPE_APP) {//代码文件
unsigned int magic = buf[1] | (buf[2] << 8) | (buf[3] << 16) | (buf[4] << 24);
if (magic != UPFILE_APP_MAGIC) {
printf("Wrong app file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
unsigned char *tmp = buf + 1 + NEW_APPLDR_CHECKSUM_OFFSET;
checksum = tmp[0] | (tmp[1] <<8) | (tmp[2] << 16) | (tmp[3] << 24);
}else if (uup_file_type == UPFILE_TYPE_ANIMATION) {//动画文件
BANIHEADER *header = (BANIHEADER *)&buf[1];
if (header->magic != MKTAG('B', 'A', 'N', 'I')) {
printf("Wrong animation file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
checksum = header->checksum;
}else if (uup_file_type == UPFILE_TYPE_RESOURCE) {//资源文件
RomHeader *header = (RomHeader *)&buf[1];
if (header->magic != MKTAG('R', 'O', 'M', 'A')) {
printf("Wrong resource file magic.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
checksum = header->checksum;
}
printf(" file_type = %d ,No1.checksum = 0x%x\n",uup_file_type,checksum);
}
framelen = len - 2;
//printf("framelen = %d ,uup_packet_num =%d ,uup_rev_packet = %d \n",framelen,uup_packet_num,uup_rev_packet);
/* only last frame size is less than UUP_PACKET_SIZE */
if (framelen > UUP_PACKET_A27_SIZE ||
(framelen < UUP_PACKET_A27_SIZE && uup_rev_packet != uup_packet_num)) { //UUP_PACKET_A27_SIZE
printf("Wrong packet len.\n");
printf("uup_rev_packet = %d, uup_packet_num = %d \n",uup_rev_packet,uup_packet_num);
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
memcpy(uup_buf + uup_buf_len, buf+1, framelen);
uup_buf_len += framelen;
uup_rev_packet++;
//uup_send_ack(uap, frametype, UUP_ACK_OK);
if (uup_buf_len == UUP_BUF_SIZE) {
printf("uup_rev_packet = %d , save_data.\n",uup_rev_packet);
uup_send_ack(uap, frametype, UUP_ACK_OK);
Set_sys_pace(uup_rev_packet);
//printf("addr=0x%x,size=%x\n",uup_burn_offset,framelen);
//sfud_erase_write(sflash, uup_burn_offset, UUP_BUF_SIZE, uup_buf);
sfud_write(sflash, uup_burn_offset, UUP_BUF_SIZE, uup_buf);
if (uup_rev_packet == 1){//UUP_BUF_SIZE/UUP_PACKET_SIZE) {
//printf("enter1 uup_rev_packet = %d \n",uup_rev_packet);
/*if (uup_file_type == UPFILE_TYPE_WHOLE) {
UpFileHeader *pheader = (UpFileHeader *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_RESOURCE) {
RomHeader *pheader = (RomHeader *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_ANIMATION) {
BANIHEADER *pheader = (BANIHEADER *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_APP) {*/
if (uup_file_type == UPFILE_TYPE_APP) {//代码文件
unsigned int *tmp = (unsigned int *)(uup_buf + NEW_APPLDR_CHECKSUM_OFFSET);
*tmp = 0;
}else if (uup_file_type == UPFILE_TYPE_ANIMATION) {//动画文件
BANIHEADER *pheader = (BANIHEADER *)uup_buf;
pheader->checksum = 0;
}else if (uup_file_type == UPFILE_TYPE_RESOURCE) {//资源文件
RomHeader *pheader = (RomHeader *)uup_buf;
pheader->checksum = 0;
}
//}
}
calc_checksum = xcrc32(uup_buf, UUP_BUF_SIZE, calc_checksum);//计算校验和
uup_buf_len =0;
uup_burn_offset += UUP_BUF_SIZE;
}else if (uup_buf_len > UUP_BUF_SIZE) {
printf("loader file is too large.\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
/*memcpy(&uup_sysinfo, &buf[2], sizeof(SysInfo));
sfud_erase_write(sflash, uup_burn_offset, framelen, &buf[1]);//128字节写一次
uup_burn_offset += framelen;*/
uup_status = UUP_STATE_FILE_TFR;
break;
case UART_FRAME_FINISH:
if (uup_status != UUP_STATE_FILE_TFR && uup_status != UART_FRAME_FINISH) {
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
break;
}
if (!buf[0]) {
printf("update end with error!\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
uup_status = UUP_STATE_END;
break;
}
framelen = len - 2;
//printf("finish calc_checksum =%x\n",calc_checksum);
if(uup_buf_len){//若最后一包数据不为0 则存数据并且继续计算校验和
//sfud_erase_write(sflash, uup_burn_offset, uup_buf_len, uup_buf);
sfud_write(sflash, uup_burn_offset, uup_buf_len, uup_buf);
//若数据为32 即首次的4k 那么将其置为0
if (uup_rev_packet <= 1){//< UUP_BUF_SIZE / UUP_PACKET_SIZE) {
printf("enter2 uup_rev_packet = %d \n",uup_rev_packet);
/*if (uup_file_type == UPFILE_TYPE_WHOLE) {
UpFileHeader *pheader = (UpFileHeader *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_RESOURCE) {
RomHeader *pheader = (RomHeader *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_ANIMATION) {
BANIHEADER *pheader = (BANIHEADER *)uup_buf;
pheader->checksum = 0;
} else if (uup_file_type == UPFILE_TYPE_APP) {*/
if (uup_file_type == UPFILE_TYPE_APP) {
unsigned int *checksum = (unsigned int *)(uup_buf + NEW_APPLDR_CHECKSUM_OFFSET);
*checksum = 0;
}else if (uup_file_type == UPFILE_TYPE_ANIMATION) {
BANIHEADER *pheader = (BANIHEADER *)uup_buf;
pheader->checksum = 0;
}else if (uup_file_type == UPFILE_TYPE_RESOURCE) {
RomHeader *pheader = (RomHeader *)uup_buf;
pheader->checksum = 0;
}
}
printf("enter2 uup_buf_len =%d calc_checksum================0x%x\n",uup_buf_len,calc_checksum);
calc_checksum = xcrc32(uup_buf, uup_buf_len, calc_checksum);
Set_sys_pace(0);
Set_sys_upgrade(1);
}
/*if (calc_checksum != checksum) {
printf("checksum error ! ! ! .\r\n");
}else{
printf("checksum ok .\r\n");
}*/
if (calc_checksum != checksum) {
printf("calc_checksum = 0x%02x,checksum = 0x%02x.\n",calc_checksum,checksum);
printf("whole crc check after burn fail!\n");
uup_send_ack(uap, frametype, UUP_ACK_FAIL);
uup_rev_packet = 0;
checksum = 0;
calc_checksum = 0xffffffff;
uup_buf_len = 0;
framelen = 0;
break;
} else {
uup_send_ack(uap, frametype, UUP_ACK_OK);
vTaskDelay(1000);
UART3_Modification_Type();
printf("uap close .\r\n");
printf("test amt630h update ok!\n");
sysinfo->image_offset=0x40000;
sysinfo->reserved[9] = uup_file_type;
sysinfo->upgrade_flag=uup_buf_len;
sysinfo->upgrade_appsize=uup_file_size;
SaveSysInfo();
vTaskDelay(500);
printf("TaskDelay 500ms SaveSysInfo .\n");
flash_copy_demo();
wdt_cpu_reboot();
}
uup_rev_packet = 0;
checksum = 0;
calc_checksum = 0xffffffff;
uup_buf_len = 0;
framelen = 0;
uup_status = UUP_STATE_END;
break;
}
}
int flash_copy_demo(void)
{
uint32_t calchecksum,appchecksum,imageoff,new_appoffset,new_appsize;
int i;
uint8_t *buf;
sfud_flash *sflash = sfud_get_device(0);
printf("enter copy flash .\n");
new_appsize=uup_file_size; //根据串口升级的协议获取
new_appoffset = NEW_APPFOOSET; //升级的程序可以固定写在这个地址预留3M
if(uup_file_type == UPFILE_TYPE_APP){
imageoff = AMT630_BIN_OFFSET; //固定的 运行区固定地址
}else if(uup_file_type == UPFILE_TYPE_ANIMATION){
imageoff = BOOTANIM_BIN_OFFSET; //固定的 运行区固定地址
}else if(uup_file_type == UPFILE_TYPE_RESOURCE){
imageoff = ROM_BIN_OFFSET;
}
//imageoff = AMT630_BIN_OFFSET; //固定的 运行区固定地址
printf("copy flash init ok.\n");
Set_sys_plan((new_appsize/IMAGE_RW_SIZE)+1);
printf("new_appsize = %x ,start flash copy .\n",new_appsize);
// sfud_qspi_fast_read_enable(sfud_get_device(0), 1);
// printf("sfud_qspi_fast_read_enable ok.\n");
buf = pvPortMalloc(IMAGE_RW_SIZE);
if (!buf) {
printf("%s %d malloc %d bytes fail.\n", __FUNCTION__, __LINE__, IMAGE_RW_SIZE);
return -1;
}
printf("start copy flash ok.\n");
for(i=0;i<new_appsize/IMAGE_RW_SIZE;i++)
{
printf("i = %d start read .\r\n",i);
sfud_read(sflash, new_appoffset+IMAGE_RW_SIZE*i, IMAGE_RW_SIZE, buf);
printf("start erase write .\r\n");
sfud_erase_write(sflash, imageoff+IMAGE_RW_SIZE*i, IMAGE_RW_SIZE, buf);
printf("start erase write ok.\r\n");
Set_sys_pace(i+1);
if(i==0)
{
if (uup_file_type == UPFILE_TYPE_APP) {//代码文件
unsigned int *tmp = (unsigned int *)(buf + NEW_APPLDR_CHECKSUM_OFFSET);
appchecksum = *tmp;
*tmp = 0;
}else if (uup_file_type == UPFILE_TYPE_ANIMATION) {//动画文件
BANIHEADER *pheader = (BANIHEADER *)buf;
appchecksum = pheader->checksum;
pheader->checksum = 0;
}else if (uup_file_type == UPFILE_TYPE_RESOURCE) {//资源文件
RomHeader *pheader = (RomHeader *)buf;
appchecksum = pheader->checksum;
pheader->checksum = 0;
}
printf("file_type = %d. %X\r\n",uup_file_type,appchecksum);
calchecksum = xcrc32(buf, IMAGE_RW_SIZE, 0xffffffff);
printf("i=0 calchecksum = 0x%X.\n",calchecksum);
}
else
{
calchecksum = xcrc32(buf, IMAGE_RW_SIZE, calchecksum);
printf("i=%d ,r_add = 0x%X ,w_add = 0x%X , calchecksum = 0x%X.\n",i,new_appoffset+IMAGE_RW_SIZE*i,imageoff+IMAGE_RW_SIZE*i,calchecksum);
}
}
if(new_appsize%IMAGE_RW_SIZE)
{
uint32_t red_add,wri_add,size,count;
int k;
count = (new_appsize%IMAGE_RW_SIZE )/0x1000;
red_add = new_appoffset+new_appsize- new_appsize%IMAGE_RW_SIZE;
wri_add = imageoff+new_appsize- new_appsize%IMAGE_RW_SIZE;
size = 0x1000;
printf("count = %d .\n",count);
for(k=0;k<count;k++){
sfud_read(sflash, red_add, size, buf);
sfud_erase_write(sflash, wri_add, size, buf);
calchecksum = xcrc32(buf, size, calchecksum);
printf("k=%d ,calchecksum = 0x%X.\n",k,calchecksum);
red_add +=size;
wri_add +=size;
}
if(uup_buf_len){//若最后一包数据不满0x1000 则存数据并且继续计算校验和
sfud_read(sflash, red_add, uup_buf_len, buf);
sfud_erase_write(sflash, wri_add, uup_buf_len, buf);
calchecksum = xcrc32(buf, uup_buf_len, calchecksum);
printf("end calchecksum = 0x%X.\n",calchecksum);
}
}
printf("end flash copy.\n");
vPortFree(buf);
printf("calchecksum is 0x%X\r\n",calchecksum);
printf("appchecksum is 0x%X\r\n",appchecksum);
if(calchecksum==appchecksum)
{
printf("crc32 OK\r\n");
SysInfo *sysinfo = GetSysInfo();
if(uup_file_type == UPFILE_TYPE_APP)
sysinfo->app_size = new_appsize;
sysinfo->image_offset=0x40000;
sysinfo->upgrade_flag = 0;
sysinfo->upgrade_appsize =0;
sysinfo->reserved[9] = 0;
SaveSysInfo();
vTaskDelay(500);
wdt_cpu_reboot();
return 0;
}
else
{
SysInfo *sysinfo = GetSysInfo();
sysinfo->image_offset=0x40000;
sysinfo->upgrade_flag = 0;
sysinfo->upgrade_appsize =0;
sysinfo->reserved[9] = 0;
SaveSysInfo();
vTaskDelay(500);
printf("crc32 ERROR\r\n");
return -1;
}
}

View File

@ -0,0 +1,6 @@
#ifndef OTA_PROTOCOL_H
#define OTA_PROTOCOL_H
#include "tkc/types_def.h"
#endif

View File

@ -79,7 +79,8 @@ void pressure_buffer_event_handing(Pressure_t pressure,char buffer[],uint8_t typ
pressure.temp = data;
if(data>=70 && data<128){
pressure.temp_state = 1;
}
}else
pressure.temp_state = 0;
//DEBUG_PRINT("%x, ",data);
//P
sum = 0;

View File

@ -11,7 +11,7 @@
#include "moto_adc.h"
// uint8_t save_data = 0;
uint8_t save_data = 0;
#define ADC_VPLTAGE_MIN 1666
#define ADC_VPLTAGE_MAX 2486
@ -20,7 +20,7 @@ int adc_light = 0;
int adc_voltage = 0;
extern uint32_t fml_stamp_to_time(uint32_t timep , uint32_t time[]);
extern uint16_t light_buffer[];
extern uint8_t light_buffer[];
extern double cell_buffer[];
extern uint8_t data_storage;
extern uint32_t tire_front_time;
@ -54,10 +54,10 @@ double adc_voltage_calculation(void){
value = 16.5;
else
value = (adc_voltage - ADC_VPLTAGE_MIN) * (16.5 - 11.0) / (ADC_VPLTAGE_MAX - ADC_VPLTAGE_MIN) + 11.0;
printf("adc_voltage = %d value = %lf.\r\n",adc_voltage,value);
// printf("adc_voltage = %d value = %lf.\r\n",adc_voltage,value);
return value;
}
extern uint8_t device_flag;
//MOTO通讯 设备信息+时间戳解析协议
void device_data_analysis(uint8_t *buf){
DEBUG_PRINT("enter device_data_analysis .\r\n");
@ -77,8 +77,7 @@ void device_data_analysis(uint8_t *buf){
// DEBUG_PRINT("0x47 -- %02x .\n",data);
if(data!=0x47)
return;
if(!device_flag)
device_flag = 1;
//设备相关信息
data = *(buf++);//0x01
// DEBUG_PRINT("0x01 -- %02x .\n",data);
@ -199,7 +198,7 @@ void device_data_analysis(uint8_t *buf){
Set_device_ability(data);
}
int test_light = 0;
//MOTO通讯协议
void data_analysis(uint8_t *buf){
uint32_t data;
@ -211,7 +210,8 @@ void data_analysis(uint8_t *buf){
uint8_t light = 0;
double cell = 0;
uint8_t sys_state = 0;
uint8_t save_data = 0;
save_data = 0;
if(Get_sys_power_on_self_test()==100)
sys_state=1;
@ -279,11 +279,14 @@ void data_analysis(uint8_t *buf){
save_data = getBitValue(data,7);
if(sys_state){
// right_led_switch(getBitValue(data,0));
// left_led_switch(getBitValue(data,1));
right_led_switch(getBitValue(data,0));
left_led_switch(getBitValue(data,1));
yg_led_switch(getBitValue(data,2));
// abs_led_switch(getBitValue(data,4));
// eng_led_switch(getBitValue(data,6));
#if (MOTO_WARE_HOSE == MOTO_ICMX_A580A)
abs_led_switch(getBitValue(data,4));
eng_led_switch(getBitValue(data,6));
#endif
}
//档位
@ -343,7 +346,7 @@ void data_analysis(uint8_t *buf){
}
if(save_data){
DEBUG_PRINT("save_data.\r\n");
// DEBUG_PRINT("save_data.\r\n");
// printf("light = %d .\r\n",light);
Set_sys_gas(oil);
Set_sys_temp(temp);
@ -364,8 +367,11 @@ void data_analysis(uint8_t *buf){
//adc采样光感计算
int light_num = (adc_light/10);
if(light_num>=100)
light_num = 100;
test_light = light_num;
if(light_num>=200)
light_num = 200;
if(Get_sys_power_on_self_test()<100)
light_num = 10;
light_buffer[data_storage] =light_num;
data_storage++;
if(data_storage>=SAVE_DATA_SIZE){//满足存储大小 计算均值

View File

@ -3,4 +3,14 @@
#include "tkc/types_def.h"
// 封装的函数,根据位位置获取对应的值
uint8_t getBitValue(uint8_t count, int bitPosition);
// 封装的函数获取2个bit组合成的值
uint8_t getBit2Value(uint8_t count, int bitPosition);
// 封装的函数获取3个bit组合成的值
uint8_t getBit3Value(uint8_t count, int bitPosition);
// 封装的函数获取4个bit组合成的值
uint8_t getBit4Value(uint8_t count, int bitPosition);
#endif