123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "task.h"
- #include "cjson.h"
- #include "myFile.h"
- #include "gateway_message.h"
- #include "log.h"
- #include "malloc.h"
- #include "sx1276.h"
- #include "radio.h"
- #include "protocol.h"
- #include "usart.h"
- #include "node_data_acquisition.h"
- void master_task(uint8_t *string,uint16_t stringlength);
- void slave_task();
- tRadioDriver *Radio = NULL;
- uint16_t BufferSize;
- uint8_t Buffer[256];
- uint32_t rx_num = 0;
- uint8_t PingMsg[] = "PING\0";
- uint8_t PongMsg[] = "PONG\0";
- /*
- *********************************************************************************************************
- * 函 数 名: void data_task(void *pdata)
- * 功能说明: 主要是data_task处理线程,优先级高。其运行逻辑是将nandflash中的数据解析出来轮询发送数据
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void data_task(void *pdata)
- {
- OS_CPU_SR cpu_sr;
- pdata = pdata;
- //初始化lora
- Radio = RadioDriverInit();
- Radio->Init();
-
- dlt645_init(100);
- mmodbus_init(100);
-
-
-
- char *lora_config_json = mymalloc(SRAMEX, 9 * 1024);
- read_file("lora_json.txt", lora_config_json);
- addGatewayParams(lora_config_json);
- myfree(SRAMEX, lora_config_json);
- #ifdef MASTER
- GATEWAY_PARAMS *get;
- get= get_gateway_config_params();
- int nodeIndex=0;
- NODE_PARAMS *current_node=get->node_params;
- uint8_t string[256];
- uint16_t bufferLength;
- while (current_node!=NULL)
- {
- while(!masterSendNodeString(nodeIndex,string,&bufferLength)) //轮询读出
- {
- //测试代码不经过转发直接测试
- SlaveProtocolAnalysis(string,BufferSize);
- data_acquisition();
- /*
- master_task(string,bufferLength); //进入发送流程
- int i=0;
- */
- }
- if(current_node->nextNode!=NULL)
- {
- current_node=current_node->nextNode;
- nodeIndex++;
- }
- else
- {
- nodeIndex=0;
- current_node=get->node_params;
- }
- }
- #else
- Radio->StartRx();
- while (1)
- {
- slave_task();
- OSTimeDlyHMSM(0, 0, 0, 200);
- }
- #endif
- while (1)
- {
- }
- // Radio = RadioDriverInit();
- // Radio->Init();
- // #ifdef MASTER
- // Radio->SetTxPacket(PingMsg, strlen((const char *)PingMsg));
- // printf("MASTER");
- // #else
- // Radio->StartRx();
- // printf("SLAVE");
- // #endif
- // while (1)
- // {
- // #ifdef MASTER
- // master_task("a");
- // #else
- // slave_task();
- // #endif
- // }
- }
- /*
- *********************************************************************************************************
- * 函 数 名: void master_task(char *string)
- * 功能说明: 主网关sx1278轮询发送调用接口,发送结束后就将状态切换到接收状态,等待从机的响应值,当从机超时或接收到数据进行后续数据处理的流程
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- volatile uint32_t startTime; // 记录开始的时间且开始时间到结束时间超过一定范围则判定为超时状态,这时对其进行再次发送
- void master_task(uint8_t *string,uint16_t stringlength)
- {
- int retry_count=0; //发送计数,暂时不开启失败重发机制
- while (1)
- {
- switch (Radio->Process())
- {
- case RF_RX_DONE:
- Radio->GetRxPacket(Buffer, &BufferSize);
- break;
- case RF_TX_DONE:
- startTime = OSTimeGet();
- Radio->StartRx();
- case RF_BUSY:
- case RF_IDLE:
- if(retry_count==0) //第一次发送
- {
- Radio->SetTxPacket(string, stringlength);
- retry_count++;
- }
- if (OSTimeGet() - startTime > 10000) // 每次发送信号时记录上一次发送的时间如果超过一段时间没有响应则进行下一次发送
- {
- return;
- }
- default:
- OSTimeDlyHMSM(0, 0, 0, 200);
- break;
- }
- }
- }
- /*
- *********************************************************************************************************
- * 函 数 名: void slave_task(char *string)
- * 功能说明: 负责从站数据处理
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- volatile bool rxflag = false;
- void slave_task()
- {
- switch (Radio->Process())
- {
- case RF_RX_DONE:
- Radio->GetRxPacket(Buffer, &BufferSize);
- if(SlaveProtocolAnalysis(Buffer,BufferSize)) //判断是否为该节点信息
- {
- data_acquisition();
- }
- Radio->StartRx();
- break;
- case RF_TX_DONE:
- Radio->StartRx();
- break;
- case RF_IDLE:
- case RF_BUSY:
- default:
- OSTimeDlyHMSM(0, 0, 0, 200);
- }
- }
- void processString(char *string)
- {
- }
|