|
@@ -30,29 +30,58 @@
|
|
|
#include "Log_Module.h"
|
|
#include "Log_Module.h"
|
|
|
#include "At_Module.h"
|
|
#include "At_Module.h"
|
|
|
#include "Common_Util.h"
|
|
#include "Common_Util.h"
|
|
|
-uint8_t mcu_id[8]="8945809";
|
|
|
|
|
-uint16_t Version_data = 1032;
|
|
|
|
|
-uint8_t regist_result =0;
|
|
|
|
|
|
|
+static uint8_t mcu_id[8]="8945809";
|
|
|
|
|
+static uint16_t Version_data = 1032;
|
|
|
|
|
+static uint8_t regist_result =0;
|
|
|
|
|
+static uint8_t register_status;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
-//uint8_t registlen=0;
|
|
|
|
|
|
|
|
|
|
-extern struct AT_Struct AT;
|
|
|
|
|
unsigned char key[17]="tuorenzhinenghua";
|
|
unsigned char key[17]="tuorenzhinenghua";
|
|
|
-extern Coefficient_Data flashdata;
|
|
|
|
|
-extern uint8_t register_success;
|
|
|
|
|
-//static uint8_t tcpcontextID = 1;
|
|
|
|
|
|
|
+static Coefficient_Data flashdata;
|
|
|
|
|
+
|
|
|
static uint8_t tcpconnectID = 2;
|
|
static uint8_t tcpconnectID = 2;
|
|
|
static char * REGIST_SERVER ="8337239yf4.yicp.fun" ; //注册服务器地址
|
|
static char * REGIST_SERVER ="8337239yf4.yicp.fun" ; //注册服务器地址
|
|
|
static uint16_t REGIST_PORT=22155; //端口号
|
|
static uint16_t REGIST_PORT=22155; //端口号
|
|
|
static char qcciddata[31]={0};//
|
|
static char qcciddata[31]={0};//
|
|
|
//char registData[100] = {0};
|
|
//char registData[100] = {0};
|
|
|
static char recvdata[512]={0};//和registData共用
|
|
static char recvdata[512]={0};//和registData共用
|
|
|
|
|
+
|
|
|
|
|
+//清空flash
|
|
|
|
|
+void clearflash(void){
|
|
|
|
|
+flashdata.read_flag=0;
|
|
|
|
|
+memcpy(flashdata.deviceSecret,"0",40);
|
|
|
|
|
+memcpy(flashdata.productKey,"0",20);
|
|
|
|
|
+memcpy(flashdata.deviceName,"0",20);
|
|
|
|
|
+delay_ms(10);
|
|
|
|
|
+STMFLASH_Write(FLASH_SAVE_ADDR,(uint16_t*)&flashdata,sizeof(flashdata));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void storedata(void){
|
|
|
|
|
+
|
|
|
|
|
+flashdata.read_flag=1;
|
|
|
|
|
+ Log_Printf_Debug("###########\r\n");
|
|
|
|
|
+ Log_Printf_Debug("deviceSecret:%s,productKey:%s,deviceName:%s,read_flag:%d\r\n",flashdata.deviceSecret,flashdata.productKey,flashdata.deviceName,flashdata.read_flag);
|
|
|
|
|
+ Log_Printf_Debug("结构体大小: %d\r\n", sizeof(Coefficient_Data));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ delay_ms(10);
|
|
|
|
|
+ STMFLASH_Write(FLASH_SAVE_ADDR,(uint16_t*)&flashdata,sizeof(flashdata));
|
|
|
|
|
+ flashdata.read_flag=0;
|
|
|
|
|
+ delay_ms(10);
|
|
|
|
|
+ Log_Printf_Debug("写入数据完成\r\n");
|
|
|
|
|
+ STMFLASH_Read(FLASH_SAVE_ADDR,(uint16_t*)&flashdata,sizeof(flashdata));
|
|
|
|
|
+ Log_Printf_Debug("读取完成read_flag:%d,deviceSecret:%s,productKey:%s,deviceName:%s\r\n",flashdata.read_flag,flashdata.deviceSecret,flashdata.productKey,flashdata.deviceName);
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
*注册信息打包
|
|
*注册信息打包
|
|
|
*/
|
|
*/
|
|
|
enum Result packRegistDataAnd(uint8_t *length){
|
|
enum Result packRegistDataAnd(uint8_t *length){
|
|
|
enum Result result = Result_None;
|
|
enum Result result = Result_None;
|
|
|
|
|
+ //
|
|
|
// int i=0;
|
|
// int i=0;
|
|
|
int datalen = 0;
|
|
int datalen = 0;
|
|
|
memset(qcciddata,'\0',sizeof(qcciddata));
|
|
memset(qcciddata,'\0',sizeof(qcciddata));
|
|
@@ -121,7 +150,7 @@ enum Result analysis_recvdata()
|
|
|
strcpy(flashdata.deviceSecret,json_deviceSecret->valuestring);
|
|
strcpy(flashdata.deviceSecret,json_deviceSecret->valuestring);
|
|
|
strcpy(flashdata.productKey,json_productKey->valuestring);
|
|
strcpy(flashdata.productKey,json_productKey->valuestring);
|
|
|
strcpy(flashdata.deviceName,json_deviceName->valuestring);
|
|
strcpy(flashdata.deviceName,json_deviceName->valuestring);
|
|
|
- memset(®ister_success, 1, sizeof(register_success));
|
|
|
|
|
|
|
+ memset(®ister_status, 1, sizeof(register_status));
|
|
|
cJSON_Delete(json);
|
|
cJSON_Delete(json);
|
|
|
|
|
|
|
|
return Result_Success;
|
|
return Result_Success;
|
|
@@ -234,10 +263,43 @@ uint8_t regist_device_sync(void)
|
|
|
if(regist_flag==0)//注册流程失败不储存flash
|
|
if(regist_flag==0)//注册流程失败不储存flash
|
|
|
{
|
|
{
|
|
|
flashdata.read_flag=0;
|
|
flashdata.read_flag=0;
|
|
|
|
|
+ register_status=0;
|
|
|
|
|
+ clearflash();
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- store();//存储到flash
|
|
|
|
|
- return 1;
|
|
|
|
|
|
|
+ if(register_status==1){
|
|
|
|
|
+ storedata();//存储到flash
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ Log_Printf_Debug("注册失败。。。regist_flag:%d,register_status:%d\r\n",regist_flag,register_status);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+enum Regist_Result regist_get_result(void)
|
|
|
|
|
+{
|
|
|
|
|
+ if(register_status){
|
|
|
|
|
+ return Regist_Result_Success;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ return Regist_Result_Failure;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+char * regist_get_aliyun_productKey(void)
|
|
|
|
|
+{
|
|
|
|
|
+ return flashdata.productKey;
|
|
|
|
|
+}
|
|
|
|
|
+char * regist_get_aliyun_deviceName(void)
|
|
|
|
|
+{
|
|
|
|
|
+ return flashdata.deviceName;
|
|
|
|
|
+}
|
|
|
|
|
+char * regist_get_aliyun_deviceSecret(void)
|
|
|
|
|
+{
|
|
|
|
|
+ return flashdata.deviceSecret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|