修改驱动程序
This commit is contained in:
1 parent
063c3fcc07
commit
a69c1a58d6
39 files changed
+1627
-641
No files matched your search
+207
-201
@@ -7,11 +7,11 @@
|
||||
|
||||
|
||||
// 尝试创建Socket
|
||||
const char
|
||||
const char
|
||||
|
||||
|
||||
|
||||
void EthMqttTick(void)
|
||||
void EthMqttTick (void)
|
||||
{
|
||||
if (s_tx_timeout > 1)
|
||||
s_tx_timeout--;
|
||||
@@ -27,7 +27,8 @@ void EthMqttTick(void)
|
||||
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
|
||||
//}
|
||||
|
||||
static enum {
|
||||
static enum
|
||||
{
|
||||
DeviceReboot,
|
||||
DeviceConfig,
|
||||
DeviceGetPara,
|
||||
@@ -35,13 +36,14 @@ static enum {
|
||||
DeviceReset,
|
||||
DeviceLink,
|
||||
DeviceIdle,
|
||||
}DeviceState = DeviceReboot ;
|
||||
static enum {
|
||||
} DeviceState = DeviceReboot ;
|
||||
static enum
|
||||
{
|
||||
FistIn,
|
||||
Runing,
|
||||
End,
|
||||
JumpUp
|
||||
}s_run = FistIn;
|
||||
} s_run = FistIn;
|
||||
|
||||
|
||||
|
||||
@@ -54,11 +56,11 @@ static enum {
|
||||
// NetFunc.ReSubTopic = EthMqttReSubTopic;
|
||||
// NetFunc.Task = EthMqttTask;
|
||||
|
||||
void EthMqttInit(void)
|
||||
void EthMqttInit (void)
|
||||
{
|
||||
// char str[128];
|
||||
// char addr_str[10];
|
||||
|
||||
|
||||
// GPIO_InitTypeDef GPIO_InitStruct;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
@@ -67,7 +69,7 @@ void EthMqttInit(void)
|
||||
// GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
// HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
|
||||
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
|
||||
|
||||
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
@@ -101,42 +103,42 @@ void EthMqttDisConnectd (void)
|
||||
s_lost_timer = 0;
|
||||
DisWriteNetSte (2, QUEUE);
|
||||
DeviceState = DeviceReboot;
|
||||
dbg_printf("Eth Device IsDisconnected \r\n");
|
||||
dbg_printf ("Eth Device IsDisconnected \r\n");
|
||||
}
|
||||
|
||||
int EthMqttReadData(char * buf,int length)
|
||||
int EthMqttReadData (char * buf, int length)
|
||||
{
|
||||
int k =0;
|
||||
if (UartInfoRxIsReady(uEth) == 1)
|
||||
int k = 0;
|
||||
if (UartInfoRxIsReady (uEth) == 1)
|
||||
{
|
||||
k = UartInfoReadData(uEth,(char *)buf,length);
|
||||
dbg_printf("<<<<<<<<<<<<%d\r\n",k);
|
||||
k = UartInfoReadData (uEth, (char *) buf, length);
|
||||
dbg_printf ("<<<<<<<<<<<<%d\r\n", k);
|
||||
s_lost_timer = 60000;
|
||||
DisWriteNetSte (1, QUEUE);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
int EthMqttIsReady(void)
|
||||
int EthMqttIsReady (void)
|
||||
{
|
||||
if (DeviceState != DeviceIdle )
|
||||
if (DeviceState != DeviceIdle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return UartInfoRxIsReady(uEth);
|
||||
return UartInfoRxIsReady (uEth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EthMqttWriteData(char * data,int length)
|
||||
void EthMqttWriteData (char * data, int length)
|
||||
{
|
||||
UartInfoWriteData(uEth,data,length);
|
||||
UartInfoWriteData (uEth, data, length);
|
||||
}
|
||||
|
||||
|
||||
int EthMqttIsIdle(void)
|
||||
int EthMqttIsIdle (void)
|
||||
{
|
||||
if (EthMqttIsConnect() == 0)
|
||||
{
|
||||
@@ -148,209 +150,213 @@ int EthMqttIsIdle(void)
|
||||
}
|
||||
|
||||
|
||||
int EthMqttIsConnect(void)
|
||||
int EthMqttIsConnect (void)
|
||||
{
|
||||
if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_4) == GPIO_PIN_SET)
|
||||
if (HAL_GPIO_ReadPin (GPIOC, GPIO_PIN_4) == GPIO_PIN_SET)
|
||||
return 1;
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
//return s_isconnect;
|
||||
}
|
||||
|
||||
void EthMqttTask(void)
|
||||
void EthMqttTask (void)
|
||||
{
|
||||
int rx_size;
|
||||
char str[128];
|
||||
//static pst_Work_Pragma pstWork_Pragma;
|
||||
switch(DeviceState)
|
||||
switch (DeviceState)
|
||||
{
|
||||
case DeviceReboot:
|
||||
case DeviceReboot:
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
dbg_printf("EthDeviceReboot\r\n");
|
||||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
|
||||
s_run_timer = 500;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if(s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
s_run = End;
|
||||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
|
||||
dbg_printf("Reboot Finsh\r\n");
|
||||
s_run_timer = 5000;
|
||||
}
|
||||
}
|
||||
else if (s_run == End){
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
//dbg_printf("Reboot Finsh\r\n");
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
s_run = FistIn ;
|
||||
DeviceState = DeviceConfig;
|
||||
}
|
||||
break;
|
||||
dbg_printf ("EthDeviceReboot\r\n");
|
||||
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
s_run_timer = 500;
|
||||
s_run = Runing;
|
||||
}
|
||||
// 这里要等待3s
|
||||
case DeviceConfig: // 进入配置模式
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if(s_run == FistIn)
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
dbg_printf("DeviceConfig\r\n");
|
||||
UartInfoClearData (uEth) ;
|
||||
UartInfoWriteData(uEth,"++++++++++",10);
|
||||
s_run_timer = 0;
|
||||
s_run = End;
|
||||
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
|
||||
dbg_printf ("Reboot Finsh\r\n");
|
||||
s_run_timer = 5000;
|
||||
}
|
||||
}
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
//dbg_printf("Reboot Finsh\r\n");
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_run = FistIn ;
|
||||
DeviceState = DeviceConfig;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 这里要等待3s
|
||||
case DeviceConfig: // 进入配置模式
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
dbg_printf ("DeviceConfig\r\n");
|
||||
UartInfoClearData (uEth) ;
|
||||
UartInfoWriteData (uEth, "++++++++++", 10);
|
||||
s_run_timer = 50;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
UartInfoWriteData (uEth, "{\"Command\":\"config\"}", strlen ("{\"Command\":\"config\"}"));
|
||||
dbg_printf ("Command\r\n");
|
||||
s_run = End;
|
||||
s_run_timer = 3000;
|
||||
}
|
||||
// 获取发送的数据
|
||||
}
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_run = FistIn;
|
||||
DeviceState = DeviceGetPara;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeviceGetPara:
|
||||
{
|
||||
if (UartInfoRxIsReady (uEth) == 1)
|
||||
{
|
||||
dbg_printf ("DeviceGetPara\r\n");
|
||||
rx_size = UartInfoReadData (uEth, (char *) s_buffer, 1024);
|
||||
dbg_printf ("(%d)[%d]\r\n", rx_size, s_buffer[0]) ;
|
||||
DeviceState = DeviceSetPara;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeviceSetPara:
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
memset (s_buffer, 0, 1024);
|
||||
//dbg_printf("subtopic:%s\r\n",(char *)pstWork_Pragma->stExternPragma.stMQTTClient.SubTopic);
|
||||
sprintf (s_buffer,
|
||||
"{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":%d,\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\"}",
|
||||
"Command", "config",
|
||||
"RemoteHost", SysInfo.remoteAddr,
|
||||
"RemotePort", SysInfo.remotePort,
|
||||
"WorkMode", "MQTT",
|
||||
"UserName", SysInfo.remoteuser,
|
||||
"Password", SysInfo.remotepass,
|
||||
"PubTopic", pub_topic,
|
||||
"SubTopic", sub_topic
|
||||
);
|
||||
//SetParametersToData(pstWork_Pragma,(char *)s_buffer,1024);
|
||||
dbg_printf ("%s\r\n", s_buffer);
|
||||
UartInfoWriteData (uEth, s_buffer, strlen (s_buffer));
|
||||
s_run_timer = 1000;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
UartInfoWriteData (uEth, "{\"Command\":\"exit\"}", strlen ("{\"Command\":\"exit\"}"));
|
||||
dbg_printf ("Command\r\n");
|
||||
s_run = End;
|
||||
s_run_timer = 50;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if(s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
UartInfoWriteData(uEth,"{\"Command\":\"config\"}",strlen("{\"Command\":\"config\"}"));
|
||||
dbg_printf("Command\r\n");
|
||||
s_run = End;
|
||||
s_run_timer = 3000;
|
||||
}
|
||||
// 获取发送的数据
|
||||
}
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_run = FistIn;
|
||||
DeviceState = DeviceGetPara;
|
||||
}
|
||||
break;
|
||||
// 获取发送的数据
|
||||
}
|
||||
case DeviceGetPara:
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (UartInfoRxIsReady(uEth) == 1)
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
dbg_printf("DeviceGetPara\r\n");
|
||||
rx_size = UartInfoReadData(uEth,(char *)s_buffer,1024);
|
||||
dbg_printf("(%d)[%d]\r\n",rx_size,s_buffer[0]) ;
|
||||
DeviceState = DeviceSetPara;
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeviceSetPara:
|
||||
else
|
||||
{
|
||||
if(s_run == FistIn)
|
||||
{
|
||||
memset(s_buffer,0,1024);
|
||||
//dbg_printf("subtopic:%s\r\n",(char *)pstWork_Pragma->stExternPragma.stMQTTClient.SubTopic);
|
||||
sprintf(s_buffer,
|
||||
"{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":%d,\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\"}",
|
||||
"Command", "config",
|
||||
"RemoteHost",SysInfo.remoteAddr,
|
||||
"RemotePort",SysInfo.remotePort,
|
||||
"WorkMode","MQTT",
|
||||
"UserName",SysInfo.remoteuser,
|
||||
"Password" ,SysInfo.remotepass,
|
||||
"PubTopic",pub_topic,
|
||||
"SubTopic",sub_topic
|
||||
);
|
||||
//SetParametersToData(pstWork_Pragma,(char *)s_buffer,1024);
|
||||
dbg_printf("%s\r\n",s_buffer);
|
||||
UartInfoWriteData(uEth,s_buffer,strlen(s_buffer));
|
||||
s_run_timer = 1000;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if(s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
UartInfoWriteData(uEth,"{\"Command\":\"exit\"}",strlen("{\"Command\":\"exit\"}"));
|
||||
dbg_printf("Command\r\n");
|
||||
s_run = End;
|
||||
s_run_timer = 50;
|
||||
}
|
||||
// 获取发送的数据
|
||||
}
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_run = FistIn;
|
||||
DeviceState = DeviceReset;
|
||||
}
|
||||
break;
|
||||
s_run = FistIn;
|
||||
DeviceState = DeviceReset;
|
||||
}
|
||||
case DeviceReset:
|
||||
break;
|
||||
}
|
||||
case DeviceReset:
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
if (s_run == FistIn)
|
||||
{
|
||||
|
||||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
|
||||
s_run_timer = 500;
|
||||
s_run = Runing;
|
||||
}
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
if(s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
s_run = End;
|
||||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
|
||||
dbg_printf("Reboot Finsh\r\n");
|
||||
s_run_timer = 3000;
|
||||
}
|
||||
}
|
||||
else if (s_run == End){
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
dbg_printf("Reboot Finsh\r\n");
|
||||
UartInfoClearData (uEth) ;
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
s_run = FistIn ;
|
||||
DeviceState = DeviceIdle;
|
||||
}
|
||||
break;
|
||||
|
||||
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
s_run_timer = 500;
|
||||
s_run = Runing;
|
||||
}
|
||||
case DeviceLink:// 检查上线
|
||||
else if (s_run == Runing)
|
||||
{
|
||||
s_isconnect = 1;
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
s_run_timer = 0;
|
||||
s_run = End;
|
||||
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
|
||||
dbg_printf ("Reboot Finsh\r\n");
|
||||
s_run_timer = 3000;
|
||||
}
|
||||
}
|
||||
else if (s_run == End)
|
||||
{
|
||||
if (s_run_timer == 1)
|
||||
{
|
||||
dbg_printf ("Reboot Finsh\r\n");
|
||||
UartInfoClearData (uEth) ;
|
||||
s_run = JumpUp;
|
||||
s_run_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_run = FistIn ;
|
||||
DeviceState = DeviceIdle;
|
||||
break;
|
||||
}
|
||||
case DeviceIdle:
|
||||
break;
|
||||
}
|
||||
case DeviceLink:// 检查上线
|
||||
{
|
||||
s_isconnect = 1;
|
||||
DeviceState = DeviceIdle;
|
||||
break;
|
||||
}
|
||||
case DeviceIdle:
|
||||
{
|
||||
if (s_lost_timer == 0)
|
||||
{
|
||||
if (s_lost_timer == 0)
|
||||
if (EthMqttIsConnect())
|
||||
{
|
||||
if (EthMqttIsConnect())
|
||||
{
|
||||
EthMqttConnectd();
|
||||
s_lost_timer = 60000;
|
||||
}
|
||||
// 第一次上线
|
||||
EthMqttConnectd();
|
||||
s_lost_timer = 60000;
|
||||
}
|
||||
break;
|
||||
// 第一次上线
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (s_lost_timer == 1)
|
||||
{
|
||||
@@ -358,17 +364,17 @@ void EthMqttTask(void)
|
||||
s_run = FistIn ;
|
||||
}
|
||||
}
|
||||
int EthMqttReSubTopic(char * topic)
|
||||
int EthMqttReSubTopic (char * topic)
|
||||
{
|
||||
char addr_str[10];
|
||||
memset(addr_str,0,10);
|
||||
hexbyte_to_hex_str((char *)SysInfo.Addr,addr_str,4);
|
||||
memset(sub_topic,0,64);
|
||||
sprintf(sub_topic,"device/%s/tx/22000073%s",topic,addr_str);
|
||||
memset(pub_topic,0,64);
|
||||
sprintf(pub_topic,"device/%s/rx/22000073%s",topic,addr_str);
|
||||
|
||||
dbg_printf("EthMqttReSubTopic\r\n");
|
||||
char addr_str[10];
|
||||
memset (addr_str, 0, 10);
|
||||
hexbyte_to_hex_str ( (char *) SysInfo.Addr, addr_str, 4);
|
||||
memset (sub_topic, 0, 64);
|
||||
sprintf (sub_topic, "device/%s/tx/22000073%s", topic, addr_str);
|
||||
memset (pub_topic, 0, 64);
|
||||
sprintf (pub_topic, "device/%s/rx/22000073%s", topic, addr_str);
|
||||
|
||||
dbg_printf ("EthMqttReSubTopic\r\n");
|
||||
// memset(sub_topic,0,64);
|
||||
// sprintf(sub_topic,"device/%s/tx/22000000%08x",topic,SysInfo.Addr);
|
||||
// memset(pub_topic,0,64);
|
||||
|
||||
Reference in new issue
Block a user