133 lines
2.7 KiB
C
133 lines
2.7 KiB
C
#include <cat1drv.h>
|
||
#include <rtthread.h>
|
||
#include <os-app.h>
|
||
#include "main.h"
|
||
#include "usart-board.h"
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <easyflash.h>
|
||
#include "netdrv.h"
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#if !defined(LOG_TAG)
|
||
#define LOG_TAG "CAT1"
|
||
#endif
|
||
#include <elog.h>
|
||
|
||
|
||
ALIGN (RT_ALIGN_SIZE)
|
||
static char thread_stack[4096];
|
||
static struct rt_thread thread;
|
||
static char tcprxbbuff[1200];
|
||
static char tcptxbbuff[1200];
|
||
|
||
|
||
static const uint8_t header[] = {0xed, 0xf2, 0xa3, 0x56, 0xca, 0xdb, 0x91, 0x84, 0xb0, 0xd7};
|
||
static const uint8_t readip[] = {0xed, 0xf2, 0xa3, 0x56, 0xca, 0xdb, 0x91, 0x84, 0xb0, 0xd7, 0x00, 0x00, 0x04};
|
||
|
||
|
||
netDrv_t g_ZS001Drv =
|
||
{
|
||
0, // 信号值
|
||
"", // iccid
|
||
Init, // 状态
|
||
tcprxbbuff, // 接受缓存
|
||
0, // 接受数据长度
|
||
tcptxbbuff, // 发送数据缓存
|
||
0, // 发送数据长度
|
||
};
|
||
|
||
|
||
static void zs001_rx_done (void)
|
||
{
|
||
rt_event_send (gUartEvents, EVENT_UART_ETH1_RX);
|
||
|
||
}
|
||
|
||
|
||
|
||
static int zs001_packet_commad (int type, int loc, int size, char * data)
|
||
{
|
||
int index = 0;
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
data[index++] = header[i];
|
||
}
|
||
data[index++] = type;
|
||
data[index++] = loc;
|
||
data[index++] = size;
|
||
return index;
|
||
}
|
||
|
||
|
||
static void thread_entry (void * argument)
|
||
{
|
||
|
||
// char at_cmd[128] = {NULL};
|
||
// char ipaddr[32] = {NULL};
|
||
// int ipport;
|
||
// char *p;
|
||
// int retry = 0;
|
||
|
||
|
||
|
||
// char send_data[32];
|
||
// int size = 0;
|
||
// size = zs001_packet_commad(0,)
|
||
// p = ef_get_env ("mqtt_addr");
|
||
// rt_strncpy (ipaddr, p, rt_strlen (p));
|
||
// p = ef_get_env ("mqtt_port");
|
||
// ipport = atoi (p);
|
||
//rt_sprintf (at_cmd, "AT+QIOPEN=1,0,\"TCP\",\"%s\",%d,0,0\r", ipaddr, ipport);
|
||
g_ETH1Drv.rxdone = zs001_rx_done;
|
||
g_ETH1Drv.BaudRate = 115200;
|
||
// 启动4G 模块电源
|
||
// 拉高4G 模块复位
|
||
MX_UART_Init (&g_ETH1Drv);
|
||
HAL_GPIO_WritePin (ETH_RST_GPIO_Port, ETH_RST_Pin, GPIO_PIN_SET);
|
||
rt_thread_mdelay (1000);
|
||
HAL_GPIO_WritePin (GPIOA, ETH_PW_Pin | GSM_PW_Pin, GPIO_PIN_SET);
|
||
rt_thread_mdelay (3000);
|
||
while (1)
|
||
{
|
||
|
||
// rt_kprintf("zs0010+++++++++++++++++++\r\n");
|
||
MX_UART_PutBuffer (&g_ETH1Drv, (char *) readip, 13) ;
|
||
|
||
// 发送数据
|
||
if (RT_EOK == rt_event_recv (gUartEvents, EVENT_UART_ETH1_RX, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 2000, RT_NULL)) // 需要发送数据
|
||
{
|
||
for (int i = 0 ; i < g_ETH1Drv.rx_size; i++)
|
||
{
|
||
rt_kprintf ("%02X", g_ETH1Drv.rx_buffer[i]);
|
||
}
|
||
rt_kprintf ("\r\n");
|
||
MX_UART_Clear (&g_ETH1Drv) ;
|
||
}
|
||
|
||
rt_thread_mdelay (3000);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
void ZS001ThreadStart (void)
|
||
{
|
||
/* 创建线程1,名称是thread1,入口是thread1_entry */
|
||
rt_thread_init (&thread, "zs001_thread",
|
||
thread_entry, RT_NULL,
|
||
&thread_stack[0],
|
||
sizeof (thread_stack),
|
||
ZS001_THREAD_PRIORITY, ZS001_THREAD_TIMESLICE);
|
||
rt_thread_startup (&thread);
|
||
|
||
return ;
|
||
}
|