Commit d272b692 by zhanggf

Debug OK.

Signed-off-by: zhanggf <zhanggf@example.com>
parent 78c1bd59
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
\ No newline at end of file
{
"files.associations": {
"cyton_esp12data.h": "c",
"key.h": "c",
"myqueue.h": "c",
"esp8266.h": "c",
"usart.h": "c",
"cyton_process.h": "c",
"cyton_datapkg.h": "c"
}
}
\ No newline at end of file
......@@ -9,6 +9,9 @@
#include "myQueue.h"
#define CYTON__DATA_PKG_BUF_LEN (33)
static uint8_t aucSampNumber = 0;
void Cyton_DataPkg_ClearSampNum()
......@@ -43,3 +46,8 @@ int Cyton_DataFormat2Package(uint8_t *pszData, uint32_t pszDataChannel[], uint8_
return (pszIndex - pszData);
}
int Cyton_GetDataPkg_Len()
{
return CYTON__DATA_PKG_BUF_LEN;
}
\ No newline at end of file
......@@ -11,5 +11,6 @@
void Cyton_DataPkg_ClearSampNum();
int Cyton_DataFormat2Package(uint8_t *pszData, uint32_t pszDataChannel[], uint8_t aucChannelCnt);
int Cyton_GetDataPkg_Len();
#endif
......@@ -201,10 +201,11 @@ void Ctron_Esp12Data_Recv(int iFD, uint8_t *szData, int iLen)
ESP8266_DEBUG("stream start rsp\n");
g_stCytron_DevSeting.aucStreamStat = 1;
Ctron_Esp12Data_Send(iFD, (uint8_t *)szStreamStartRsp, strlen(szStreamStartRsp), 1);
CytonProcess_TimerCollStart(1000);
} else if (strstr(szData, "/stream/stop")) {
ESP8266_DEBUG("stream stop rsp\n");
g_stCytron_DevSeting.aucStreamStat = 0;
CytonProcess_TimerCollStop();
Ctron_Esp12Data_Send(iFD, (uint8_t *)szStreamStopRsp, strlen(szStreamStopRsp), 1);
} else {
ESP8266_DEBUG("Prase failed\n");
......@@ -215,12 +216,13 @@ void Ctron_Esp12Data_Send(int iFD, uint8_t *szData, int iLen, int iClose)
{
uint8_t szCmd[64] = 0;
delay_ms(20);
sprintf(szCmd, "AT+CIPSEND=%d,%d\r\n", iFD, iLen);
/* AT+CIPSEND=<link ID>,<length> */
ESP8266_SendCmd(szCmd, ">", 100);
ESP8266_SendData(szData, iLen);
//delay_ms(20);
if (iClose) {
delay_ms(200);
memset(szCmd, 0, sizeof(szCmd));
......@@ -262,4 +264,37 @@ int CytonEsp12_StreamStat()
return g_stCytron_DevSeting.aucStreamStat;
}
int CytonEsp12_GetCurrentRate()
{
int iRate = g_stCytron_DevSeting.aucRate;
int iRet = 1000;
switch(iRate) {
case 0:
iRet = 16000;
break;
case 1:
iRet = 8000;
break;
case 2:
iRet = 4000;
break;
case 3:
iRet = 2000;
break;
case 4:
iRet = 1000;
break;
case 5:
iRet = 500;
case 6:
iRet = 250;
break;
default:
break;
}
return iRet;
}
......@@ -29,5 +29,6 @@ void Ctron_Esp12Data_Recv(int iFd, uint8_t *szData, int iLen);
void Ctron_Esp12Data_Send(int iFd, uint8_t *szData, int iLen, int iClose);
int CytonEsp12_DataGetReportFd();
int CytonEsp12_StreamStat();
int CytonEsp12_GetCurrentRate();
#endif
#include "Cyton_Process.h"
#include "Cyton_SysApi.h"
#include "usart.h"
#include <string.h>
#include "delay.h"
......@@ -11,8 +12,88 @@
#include "myQueue.h"
static uint8_t g_szCytonProcess_DataCache[512] = {0};
static int g_iPackageOffset = 0;
#define CYTON_COLLECTOR_DATA_CACHE_LEN (4096)
typedef struct stCyton_DataCacheInfo {
uint8_t DataCache[CYTON_COLLECTOR_DATA_CACHE_LEN + 1];
uint32_t iSendIndex;
uint32_t iWriteIndex;
uint32_t iWriteMax;
} CYTON_DATACACHE_INFO_T;
static CYTON_DATACACHE_INFO_T g_stCyton_DataCache;
static void cyton_dataCacheClear()
{
memset(&g_stCyton_DataCache, 0, sizeof(CYTON_DATACACHE_INFO_T));
}
static void cyton_SetdataCacheMaxByOnePkg(uint8_t aucLen)
{
g_stCyton_DataCache.iWriteMax = CYTON_COLLECTOR_DATA_CACHE_LEN / aucLen * aucLen;
}
static uint8_t * cyton_getUnsendData(int *iLen)
{
int iOneBufLen = 0;
iOneBufLen = Cyton_GetDataPkg_Len();
if (g_stCyton_DataCache.iWriteIndex != g_stCyton_DataCache.iSendIndex) {
if (g_stCyton_DataCache.iWriteIndex > g_stCyton_DataCache.iSendIndex) {
*iLen = g_stCyton_DataCache.iWriteIndex - g_stCyton_DataCache.iSendIndex;
} else {
*iLen = g_stCyton_DataCache.iWriteMax - g_stCyton_DataCache.iSendIndex;
}
if (*iLen > 2048) {
*iLen = 2048 / iOneBufLen * iOneBufLen;
}
return &g_stCyton_DataCache.DataCache[g_stCyton_DataCache.iSendIndex];
}
return NULL;
}
static void cyton_setSendDataDone(int iLen)
{
g_stCyton_DataCache.iSendIndex += iLen;
if (g_stCyton_DataCache.iSendIndex >= g_stCyton_DataCache.iWriteMax) {
g_stCyton_DataCache.iSendIndex = 0;
}
//ESP8266_DEBUG("g_stCyton_DataCache.iSendIndex %d\n", g_stCyton_DataCache.iSendIndex);
}
void CytonProcess_TimerCollCB(int iTIndex)
{
int iRet = 0;
uint32_t puiChannel[8];
//ESP8266_DEBUG("CytonProcess_TimerCollCB %d\n", iTIndex);
iRet = Cyton_DataFormat2Package(&g_stCyton_DataCache.DataCache[g_stCyton_DataCache.iWriteIndex], puiChannel, CYTON_DATA_PKG_CHANNEL8);
g_stCyton_DataCache.iWriteIndex += iRet;
if (g_stCyton_DataCache.iWriteIndex >= g_stCyton_DataCache.iWriteMax) {
g_stCyton_DataCache.iWriteIndex = 0;
}
//ESP8266_DEBUG("g_stCyton_DataCache.iWriteIndex %d\n", g_stCyton_DataCache.iWriteIndex);
}
void CytonProcess_TimerCollStart(int iHz)
{
int iOneBufLen = 0;
cyton_dataCacheClear();
iOneBufLen = Cyton_GetDataPkg_Len();
cyton_SetdataCacheMaxByOnePkg(iOneBufLen);
CytonSys_CollectorTimerStart(iHz, CytonProcess_TimerCollCB);
}
void CytonProcess_TimerCollStop()
{
CytonSys_Stop();
}
void CytonProcess_Loop()
{
......@@ -20,18 +101,19 @@ void CytonProcess_Loop()
uint32_t puiChannel[8];
int iFd = -1;
int iStreamStat = 0;
uint8_t *pszSendBuf = NULL;
int iSendBufLen = 0;
iFd = CytonEsp12_DataGetReportFd();
iStreamStat = CytonEsp12_StreamStat();
if (iFd >= 0 && iStreamStat) {
iRet = Cyton_DataFormat2Package(&g_szCytonProcess_DataCache[g_iPackageOffset], puiChannel, CYTON_DATA_PKG_CHANNEL8);
g_iPackageOffset += iRet;
if (g_iPackageOffset > 330) {
ESP8266_DEBUG("Start Report Data %d\n", g_iPackageOffset);
Ctron_Esp12Data_Send(iFd, (uint8_t *)g_szCytonProcess_DataCache, g_iPackageOffset, 0);
g_iPackageOffset = 0;
pszSendBuf = cyton_getUnsendData(&iSendBufLen);
if (NULL != pszSendBuf) {
ESP8266_DEBUG("Start Report Data %d\n", iSendBufLen);
Ctron_Esp12Data_Send(iFd, pszSendBuf, iSendBufLen, 0);
ESP8266_DEBUG("Start Report Data End\n");
cyton_setSendDataDone(iSendBufLen);
}
}
}
\ No newline at end of file
......@@ -6,5 +6,7 @@
void CytonProcess_Loop();
void CytonProcess_TimerCollStart(int iHz);
void CytonProcess_TimerCollStop();
#endif
#include "Cyton_SysApi.h"
#include "usart.h"
#include <string.h>
#include "delay.h"
#include "led.h"
#include "key.h"
#include "Timer.h"
#include "ADS129x.h"
#include "myQueue.h"
static CYTON_SYS_API_TIMER_CB g_pfCollectorTimerCB = NULL;
static int g_iSysApi_collectorTIndex = 0;
void CytonSys_CollectorTimerStart(int iHz, CYTON_SYS_API_TIMER_CB pfCB)
{
int iArr = 0;
g_pfCollectorTimerCB = pfCB;
/* 10000 1s CB.*/
iArr = 10000 / iHz;
/* 7200 0000 */
TIM1_Init(iArr, 7200);
TIM1_Start();
}
void CytonSys_Stop()
{
TIM1_Stop();
}
void CytonSys_CollectorCB()
{
g_iSysApi_collectorTIndex ++;
if (g_pfCollectorTimerCB) {
(*g_pfCollectorTimerCB)(g_iSysApi_collectorTIndex);
}
}
\ No newline at end of file
#ifndef __CYTON_SYS_API_H
#define __CYTON_SYS_API_H
#include "sys.h"
#include "myQueue.h"
typedef void (*CYTON_SYS_API_TIMER_CB)(int iTimeIndex);
void CytonSys_CollectorTimerStart(int iHz, CYTON_SYS_API_TIMER_CB pfCB);
void CytonSys_Stop();
void CytonSys_CollectorCB();
#endif
......@@ -47,22 +47,28 @@ u8 Wifi_Sendbuf_Init(void)
}
//发送指令,并判断指定字符串是否缓冲区中
//返回-1 没有指定的串
//0-125 字符串在数组中的位置
s16 ESP8266_SendCmd(u8* cmd, u8* result, u16 timeOut)
{
s16 res;
s16 res = -1;
if (NULL == strstr(USART2_RX_BUF, "+IPD,")) {
ESP8266_CLEAR();//清空缓冲区
}
USARTx_Send(ESP8266_UART,(uint8_t*) cmd, strlen(cmd));
delay_ms(timeOut);
while(timeOut > 0) {
timeOut --;
delay_ms(1);
res = Str_search(ESP8266_RX_BUF, ESP8266_RX_LEN, result);//查询字符串
if (res > 0) {
ESP8266_DEBUG("ESP8266 rsp:%s \r\n",ESP8266_RX_BUF);
res = Str_search(ESP8266_RX_BUF,ESP8266_RX_LEN,result);//查询字符串
return res;
}
}
return res;
}
......@@ -384,6 +390,16 @@ void ESP8266_Config_Http_connectTcp(void)
{
ESP8266_Goto_Cmd();//进入AT指令模式
ESP8266_DEBUG("select version:\r\n");
while(1)
{
if(ESP8266_SendCmd("AT+GMR\r\n", "OK", 500) >= 0)//设置单链接模式,用于透传,开机默认单链接
break;
else
LED2=!LED2;
}
ESP8266_DEBUG("设置工作模式:AP \r\n");
while(1)
{
......@@ -456,13 +472,13 @@ void ESP8266_Config_Http_connectTcp(void)
}
ESP8266_DEBUG("\r\n等待连接WIFI\r\n");
//CytonProcess_TimerCollStart();
while(1)
{
delay_ms(10);
if (USART2_RX_LEN > 35)
ESP8266_DEBUG("ESP8266 rsp (%d):%s \r\n",USART2_RX_LEN, ESP8266_RX_BUF);
//if (USART2_RX_LEN > 35)
// ESP8266_DEBUG("ESP8266 rsp (%d):%s \r\n",USART2_RX_LEN, ESP8266_RX_BUF);
if (USART2_RX_LEN == 20) {
//ESP8266_DEBUG("Start connect 1234\r\n");
......
......@@ -2,7 +2,7 @@
#include "led.h"
#include "key.h"
#include "adc.h"
#include "Cyton_SysApi.h"
......@@ -37,6 +37,17 @@ void TIM1_Init(u16 arr,u16 psc)
TIM_ITConfig(TIM1, TIM_IT_Update|TIM_IT_Trigger, ENABLE );//允许更新
TIM_Cmd(TIM1, DISABLE);
}
void TIM1_Start()
{
TIM_Cmd(TIM1, ENABLE);
}
void TIM1_Stop()
{
TIM_Cmd(TIM1, DISABLE);
}
//定时器中断服务程序
void TIM1_UP_IRQHandler(void)
{
......@@ -44,6 +55,7 @@ void TIM1_UP_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_Update);//清中断标志
Tim1_flag++;
CytonSys_CollectorCB();
}
}
......
......@@ -11,6 +11,9 @@ extern u8 TIM4_Timing;
void TIM1_Init(u16 arr,u16 psc);
void TIM1_Start();
void TIM1_Stop();
void TIM2_Init(u16 arr,u16 psc);
void TIM3_Init(u16 arr,u16 psc);
void TIM4_Init(u16 arr,u16 psc);
......
......@@ -30,7 +30,7 @@
//内存参数设定.
#define MEM_BLOCK_SIZE 32 //内存块大小为32字节
#define MEM_MAX_SIZE 12*1024 //最大管理内存
#define MEM_MAX_SIZE 4*1024 //最大管理内存
#define MEM_ALLOC_TABLE_SIZE MEM_MAX_SIZE/MEM_BLOCK_SIZE //内存表大小
......
......@@ -149,7 +149,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U460024000D00004637364D4E -I0 -O9422 -S1 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO31 -FD20000000 -FC1000 -FN0</Name>
<Name>-U303030303030303030303031 -I0 -O9422 -S1 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO31 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash/STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
......@@ -628,7 +628,7 @@
<Group>
<GroupName>USER</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
......@@ -931,4 +931,98 @@
</File>
</Group>
<Group>
<GroupName>CYTON</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>50</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Cyton\Cyton_Esp12Data.c</PathWithFileName>
<FilenameWithoutPath>Cyton_Esp12Data.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>51</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Cyton\Cyton_PraseCmd.c</PathWithFileName>
<FilenameWithoutPath>Cyton_PraseCmd.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>52</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Cyton\cJSON.c</PathWithFileName>
<FilenameWithoutPath>cJSON.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>53</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Cyton\Cyton_DataPkg.c</PathWithFileName>
<FilenameWithoutPath>Cyton_DataPkg.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>54</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Cyton\Cyton_Process.c</PathWithFileName>
<FilenameWithoutPath>Cyton_Process.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>CYTON_HAL</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>8</GroupNumber>
<FileNumber>55</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\CytonHal\Cyton_SysApi.c</PathWithFileName>
<FilenameWithoutPath>Cyton_SysApi.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
</ProjectOpt>
......@@ -347,7 +347,7 @@
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>1</Optim>
<Optim>3</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>0</OneElfS>
......@@ -365,7 +365,7 @@
<MiscControls></MiscControls>
<Define>STM32F10X_MD,USE_STDPERIPH_DRIVER</Define>
<Undefine></Undefine>
<IncludePath>..\USER;..\STM32F10x_FWLib\inc;..\SYSTEM;..\Hardware;..\Fatfs\exfuns;..\Fatfs\src;..\Fatfs\src\option;..\ADS129x;..\LCD;..\USB\CONFIG;..\USB\STM32_USB-FS-Device_Driver\inc</IncludePath>
<IncludePath>..\USER;..\STM32F10x_FWLib\inc;..\SYSTEM;..\Hardware;..\Fatfs\exfuns;..\Fatfs\src;..\Fatfs\src\option;..\ADS129x;..\LCD;..\USB\CONFIG;..\USB\STM32_USB-FS-Device_Driver\inc;..\Cyton;..\CytonHal</IncludePath>
</VariousControls>
</Cads>
<Aads>
......@@ -820,6 +820,46 @@
</File>
</Files>
</Group>
<Group>
<GroupName>CYTON</GroupName>
<Files>
<File>
<FileName>Cyton_Esp12Data.c</FileName>
<FileType>1</FileType>
<FilePath>..\Cyton\Cyton_Esp12Data.c</FilePath>
</File>
<File>
<FileName>Cyton_PraseCmd.c</FileName>
<FileType>1</FileType>
<FilePath>..\Cyton\Cyton_PraseCmd.c</FilePath>
</File>
<File>
<FileName>cJSON.c</FileName>
<FileType>1</FileType>
<FilePath>..\Cyton\cJSON.c</FilePath>
</File>
<File>
<FileName>Cyton_DataPkg.c</FileName>
<FileType>1</FileType>
<FilePath>..\Cyton\Cyton_DataPkg.c</FilePath>
</File>
<File>
<FileName>Cyton_Process.c</FileName>
<FileType>1</FileType>
<FilePath>..\Cyton\Cyton_Process.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>CYTON_HAL</GroupName>
<Files>
<File>
<FileName>Cyton_SysApi.c</FileName>
<FileType>1</FileType>
<FilePath>..\CytonHal\Cyton_SysApi.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>
......
......@@ -115,6 +115,9 @@ int main(void)
ADS129x_GPIO_Init();//初始化ADS129X外设
HCO5_IO_Init(); //关蓝牙电源
ESP8266_IO_Init();//关WIFI电源
//ESP8266_PWOERON;
//while (1);
uart1_init(460800);//串口初始化
Main_printf("上电\r\n");
//while(Power_ON());//按键开机检测
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment