新建项目

This commit is contained in:
gitea committed 2023-04-29 09:09:12 +08:00
1 parent 5e2e890cfc
commit 633d9b872b
1351 files changed
+730564

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
#include "main.h"
int DiReadChann(int chann)
{
int ret = -1;
switch(chann)
{
case 1:
{
ret = HAL_GPIO_ReadPin(DI1_GPIO_Port,DI1_Pin);
break;
}
case 2:
{
ret = HAL_GPIO_ReadPin(DI2_GPIO_Port,DI2_Pin);
break;
}
case 3:
{
ret = HAL_GPIO_ReadPin(DI3_GPIO_Port,DI4_Pin);
break;
}
case 4:
{
ret = HAL_GPIO_ReadPin(DI4_GPIO_Port,DI4_Pin);
break;
}
case 5:
{
ret = HAL_GPIO_ReadPin(DI5_GPIO_Port,DI5_Pin);
break;
}
case 6:
{
ret = HAL_GPIO_ReadPin(DI6_GPIO_Port,DI6_Pin);
break;
}
}
return ret;
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef _DI_BOARD_H
#define _DI_BOARD_H
void DiInit(void);
int DiReadChann(int chann);
#endif
+377
View File
@@ -0,0 +1,377 @@
#include "eth-board.h"
#include "usart.h"
#include "proto-sl651.h"
#include <string.h>
// 尝试创建Socket
const char
void EthMqttTick(void)
{
if (s_tx_timeout > 1)
s_tx_timeout--;
if (s_run_timer > 1)
s_run_timer--;
if (s_lost_timer > 1)
s_lost_timer--;
}
//void EthMqttReboot(void)
//{
// DelayMs(500);
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
//}
static enum {
DeviceReboot,
DeviceConfig,
DeviceGetPara,
DeviceSetPara,
DeviceReset,
DeviceLink,
DeviceIdle,
}DeviceState = DeviceReboot ;
static enum {
FistIn,
Runing,
End,
JumpUp
}s_run = FistIn;
// NetFunc.Init = EthMqttInit;
// NetFunc.IsConnected = EthMqttIsConnect;
// NetFunc.IsReady = EthMqttIsReady;
// NetFunc.ReadData = EthMqttReadData;
// NetFunc.WriteData = EthMqttWriteData;
// NetFunc.IsIdle = EthMqttIsIdle;
// NetFunc.ReSubTopic = EthMqttReSubTopic;
// NetFunc.Task = EthMqttTask;
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;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// 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;
// // 状态
// GPIO_InitStruct.Pin = GPIO_PIN_4;
// HAL_GPIO_Init (GPIOC, &GPIO_InitStruct);
// memset(addr_str,0,10);
// hexbyte_to_hex_str((char *)SysInfo.Addr,addr_str,4);
// UartInfoInit(uEth); // 初始化以太网接口
// memset(sub_topic,0,64);
// sprintf(sub_topic,"device/sluice/tx/22000073%s",addr_str);
// memset(pub_topic,0,64);
// sprintf(pub_topic,"device/sluice/rx/22000073%s",addr_str);
// s_tx_timeout = 1;
}
// // 上线
// void EthMqttConnectd (void)
// {
// s_isconnect = 1;
// //DisWriteNetSte (1, QUEUE);
// s_lost_timer = 60000;
// dbg_printf("Eth Device Isconnected \r\n");
// }
// 掉线
void EthMqttDisConnectd (void)
{
s_lost_timer = 0;
DisWriteNetSte (2, QUEUE);
DeviceState = DeviceReboot;
dbg_printf("Eth Device IsDisconnected \r\n");
}
int EthMqttReadData(char * buf,int length)
{
int k =0;
if (UartInfoRxIsReady(uEth) == 1)
{
k = UartInfoReadData(uEth,(char *)buf,length);
dbg_printf("<<<<<<<<<<<<%d\r\n",k);
s_lost_timer = 60000;
DisWriteNetSte (1, QUEUE);
}
return k;
}
int EthMqttIsReady(void)
{
if (DeviceState != DeviceIdle )
{
return 0;
}
else
{
return UartInfoRxIsReady(uEth);
}
}
void EthMqttWriteData(char * data,int length)
{
UartInfoWriteData(uEth,data,length);
}
int EthMqttIsIdle(void)
{
if (EthMqttIsConnect() == 0)
{
return 0;
}
if (DeviceState == DeviceIdle)
return 1;
return 0;
}
int EthMqttIsConnect(void)
{
if (HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_4) == GPIO_PIN_SET)
return 1;
else
return 0;
//return s_isconnect;
}
void EthMqttTask(void)
{
int rx_size;
char str[128];
//static pst_Work_Pragma pstWork_Pragma;
switch(DeviceState)
{
case DeviceReboot:
{
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;
}
// 这里要等待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;
}
// 获取发送的数据
}
else if (s_run == End)
{
if (s_run_timer == 1)
{
s_run = JumpUp;
s_run_timer = 0;
}
}
else
{
s_run = FistIn;
DeviceState = DeviceReset;
}
break;
}
case DeviceReset:
{
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;
}
case DeviceLink:// 检查上线
{
s_isconnect = 1;
DeviceState = DeviceIdle;
break;
}
case DeviceIdle:
{
if (s_lost_timer == 0)
{
if (EthMqttIsConnect())
{
EthMqttConnectd();
s_lost_timer = 60000;
}
// 第一次上线
}
break;
}
}
if (s_lost_timer == 1)
{
EthMqttDisConnectd();
s_run = FistIn ;
}
}
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");
// memset(sub_topic,0,64);
// sprintf(sub_topic,"device/%s/tx/22000000%08x",topic,SysInfo.Addr);
// memset(pub_topic,0,64);
// sprintf(pub_topic,"device/%s/rx/22000000%08x",topic,SysInfo.Addr);
EthMqttDisConnectd();
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef _ETH_BOARD_H
#define _ETH_BOARD_H µçѹ
void EthMqttTick(void);
void EthMqttTask(void);
void EthMqttInit(void);
int EthMqttReadData(char * buf,int length);
int EthMqttIsReady(void);
void EthMqttWriteData(char * data,int length);
int EthMqttIsIdle(void);
int EthMqttIsConnect(void);
int EthMqttReSubTopic(char * topic);
#endif
+79
View File
@@ -0,0 +1,79 @@
#include "pwm-board.h"
void PwmInfoInit()
{
GPIO_InitTypeDef GPIO_InitStruct;
MX_TIM2_PWMInit(5); // PA15
// // __HAL_RCC_GPIOA_CLK_ENABLE();
// // __HAL_RCC_GPIOB_CLK_ENABLE();
//// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
//// GPIO_InitStruct.Pull = GPIO_PULLUP;
//// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
//// GPIO_InitStruct.Pin = GPIO_PIN_15;
//// HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
//// HAL_GPIO_WritePin(GPIOA,GPIO_PIN_15,GPIO_PIN_RESET);
//
// //TIM2-CH2 PB3 GPIO_AF2_TIM2
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// //GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;
// GPIO_InitStruct.Pin = GPIO_PIN_3;
// HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_SET);
//
// //TIM2-CH3 PB10 GPIO_AF2_TIM2
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// //GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;
// GPIO_InitStruct.Pin = GPIO_PIN_10;
// HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET);
// //TIM2-CH3 PB11 GPIO_AF2_TIM2
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// //GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;
// GPIO_InitStruct.Pin = GPIO_PIN_11;
// HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET);
//
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_RESET);
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET);
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_RESET);
////
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_SET);
//// HAL_Delay(10);
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_SET);
//// HAL_Delay(10);
//// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET);
//// HAL_Delay(10);
// //PwmInfoStart(1);
// //PwmInfoStart(2);
// //PwmInfoStart(3);
// //PwmInfoStart(4);
PwmInfoSetDuty(1,100) ;// 全部默认100 占空比
PwmInfoSetDuty(2,100) ;// 全部默认100 占空比
PwmInfoSetDuty(3,100) ;// 全部默认100 占空比
PwmInfoSetDuty(4,100) ;// 全部默认100 占空比
}
// 占空比
void PwmInfoSetDuty(int index,int duty)
{
MX_TIM2_PWMStart(index,duty);
}
//void PwmInfoStop(int index)
//{
// MX_TIM2_PWMStop(index);
//}
+19
View File
@@ -0,0 +1,19 @@
#ifndef _PWM_BOARD_H
#define _PWM_BOARD_H
#include "stm32l0xx_hal.h"
#include "stgpio.h"
#include "tim.h"
#define PWM_DIO 0//设置为普通IO空输出
#define PWM_PWM 1//设置为PWM输出
void PwmInfoInit(void);
void PwmInfoSetDuty(int index,int duty);
void PwmInfoStop(int index) ;
#endif
+53
View File
@@ -0,0 +1,53 @@
#include "relay-board.h"
RelayInfo_t RelayInfo = {
{GPIOB, GPIO_PIN_8, GPIO_MODE_OUTPUT_PP,GPIO_PULLUP, GPIO_SPEED_FREQ_VERY_HIGH, NULL}, //PB5
{GPIOB, GPIO_PIN_9, GPIO_MODE_OUTPUT_PP,GPIO_PULLUP, GPIO_SPEED_FREQ_VERY_HIGH, NULL}, //PB5
};
/********************************************
函数名称:UartInfoInit
输入参数:串口句柄
输出参数:NULL
功能描述:初始化一个串口
********************************************/
void RelayInfoInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Mode = RelayInfo.Relay1.mode;
GPIO_InitStruct.Pull = RelayInfo.Relay1.Pull;
GPIO_InitStruct.Speed = RelayInfo.Relay1.Speed;
GPIO_InitStruct.Pin = RelayInfo.Relay1.pin;
HAL_GPIO_Init (RelayInfo.Relay1.GPIOx, &GPIO_InitStruct);
HAL_GPIO_WritePin(RelayInfo.Relay1.GPIOx,RelayInfo.Relay1.pin,GPIO_PIN_RESET);
GPIO_InitStruct.Mode = RelayInfo.Relay2.mode;
GPIO_InitStruct.Pull = RelayInfo.Relay2.Pull;
GPIO_InitStruct.Speed = RelayInfo.Relay2.Speed;
GPIO_InitStruct.Pin = RelayInfo.Relay2.pin;
HAL_GPIO_Init (RelayInfo.Relay2.GPIOx, &GPIO_InitStruct);
HAL_GPIO_WritePin(RelayInfo.Relay2.GPIOx,RelayInfo.Relay2.pin,GPIO_PIN_RESET);
}
void RelayOpenDoor(void)
{
HAL_GPIO_WritePin(RelayInfo.Relay1.GPIOx,RelayInfo.Relay1.pin,GPIO_PIN_SET);
}
void RelayCloseDoor(void)
{
HAL_GPIO_WritePin(RelayInfo.Relay1.GPIOx,RelayInfo.Relay1.pin,GPIO_PIN_RESET);
}
void RelayOpenK2(void)
{
HAL_GPIO_WritePin(RelayInfo.Relay2.GPIOx,RelayInfo.Relay2.pin,GPIO_PIN_SET);
}
void RelayCloseK2(void)
{
HAL_GPIO_WritePin(RelayInfo.Relay2.GPIOx,RelayInfo.Relay2.pin,GPIO_PIN_RESET);
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef _RELAY_BOARD_H
#define _RELAY_BOARD_H
#include "stm32l0xx_hal.h"
#include "stgpio.h"
typedef struct RelayInfo_t
{
// GpioInfo_t Tx;
// GpioInfo_t Rx;
GpioInfo_t Relay1; // 用于控制485的收发
GpioInfo_t Relay2; // 用于控制485的收发
}RelayInfo_t;
void RelayInfoInit(void);
void RelayOpenDoor(void);
void RelayCloseDoor(void);
void RelayOpenK2(void);
void RelayCloseK2(void);
#endif