123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #include "task.h"
- #include "cjson.h"
- #include "myFile.h"
- #include "gateway_message.h"
- #include "log.h"
- #include "malloc.h"
- #include "sx1276.h"
- #include "protocol.h"
- #include "usart.h"
- #include "node_data_acquisition.h"
- #include "sys_mqtt.h"
- #include "sys_http.h"
- void master_task(uint8_t *string,uint16_t stringlength);
- void slave_task();
- uint16_t BufferSize;
- uint8_t Buffer[256];
- uint32_t rx_num = 0;
- uint8_t PingMsg[] = "PING\0";
- uint8_t PongMsg[] = "PONG\0";
- tRadioDriver *Radio=NULL;
- void data_task(void *pdata)
- {
- OS_CPU_SR cpu_sr;
- pdata = pdata;
- uint16_t data;
- mmodbus_readHoldingRegister16i(0x01,0x00,&data);
- Radio = RadioDriverInit();
- Radio->Init();
- #if 0
- 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);
- 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;
- OS_Q_DATA Qnum;
- StringInfo message;
- char *mqttRecv;
- uint8_t err;
- while (current_node!=NULL)
- {
- while(!masterSendNodeString(nodeIndex,string,&bufferLength))
- {
- master_task(string,bufferLength);
- }
- OSQQuery(JsonQ,&Qnum);
-
- if(Qnum.OSNMsgs!=0)
- {
- mqttRecv=malloc(250);
- message=*(StringInfo *)OSQPend(JsonQ,0, &err);
- while(Qnum.OSNMsgs!=0)
- {
- sprintf(mqttRecv,"%s",message.p);
- }
- }
- if(current_node->nextNode!=NULL)
- {
- current_node=current_node->nextNode;
- nodeIndex++;
- }
- else
- {
- nodeIndex=0;
- current_node=get->node_params;
- }
-
- }
- #else
- dlt645_init(100);
- mmodbus_init(100);
- Radio->StartRx();
- while (1)
- {
- slave_task();
- OSTimeDlyHMSM(0, 0, 0, 200);
- }
- #endif
- }
- 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);
- if(GatewayProtocolAnalysis(Buffer,BufferSize)==0)
- {
-
- Radio->StartRx();
- }
- else
- {
- delay_ms(1000);
- return;
- }
- case RF_TX_DONE:
- Radio->StartRx();
- case RF_BUSY:
- case RF_IDLE:
- if(retry_count==0)
- {
- startTime = OSTimeGet();
- Radio->SetTxPacket(string, stringlength);
- retry_count++;
- }
- if (OSTimeGet() - startTime > 10000)
- {
- return;
- }
- default:
- OSTimeDlyHMSM(0, 0, 0, 200);
- break;
- }
- }
- }
- volatile bool rxflag = false;
- void slave_task()
- {
- switch (Radio->Process())
- {
- case RF_RX_DONE:
- Radio->GetRxPacket(Buffer, &BufferSize);
- if(SlaveProtocolAnalysis(Buffer,BufferSize)==1)
- {
- data_acquisition();
- uint8_t node_string[256];
- uint16_t node_string_Length;
- nodeSendReaddValue(node_string,&node_string_Length);
- Radio->SetTxPacket(node_string, node_string_Length);
- }
- delay_ms(1000);
- break;
- case RF_TX_DONE:
- Radio->StartRx();
- break;
- case RF_IDLE:
- case RF_BUSY:
- default:
- OSTimeDlyHMSM(0, 0, 0, 200);
- }
- }
- #if 0
- SlaveProtocolAnalysis(string,bufferLength);
- data_acquisition();
- uint8_t node_string[256];
- uint16_t node_string_Length;
- nodeSendReaddValue(node_string,&node_string_Length);
- GatewayProtocolAnalysis(node_string,node_string_Length);
- #endif
-
|