CARPLAY版本整理
This commit is contained in:
385
MXC_A27-PCB4.5-270T/app/moto/protocol/Bt_Interaction_protocol.c
Normal file
385
MXC_A27-PCB4.5-270T/app/moto/protocol/Bt_Interaction_protocol.c
Normal file
@ -0,0 +1,385 @@
|
||||
#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"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// #define MAX_ENTRIES 500 // 假设最大条目数为500
|
||||
#define MAX_ENTRIES 3000 // 假设最大条目数为500
|
||||
uint8_t time_flag = 0;
|
||||
|
||||
char bt121_name[50];
|
||||
char bt121_name1[50];
|
||||
// 定义电话本条目结构体
|
||||
typedef struct {
|
||||
char name[50];
|
||||
char phone[20];
|
||||
} PhoneBookEntry;
|
||||
|
||||
PhoneBookEntry phoneBook[MAX_ENTRIES]; // 存储电话本信息的数组
|
||||
int numEntries = 0; // 当前电话本条目数量
|
||||
uint8_t pbstat_state = 0; //当前下载状态
|
||||
uint8_t bt121_state = 0; //检测蓝牙开关操作状态
|
||||
|
||||
|
||||
void Phone_book_analysis(void){
|
||||
// 打印存储的电话本信息
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
printf("ID%d:Name-%s,Phone-%s\n", i+1, phoneBook[i].name, phoneBook[i].phone);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 通过电话号码查询姓名
|
||||
char* findNameByPhoneNumber(const char* phoneNumber) {
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
if (strcmp(phoneBook[i].phone, phoneNumber) == 0) {
|
||||
printf("find> i=%d,name=%s.\r\n",i,phoneBook[i].name);
|
||||
return phoneBook[i].name;
|
||||
}
|
||||
}
|
||||
printf("unfind .\r\n");
|
||||
|
||||
if(Get_sys_language())
|
||||
return "Unknown number";
|
||||
else
|
||||
return "未知号码"; // 如果未找到匹配的电话号码,返回 "Not found"
|
||||
}
|
||||
|
||||
void Call_analysis(){
|
||||
|
||||
}
|
||||
extern uint8_t bw_121_time;
|
||||
void BW_121_Switch(uint8_t type){
|
||||
if(!bw_121_time){
|
||||
bw_121_time = 10;
|
||||
|
||||
switch(type){
|
||||
case 0:
|
||||
printf("send close bt.\r\n");
|
||||
console_send_atcmd("AT+BTEN=0\r\n", strlen("AT+BTEN=0\r\n"));//关蓝牙
|
||||
bt121_state = 1;
|
||||
break;
|
||||
case 1:
|
||||
printf("send open bt.\r\n");
|
||||
console_send_atcmd("AT+BTEN=1\r\n", strlen("AT+BTEN=1\r\n"));//开蓝牙
|
||||
bt121_state = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void extract_numbers(const char *num) {
|
||||
int length = strlen(num);
|
||||
int count = 0;
|
||||
int segment = 1;
|
||||
int non_digits = 0;
|
||||
|
||||
printf("\r\n**************************\r\n");
|
||||
printf("extract_numbers number:%s.length=%d.\n",num,length);
|
||||
printf("\r\n**************************\r\n");
|
||||
|
||||
|
||||
printf("%d number>", segment);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (isdigit(num[i])) {
|
||||
// printf("i=%d,%02X\r\n",i,num[i]);
|
||||
putchar(num[i]);
|
||||
} else {
|
||||
// printf("i>>>%d,%02X\r\n",i,num[i]);
|
||||
non_digits++;
|
||||
segment++;
|
||||
if (segment > 1) {
|
||||
printf("\n%d number>", segment);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n**********************************%d.\n", non_digits);
|
||||
}
|
||||
|
||||
void number_event_handle(char* number_data){
|
||||
int length = strlen(number_data);
|
||||
int endIndex = length - 1;
|
||||
// 找到电话号码的结束位置
|
||||
while (endIndex >= 0 && !isdigit(number_data[endIndex])) {
|
||||
endIndex--;
|
||||
}
|
||||
// 截断非电话号码数据
|
||||
number_data[endIndex + 1] = '\0';
|
||||
}
|
||||
|
||||
void bw121call_number_data_event_handler(char* cAtCmd){
|
||||
int length = strlen(cAtCmd);
|
||||
int count = 0;
|
||||
int segment = 1;
|
||||
int non_digits = 0;
|
||||
|
||||
char type_data[2]; // 存储数据 "5" 5为来电 4为去电
|
||||
char number_data[20]; // 存储number数据
|
||||
char renumber_data[20]; // 存储number数据
|
||||
char mac_data2[12]; // 存储MAC数据
|
||||
uint8_t type = 0;
|
||||
memset(type_data, 0, sizeof(type_data));
|
||||
memset(number_data, 0, sizeof(number_data));
|
||||
memset(renumber_data, 0, sizeof(renumber_data));
|
||||
memset(mac_data2, 0, sizeof(mac_data2));
|
||||
|
||||
// printf("\r\n**************************\r\n");
|
||||
// printf("extract_numbers number:%s.length=%d.\n",cAtCmd,length);
|
||||
// printf("\r\n**************************\r\n");
|
||||
|
||||
|
||||
// printf("num=%d,data>", segment);
|
||||
int j = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if ((cAtCmd[i])!=0xFF && (cAtCmd[i])!='=') {
|
||||
switch(segment){
|
||||
case 1://前缀
|
||||
// printf("%c",cAtCmd[i]);
|
||||
break;
|
||||
case 2://MAC地址
|
||||
mac_data2[j] = cAtCmd[i];
|
||||
// printf("%c",cAtCmd[i]);
|
||||
break;
|
||||
case 3://当前通话类型
|
||||
type_data[j] = cAtCmd[i];
|
||||
// printf("%c",cAtCmd[i]);
|
||||
break;
|
||||
case 4://号码1
|
||||
number_data[j] = cAtCmd[i];
|
||||
// printf("%c",cAtCmd[i]);
|
||||
break;
|
||||
case 5://号码2
|
||||
renumber_data[j] = cAtCmd[i];
|
||||
// printf("%c",cAtCmd[i]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
} else {
|
||||
non_digits++;
|
||||
j = 0;
|
||||
segment++;
|
||||
if (segment > 1) {
|
||||
// printf("\nnum=%d,data>", segment);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
type = cAtCmd[22] - '0';
|
||||
if(cAtCmd[23]!=0xFF){
|
||||
type = type*10 + (cAtCmd[23] - '0');
|
||||
}
|
||||
|
||||
number_event_handle(number_data);
|
||||
if(segment>=5)
|
||||
number_event_handle(renumber_data);
|
||||
|
||||
// printf("**************************\r\n");
|
||||
// printf("Cleaned number:%s.\n", number_data); // 输出清理后的电话号码
|
||||
// if(segment>=5)
|
||||
// printf("Cleaned renumber:%s.\n", renumber_data); // 输出清理后的电话号码
|
||||
// printf("Cleaned type:%d.\n", type); // 输出清理后的类型
|
||||
// printf("**************************\r\n");
|
||||
char* name;
|
||||
if(type == 8)
|
||||
name = findNameByPhoneNumber(renumber_data);
|
||||
else
|
||||
name = findNameByPhoneNumber(number_data);
|
||||
|
||||
if(type >=11 || type==7)
|
||||
return;
|
||||
// time_flag
|
||||
//若无通话 则将通话存入
|
||||
if(!Get_sys_call_state()){
|
||||
Set_sys_call_number(number_data);
|
||||
Set_sys_call_name(name);
|
||||
Set_sys_call_state(1);
|
||||
Set_sys_call_type(type);
|
||||
}else{//多通话情况
|
||||
|
||||
if(type == 6){
|
||||
Set_sys_call_number(number_data);
|
||||
Set_sys_call_name(name);
|
||||
Set_sys_call_state(2);
|
||||
Set_sys_call_type(type);
|
||||
}else{
|
||||
if(type == 8)
|
||||
Set_sys_call_renumber(renumber_data);
|
||||
else
|
||||
Set_sys_call_renumber(number_data);
|
||||
Set_sys_call_rename(name);
|
||||
|
||||
if(strcmp(Get_sys_call_number(), number_data) == 0)
|
||||
time_flag = 0;
|
||||
else
|
||||
time_flag = 1;
|
||||
Set_sys_call_state(3);
|
||||
Set_sys_call_type(type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static uint8_t flag = 0;
|
||||
|
||||
void parseBtATCommand(char* cAtCmd,int cATLen) {
|
||||
// printf("###");
|
||||
// for(uint16_t i =0;i<cATLen;i++){
|
||||
// printf("%c",cAtCmd[i]);
|
||||
// }
|
||||
|
||||
if(strlen(cAtCmd) >= 2 && !memcmp(cAtCmd,"OK",2))//蓝牙连接设备信息 远端设备信息 蓝牙连接
|
||||
{
|
||||
switch(bt121_state){
|
||||
case 1:
|
||||
Set_sys_bt_on_off(0);
|
||||
break;
|
||||
case 2:
|
||||
Set_sys_bt_on_off(1);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+A2DPDEV",8))//蓝牙连接设备信息 远端设备信息 蓝牙连接
|
||||
{
|
||||
Set_sys_bt_connect_state(1);
|
||||
vTaskDelay(500);
|
||||
//查询电话本信息
|
||||
printf("select phonebook.\r\n");
|
||||
console_send_atcmd("AT+PBDOWN=1\r\n", strlen("AT+PBDOWN=1\r\n"));
|
||||
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+DEVSTAT",8)){//设备状态
|
||||
uint32_t num = 0;
|
||||
num = cAtCmd[9] - '0';//状态 0 off 1 on
|
||||
printf("bt>state = %d",num);
|
||||
switch(num){
|
||||
case 0:
|
||||
Set_sys_bt_on_off(0);
|
||||
break;
|
||||
case 1:
|
||||
Set_sys_bt_on_off(1);
|
||||
break;
|
||||
}
|
||||
printf(".ok\r\n");
|
||||
|
||||
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+HFPSTAT",8)){//来电 或 蓝牙断开
|
||||
if(strlen(cAtCmd) == 10){
|
||||
uint32_t num = 0;
|
||||
num = atoi(cAtCmd + 9); //从数字的起始位置开始转换为整数
|
||||
// printf("num = %d .\r\n",num);
|
||||
switch(num){
|
||||
case 1:
|
||||
Set_sys_bt_connect_state(0);
|
||||
break;
|
||||
case 3://通话断开
|
||||
Set_sys_call_state(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// printf("HFPSTAT %d.\r\n",num);
|
||||
}else{
|
||||
bw121call_number_data_event_handler(cAtCmd);
|
||||
}
|
||||
|
||||
}else if(strlen(cAtCmd) > 9 && !memcmp(cAtCmd,"+A2DPLOST",9)){//远距离断开 设备丢失
|
||||
Set_sys_bt_connect_state(0);
|
||||
}else if(strlen(cAtCmd) > 5 && !memcmp(cAtCmd,"+NAME",5)){//远距离断开 设备丢失
|
||||
sscanf(cAtCmd, "+NAME=%s", bt121_name1);
|
||||
}else if(strlen(cAtCmd) > 7 && !memcmp(cAtCmd,"+LEADDR",7)){//远距离断开 设备丢失
|
||||
char last_four[5];
|
||||
strncpy(last_four, cAtCmd + strlen(cAtCmd) - 4, 4);
|
||||
last_four[4] = '\0';
|
||||
// sscanf(cAtCmd, "+LEADDR=%s", last_four);
|
||||
sprintf(bt121_name, "%s_%s", bt121_name1, last_four);
|
||||
// Set_sys_bt_connect_state(0);
|
||||
}else if(strlen(cAtCmd) > 12 && !memcmp(cAtCmd,"+AVRCPSTAT=1",12)){//AVRCP状态 1是配对状态 蓝牙断开
|
||||
Set_sys_bt_connect_state(0);
|
||||
}else if(strlen(cAtCmd) > 11 && !memcmp(cAtCmd,"+PLAYSTAT=0",11)){//PLAY状态 1是配对状态 蓝牙断开
|
||||
Set_sys_bt_connect_state(0);
|
||||
}else if(strlen(cAtCmd) > 6 && !memcmp(cAtCmd,"+PBCNT",6)){//电话本数量
|
||||
uint32_t num = 0;
|
||||
num = atoi(cAtCmd + 7); //从数字的起始位置开始转换为整数
|
||||
printf("Extracted number from command: %d\n", num);
|
||||
numEntries = 0;
|
||||
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+HFPTIME",8)){//蓝牙连接后同步时间
|
||||
#if 1
|
||||
int year, month, day, hour, minute, second;
|
||||
sscanf(cAtCmd, "+HFPTIME=%d/%d/%d,%d:%d:%d", &year, &month, &day, &hour, &minute, &second);
|
||||
int check_buffer[6];
|
||||
check_buffer[0] = 2000+year;
|
||||
check_buffer[1] = month;
|
||||
check_buffer[2] = day;
|
||||
check_buffer[3] = hour;
|
||||
check_buffer[4] = minute;
|
||||
check_buffer[5] = second;
|
||||
send_wifi_set_time(check_buffer);
|
||||
#endif
|
||||
printf(">>bt time %s.\r\n",cAtCmd);
|
||||
}else if(strlen(cAtCmd) > 7 && !memcmp(cAtCmd,"+PBSTAT",7)){//下载状态
|
||||
pbstat_state = atoi(cAtCmd + 8);
|
||||
printf("pbstat_state = %d ,numEntries =%d .\r\n",pbstat_state,numEntries);
|
||||
if(pbstat_state == 3 && numEntries){//发送指令去获取时间
|
||||
//获取时间 当前只有苹果小米可用
|
||||
console_send_atcmd("AT+HFPTIME\r\n", strlen("AT+HFPTIME\r\n"));
|
||||
}else if(pbstat_state == 4){
|
||||
printf("bt Block sound .\r\n");
|
||||
//关闭音频
|
||||
console_send_atcmd("AT+A2DPMUTE=1\r\n", strlen("AT+A2DPMUTE=1\r\n"));
|
||||
}
|
||||
}else if(strlen(cAtCmd) > 7 && !memcmp(cAtCmd,"+PBDATA",7) && (pbstat_state==4) ){//电话号码 //为4时是在下载电话号码
|
||||
if(numEntries >= MAX_ENTRIES)
|
||||
return;
|
||||
// 解析字符串并提取姓名和电话号码
|
||||
uint8_t count = 0;
|
||||
char call_num[20];
|
||||
char call_name[50];
|
||||
memset(call_name, 0, sizeof(call_name));
|
||||
memset(call_num, 0, sizeof(call_num));
|
||||
uint16_t y = 0;
|
||||
for(uint16_t i =0;i<cATLen;i++){
|
||||
if(cAtCmd[i] == 0xFF){
|
||||
count++;
|
||||
y=0;
|
||||
continue;
|
||||
}
|
||||
// printf("%02X ",cAtCmd[i]);
|
||||
if(count == 1){
|
||||
call_name[y] = cAtCmd[i];
|
||||
}else if(count == 2){
|
||||
call_num[y] = cAtCmd[i];
|
||||
}
|
||||
y++;
|
||||
}
|
||||
|
||||
// printf("ID:%d,name:%s,call:%s.\r\n",numEntries,call_name,call_num);
|
||||
if(strlen(call_name) && strlen(call_num)){
|
||||
strcpy(phoneBook[numEntries].name, call_name);
|
||||
strcpy(phoneBook[numEntries].phone, call_num);
|
||||
numEntries++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
#ifndef BT_INTERACTION_PROTOCOL_H
|
||||
#define BT_INTERACTION_PROTOCOL_H
|
||||
|
||||
|
||||
|
||||
#endif
|
127
MXC_A27-PCB4.5-270T/app/moto/protocol/can_protocol.c
Normal file
127
MXC_A27-PCB4.5-270T/app/moto/protocol/can_protocol.c
Normal file
@ -0,0 +1,127 @@
|
||||
#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;
|
||||
uint8_t state_data = 0;
|
||||
double buf_value = 0;
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
|
||||
data = *(buf++) &0xFF;
|
||||
data = (*(buf++)&0xFF) | data<<8;
|
||||
|
||||
buf_value = data;
|
||||
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);
|
||||
state_data = *(buf++);
|
||||
Set_sys_can_state(state_data);
|
||||
|
||||
}
|
||||
|
||||
//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;
|
||||
Set_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;
|
||||
Set_can_abs_dtc(dtc);
|
||||
}
|
||||
|
||||
uint8_t dtc_flag = 0;
|
||||
void A59_dtc_event_handing(int *buf){
|
||||
uint32_t sum,sum1,sum2;
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
*(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
////低位再前
|
||||
//sum = sum1 | sum2<<8;
|
||||
//高位再前
|
||||
sum = sum1<<8 | sum2;
|
||||
// if (sum !=0)
|
||||
Set_sys_now_defect_code(sum);
|
||||
|
||||
dtc_flag = *(buf++)&0xFF;
|
||||
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
*(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
sum = sum1<<8 | sum2;
|
||||
// if (sum !=0)
|
||||
Set_sys_his_defect_code(sum);
|
||||
|
||||
}
|
||||
|
||||
//101
|
||||
void A59_speed_event_handing(int *buf){
|
||||
uint16_t eng_temp = 0;
|
||||
uint16_t data = 0;
|
||||
uint8_t state_data = 0;
|
||||
double buf_value = 0;
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
*(buf++);
|
||||
|
||||
data = *(buf++) &0xFF;
|
||||
data = (*(buf++)&0xFF) | data<<8;
|
||||
|
||||
buf_value = data;
|
||||
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);
|
||||
state_data = *(buf++);
|
||||
Set_sys_can_state(state_data);
|
||||
|
||||
}
|
6
MXC_A27-PCB4.5-270T/app/moto/protocol/can_protocol.h
Normal file
6
MXC_A27-PCB4.5-270T/app/moto/protocol/can_protocol.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef CAN_PROTOCOL_H
|
||||
#define CAN_PROTOCOL_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
#endif
|
2
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.c
Normal file
2
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include "awtk.h"
|
||||
#include "cat1_protocol.h"
|
6
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.h
Normal file
6
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef CAT1_PROTOCOL_H
|
||||
#define CAT1_PROTOCOL_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
#endif
|
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.obj
Normal file
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/cat1_protocol.obj
Normal file
Binary file not shown.
421
MXC_A27-PCB4.5-270T/app/moto/protocol/conversation_protocol.c
Normal file
421
MXC_A27-PCB4.5-270T/app/moto/protocol/conversation_protocol.c
Normal file
@ -0,0 +1,421 @@
|
||||
#include "awtk.h"
|
||||
#include "conversation_protocol.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 CALL_NUM_SIZE 20
|
||||
|
||||
extern uint8_t cmdstr[64];
|
||||
extern uint8_t cmdlen;
|
||||
// uint8_t cmdstr[64];
|
||||
// uint8_t cmdlen = 0;
|
||||
|
||||
uint8_t bt2_call_answer = 0;//接听标志
|
||||
uint8_t bt2_call_hangup = 0;//挂断标志
|
||||
uint8_t bt2_recall_answer = 0;//接听2标志
|
||||
uint8_t bt2_recall_hangup = 0;//挂断2标志
|
||||
uint8_t bt2_switch = 0;//发送蓝牙开关标志
|
||||
uint8_t bt2_switch_state = 0;//蓝牙状态标志
|
||||
uint8_t bt2_switch_time = 0;//开关蓝牙时间限制
|
||||
uint8_t call_time = 0;//命令延迟限制
|
||||
uint8_t complex_call = 0;//多重来电标志
|
||||
|
||||
|
||||
static uint8_t error_answer_state =0;//接电话失败,切换命令再次接听电话
|
||||
static uint8_t error_hang_up_state =0;//挂断电话失败,切换命令再次挂断电话标志
|
||||
|
||||
static uint8_t return_call_state = 0;//返回的call标志
|
||||
static uint8_t call_state_time = 0;
|
||||
static uint8_t test_call_state = 0;//暂停通话标志
|
||||
static uint8_t bt2_call_state = 0;//查询当前蓝牙状态信息
|
||||
|
||||
uint8_t bt2_state = 0;
|
||||
uint8_t bt2_state_now_flag = 0;
|
||||
|
||||
|
||||
void uart_test_tx_demo_thread(void *param)
|
||||
{
|
||||
UartPort_t *uap = param;
|
||||
uint8_t uarttx_CH[32] = "AT#CH\r\n";//接听 挂断
|
||||
uint8_t uarttx_CJ1[32] = "AT#CJ=01\r\n";//挂断
|
||||
uint8_t uarttx_CJ2[32] = "AT#CJ=02\r\n";//挂断1接听2
|
||||
uint8_t uarttx_CJ3[32] = "AT#CJ=03\r\n";//挂断2
|
||||
|
||||
uint8_t uarttx_CJ4[32] = "AT#CJ=04\r\n";//挂断2
|
||||
uint8_t uarttx_CJ5[32] = "AT#CJ=05\r\n";//挂断2
|
||||
|
||||
uint8_t uarttx_CO[32] = "AT#CO\r\n";//开蓝牙
|
||||
uint8_t uarttx_CP[32] = "AT#CP\r\n";//关蓝牙
|
||||
|
||||
uint8_t uarttx_CT[32] = "AT#CT\r\n";//查询当前状态
|
||||
|
||||
|
||||
for (;;) {
|
||||
if(bt2_switch_time){
|
||||
bt2_switch_time--;
|
||||
}
|
||||
if(call_time){
|
||||
call_time--;
|
||||
}
|
||||
|
||||
if(call_state_time){
|
||||
call_state_time--;
|
||||
}
|
||||
|
||||
if(test_call_state){//暂停通话改为正常通话
|
||||
test_call_state = 0;
|
||||
DEBUG_PRINT("tx >> ------------CJ4\r\n");
|
||||
iUartWrite(uap, uarttx_CJ4, strlen((char*)uarttx_CJ4), pdMS_TO_TICKS(100));
|
||||
}
|
||||
|
||||
if(bt2_call_state || bt2_state){
|
||||
DEBUG_PRINT("#####AT#CT \r\n");
|
||||
iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100));
|
||||
bt2_call_state = 0;
|
||||
bt2_state = 0;
|
||||
bt2_state_now_flag = 1;
|
||||
}
|
||||
|
||||
|
||||
if(Get_sys_call_key_state()==1 && !call_state_time){//接听电话1 //挂断电话1接听电话2
|
||||
|
||||
DEBUG_PRINT("tx >> AT#CT \r\n");
|
||||
iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100));
|
||||
call_state_time = 5;
|
||||
}else if(Get_sys_call_key_state()==2 && !call_state_time){//挂断电话 //挂断电话2
|
||||
DEBUG_PRINT("tx >> AT#CT \r\n");
|
||||
iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100));
|
||||
call_state_time = 5;
|
||||
}
|
||||
|
||||
switch(return_call_state){
|
||||
case 1://接听1
|
||||
DEBUG_PRINT(">>>>>> AT#CH \r\n");
|
||||
iUartWrite(uap, uarttx_CH, strlen((char*)uarttx_CH), pdMS_TO_TICKS(100));
|
||||
bt2_call_answer = 1;
|
||||
return_call_state = 0;
|
||||
break;
|
||||
case 2://挂1接2
|
||||
DEBUG_PRINT(">>>>>> AT#CJ2 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ2, strlen((char*)uarttx_CJ2), pdMS_TO_TICKS(100));
|
||||
bt2_recall_answer = 1;
|
||||
return_call_state = 0;
|
||||
break;
|
||||
case 3://挂1
|
||||
DEBUG_PRINT(">>>>>> AT#CJ1 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ1, strlen((char*)uarttx_CJ1), pdMS_TO_TICKS(100));
|
||||
bt2_call_hangup = 1;
|
||||
return_call_state = 0;
|
||||
break;
|
||||
case 4://拒接2
|
||||
DEBUG_PRINT(">>>>>> AT#CJ3 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ3, strlen((char*)uarttx_CJ3), pdMS_TO_TICKS(100));
|
||||
bt2_recall_hangup = 1;
|
||||
return_call_state = 0;
|
||||
break;
|
||||
default://常规
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(bt2_switch == 1 && bt2_switch_time == 0){//关蓝牙
|
||||
DEBUG_PRINT("\ntx >> AT#CP \r\n");
|
||||
iUartWrite(uap, uarttx_CP, strlen((char*)uarttx_CP), pdMS_TO_TICKS(100));
|
||||
|
||||
bt2_switch_time = 100;
|
||||
|
||||
}else if (bt2_switch == 2 && bt2_switch_time == 0){//开蓝牙
|
||||
DEBUG_PRINT("\ntx >> AT#CO \r\n");
|
||||
iUartWrite(uap, uarttx_CO, strlen((char*)uarttx_CO), pdMS_TO_TICKS(100));
|
||||
|
||||
bt2_switch_time = 100;
|
||||
|
||||
}
|
||||
|
||||
if(error_hang_up_state == 1){//挂2失败 尝试一次挂1
|
||||
DEBUG_PRINT("\nerror_hang_up_state == 1 tx >> AT#CJ=1 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ1, strlen((char*)uarttx_CJ1), pdMS_TO_TICKS(100));
|
||||
error_hang_up_state = 0;
|
||||
}else if(error_hang_up_state == 2){//挂1失败 尝试一次挂2
|
||||
DEBUG_PRINT("\nerror_hang_up_state == 2 tx >> AT#CJ=3 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ3, strlen((char*)uarttx_CJ3), pdMS_TO_TICKS(100));
|
||||
error_hang_up_state = 0;
|
||||
}
|
||||
|
||||
if(error_answer_state == 1){//接1失败 尝试挂2接1
|
||||
DEBUG_PRINT("\nerror_answer_state = 1 tx >> AT#CJ=2 \r\n");
|
||||
iUartWrite(uap, uarttx_CJ2, strlen((char*)uarttx_CJ2), pdMS_TO_TICKS(100));
|
||||
error_answer_state = 0;
|
||||
}else if(error_answer_state == 2){//挂2接1失败 尝试接1
|
||||
DEBUG_PRINT("\nerror_answer_state = 2 tx >> AT#CH \r\n");
|
||||
iUartWrite(uap, uarttx_CH, strlen((char*)uarttx_CH), pdMS_TO_TICKS(100));
|
||||
error_answer_state = 0;
|
||||
}
|
||||
|
||||
vTaskDelay(50);
|
||||
}
|
||||
}
|
||||
|
||||
void BT2_init_close(void){
|
||||
DEBUG_PRINT("BT2_init_close >>>>>>> bt2_switch_time = %d .\r\n",bt2_switch_time);
|
||||
if(bt2_switch_time)
|
||||
bt2_switch_time = 0;
|
||||
bt2_switch = 1;
|
||||
}
|
||||
|
||||
void BT2_init_open(void){
|
||||
DEBUG_PRINT("BT2_open >>>>>>> bt2_switch_time = %d .\r\n",bt2_switch_time);
|
||||
if(bt2_switch_time)
|
||||
bt2_switch_time = 0;
|
||||
bt2_switch = 2;
|
||||
}
|
||||
|
||||
void BT2_Switch(int type){
|
||||
if(bt2_switch_time == 0){
|
||||
switch(type){
|
||||
case 0://关闭蓝牙
|
||||
// if(gpio_get_value(47)){
|
||||
// gpio_direction_output(47, 0);
|
||||
// }
|
||||
bt2_switch = 1;
|
||||
break;
|
||||
case 1://开启蓝牙
|
||||
// if(gpio_get_value(47)){
|
||||
// gpio_direction_output(47, 0);
|
||||
// }
|
||||
bt2_switch = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
DEBUG_PRINT("BT2_Switch error ! bt2_switch_time =%d .\r\n",bt2_switch_time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 解析接收到的 AT 指令
|
||||
// void parseATCommand(uint8_t cmdstr[],uint8_t cmdlen) {
|
||||
void parseATCommand(void) {
|
||||
uint8_t str[64];
|
||||
static uint8_t flag = 0;
|
||||
uint8_t j=0;
|
||||
for(uint8_t i=0;i<cmdlen;i++)
|
||||
{
|
||||
if(cmdstr[i] == 0x00) continue;
|
||||
str[j] = cmdstr[i];
|
||||
j++;
|
||||
|
||||
if(cmdstr[i]=='\n'){
|
||||
if (strncmp(str, "+MC", 3) == 0) {//1路通话1路来电
|
||||
DEBUG_PRINT("+MC --\n");
|
||||
if(Get_sys_call_key_state()==1){//接听1
|
||||
Set_sys_call_key_state(0);
|
||||
DEBUG_PRINT("return_call_state = 1 --\n");
|
||||
return_call_state = 1;
|
||||
}else if(Get_sys_call_key_state()==2){//挂断1
|
||||
Set_sys_call_key_state(0);
|
||||
DEBUG_PRINT("return_call_state = 3 --\n");
|
||||
return_call_state = 3;
|
||||
}
|
||||
|
||||
} else if (strncmp(str, "+MI", 3) == 0) {//通话中
|
||||
// 处理 +AT 指令
|
||||
DEBUG_PRINT("+MI --\n");
|
||||
if(Get_sys_call_state() == 1){
|
||||
Set_sys_call_state(2);
|
||||
}else if(Get_sys_call_state() == 3){
|
||||
Set_sys_call_state(2);
|
||||
}
|
||||
|
||||
if(Get_sys_call_key_state()==1){//接听1
|
||||
return_call_state = 1;
|
||||
}else if(Get_sys_call_key_state()==2){//挂断1
|
||||
return_call_state = 3;
|
||||
}
|
||||
|
||||
} else if (strncmp(str, "+OK", 3) == 0) {//回复OK
|
||||
DEBUG_PRINT("+OK --\n");
|
||||
if(bt2_switch == 1){//关蓝牙
|
||||
bt2_switch = 0;
|
||||
Set_sys_bt_on_off(0);
|
||||
DEBUG_PRINT("close bt ok .\r\n");
|
||||
}else if(bt2_switch == 2){//开蓝牙
|
||||
bt2_switch = 0;
|
||||
Set_sys_bt_on_off(1);
|
||||
DEBUG_PRINT("open bt ok .\r\n");
|
||||
}else if(bt2_call_answer == 1){//接电话1
|
||||
bt2_call_answer = 0;
|
||||
Set_sys_call_key_state(0);
|
||||
DEBUG_PRINT("call answer ok .\r\n");
|
||||
Set_sys_call_state(2);//接听
|
||||
Set_sys_call_time(0);//时间归0
|
||||
call_time=20;
|
||||
}else if(bt2_call_hangup == 1){//挂电话1
|
||||
bt2_call_hangup = 0;
|
||||
Set_sys_call_key_state(0);
|
||||
DEBUG_PRINT("call hang up ok .\r\n");
|
||||
if(Get_sys_call_state()==4)
|
||||
Set_sys_call_state(2);//状态为2
|
||||
else if(Get_sys_call_state()==2)
|
||||
Set_sys_call_state(0);//状态为0
|
||||
call_time=20;
|
||||
|
||||
}else if(bt2_recall_answer == 1){//挂电话1接电话2
|
||||
bt2_recall_answer = 0;
|
||||
Set_sys_call_key_state(0);
|
||||
Set_sys_call_state(4);
|
||||
Set_sys_call_time(0);//时间归0
|
||||
call_time=20;
|
||||
}else if(bt2_recall_hangup == 1){//挂电话2
|
||||
bt2_recall_hangup = 0;
|
||||
Set_sys_call_key_state(0);
|
||||
Set_sys_call_state(2);
|
||||
call_time=20;
|
||||
}
|
||||
|
||||
} else if (strncmp(cmdstr, "+CP", 3) == 0) {//蓝牙进入配对模式
|
||||
DEBUG_PRINT("+CP --\n");
|
||||
Set_sys_bt_connect_state(0);
|
||||
Set_sys_call_state(0);//挂断蓝牙 call状态回归
|
||||
Set_sys_call_key_state(0);
|
||||
} else if (strncmp(cmdstr, "+CC", 3) == 0) {//蓝牙进入配对模式
|
||||
DEBUG_PRINT("+CC --\n");
|
||||
Set_sys_bt_connect_state(0);
|
||||
Set_sys_call_state(0);//挂断蓝牙 call状态回归
|
||||
Set_sys_call_key_state(0);
|
||||
} else if (strncmp(cmdstr, "+CI", 3) == 0) {//蓝牙进入配对模式
|
||||
DEBUG_PRINT("+CI --\n");
|
||||
Set_sys_bt_connect_state(0);
|
||||
Set_sys_call_state(0);//挂断蓝牙 call状态回归
|
||||
Set_sys_call_key_state(0);
|
||||
} else if (strncmp(str, "+M2I", 4) == 0) {//多路通话 即 有电话是保持状态
|
||||
DEBUG_PRINT("+M2I --\n");
|
||||
|
||||
if(Get_sys_call_key_state()==1){//切换通话线路
|
||||
Set_sys_call_key_state(0);
|
||||
test_call_state = 1;
|
||||
}else if(Get_sys_call_key_state()==2){//切换通话线路并挂断1 若两个通话同时存在则切换线路挂断通话 应该直接挂断通话
|
||||
Set_sys_call_key_state(0);
|
||||
if(Get_sys_call_state()==4){
|
||||
// DEBUG_PRINT("4---------------------------------close call");
|
||||
return_call_state = 3;
|
||||
}else{
|
||||
test_call_state = 1;
|
||||
vTaskDelay(1500);
|
||||
return_call_state = 3;
|
||||
}
|
||||
}else if(Get_sys_call_state()==3){
|
||||
Set_sys_call_state(4);
|
||||
}else
|
||||
Set_sys_call_state(2);
|
||||
|
||||
} else if (strncmp(str, "+M2C", 4) == 0) {//1路通话1路来电
|
||||
DEBUG_PRINT("+M2C --\n");
|
||||
|
||||
//按键
|
||||
if(Get_sys_call_key_state()==1){//挂1接2
|
||||
Set_sys_call_key_state(0);
|
||||
return_call_state = 2;
|
||||
}else if(Get_sys_call_key_state()==2){//拒2
|
||||
Set_sys_call_key_state(0);
|
||||
return_call_state = 4;
|
||||
}
|
||||
|
||||
} else if (strncmp(str, "+ERROR", 6) == 0) {//回复ERROR
|
||||
DEBUG_PRINT("+ERROR --\n");
|
||||
if(bt2_switch == 1){//关蓝牙失败
|
||||
bt2_switch = 0;
|
||||
DEBUG_PRINT("close bt error .\r\n");
|
||||
}else if(bt2_switch == 2){//开蓝牙失败
|
||||
bt2_switch = 0;
|
||||
DEBUG_PRINT("open bt error .\r\n");
|
||||
}else if(bt2_call_answer == 1){//接电话
|
||||
bt2_call_answer = 0;
|
||||
DEBUG_PRINT("call1 answer error .\r\n");
|
||||
Set_sys_call_key_state(0);
|
||||
error_answer_state = 1;
|
||||
}else if(bt2_call_hangup == 1){//挂电话
|
||||
bt2_call_hangup = 0;
|
||||
DEBUG_PRINT("call1 hang up error .\r\n");
|
||||
Set_sys_call_key_state(0);
|
||||
error_hang_up_state = 2;//挂1失败尝试一次挂2
|
||||
}else if(bt2_recall_answer == 1){//接电话
|
||||
bt2_recall_answer = 0;
|
||||
DEBUG_PRINT("call2 answer error .\r\n");
|
||||
Set_sys_call_key_state(0);
|
||||
error_answer_state = 2;
|
||||
}else if(bt2_recall_hangup == 1){//挂电话 回到状态2
|
||||
bt2_recall_hangup = 0;
|
||||
DEBUG_PRINT("call2 hang up error .\r\n");
|
||||
Set_sys_call_key_state(0);
|
||||
error_hang_up_state = 1;//挂2失败尝试挂1
|
||||
}
|
||||
} else if (strncmp(str, "+CALL_NUM:", 10) == 0) {//来电
|
||||
// DEBUG_PRINT("+CALL_NUM-------------------------------\n");
|
||||
//char str[20]={0};
|
||||
char call_num[CALL_NUM_SIZE];
|
||||
// 处理 +CALL_NUM 指令
|
||||
char *start = str + 10;
|
||||
char *end = strchr(start, '\r');
|
||||
if (end) {
|
||||
*end = '\0';
|
||||
strncpy(call_num, start, CALL_NUM_SIZE - 1);
|
||||
call_num[CALL_NUM_SIZE - 1] = '\0'; // 确保字符串以null结尾
|
||||
if(call_time == 0){
|
||||
// DEBUG_PRINT("call_state ========== %d .\r\n",Get_sys_call_state());
|
||||
Set_sys_call_number(call_num);
|
||||
Set_sys_call_renumber(call_num);
|
||||
if(Get_sys_call_state()==0){
|
||||
// DEBUG_PRINT("call num1-----------------\r\n");
|
||||
Set_sys_call_state(1);
|
||||
}else if(Get_sys_call_state()==2 || Get_sys_call_state()==4){
|
||||
if(flag==2){
|
||||
//电话2来电
|
||||
// DEBUG_PRINT("call num2-----------------\r\n");
|
||||
Set_sys_call_state(3);
|
||||
flag = 0;
|
||||
}
|
||||
flag++;
|
||||
}
|
||||
call_time=20;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strncmp(str, "+PHONE_NUM:", 11) == 0) {//当前通话号码
|
||||
DEBUG_PRINT("+PHONE_NUM --\n");
|
||||
char call_num[CALL_NUM_SIZE];
|
||||
// 处理 +PHONE_NUM 指令
|
||||
char *start = str + 11;
|
||||
char *end = strchr(start, '\r');
|
||||
if (end) {
|
||||
*end = '\0';
|
||||
strncpy(call_num, start, CALL_NUM_SIZE - 1);
|
||||
call_num[CALL_NUM_SIZE - 1] = '\0'; // 确保字符串以null结尾
|
||||
//DEBUG_PRINT("PHONE_NUM: %s\n", call_num);
|
||||
}
|
||||
Set_sys_call_state(2);
|
||||
memset(call_num, 0, sizeof(call_num));
|
||||
} else if (strncmp(str, "+MA", 3) == 0) {//当前通话号码
|
||||
DEBUG_PRINT("+MA --\n");
|
||||
Set_sys_call_state(0);
|
||||
Set_sys_bt_connect_state(1);
|
||||
} else{
|
||||
for(uint8_t t=0;t<j;t++){
|
||||
DEBUG_PRINT("%c",str[t]);
|
||||
}
|
||||
DEBUG_PRINT("############################\r\n");
|
||||
}
|
||||
j=0;
|
||||
bt2_state_now_flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
#ifndef CONVERSATION_PROTOCOL_H
|
||||
#define CONVERSATION_PROTOCOL_H
|
||||
|
||||
void uart_test_tx_demo_thread(void *param);
|
||||
void parseATCommand(void);
|
||||
#endif
|
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/conversation_protocol.obj
Normal file
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/conversation_protocol.obj
Normal file
Binary file not shown.
130
MXC_A27-PCB4.5-270T/app/moto/protocol/gear_protocol.c
Normal file
130
MXC_A27-PCB4.5-270T/app/moto/protocol/gear_protocol.c
Normal file
@ -0,0 +1,130 @@
|
||||
#include "awtk.h"
|
||||
#include "key_protocol.h"
|
||||
#include "gpio_protocol.h"
|
||||
#include "board.h"
|
||||
#include "chip.h"
|
||||
#include "data_port.h"
|
||||
#include "gear_protocol.h"
|
||||
|
||||
// 定义定时器句柄
|
||||
TimerHandle_t xTimer;
|
||||
uint8_t GPIO_value_high[7];
|
||||
|
||||
#define IO_KEEP 4
|
||||
void grade_key(void){
|
||||
uint8_t Gear_value = 7;
|
||||
//数据顺序 N 1 2 3 4 5 6 ABS TCS FAN ENG YG R L RMT
|
||||
//挡位高电平触发, 灯光、ABS、TCS、FAN ENG 低电平触发
|
||||
if(gpio_get_value(GPIO_GRADE_N))
|
||||
{
|
||||
GPIO_value_high[GPIO_N]++;
|
||||
if(GPIO_value_high[GPIO_N] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 0;
|
||||
printf("N\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_N] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D1))
|
||||
{
|
||||
GPIO_value_high[GPIO_D1]++;
|
||||
if(GPIO_value_high[GPIO_D1] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 1;
|
||||
printf("D1\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D1] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D2))
|
||||
{
|
||||
GPIO_value_high[GPIO_D2]++;
|
||||
if(GPIO_value_high[GPIO_D2] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 2;
|
||||
printf("D2\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D2] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D3))
|
||||
{
|
||||
GPIO_value_high[GPIO_D3]++;
|
||||
if(GPIO_value_high[GPIO_D3] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 3;
|
||||
printf("D3\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D3] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D4))
|
||||
{
|
||||
GPIO_value_high[GPIO_D4]++;
|
||||
if(GPIO_value_high[GPIO_D4] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 4;
|
||||
printf("D4\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D4] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D5))
|
||||
{
|
||||
GPIO_value_high[GPIO_D5]++;
|
||||
if(GPIO_value_high[GPIO_D5] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 5;
|
||||
printf("D5\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D5] = 0;
|
||||
|
||||
if(gpio_get_value(GPIO_GRADE_D6))
|
||||
{
|
||||
GPIO_value_high[GPIO_D6]++;
|
||||
if(GPIO_value_high[GPIO_D6] == IO_KEEP)
|
||||
{
|
||||
Gear_value = 6;
|
||||
printf("D6\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
GPIO_value_high[GPIO_D6] = 0;
|
||||
|
||||
Set_sys_grade(Gear_value);
|
||||
}
|
||||
|
||||
// 定时器回调函数
|
||||
void vTimerCallback(TimerHandle_t xTimer) {
|
||||
// 定时器到期时执行的代码
|
||||
//按键检测
|
||||
check_key();
|
||||
//档位检测
|
||||
grade_key();
|
||||
}
|
||||
|
||||
void Moto_gpio_timer(void) {
|
||||
|
||||
// 创建定时器
|
||||
xTimer = xTimerCreate("MyTimer", // 定时器名称
|
||||
pdMS_TO_TICKS(20), // 定时器周期(1000毫秒)
|
||||
pdTRUE, // 自动重载定时器
|
||||
(void *)0, // 定时器 ID
|
||||
vTimerCallback); // 回调函数
|
||||
|
||||
// 启动定时器
|
||||
if (xTimerStart(xTimer, 0) != pdPASS) {
|
||||
// 启动定时器失败的处理
|
||||
printf("xTimer error!!!!!!!!!!!!!!!!!.\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
28
MXC_A27-PCB4.5-270T/app/moto/protocol/gear_protocol.h
Normal file
28
MXC_A27-PCB4.5-270T/app/moto/protocol/gear_protocol.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef GEAR_PROTOCOL_H
|
||||
#define GEAR_PROTOCOL_H
|
||||
|
||||
enum
|
||||
{
|
||||
GPIO_N,
|
||||
GPIO_D1,
|
||||
GPIO_D2,
|
||||
GPIO_D3,
|
||||
GPIO_D4,
|
||||
GPIO_D5,
|
||||
GPIO_D6,
|
||||
};
|
||||
|
||||
#define GPIO_GRADE_N 8
|
||||
#define GPIO_GRADE_D1 9
|
||||
#define GPIO_GRADE_D2 10
|
||||
#define GPIO_GRADE_D3 11
|
||||
#define GPIO_GRADE_D4 12
|
||||
#define GPIO_GRADE_D5 13
|
||||
#define GPIO_GRADE_D6 14
|
||||
|
||||
|
||||
void grade_key(void);
|
||||
void vTimerCallback(TimerHandle_t xTimer);
|
||||
void Moto_gpio_timer(void);
|
||||
|
||||
#endif
|
247
MXC_A27-PCB4.5-270T/app/moto/protocol/gpio_protocol.c
Normal file
247
MXC_A27-PCB4.5-270T/app/moto/protocol/gpio_protocol.c
Normal file
@ -0,0 +1,247 @@
|
||||
#include "awtk.h"
|
||||
#include "gpio_protocol.h"
|
||||
#include "board.h"
|
||||
#include "chip.h"
|
||||
|
||||
|
||||
void right_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_R_LED, TRUE);
|
||||
}
|
||||
|
||||
void right_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_R_LED, FALSE);
|
||||
}
|
||||
|
||||
void left_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_L_LED, TRUE);
|
||||
}
|
||||
|
||||
void left_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_L_LED, FALSE);
|
||||
}
|
||||
|
||||
void yg_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_YG_LED, TRUE);
|
||||
}
|
||||
|
||||
void yg_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_YG_LED, FALSE);
|
||||
}
|
||||
|
||||
void abs_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_ABS, TRUE);
|
||||
}
|
||||
|
||||
void abs_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_ABS, FALSE);
|
||||
}
|
||||
|
||||
void oil_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_OIL, TRUE);
|
||||
}
|
||||
|
||||
void oil_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_OIL, FALSE);
|
||||
}
|
||||
|
||||
void n_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_N_LED, TRUE);
|
||||
}
|
||||
|
||||
void n_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_N_LED, FALSE);
|
||||
}
|
||||
|
||||
void eng_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_ENG_LED, TRUE);
|
||||
}
|
||||
|
||||
void eng_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_ENG_LED, FALSE);
|
||||
}
|
||||
|
||||
void vbat_led_on(void){
|
||||
gpio_direction_output(GPIO_LIGHT_VBAT_LED, TRUE);
|
||||
}
|
||||
|
||||
void vbat_led_off(void){
|
||||
gpio_direction_output(GPIO_LIGHT_VBAT_LED, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void right_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:right_led_off();break;
|
||||
case 1:right_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void left_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:left_led_off();break;
|
||||
case 1:left_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void yg_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:yg_led_off();break;
|
||||
case 1:
|
||||
yg_led_on();
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void abs_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:abs_led_off();break;
|
||||
case 1:abs_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void oil_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:oil_led_off();break;
|
||||
case 1:oil_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void n_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:n_led_off();break;
|
||||
case 1:n_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void vbat_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:vbat_led_off();break;
|
||||
case 1:vbat_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void eng_led_switch(uint8_t type){
|
||||
switch(type){
|
||||
case 0:eng_led_off();break;
|
||||
case 1:eng_led_on();break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void light_gpio_init(void){
|
||||
//灯光使能
|
||||
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);
|
||||
//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);
|
||||
#if DEVICE_MXC_A58
|
||||
//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();//按键 //左右灯光
|
||||
|
||||
}
|
||||
|
||||
void light_off(void){
|
||||
//R_LED
|
||||
gpio_direction_output(GPIO_LIGHT_R_LED, FALSE);
|
||||
//YG_LED
|
||||
gpio_direction_output(GPIO_LIGHT_YG_LED, 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);
|
||||
#if DEVICE_MXC_A58
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t gpio_state = 0;
|
||||
extern uint8_t complex_call;
|
||||
extern void Set_sys_call_state(uint8_t value);
|
||||
extern void Set_sys_call_key_state(uint8_t value);
|
||||
extern void Set_sys_call_number(char *value);
|
||||
extern void Set_sys_call_renumber(char *value);
|
||||
|
||||
static void gpio_bt2_handler(void *param)
|
||||
{
|
||||
|
||||
if(gpio_get_value(BT2_CALL_INT)){
|
||||
gpio_state = 0;
|
||||
printf("gpio 47 >1 cat1\n");
|
||||
//if(Get_sys_call_state() == 2)
|
||||
Set_sys_call_state(0);
|
||||
complex_call = 0;
|
||||
Set_sys_call_key_state(0);
|
||||
Set_sys_call_number(0);
|
||||
Set_sys_call_renumber(0);
|
||||
|
||||
// gpio_direction_output(BT2_CALL_UART_SW, 0);//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ӧ<><D3A6>Ϊ1 <20><><EFBFBD><EFBFBD>cat1
|
||||
}else{
|
||||
printf("gpio 47 >0 bt2\n");
|
||||
// gpio_direction_output(BT2_CALL_UART_SW, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void BT2_reset(void)
|
||||
{
|
||||
gpio_direction_input(BT2_CALL_INT);
|
||||
gpio_direction_output(BT2_CALL_UART_SW, 0);
|
||||
gpio_irq_request(BT2_CALL_INT,GPIOIRQ_TYPE_EDGE_BOTH, gpio_bt2_handler, NULL);
|
||||
}
|
||||
|
||||
void BT2_state_error_reset(void){
|
||||
gpio_direction_output(BT2_CALL_RET, 1);
|
||||
mdelay(100);
|
||||
gpio_direction_output(BT2_CALL_RET, 0);
|
||||
}
|
||||
|
||||
void cat1_enable(void){
|
||||
printf("cat1 close .\r\n");
|
||||
// printf("cat1 open .\r\n");
|
||||
// gpio_direction_output(CAT_PWTKEY_GPIO, 1);
|
||||
}
|
||||
|
||||
void CAT1_reset(void)
|
||||
{
|
||||
// gpio_direction_output(CAT1_UART_SW_GPIO, 1);
|
||||
gpio_direction_output(CAT1_RESET_GPIO, 0);
|
||||
|
||||
gpio_direction_output(CAT_PWTKEY_GPIO, 0);
|
||||
// gpio_direction_output(CAT1_UART_SW_GPIO, 0);
|
||||
}
|
84
MXC_A27-PCB4.5-270T/app/moto/protocol/gpio_protocol.h
Normal file
84
MXC_A27-PCB4.5-270T/app/moto/protocol/gpio_protocol.h
Normal file
@ -0,0 +1,84 @@
|
||||
#ifndef GPIO_PROTOCOL_H
|
||||
#define GPIO_PROTOCOL_H
|
||||
|
||||
|
||||
#include "awtk.h"
|
||||
#include "gpio_protocol.h"
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
//硬件控制
|
||||
#define DEVICE_MXC_A58 0
|
||||
#define DEVICE_MXC_A59 0
|
||||
#define DEVICE_MXC_A27 1
|
||||
|
||||
#define GPIO_LIGHT_R_LED_FLAG 11
|
||||
#define GPIO_LIGHT_L_LED_FLAG 10
|
||||
#if !DEVICE_MXC_A27
|
||||
#define GPIO_LIGHT_MODE 9
|
||||
#define GPIO_LIGHT_SET 8
|
||||
#else
|
||||
#define GPIO_LIGHT_MODE 51
|
||||
#define GPIO_LIGHT_SET 15
|
||||
#endif
|
||||
|
||||
#define GPIO_LIGHT_R_LED 56
|
||||
#define GPIO_LIGHT_L_LED 5
|
||||
#define GPIO_LIGHT_YG_LED 53
|
||||
#define GPIO_LIGHT_ABS 55
|
||||
#define GPIO_LIGHT_OIL 54
|
||||
#define GPIO_LIGHT_N_LED 4
|
||||
#define GPIO_LIGHT_ENG_LED 15
|
||||
#define GPIO_LIGHT_VBAT_LED 61
|
||||
|
||||
|
||||
|
||||
|
||||
#define CAT1_RESET_GPIO 100
|
||||
#define CAT_PWTKEY_GPIO 101
|
||||
|
||||
#define BT2_CALL_UART_SW 47
|
||||
#define BT2_CALL_INT 7//48
|
||||
#define BT2_CALL_RET 5
|
||||
|
||||
void light_gpio_init(void);
|
||||
void right_led_on(void);
|
||||
void right_led_off(void);
|
||||
void left_led_on(void);
|
||||
void left_led_off(void);
|
||||
void yg_led_on(void);
|
||||
void yg_led_off(void);
|
||||
void abs_led_on(void);
|
||||
void abs_led_off(void);
|
||||
void oil_led_on(void);
|
||||
void oil_led_off(void);
|
||||
void n_led_on(void);
|
||||
void n_led_off(void);
|
||||
void eng_led_on(void);
|
||||
void eng_led_off(void);
|
||||
void vbat_led_on(void);
|
||||
void vbat_led_off(void);
|
||||
void light_off(void);
|
||||
|
||||
static void gpio_right_handler(void);
|
||||
static void gpio_left_handler(void);
|
||||
static void gpio_mode_handler(void);
|
||||
static void gpio_set_handler(void);
|
||||
static void gpio_handler(void *param);
|
||||
|
||||
void right_led_switch(uint8_t type);
|
||||
void left_led_switch(uint8_t type);
|
||||
void yg_led_switch(uint8_t type);
|
||||
void abs_led_switch(uint8_t type);
|
||||
void oil_led_switch(uint8_t type);
|
||||
void n_led_switch(uint8_t type);
|
||||
void vbat_led_switch(uint8_t type);
|
||||
void eng_led_switch(uint8_t type);
|
||||
|
||||
static void gpio_bt2_handler(void *param);
|
||||
void BT2_reset(void);
|
||||
void BT2_state_error_reset(void);
|
||||
void cat1_enable(void);
|
||||
void CAT1_reset(void);
|
||||
|
||||
#endif
|
179
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.c
Normal file
179
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.c
Normal file
@ -0,0 +1,179 @@
|
||||
#include "awtk.h"
|
||||
#include "key_protocol.h"
|
||||
#include "gpio_protocol.h"
|
||||
#include "board.h"
|
||||
#include "chip.h"
|
||||
#include "data_port.h"
|
||||
|
||||
KEY_DAT gs_keyDat[KEY_NUMBERS]={0};
|
||||
|
||||
bool key_readKeyPin(uint8_t keyx)
|
||||
{
|
||||
bool 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)
|
||||
{
|
||||
uint8_t i;
|
||||
bool status;
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
{
|
||||
status=key_readKeyPin(i);
|
||||
if(status==0) gs_keyDat[i].flag_Pressed=KEY_ON;
|
||||
else gs_keyDat[i].flag_Pressed=KEY_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
extern uint8_t map_flag;
|
||||
static int step_about = 0;
|
||||
static int step = 0;
|
||||
|
||||
void check_key(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
key_Scan();
|
||||
for(i=0;i<KEY_NUMBERS;i++)
|
||||
{
|
||||
if(gs_keyDat[i].flag_Pressed==KEY_ON)
|
||||
{
|
||||
if(gs_keyDat[0].keyCnt>KEY_LLONGPRESS_COUNTER && gs_keyDat[1].keyCnt>KEY_LLONGPRESS_COUNTER)
|
||||
{
|
||||
gs_keyDat[0].flag_Reset=1;
|
||||
gs_keyDat[1].flag_Reset=1;
|
||||
gs_keyDat[0].keyCnt=0;
|
||||
gs_keyDat[1].keyCnt=0;
|
||||
// printf("two long key ---------------------\r\n");
|
||||
Key_Distinction(KEY_SHORT_ON,LV_KEY_OTHER1);
|
||||
}
|
||||
else if(gs_keyDat[i].keyCnt==KEY_LONGPRESS_COUNTER)
|
||||
{
|
||||
if(gs_keyDat[i].flag_Reset==0)
|
||||
{
|
||||
if(i==0 && gs_keyDat[1].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
gs_keyDat[i].flag_Reset=1;
|
||||
gs_keyDat[i].keyCnt=0;
|
||||
// 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("LV_KEY_SELECT key long key\r\n");
|
||||
Key_Distinction(KEY_LONG_ON,LV_KEY_SELECT);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(gs_keyDat[i].flag_Reset==0) gs_keyDat[i].keyCnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(gs_keyDat[i].keyCnt>=KEY_PRESS_HOLD && gs_keyDat[i].keyCnt<KEY_LONGPRESS_COUNTER)
|
||||
{
|
||||
if(i==0 && gs_keyDat[1].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
// 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("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;
|
||||
gs_keyDat[i].flag_Reset=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void gpio_right_handler(void)
|
||||
{
|
||||
uint8_t cph_cnt = 0;
|
||||
for(uint8_t i=0;i<IODELAY;i++)//防抖动
|
||||
{
|
||||
if(gpio_get_value(GPIO_LIGHT_R_LED_FLAG))
|
||||
cph_cnt++;
|
||||
}
|
||||
if(cph_cnt > (IODELAY-4)){
|
||||
right_led_on();
|
||||
}else{
|
||||
right_led_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void gpio_left_handler(void)
|
||||
{
|
||||
uint8_t cph_cnt = 0;
|
||||
for(uint8_t i=0;i<IODELAY;i++)//防抖动
|
||||
{
|
||||
if(gpio_get_value(GPIO_LIGHT_L_LED_FLAG))
|
||||
cph_cnt++;
|
||||
}
|
||||
if(cph_cnt > (IODELAY-4)){
|
||||
// if(gpio_get_value(GPIO_LIGHT_L_LED_FLAG)){
|
||||
left_led_on();
|
||||
}else{
|
||||
left_led_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void gpio_handler(void *param)
|
||||
{
|
||||
|
||||
for (;;) {
|
||||
// printf("gpio 10> %d gpio 11> %d.\r\n",gpio_get_value(8),gpio_get_value(9));
|
||||
if(Get_sys_power_on_self_test() == 100){
|
||||
gpio_right_handler();
|
||||
gpio_left_handler();
|
||||
check_key();//按键检测
|
||||
}
|
||||
vTaskDelay(20);
|
||||
}
|
||||
}
|
||||
|
||||
int gpio_timer(void){
|
||||
// printf("gpio_timer .\r\n");
|
||||
if (xTaskCreate(gpio_handler, "gpio_handler", configMINIMAL_STACK_SIZE, NULL,
|
||||
configMAX_PRIORITIES - 5, NULL) != pdPASS) {
|
||||
printf("create uart rx demo task fail.\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
35
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.h
Normal file
35
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef KEY_PROTOCOL_H
|
||||
#define KEY_PROTOCOL_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t keyCnt;
|
||||
uint8_t flag_Pressed;
|
||||
uint8_t flag_Reset;
|
||||
}KEY_DAT;
|
||||
#define KEY_NUMBERS 2
|
||||
|
||||
#define KEY_OFF 0
|
||||
#define KEY_ON 1
|
||||
|
||||
#define KEY_SHORT_ON 1 //短按
|
||||
#define KEY_LONG_ON 2 //长按
|
||||
#define KEY_PRESS_HOLD 1 //按键识别次数
|
||||
|
||||
#define KEY_LONGPRESS_COUNTER 100 //每次timer时间*次数=长按键识别时间 150*20ms=3000ms
|
||||
#define KEY_LLONGPRESS_COUNTER 500
|
||||
|
||||
#define IODELAY 10
|
||||
// #define IODELAY 8
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
LV_KEY_OPTION = 113, // 0x11
|
||||
LV_KEY_SELECT = 119, // 0x12
|
||||
LV_KEY_OTHER1 = 122, // 0x12
|
||||
};
|
||||
|
||||
#endif
|
12
MXC_A27-PCB4.5-270T/app/moto/protocol/moto_adc.c
Normal file
12
MXC_A27-PCB4.5-270T/app/moto/protocol/moto_adc.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include "keypad.h"
|
||||
|
||||
#include "moto_adc.h"
|
||||
|
||||
void moto_adc_Init(void)
|
||||
{
|
||||
adc_channel_enable(ADC_CH_AUX2);
|
||||
adc_channel_enable(ADC_CH_AUX3);
|
||||
}
|
7
MXC_A27-PCB4.5-270T/app/moto/protocol/moto_adc.h
Normal file
7
MXC_A27-PCB4.5-270T/app/moto/protocol/moto_adc.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef MOTO_ADC_H
|
||||
#define MOTO_ADC_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
void moto_adc_Init(void);
|
||||
#endif
|
545
MXC_A27-PCB4.5-270T/app/moto/protocol/ota_protocol.c
Normal file
545
MXC_A27-PCB4.5-270T/app/moto/protocol/ota_protocol.c
Normal file
@ -0,0 +1,545 @@
|
||||
|
||||
#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);
|
||||
extern uint8_t bt_upgrade_flag;
|
||||
|
||||
#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);
|
||||
bt_upgrade_flag = 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);
|
||||
printf("uup_packet_num = %d .\r\n",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-1))) { //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-1));
|
||||
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();
|
||||
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);
|
||||
printf("crc32 ERROR\r\n");
|
||||
bt_upgrade_flag = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
6
MXC_A27-PCB4.5-270T/app/moto/protocol/ota_protocol.h
Normal file
6
MXC_A27-PCB4.5-270T/app/moto/protocol/ota_protocol.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef OTA_PROTOCOL_H
|
||||
#define OTA_PROTOCOL_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
#endif
|
548
MXC_A27-PCB4.5-270T/app/moto/protocol/tire_pressure_protocol.c
Normal file
548
MXC_A27-PCB4.5-270T/app/moto/protocol/tire_pressure_protocol.c
Normal file
@ -0,0 +1,548 @@
|
||||
#include "awtk.h"
|
||||
#include "chip.h"//bool声明
|
||||
#include "tire_pressure_protocol.h"
|
||||
#include "user_data.h"
|
||||
#include "data_port.h"
|
||||
#include "universal.h"
|
||||
|
||||
|
||||
extern void SaveDataToFlash(SfudData_t user_data);
|
||||
|
||||
uint8_t power_on_flag = 0;
|
||||
uint32_t tire_pressure_flag = 0;
|
||||
uint32_t tire_front_time = 0;
|
||||
uint32_t tire_rear_time = 0;
|
||||
|
||||
//保存里程信息
|
||||
static void Save_tire_data(void){
|
||||
Pressure_t ago_pressure = Get_sys_front_pressure();
|
||||
Pressure_t after_pressure = Get_sys_rear_pressure();
|
||||
DEBUG_PRINT("****************\r\n");
|
||||
DEBUG_PRINT("mac: %02X%02X%02X%02X%02X%02X , %02X%02X%02X%02X%02X%02X \r\n",
|
||||
ago_pressure.mac_address[0],ago_pressure.mac_address[1],ago_pressure.mac_address[2],
|
||||
ago_pressure.mac_address[3],ago_pressure.mac_address[4],ago_pressure.mac_address[5],
|
||||
after_pressure.mac_address[0],after_pressure.mac_address[1],after_pressure.mac_address[2],
|
||||
after_pressure.mac_address[3],after_pressure.mac_address[4],after_pressure.mac_address[5]);
|
||||
DEBUG_PRINT("****************\r\n");
|
||||
DEBUG_PRINT("mac: %02X%02X%02X%02X%02X%02X , %02X%02X%02X%02X%02X%02X \r\n",
|
||||
custom_data.user_data.f_mac_address[0],custom_data.user_data.f_mac_address[1],custom_data.user_data.f_mac_address[2],
|
||||
custom_data.user_data.f_mac_address[3],custom_data.user_data.f_mac_address[4],custom_data.user_data.f_mac_address[5],
|
||||
custom_data.user_data.r_mac_address[0],custom_data.user_data.r_mac_address[1],custom_data.user_data.r_mac_address[2],
|
||||
custom_data.user_data.r_mac_address[3],custom_data.user_data.r_mac_address[4],custom_data.user_data.r_mac_address[5]);
|
||||
DEBUG_PRINT("****************\r\n");
|
||||
strcpy(custom_data.user_data.f_mac_address,ago_pressure.mac_address);
|
||||
custom_data.user_data.f_mac_address[6]=ago_pressure.temp&0xFF;
|
||||
custom_data.user_data.f_mac_address[7]=ago_pressure.psi>>8&0xFF;
|
||||
custom_data.user_data.f_mac_address[8]=ago_pressure.psi&0xFF;
|
||||
strcpy(custom_data.user_data.r_mac_address,after_pressure.mac_address);
|
||||
custom_data.user_data.r_mac_address[6]=after_pressure.temp&0xFF;
|
||||
custom_data.user_data.r_mac_address[7]=after_pressure.psi>>8&0xFF;
|
||||
custom_data.user_data.r_mac_address[8]=after_pressure.psi&0xFF;
|
||||
Set_sys_pressure_signal(0);
|
||||
//保存flash
|
||||
SaveDataToFlash(custom_data.user_data);//保存数据
|
||||
}
|
||||
|
||||
//数据刷新函数
|
||||
void pressure_buffer_event_handing(Pressure_t pressure,char buffer[],uint8_t type,uint8_t pairing_status){
|
||||
uint8_t len = strlen(buffer);
|
||||
// uint8_t buffer_state=0;
|
||||
// uint8_t buffer_check=0;
|
||||
uint8_t data = 0;
|
||||
//double value = 0;
|
||||
//double auxiliary_value=0;
|
||||
|
||||
uint32_t auxiliary_data;
|
||||
uint32_t sum;
|
||||
char *sign;
|
||||
//S
|
||||
sign=&buffer[6];
|
||||
data = *(sign++);
|
||||
// //若配对模式 检测配对标识是否为1 是则继续 反之则退出
|
||||
// if(pairing_status){//若配对模式
|
||||
// if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
// DEBUG_PRINT("pairing_status = 1 && JUDGE_BIN_0(data) =0.\r\n");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//DEBUG_PRINT("%x, ",data);
|
||||
pressure.blow_by_state = JUDGE_BIN_1(data);
|
||||
pressure.voltage_state = JUDGE_BIN_2(data);
|
||||
//pressure.temp_state = JUDGE_BIN_3(data);
|
||||
|
||||
//V
|
||||
data = *(sign++);//电压 0x1e=>30=>3.0V
|
||||
pressure.voltage = data;
|
||||
//DEBUG_PRINT("%x, ",data);
|
||||
//T
|
||||
data = *(sign++);//温度 0x14=>20=>20°C
|
||||
pressure.temp = data;
|
||||
if(data>=70 && data<128){
|
||||
pressure.temp_state = 1;
|
||||
}else
|
||||
pressure.temp_state = 0;
|
||||
//DEBUG_PRINT("%x, ",data);
|
||||
//P
|
||||
sum = 0;
|
||||
data = *(sign++);//压强 0x00AF=>175=>17.5 17.5-14.6=2.9
|
||||
//DEBUG_PRINT("%x, ",data);
|
||||
auxiliary_data = data<<8;
|
||||
sum += auxiliary_data;
|
||||
data = *(sign++);
|
||||
//DEBUG_PRINT("%x, ",data);
|
||||
auxiliary_data = data;
|
||||
sum += auxiliary_data;
|
||||
//DEBUG_PRINT(" == %d ",sum);
|
||||
//data = *(sign++);//压强 0x00AF=>175=>17.5 17.5-14.6=2.9
|
||||
//data = *(sign++);//压强 0x00AF=>175=>17.5 17.5-14.6=2.9
|
||||
pressure.psi = sum;
|
||||
|
||||
date_time_t dt;
|
||||
date_time_init(&dt);
|
||||
uint16_t check_buffer[6];
|
||||
check_buffer[0] = dt.year;
|
||||
check_buffer[1] = dt.month;
|
||||
check_buffer[2] = dt.day;
|
||||
check_buffer[3] = dt.hour;
|
||||
check_buffer[4] = dt.minute;
|
||||
check_buffer[5] = dt.second;
|
||||
sum = fml_time_to_stamp(check_buffer);
|
||||
pressure.lose_flag = 0;
|
||||
//pressure.state = 1;
|
||||
|
||||
DEBUG_PRINT("type =%d pressure >>>>>>> mac = %02X%02X%02X%02X%02X%02X, %d-%d-%d, temp=%d, psi=%d \n",type,pressure.mac_address[0],pressure.mac_address[1],pressure.mac_address[2],
|
||||
pressure.mac_address[3],pressure.mac_address[4],pressure.mac_address[5],
|
||||
pressure.blow_by_state,pressure.voltage_state,pressure.temp_state,pressure.temp,pressure.psi);
|
||||
switch(type){
|
||||
case 1:
|
||||
if((sum - tire_front_time)>3600){
|
||||
pressure.lose_flag = 1;
|
||||
}
|
||||
Set_sys_front_pressure(pressure);
|
||||
break;
|
||||
case 2:
|
||||
if((sum - tire_rear_time)>3600){
|
||||
pressure.lose_flag = 1;
|
||||
}
|
||||
Set_sys_rear_pressure(pressure);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
if(pairing_status){//若配对模式
|
||||
Send_tire_pressure_information();
|
||||
Set_sys_tire_pressure_mesg(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool compare_arrays(char arr1[], char arr2[], uint8_t size) {
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
if (arr1[i] != arr2[i]) {
|
||||
return false; // 只要有一个元素不相同,即返回 false
|
||||
}
|
||||
}
|
||||
return true; // 所有元素都相同,返回 true
|
||||
}
|
||||
|
||||
//协议解析
|
||||
void tire_pressure_data_analysis(uint8_t *buf){
|
||||
|
||||
uint8_t data;
|
||||
char trip_buffer1[11] = {0};
|
||||
char trip_buffer2[11] = {0};
|
||||
char mac1[6] = {0};
|
||||
char mac2[6] = {0};
|
||||
uint8_t data_flag = 0;
|
||||
|
||||
Pressure_t ago_pressure = Get_sys_front_pressure();
|
||||
Pressure_t after_pressure = Get_sys_rear_pressure();
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0xAA)
|
||||
return;
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0x1b)
|
||||
return;
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0x03)
|
||||
return;
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0x51)
|
||||
return;
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0x17)
|
||||
return;
|
||||
|
||||
data_flag = *(buf++);
|
||||
if(!data_flag && !power_on_flag){
|
||||
return;
|
||||
}else{
|
||||
date_time_t dt;
|
||||
date_time_init(&dt);
|
||||
uint16_t check_buffer[6];
|
||||
check_buffer[0] = dt.year;
|
||||
check_buffer[1] = dt.month;
|
||||
check_buffer[2] = dt.day;
|
||||
check_buffer[3] = dt.hour;
|
||||
check_buffer[4] = dt.minute;
|
||||
check_buffer[5] = dt.second;
|
||||
uint32_t sum = fml_time_to_stamp(check_buffer);
|
||||
switch(data_flag){
|
||||
case 1:tire_front_time =sum;break;
|
||||
case 2:tire_rear_time =sum;break;
|
||||
case 3:tire_front_time =sum;tire_rear_time =sum;break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i=0;i<11;i++){
|
||||
trip_buffer1[i] = *(buf++);
|
||||
if(i<6)
|
||||
mac1[i]=trip_buffer1[i];
|
||||
}
|
||||
|
||||
for(uint8_t i=0;i<11;i++){
|
||||
trip_buffer2[i] = *(buf++);
|
||||
if(i<6)
|
||||
mac2[i]=trip_buffer2[i];
|
||||
}
|
||||
|
||||
//tk_snDEBUG_PRINT(mac1, sizeof(mac1), "%02X%02X%02X%02X%02X%02X",trip_buffer1[0],trip_buffer1[1],trip_buffer1[2],trip_buffer1[3],trip_buffer1[4],trip_buffer1[5]);
|
||||
//tk_snDEBUG_PRINT(mac2, sizeof(mac2), "%02X%02X%02X%02X%02X%02X",trip_buffer2[0],trip_buffer2[1],trip_buffer2[2],trip_buffer2[3],trip_buffer2[4],trip_buffer2[5]);
|
||||
DEBUG_PRINT("***************************\r\n");
|
||||
for(uint8_t i=0;i<11;i++){
|
||||
DEBUG_PRINT("%02x ",trip_buffer1[i]);
|
||||
}
|
||||
for(uint8_t i=0;i<11;i++){
|
||||
DEBUG_PRINT("%02x ",trip_buffer2[i]);
|
||||
}
|
||||
DEBUG_PRINT("\r\n");
|
||||
DEBUG_PRINT("***************************\r\n");
|
||||
|
||||
switch(Get_sys_pressure_signal()){
|
||||
case 0://正常情况下需要刷新数据
|
||||
DEBUG_PRINT("0>>>> data_flag = %d \n",data_flag);
|
||||
//if(strcmp(ago_pressure.mac_address,mac1)==0){//若和前胎压地址相同,则将数据丢给前胎压
|
||||
if(compare_arrays(ago_pressure.mac_address,mac1,6)==1 && (data_flag == 1 || data_flag == 3) || power_on_flag){//若和前胎压地址相同,则将数据丢给前胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer1,1,0);
|
||||
strcpy(custom_data.user_data.f_mac_address,ago_pressure.mac_address);
|
||||
custom_data.user_data.f_mac_address[6]=ago_pressure.temp&0xFF;
|
||||
custom_data.user_data.f_mac_address[7]=ago_pressure.psi>>8&0xFF;
|
||||
custom_data.user_data.f_mac_address[8]=ago_pressure.psi&0xFF;
|
||||
}
|
||||
//if(strcmp(after_pressure.mac_address,mac2)==0){//若和后胎压地址相同,则将数据丢给后胎压
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1 && (data_flag == 2 || data_flag == 3 || power_on_flag)){//若和后胎压地址相同,则将数据丢给后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
strcpy(custom_data.user_data.r_mac_address,after_pressure.mac_address);
|
||||
custom_data.user_data.r_mac_address[6]=after_pressure.temp&0xFF;
|
||||
custom_data.user_data.r_mac_address[7]=after_pressure.psi>>8&0xFF;
|
||||
custom_data.user_data.r_mac_address[8]=after_pressure.psi&0xFF;
|
||||
}
|
||||
if(power_on_flag){
|
||||
DEBUG_PRINT("power_on_flag = %d, tire_pressure ,ago_pressure.psi = %d , after_pressure.psi =%d .\r\n",power_on_flag,ago_pressure.psi,after_pressure.psi);
|
||||
power_on_flag--;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1://学习前胎压 前胎压不能于后胎压相同 前胎压mac清零
|
||||
DEBUG_PRINT("1>>>> data_flag = %d \n",data_flag);
|
||||
|
||||
if(data_flag==1){//只做mac1的判断
|
||||
DEBUG_PRINT("mac1-------------------.\r\n");
|
||||
//判断mac是否正常
|
||||
if(mac_address_normal(mac1,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac1 ok-------------------.\r\n");
|
||||
//判断是否等于后胎压mac地址
|
||||
if(compare_arrays(after_pressure.mac_address,mac1,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer1,2,0);
|
||||
}else{//若不等于 那么就学习前胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer1[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure ago_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
strcpy(ago_pressure.mac_address,mac1);
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer1,1,1);
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else if(data_flag==2){//只做mac2的判断
|
||||
DEBUG_PRINT("mac2 -------------------.\r\n");
|
||||
//判断mac是否正常
|
||||
if(mac_address_normal(mac2,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac2 ok-------------------.\r\n");
|
||||
//判断是否等于后胎压mac地址
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
}else{//若不等于 那么就学习前胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure ago_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ago_pressure.mac_address,mac2);
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,1);
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//先判断mac1是否正常 再判断mac2
|
||||
if(mac_address_normal(mac1,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac1 -------------------.\r\n");
|
||||
//判断是否等于后胎压mac地址
|
||||
if(compare_arrays(after_pressure.mac_address,mac1,6)==1){//若等于,那么刷新后胎压
|
||||
DEBUG_PRINT("mac1 after -------------------.\r\n");
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer1,2,0);
|
||||
//后胎压刷新完毕
|
||||
//1.判断mac2 1.是否正常 是转2 否退出
|
||||
//2.是否等于后胎压 是则刷后胎压 否转3
|
||||
//3.学习前胎压
|
||||
if(mac_address_normal(mac2,6) == 1){//判断mac2是否正常
|
||||
DEBUG_PRINT("mac2 -------------------.\r\n");
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
}else{//反之学习前胎压
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure ago_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ago_pressure.mac_address,mac2);
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,1);
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
DEBUG_PRINT("mac2 error-------------------.\r\n");
|
||||
}
|
||||
|
||||
}else{//若不等于 那么就学习前胎压
|
||||
DEBUG_PRINT("mac2 ago-------------------.\r\n");
|
||||
|
||||
//S
|
||||
data = trip_buffer1[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure ago_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ago_pressure.mac_address,mac1);
|
||||
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer1,1,1);
|
||||
// strcpy(custom_data.user_data.f_mac_address,ago_pressure.mac_address);
|
||||
//前胎压学习完毕
|
||||
//1.判断mac2 1.是否正常 是转2 否退出
|
||||
//2.是否等于前胎压 是刷前胎压 否转3
|
||||
//3.是否等于后胎压 是则刷新后胎压 否则退出
|
||||
if(mac_address_normal(mac2,6) == 1){//判断mac2是否正常
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
}else if(compare_arrays(ago_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,0);
|
||||
}
|
||||
}
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
|
||||
}else if(mac_address_normal(mac2,6) == 1){//是否正常
|
||||
//判断是否等于后胎压mac地址
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
}else{//若不等于 那么就学习前胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure ago_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ago_pressure.mac_address,mac2);
|
||||
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,1);
|
||||
|
||||
Save_tire_data();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case 2://学习后胎压
|
||||
DEBUG_PRINT("2>>>> data_flag =%d\n",data_flag);
|
||||
|
||||
if(data_flag==1){//只做mac1的判断
|
||||
DEBUG_PRINT("mac1-------------------.\r\n");
|
||||
//判断mac是否正常
|
||||
if(mac_address_normal(mac1,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac1 ok-------------------.\r\n");
|
||||
//判断是否等于前胎压mac地址
|
||||
if(compare_arrays(ago_pressure.mac_address,mac1,6)==1){//若等于,那么刷新前胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer1,1,0);
|
||||
}else{//若不等于 那么就学习后胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer1[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure after_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(after_pressure.mac_address,mac1);
|
||||
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer1,2,1);
|
||||
|
||||
Save_tire_data();
|
||||
}
|
||||
|
||||
}
|
||||
}else if(data_flag==2){
|
||||
DEBUG_PRINT("mac2 -------------------.\r\n");
|
||||
//判断mac是否正常
|
||||
if(mac_address_normal(mac2,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac2 ok-------------------.\r\n");
|
||||
//判断是否等于前胎压mac地址
|
||||
if(compare_arrays(ago_pressure.mac_address,mac2,6)==1){//若等于,那么刷新前胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,0);
|
||||
}else{//若不等于 那么就学习后胎压
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure after_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(after_pressure.mac_address,mac2);
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,1);
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//先判断mac1是否正常 再判断mac2
|
||||
if(mac_address_normal(mac1,6) == 1){//正常进
|
||||
DEBUG_PRINT("mac1 -------------------.\r\n");
|
||||
//判断是否等于前胎压mac地址
|
||||
if(compare_arrays(ago_pressure.mac_address,mac1,6)==1){//若等于,那么刷新前胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer1,1,0);
|
||||
//前胎压刷新完毕
|
||||
//1.判断mac2 1.是否正常 是转2 否退出
|
||||
//2.是否等于前胎压 是则刷前胎压 否转3
|
||||
//3.学习后胎压
|
||||
if(mac_address_normal(mac2,6) == 1){//判断mac2是否正常
|
||||
DEBUG_PRINT("mac2 -------------------.\r\n");
|
||||
if(compare_arrays(ago_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,0);
|
||||
}else{//反之学习后胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure after_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(after_pressure.mac_address,mac2);
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,1);
|
||||
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}else{//若不等于 那么就学习后胎压
|
||||
|
||||
//S
|
||||
data = trip_buffer1[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure after_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(after_pressure.mac_address,mac1);
|
||||
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer1,1,1);
|
||||
|
||||
//后胎压学习完毕
|
||||
//1.判断mac2 1.是否正常 是转2 否退出
|
||||
//2.是否等于前胎压 是刷前胎压 否转3
|
||||
//3.是否等于后胎压 是则刷新后胎压 否则退出
|
||||
if(mac_address_normal(mac2,6) == 1){//判断mac2是否正常
|
||||
if(compare_arrays(after_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,0);
|
||||
}else if(compare_arrays(ago_pressure.mac_address,mac2,6)==1){//若等于,那么刷新后胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,0);
|
||||
}
|
||||
}
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
if(mac_address_normal(mac2,6) == 1){//是否正常
|
||||
DEBUG_PRINT("mac error mac2 -------------------.\r\n");
|
||||
//判断是否等于前胎压mac地址
|
||||
if(compare_arrays(ago_pressure.mac_address,mac2,6)==1){//若等于,那么刷新前胎压
|
||||
pressure_buffer_event_handing(ago_pressure,trip_buffer2,1,0);
|
||||
}else{//若不等于 那么就学习后胎压
|
||||
//S
|
||||
data = trip_buffer2[6];
|
||||
//配对模式
|
||||
if(!(JUDGE_BIN_0(data) || JUDGE_BIN_1(data) || JUDGE_BIN_6(data))){
|
||||
DEBUG_PRINT("Learning tire pressure after_pressure error >> JUDGE_BIN_0(data) =0.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(after_pressure.mac_address,mac2);
|
||||
pressure_buffer_event_handing(after_pressure,trip_buffer2,2,1);
|
||||
|
||||
Save_tire_data();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;//学习后胎压
|
||||
default:break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
#ifndef TIRE_PRESSURE_PROTOCOL_H
|
||||
#define TIRE_PRESSURE_PROTOCOL_H
|
||||
|
||||
|
||||
|
||||
#endif
|
630
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.c
Normal file
630
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.c
Normal file
@ -0,0 +1,630 @@
|
||||
#include "awtk.h"
|
||||
#include "user_protocol.h"
|
||||
#include "gpio_protocol.h"
|
||||
#include "moto_config.h"
|
||||
#include "data_port.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include "keypad.h"
|
||||
#include "moto_adc.h"
|
||||
#include "moto_config.h"
|
||||
|
||||
|
||||
extern double total_mile;
|
||||
uint8_t data_error_flag = 0;
|
||||
|
||||
#define KEY_DATA_PRESS 0x01 // 短按
|
||||
#define KEY_DATA_LONG_PRESS 0x02 // 长按
|
||||
enum
|
||||
{
|
||||
LV_KEY_OPTION = 113, // 0x11
|
||||
LV_KEY_SELECT = 119, // 0x12
|
||||
LV_KEY_OTHER1 = 122, // 0x12
|
||||
};
|
||||
|
||||
uint8_t save_data = 0;
|
||||
|
||||
#define ADC_VPLTAGE_MIN 1666
|
||||
#define ADC_VPLTAGE_MAX 2486
|
||||
|
||||
int adc_light = 0;
|
||||
int adc_voltage = 0;
|
||||
|
||||
extern uint32_t fml_stamp_to_time(uint32_t timep , uint16_t time[]);
|
||||
extern uint8_t light_buffer[];
|
||||
extern double cell_buffer[];
|
||||
extern uint8_t data_storage;
|
||||
extern uint32_t tire_front_time;
|
||||
extern uint32_t tire_rear_time;
|
||||
uint8_t flash_flag = 1;//收到device信息标志后置为0
|
||||
|
||||
// 封装的函数,根据位位置获取对应的值
|
||||
uint8_t getBitValue(uint8_t count, int bitPosition) {
|
||||
return (count >> bitPosition) & 0x1;
|
||||
}
|
||||
// 封装的函数,获取2个bit组合成的值
|
||||
uint8_t getBit2Value(uint8_t count, int bitPosition) {
|
||||
return (count >> bitPosition) & 0x3;
|
||||
}
|
||||
|
||||
// 封装的函数,获取3个bit组合成的值
|
||||
uint8_t getBit3Value(uint8_t count, int bitPosition) {
|
||||
return (count >> bitPosition) & 0x7;
|
||||
}
|
||||
|
||||
// 封装的函数,获取4个bit组合成的值
|
||||
uint8_t getBit4Value(uint8_t count, int bitPosition) {
|
||||
return (count >> bitPosition) & 0xf;
|
||||
}
|
||||
|
||||
double adc_voltage_calculation(void){
|
||||
double value = 0;
|
||||
|
||||
if(adc_voltage<=ADC_VPLTAGE_MIN)
|
||||
value = 11.0;
|
||||
else if(adc_voltage>=ADC_VPLTAGE_MAX)
|
||||
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);
|
||||
return value;
|
||||
}
|
||||
|
||||
//MOTO通讯 设备信息+时间戳解析协议
|
||||
void device_data_analysis(uint8_t *buf){
|
||||
printf("device information............................................\r\n");
|
||||
uint8_t data;
|
||||
uint8_t sum1,sum2,sum3,sum4;
|
||||
uint32_t save_total_mile,save_trip_mile;
|
||||
uint32_t sum;
|
||||
int i=0;
|
||||
char equipment[16] = {0};
|
||||
char produce[5] = {0};
|
||||
char mac[6] = {0};
|
||||
data = *(buf++);
|
||||
if(data!=0xAA)
|
||||
return;
|
||||
|
||||
data = *(buf++);
|
||||
if(data!=0x55)
|
||||
return;
|
||||
|
||||
//设备相关信息
|
||||
data = *(buf++);//0x01
|
||||
data = *(buf++);//0x1C 总长度22+6mac
|
||||
//设备编号占16
|
||||
DEBUG_PRINT("equipment > ");
|
||||
for(i=0;i<16;i++){
|
||||
data = *(buf++);//0x16
|
||||
DEBUG_PRINT("%02x ",data);
|
||||
equipment[i] = data;
|
||||
}
|
||||
DEBUG_PRINT("\n");
|
||||
Set_device_equipment_num(equipment);
|
||||
//产品型号占5
|
||||
DEBUG_PRINT("produce > ");
|
||||
for(i=0;i<5;i++){
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("%02x ",data);
|
||||
produce[i] = data;
|
||||
}
|
||||
DEBUG_PRINT("\n");
|
||||
Set_device_produce_num(produce);
|
||||
//客户编号
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("client > %02x \n",data);
|
||||
Set_device_client_num(data);
|
||||
//mac占6
|
||||
DEBUG_PRINT("mac > ");
|
||||
for(i=0;i<6;i++){
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("%02x ",data);
|
||||
mac[i] = data;
|
||||
}
|
||||
DEBUG_PRINT("\n");
|
||||
Set_device_mac(mac);
|
||||
|
||||
//平台信息
|
||||
data = *(buf++);//0x02
|
||||
//DEBUG_PRINT("0x02 -- %02x .\n",data);
|
||||
data = *(buf++);//0x03
|
||||
//DEBUG_PRINT("0x03 -- %02x .\n",data);
|
||||
//BottomData platform[3];
|
||||
data = *(buf++);//平台ID
|
||||
DEBUG_PRINT("bottom_id > %02x \n",data);
|
||||
Set_device_bottom_id(data);
|
||||
|
||||
data = *(buf++);//主版本
|
||||
DEBUG_PRINT("bottom_softwar_host > %02x \n",data);
|
||||
Set_device_bottom_softwar_host(data);
|
||||
|
||||
data = *(buf++);//次版本
|
||||
DEBUG_PRINT("bottom_softwar_order > %02x \n",data);
|
||||
Set_device_bottom_softwar_order(data);
|
||||
//Set_device_bottom_data(platform);
|
||||
|
||||
|
||||
//平台认证
|
||||
data = *(buf++);//0x03
|
||||
//DEBUG_PRINT("0x03 -- %02x .\n",data);
|
||||
data = *(buf++);//0x14
|
||||
//DEBUG_PRINT("0x14 -- %02x .\n",data);
|
||||
DEBUG_PRINT("voucher > ");
|
||||
char voucher[20] = {0};
|
||||
for(i=0;i<20;i++){
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("%02x ",data);
|
||||
voucher[i] = data;
|
||||
}
|
||||
DEBUG_PRINT("\n");
|
||||
Set_device_voucher(voucher);
|
||||
|
||||
|
||||
//同步时间
|
||||
data = *(buf++);//0x04
|
||||
//DEBUG_PRINT("0x04 -- %02x .\n",data);
|
||||
data = *(buf++);//0x04
|
||||
//DEBUG_PRINT("0x04 -- %02x .\n",data);
|
||||
//DEBUG_PRINT("time stamp >> ");
|
||||
uint16_t time_transfer[6];
|
||||
|
||||
sum1 = *(buf++);
|
||||
sum2 = *(buf++);
|
||||
sum3 = *(buf++);
|
||||
sum4 = *(buf++);
|
||||
|
||||
//sum = sum1 | sum2<<8 | sum3<<16 | sum4<<24;
|
||||
sum = sum1<<24 | sum2<<16 | sum3<<8 | sum4;
|
||||
DEBUG_PRINT("time > %08x \n",sum);
|
||||
tire_rear_time = sum;
|
||||
tire_front_time = sum;
|
||||
// if(sum<1706198400)
|
||||
// sum = 1706198400;
|
||||
fml_stamp_to_time(sum,time_transfer);
|
||||
|
||||
Uart_set_time(time_transfer);//去设置时间并不再发送询问时间指令
|
||||
//Set_sys_ttrb_time(10);
|
||||
|
||||
data = *(buf++);//0x05
|
||||
//DEBUG_PRINT("0x05 -- %02x .\n",data);
|
||||
data = *(buf++);//0x02
|
||||
//DEBUG_PRINT("0x02 -- %02x .\n",data);
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("device_moto_type %02x \n",data);
|
||||
Set_device_moto_type(data);
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("device_screen_type %02x \n",data);
|
||||
Set_device_screen_type(data);
|
||||
|
||||
|
||||
data = *(buf++);//0x06
|
||||
//DEBUG_PRINT("0x06 -- %02x .\n",data);
|
||||
data = *(buf++);//0x01
|
||||
//DEBUG_PRINT("0x01 -- %02x .\n",data);
|
||||
data = *(buf++);
|
||||
DEBUG_PRINT("device_ability %02x .\n",data);
|
||||
Set_device_ability(data);
|
||||
|
||||
data = *(buf++);//0x07
|
||||
//DEBUG_PRINT("0x06 -- %02x .\n",data);
|
||||
data = *(buf++);//0x02
|
||||
//DEBUG_PRINT("0x01 -- %02x .\n",data);
|
||||
|
||||
data = *(buf++);//硬件主版本
|
||||
Set_device_hardware_version_host(data);
|
||||
data = *(buf++);//硬件次版本
|
||||
Set_device_hardware_version_order(data);
|
||||
|
||||
|
||||
data = *(buf++);//0x08
|
||||
//DEBUG_PRINT("0x06 -- %02x .\n",data);
|
||||
data = *(buf++);//0x08
|
||||
//DEBUG_PRINT("0x01 -- %02x .\n",data);
|
||||
|
||||
#ifdef DATA_CAN
|
||||
//里程
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
sum3 = *(buf++)&0xFF;
|
||||
sum4 = *(buf++)&0xFF;
|
||||
sum = sum1<<24 | sum2<<16 | sum3<<8 | sum4;
|
||||
save_trip_mile =sum;
|
||||
|
||||
//小计里程
|
||||
sum = 0;
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
sum3 = *(buf++)&0xFF;
|
||||
sum4 = *(buf++)&0xFF;
|
||||
sum = sum1<<24 | sum2<<16 | sum3<<8 | sum4;
|
||||
save_total_mile =sum;
|
||||
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n");
|
||||
printf("Power outage trip mile =%d , total mile =%d .\n",save_trip_mile,save_total_mile);
|
||||
if(save_trip_mile>save_total_mile)
|
||||
save_trip_mile = 0;
|
||||
Set_sys_trip_mileage(save_trip_mile);
|
||||
Set_sys_total_mileage(save_total_mile);
|
||||
if(save_total_mile < flash_trip_mile){
|
||||
flash_trip_mile = save_total_mile;
|
||||
Set_sys_trip_mileage(save_total_mile);
|
||||
}
|
||||
flash_trip_mile = save_trip_mile;
|
||||
flash_total_mile = save_total_mile;
|
||||
#endif
|
||||
total_mile = 0;
|
||||
flash_flag=0;
|
||||
data_error_flag = 0;
|
||||
flash_flag=0;
|
||||
}
|
||||
int test_light = 0;
|
||||
//MOTO通讯协议
|
||||
void data_analysis(uint8_t *buf){
|
||||
// printf("data_analysis-------------.\r\n");
|
||||
uint32_t data;
|
||||
uint32_t sum,sum1,sum2,sum3,sum4;
|
||||
volatile double value=0;
|
||||
uint8_t result = 0;
|
||||
|
||||
//一些标志
|
||||
uint8_t temp = 0;
|
||||
uint8_t oil = 0;
|
||||
uint8_t light = 0;
|
||||
uint8_t data_type = 0;
|
||||
double cell = 0;
|
||||
save_data = 0;
|
||||
|
||||
data = *(buf++);
|
||||
// if(data!=0xAA)
|
||||
// return;
|
||||
|
||||
data_type = *(buf++);
|
||||
|
||||
// if(data_type!=0x11 && data_type!=0x19)
|
||||
// return;
|
||||
|
||||
//checklen=data;
|
||||
|
||||
data = *(buf++);
|
||||
// if(data!=0x03)
|
||||
// return;
|
||||
|
||||
data = *(buf++);
|
||||
// if(data!=0x50)
|
||||
// return;
|
||||
|
||||
data = *(buf++);
|
||||
// if(data!=0x0D && data!=0x15)
|
||||
// return;
|
||||
|
||||
//按键 高set 低mod
|
||||
data = *(buf++);
|
||||
#ifdef KEY_EXCHANGE
|
||||
if(JUDGE_BIN_4(data))
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
|
||||
else if(JUDGE_BIN_5(data))
|
||||
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
|
||||
else if(JUDGE_BIN_0(data))
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
|
||||
else if(JUDGE_BIN_1(data))
|
||||
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
|
||||
else if(JUDGE_BIN_7(data)){
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
|
||||
}
|
||||
#else
|
||||
if(JUDGE_BIN_0(data))
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
|
||||
else if(JUDGE_BIN_1(data))
|
||||
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
|
||||
else if(JUDGE_BIN_4(data))
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
|
||||
else if(JUDGE_BIN_5(data))
|
||||
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
|
||||
else if(JUDGE_BIN_7(data)){
|
||||
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
|
||||
}
|
||||
#endif
|
||||
//速度
|
||||
data = *(buf++);
|
||||
#ifndef DATA_CAN
|
||||
Set_sys_velocity(data);
|
||||
#endif
|
||||
//if(data>5&& abs_data!=1)
|
||||
//abs_data = 1;
|
||||
|
||||
//转速
|
||||
sum = 0;
|
||||
sum = *(buf++)&0xFF;
|
||||
//sum = (*(buf++)&0xFF)<<8 | sum;
|
||||
sum = (*(buf++)&0xFF) | sum<<8;
|
||||
#ifndef DATA_CAN
|
||||
Set_sys_veer_velocity(sum);
|
||||
#endif
|
||||
|
||||
if(data_type==0x19){
|
||||
//里程
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
sum3 = *(buf++)&0xFF;
|
||||
sum4 = *(buf++)&0xFF;
|
||||
//sum = sum1 | sum2<<8 | sum3<<16 | sum4<<24;
|
||||
sum = sum1<<24 | sum2<<16 | sum3<<8 | sum4;
|
||||
// value = (int)(sum/100);
|
||||
// value = value/10;
|
||||
Set_sys_trip_mileage(sum);
|
||||
|
||||
//小计里程
|
||||
sum = 0;
|
||||
sum = 0;
|
||||
sum1 = *(buf++)&0xFF;
|
||||
sum2 = *(buf++)&0xFF;
|
||||
sum3 = *(buf++)&0xFF;
|
||||
sum4 = *(buf++)&0xFF;
|
||||
//sum = sum1 | sum2<<8 | sum3<<16 | sum4<<24;
|
||||
sum = sum1<<24 | sum2<<16 | sum3<<8 | sum4;
|
||||
/*sum = *(buf++)&0xFF;
|
||||
sum = (*(buf++)&0xFF)<<8 | sum;
|
||||
sum = (*(buf++)&0xFF)<<16 | sum;
|
||||
sum = (*(buf++)&0xFF)<<24 | sum;*/
|
||||
//sum = (int)sum/1000;
|
||||
Set_sys_total_mileage(sum);
|
||||
}
|
||||
//灯
|
||||
data = *(buf++);
|
||||
// printf("light data = %d.\r\n",data);
|
||||
switch(data%4){
|
||||
case 0:Set_sys_veer(0);break;
|
||||
case 1:Set_sys_veer(2);break;
|
||||
case 2:Set_sys_veer(1);break;
|
||||
case 3:Set_sys_veer(3);break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
if(JUDGE_BIN_2(data))
|
||||
Set_sys_lamplight(1);//远光灯
|
||||
else
|
||||
Set_sys_lamplight(0);//关闭远光灯
|
||||
//风扇灯
|
||||
if(JUDGE_BIN_3(data))
|
||||
Set_sys_warning_fan(1);//风扇
|
||||
else
|
||||
Set_sys_warning_fan(0);//关闭风扇
|
||||
|
||||
//abs故障灯
|
||||
if(JUDGE_BIN_4(data))
|
||||
Set_sys_warning_abs(1);//abs故障灯
|
||||
else
|
||||
Set_sys_warning_abs(0);//关闭abs
|
||||
|
||||
#ifndef DATA_CAN
|
||||
//tcs图标
|
||||
if(JUDGE_BIN_5(data)){
|
||||
Set_sys_warning_tcs(1);//tcs图标
|
||||
}else{
|
||||
Set_sys_warning_tcs(0);//tcs图标
|
||||
}
|
||||
#else
|
||||
//机油压力报警
|
||||
if(JUDGE_BIN_5(data)){
|
||||
Set_sys_warning_machine_oil(1);//tcs图标
|
||||
}else{
|
||||
Set_sys_warning_machine_oil(0);//tcs图标
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef DATA_CAN
|
||||
if(JUDGE_BIN_6(data))
|
||||
Set_sys_warning_engine(1);//引擎报警灯
|
||||
else
|
||||
Set_sys_warning_engine(0);//关闭引擎报警灯
|
||||
#endif
|
||||
|
||||
if(JUDGE_BIN_7(data))
|
||||
save_data = 1;//保存数据的标志
|
||||
|
||||
//档位
|
||||
data = *(buf++);
|
||||
if(data == 0){
|
||||
Set_sys_grade(0);
|
||||
}else if(data < 8){
|
||||
Set_sys_grade(data);
|
||||
}
|
||||
|
||||
//油量
|
||||
oil = *(buf++);
|
||||
|
||||
//温度
|
||||
temp = *(buf++);
|
||||
|
||||
//电池电压
|
||||
value = 0;
|
||||
sum = *(buf++)&0xFF;
|
||||
//value = (*(buf++)&0xFF)<<8 | sum;
|
||||
value = (*(buf++)&0xFF) | sum<<8;
|
||||
cell = value/1000;
|
||||
|
||||
//光感阻值 测试范围:57-1000
|
||||
sum = 0;
|
||||
sum = *(buf++)&0xFF;
|
||||
sum = (*(buf++)&0xFF) | sum<<8;
|
||||
Set_sys_sensor_light(sum);
|
||||
if(sum<200)
|
||||
light = sum/2;
|
||||
else
|
||||
light = 100;
|
||||
|
||||
data = *(buf++);
|
||||
// if(data)
|
||||
// printf("data = %d.\r\n",data);
|
||||
result = ((data >> 5) & 0x03);
|
||||
#ifndef DATA_CAN
|
||||
if(JUDGE_BIN_0(data)){//收到小计清零,不再发送
|
||||
DEBUG_PRINT("Received subtotal reset, no more sending.\n");
|
||||
Set_sys_odo_reset(10);
|
||||
}
|
||||
#else
|
||||
if(JUDGE_BIN_7(data)){//收到关机保存指令(停用)//小计清零,不再发送
|
||||
DEBUG_PRINT("Received subtotal reset, no more sending.\n");
|
||||
Set_sys_odo_reset(10);
|
||||
}
|
||||
if(JUDGE_BIN_0(data)){//收到蓝牙升级信号不发送can数据
|
||||
DEBUG_PRINT("Receive Bluetooth upgrade signal and do not send CAN data.\n");
|
||||
Set_sys_bt_upgrade(1);
|
||||
}
|
||||
#endif
|
||||
if(JUDGE_BIN_1(data)){//需要询问时间
|
||||
DEBUG_PRINT("start time select.\n");
|
||||
Set_sys_ttrb(0);
|
||||
}
|
||||
if(JUDGE_BIN_2(data)){//收到故障码,不再发送
|
||||
DEBUG_PRINT("Received fault code, no longer sending.\n");
|
||||
Set_sys_fault_code(0);
|
||||
}
|
||||
if(JUDGE_BIN_3(data)){//收到时间,不再发送
|
||||
DEBUG_PRINT("Received time, no longer sending.\n");
|
||||
Set_sys_ttrb_time(10);//630发送时间给蓝牙后,蓝牙回复收到信号
|
||||
}
|
||||
if(JUDGE_BIN_4(data)){//收到胎压信息,不再发送
|
||||
DEBUG_PRINT("Received tire pressure command, no longer sending.\n");
|
||||
Set_sys_tire_pressure_mesg(10);
|
||||
}
|
||||
#ifdef DATA_CAN
|
||||
switch(result){
|
||||
case 1:
|
||||
printf("result 1> start time select.\r\n");
|
||||
Set_sys_ttrb(0);
|
||||
break;
|
||||
case 2:
|
||||
printf("result 2> start time select.\r\n");
|
||||
Set_sys_ttrb(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if(save_data){
|
||||
Set_sys_gas(oil);
|
||||
Set_sys_temp(temp);
|
||||
Set_sys_voltage(cell);
|
||||
light_buffer[data_storage] = light;
|
||||
data_storage++;
|
||||
if(data_storage>=SAVE_DATA_SIZE){//满足存储大小 计算均值
|
||||
data_storage=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
void SendDataToBT(uint8_t *pBuff){
|
||||
// printf("Send>6.\r\n");
|
||||
memset(pBuff, 0, 6); //buff初始化
|
||||
|
||||
uint8_t Tag_length = 4; //包头偏移4个字节
|
||||
static uint8_t heartbeat_flag=0;
|
||||
|
||||
//帧头部分
|
||||
pBuff[0] = 0xAA;
|
||||
pBuff[1] = 0x03;
|
||||
pBuff[2] = 0x06;
|
||||
pBuff[3] = 0x01;
|
||||
pBuff[4] = heartbeat_flag;
|
||||
|
||||
uint8_t count = 0;
|
||||
for(uint8_t i=0;i<5;i++){
|
||||
count += pBuff[i+2];
|
||||
}
|
||||
|
||||
pBuff[5] = count & 0xFF;
|
||||
// printf("write = %d.",heartbeat_flag);
|
||||
heartbeat_flag++;
|
||||
// return pBuff;
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
uint8_t Lights_required_for_converting_to_BT(void){
|
||||
uint8_t value = 0;
|
||||
//刷新标志
|
||||
//if(Get_sys_warning_tcs())
|
||||
//tcs
|
||||
if(Get_sys_warning_tcs())
|
||||
value += 1;
|
||||
//引擎
|
||||
if(Get_sys_warning_engine())
|
||||
value += 2;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void SendDataToBT(uint8_t *pBuff){
|
||||
// printf("Send>21.\r\n");
|
||||
memset(pBuff, 0, 21); //buff初始化
|
||||
|
||||
uint8_t Tag_length = 4; //包头偏移4个字节
|
||||
uint32_t buf32_value;
|
||||
uint16_t buf16_value;
|
||||
uint8_t buf8_value;
|
||||
// uint16_t checksum;
|
||||
|
||||
//帧头部分
|
||||
pBuff[0] = 0xAA;
|
||||
pBuff[1] = 0x12;
|
||||
pBuff[2] = 0x04;
|
||||
pBuff[3] = 0x10;
|
||||
|
||||
//数据部分
|
||||
buf16_value = Get_sys_velocity();
|
||||
pBuff[Tag_length+0] = buf16_value & 0xFF;
|
||||
buf16_value = Get_sys_veer_velocity();
|
||||
pBuff[Tag_length+1] = (buf16_value >> 8) & 0xFF;
|
||||
pBuff[Tag_length+2] = buf16_value & 0xFF;
|
||||
buf8_value = Lights_required_for_converting_to_BT();
|
||||
pBuff[Tag_length+3] = buf8_value &0xFF;
|
||||
if(Get_sys_trip_mileage() > Get_sys_total_mileage()){
|
||||
extern void Send_software_version(void);
|
||||
Send_software_version();
|
||||
data_error_flag = 1;
|
||||
return;
|
||||
}
|
||||
buf32_value = Get_sys_trip_mileage();
|
||||
// printf("buf trip =%d,",Get_sys_trip_mileage());
|
||||
pBuff[Tag_length+4] = (buf32_value >> 24) & 0xFF;
|
||||
pBuff[Tag_length+5] = (buf32_value >> 16) & 0xFF;
|
||||
pBuff[Tag_length+6] = (buf32_value >> 8) & 0xFF;
|
||||
pBuff[Tag_length+7] = buf32_value & 0xFF;
|
||||
buf32_value = Get_sys_total_mileage();
|
||||
// printf("buf odo =%d.",Get_sys_total_mileage());
|
||||
pBuff[Tag_length+8] = (buf32_value >> 24) & 0xFF;
|
||||
pBuff[Tag_length+9] = (buf32_value >> 16) & 0xFF;
|
||||
pBuff[Tag_length+10] = (buf32_value >> 8) & 0xFF;
|
||||
pBuff[Tag_length+11] = buf32_value & 0xFF;
|
||||
buf16_value = Get_sys_now_defect_code();
|
||||
pBuff[Tag_length+12] = (buf16_value >> 8) & 0xFF;
|
||||
pBuff[Tag_length+13] = buf16_value & 0xFF;
|
||||
buf16_value = Get_sys_his_defect_code();
|
||||
pBuff[Tag_length+14] = (buf16_value >> 8) & 0xFF;
|
||||
pBuff[Tag_length+15] = buf16_value & 0xFF;
|
||||
|
||||
|
||||
|
||||
// checksum = bt_sumcrc(pBuff,21);
|
||||
uint8_t count = 0;
|
||||
for(uint8_t i=0;i<18;i++){
|
||||
count += pBuff[i+2];
|
||||
// printf("pBuff = %x .\r\n",pBuff[i+2]);
|
||||
}
|
||||
|
||||
pBuff[Tag_length+16] = count & 0xFF;
|
||||
|
||||
// return pBuff;
|
||||
}
|
||||
|
||||
#endif
|
16
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.h
Normal file
16
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef USER_PROTOCOL_H
|
||||
#define USER_PROTOCOL_H
|
||||
|
||||
#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
|
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.obj
Normal file
BIN
MXC_A27-PCB4.5-270T/app/moto/protocol/user_protocol.obj
Normal file
Binary file not shown.
474
MXC_A27-PCB4.5-270T/app/moto/protocol/wifi_ota_protocol.c
Normal file
474
MXC_A27-PCB4.5-270T/app/moto/protocol/wifi_ota_protocol.c
Normal file
@ -0,0 +1,474 @@
|
||||
|
||||
#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"
|
||||
|
||||
#include "data_port.h"
|
||||
|
||||
#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
|
||||
|
||||
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;
|
||||
|
||||
extern void wifi_uup_send_ack(int type, int ret);
|
||||
extern int timeout;
|
||||
void wifi_uup_ota_update(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();
|
||||
switch (frametype) {
|
||||
case UART_FRAME_START:
|
||||
printf("start sfud erase flash .\n");
|
||||
//擦除flash
|
||||
uup_app_offset = NEW_APPFOOSET;
|
||||
uup_burn_offset = uup_app_offset;
|
||||
printf("erase add %X , size %X .\r\n",uup_app_offset,AMT630_BIN_MAX_SIZE);
|
||||
vTaskDelay(50);
|
||||
if(sfud_erase(sflash, uup_app_offset, AMT630_BIN_MAX_SIZE)==SFUD_SUCCESS){
|
||||
printf("UART_FRAME_START sfud erase ok.\n");
|
||||
vTaskDelay(50);
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_OK);
|
||||
}else{
|
||||
vTaskDelay(50);
|
||||
printf("UART_FRAME_START sfud erase fail.\n");
|
||||
wifi_uup_send_ack(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) {
|
||||
wifi_uup_send_ack(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);
|
||||
wifi_uup_send_ack(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);
|
||||
wifi_uup_send_ack(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);
|
||||
printf("uup_packet_num = %d .\r\n",uup_packet_num);
|
||||
|
||||
uup_rev_packet = 0;
|
||||
wifi_uup_send_ack(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) {
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
break;
|
||||
}
|
||||
|
||||
packetnum = buf[0];
|
||||
if ((uup_rev_packet & 0xff) != packetnum) {
|
||||
printf("Wrong packet number.\n");
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (uup_rev_packet==0) { //第一条数据保存其crc校验码
|
||||
|
||||
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");
|
||||
wifi_uup_send_ack(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");
|
||||
wifi_uup_send_ack(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");
|
||||
wifi_uup_send_ack(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-1))) { //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-1));
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(uup_buf + uup_buf_len, buf+1, framelen);
|
||||
uup_buf_len += framelen;
|
||||
uup_rev_packet++;
|
||||
|
||||
//wifi_uup_send_ack(frametype, UUP_ACK_OK);
|
||||
if (uup_buf_len == UUP_BUF_SIZE) {
|
||||
if(uup_rev_packet==1)
|
||||
printf("plan = %d,pace = %d.\n",uup_packet_num,uup_rev_packet);
|
||||
// //最后一包数据待擦写完成后回复
|
||||
// if(uup_packet_num == uup_rev_packet){
|
||||
// sfud_write(sflash, uup_burn_offset, UUP_BUF_SIZE, uup_buf);
|
||||
// wifi_uup_send_ack(frametype, UUP_ACK_OK);
|
||||
// Set_sys_pace(uup_rev_packet);
|
||||
// }else{
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_OK);
|
||||
Set_sys_pace(uup_rev_packet);
|
||||
sfud_write(sflash, uup_burn_offset, UUP_BUF_SIZE, uup_buf);
|
||||
// }
|
||||
|
||||
if (uup_rev_packet == 1){//UUP_BUF_SIZE/UUP_PACKET_SIZE) {
|
||||
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");
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
break;
|
||||
}
|
||||
uup_status = UUP_STATE_FILE_TFR;
|
||||
break;
|
||||
case UART_FRAME_FINISH:
|
||||
// printf("finish.uup_buf_len = %d.\r\n",uup_buf_len);
|
||||
if (uup_status != UUP_STATE_FILE_TFR && uup_status != UART_FRAME_FINISH) {
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
break;
|
||||
}
|
||||
if (!buf[0]) {
|
||||
printf("update end with error!\n");
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
uup_status = UUP_STATE_END;
|
||||
break;
|
||||
}
|
||||
framelen = len - 2;
|
||||
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_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;
|
||||
}
|
||||
}
|
||||
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");
|
||||
// }
|
||||
printf("exit ota sj.\n");
|
||||
Set_sys_power_on_self_test(100);
|
||||
Set_sys_upgrade_Flag(2);
|
||||
|
||||
printf("UART3_Type_regression .\n");
|
||||
extern void UART3_Type_regression(void);
|
||||
UART3_Type_regression();
|
||||
extern uint8_t wifi_ota_state;
|
||||
extern uint8_t wifi_file_state;
|
||||
|
||||
wifi_ota_state = 0;
|
||||
wifi_file_state = 0;
|
||||
timeout = 0;
|
||||
}else{
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_OK);
|
||||
vTaskDelay(1000);
|
||||
gpio_direction_output(WIFI_RESET_IO, 0);
|
||||
printf("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");
|
||||
wifi_flash_copy_demo();
|
||||
wdt_cpu_reboot();
|
||||
}
|
||||
|
||||
/*if (calc_checksum != checksum) {
|
||||
printf("calc_checksum = 0x%02x,checksum = 0x%02x.\n",calc_checksum,checksum);
|
||||
printf("whole crc check after burn fail!\n");
|
||||
wifi_uup_send_ack(frametype, UUP_ACK_FAIL);
|
||||
uup_rev_packet = 0;
|
||||
checksum = 0;
|
||||
calc_checksum = 0xffffffff;
|
||||
uup_buf_len = 0;
|
||||
framelen = 0;
|
||||
break;
|
||||
} else {
|
||||
wifi_uup_send_ack(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 wifi_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");
|
||||
timeout = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#ifndef OTA_PROTOCOL_H
|
||||
#define OTA_PROTOCOL_H
|
||||
|
||||
#include "tkc/types_def.h"
|
||||
|
||||
void wifi_uup_ota_update(uint8_t *framebuf, size_t len, int send_type, int send_ret);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user