我将rfwsnNode中的 sendDmPacket()移植到rfwsnconcentrator中,并用按键控制,本意是想按一次键发一次数据,可是每次按键都会发送失败,显示[Cortex_M3_0] EasyLink_transmit failed 。并且我试过用sendack发送,也是失败。请问这是什么有原因呢?
void buttonCallback(PIN_Handle handle, PIN_Id pinId)
{/* Debounce logic, only toggle if the button is still pushed (low) */// CPUdelay(8000*50);
if (PIN_getInputValue(Board_BUTTON0) == 0){//Semaphore_pend(radioAccessSemHandle, BIOS_WAIT_FOREVER);txdata++;nodeaddress=knownSensorNodes[txdata].address;PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));/* Send ack packet */sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS);//Semaphore_post(radioAccessSemHandle);}
readlove1 readlove1:
贴出完整代码
xudong qin1:
回复 readlove1 readlove1:
/** Copyright (c) 2015-2016, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//***** Includes *****/ #include <xdc/std.h> #include <xdc/runtime/System.h>#include "ConcentratorRadioTask.h"#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Event.h>/* Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h>/* Board Header files */ #include "Board.h"#include "easylink/EasyLink.h" #include "RadioProtocol.h"/***** Defines *****/ #define CONCENTRATORRADIO_TASK_STACK_SIZE 1024 #define CONCENTRATORRADIO_TASK_PRIORITY3#define RADIO_EVENT_ALL0xFFFFFFFF #define RADIO_EVENT_VALID_PACKET_RECEIVED(uint32_t)(1 << 0) #define RADIO_EVENT_INVALID_PACKET_RECEIVED (uint32_t)(1 << 1)#define CONCENTRATORRADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160)#define CONCENTRATOR_ACTIVITY_LED Board_LED0/***** Type declarations *****/ //add by me--begin enum NodeRadioOperationStatus {NodeRadioStatus_Success,NodeRadioStatus_Failed,NodeRadioStatus_FailedNotConnected, }; struct RadioOperation {EasyLink_TxPacket easyLinkTxPacket;uint8_t retriesDone;uint8_t maxNumberOfRetries;uint32_t ackTimeoutMs;enum NodeRadioOperationStatus result; }; //add by me --end/***** Variable declarations *****/ static Task_Params concentratorRadioTaskParams; Task_Struct concentratorRadioTask; /* not static so you can see in ROV */ static uint8_t concentratorRadioTaskStack[CONCENTRATORRADIO_TASK_STACK_SIZE]; Event_Struct radioOperationEvent;/* not static so you can see in ROV */ static Event_Handle radioOperationEventHandle;//add by me--begin static struct DualModeSensorPacket dmSensorPacket; static struct RadioOperation currentRadioOperation; Event_Struct OperationEvent;/* not static so you can see in ROV */ static Event_Handle OperationEventHandle; //add by me --endstatic ConcentratorRadio_PacketReceivedCallback packetReceivedCallback; static union ConcentratorPacket latestRxPacket; static EasyLink_TxPacket txPacket; static struct AckPacket ackPacket; static uint8_t concentratorAddress; static int8_t latestRssi;/***** Prototypes *****/ static void concentratorRadioTaskFunction(UArg arg0, UArg arg1); static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status); static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket); static void sendAck(uint8_t latestSourceAddress); static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs); void buttonCallback(PIN_Handle handle, PIN_Id pinId);/* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState;//add by me--begin #define NODERADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; //static uint8_t txevents= 0; //add by me--end/* Configure LED Pin */PIN_Config ledPinTable[] = {CONCENTRATOR_ACTIVITY_LED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by meBoard_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by meBoard_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by mePIN_TERMINATE }; //add by me --begin PIN_Config buttonPinTable[] = {Board_BUTTON0| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON1| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON2| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON3| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON4| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,PIN_TERMINATE }; //add by me--end/***** Function definitions *****/ void ConcentratorRadioTask_init(void) {/* Open LED pins */ledPinHandle = PIN_open(&ledPinState, ledPinTable);if (!ledPinHandle){System_abort("Error initializing board 3.3V domain pins\n");}buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);if (!buttonPinHandle){System_abort("Error initializing button pins\n");}/* Create event used internally for state changes */Event_Params eventParam;Event_Params_init(&eventParam);Event_construct(&radioOperationEvent, &eventParam);radioOperationEventHandle = Event_handle(&radioOperationEvent);Event_construct(&OperationEvent, &eventParam);OperationEventHandle = Event_handle(&OperationEvent);/* Create the concentrator radio protocol task */Task_Params_init(&concentratorRadioTaskParams);concentratorRadioTaskParams.stackSize = CONCENTRATORRADIO_TASK_STACK_SIZE;concentratorRadioTaskParams.priority = CONCENTRATORRADIO_TASK_PRIORITY;concentratorRadioTaskParams.stack = &concentratorRadioTaskStack;Task_construct(&concentratorRadioTask, concentratorRadioTaskFunction, &concentratorRadioTaskParams, NULL); }void ConcentratorRadioTask_registerPacketReceivedCallback(ConcentratorRadio_PacketReceivedCallback callback) {packetReceivedCallback = callback; }static void concentratorRadioTaskFunction(UArg arg0, UArg arg1) {/* Initialize EasyLink */if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) {System_abort("EasyLink_init failed");}/* Set frequency */if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) {System_abort("EasyLink_setFrequency failed");}/* Set concentrator address */;concentratorAddress = RADIO_CONCENTRATOR_ADDRESS;EasyLink_enableRxAddrFilter(&concentratorAddress, 1, 1);/* Set up Ack packet */ackPacket.header.sourceAddress = concentratorAddress;ackPacket.header.packetType = RADIO_PACKET_TYPE_ACK_PACKET;if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0){System_abort("Error registering button callback function");}/* Enter receive */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}while (1) {uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER);uint32_t txevents = Event_pend(OperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER);if(txevents & RADIO_EVENT_VALID_PACKET_RECEIVED){sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS);/* toggle Activity LED */PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED,!PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED));//txevents=0;}/* If valid packet received */if(events & RADIO_EVENT_VALID_PACKET_RECEIVED) {/* Send ack packet */sendAck(latestRxPacket.header.sourceAddress);/* Call packet received callback */notifyPacketReceived(&latestRxPacket);/* Go back to RX */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}/* toggle Activity LED */PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED,!PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED));}/* If invalid packet received */if(events & RADIO_EVENT_INVALID_PACKET_RECEIVED) {/* Go back to RX */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}}} }static void sendAck(uint8_t latestSourceAddress) {/* Set destinationAdress, but use EasyLink layers destination adress capability */txPacket.dstAddr[0] = latestSourceAddress;/* Copy ACK packet to payload, skipping the destination adress byte.* Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */memcpy(txPacket.payload, &ackPacket.header, sizeof(ackPacket));txPacket.len = sizeof(ackPacket);/* Send packet*/if (EasyLink_transmit(&txPacket) != EasyLink_Status_Success){System_abort("EasyLink_transmit failed");} }static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket) {if (packetReceivedCallback){packetReceivedCallback(latestRxPacket, latestRssi);} }static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status) {union ConcentratorPacket* tmpRxPacket;/* If we received a packet successfully */if (status == EasyLink_Status_Success){/* Save the latest RSSI, which is later sent to the receive callback */latestRssi = (int8_t)rxPacket->rssi;/* Check that this is a valid packet */tmpRxPacket = (union ConcentratorPacket*)(rxPacket->payload);/* If this is a known packet */if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_ADC_SENSOR_PACKET){/* Save packet */memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct AdcSensorPacket));/* Signal packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);}else if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_DM_SENSOR_PACKET){/* Save packet */memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct DualModeSensorPacket));/* Signal packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);}else{/* Signal invalid packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED);}}else{/* Signal invalid packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED);} }void buttonCallback(PIN_Handle handle, PIN_Id pinId) {/* Debounce logic, only toggle if the button is still pushed (low) */// CPUdelay(8000*50);if (PIN_getInputValue(Board_BUTTON0) == 0){Event_post(OperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);// txevents=1;PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));}if (PIN_getInputValue(Board_BUTTON1) == 0){PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));}if (PIN_getInputValue(Board_BUTTON2) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}if (PIN_getInputValue(Board_BUTTON3) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}if (PIN_getInputValue(Board_BUTTON4) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}}static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) {/* Set destination address in EasyLink API */currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0;/* Copy ADC packet to payload* Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket));currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket);/* Setup retries */currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries;currentRadioOperation.ackTimeoutMs = ackTimeoutMs;currentRadioOperation.retriesDone = 0;EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs));/* Send packet*/if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success){System_abort("EasyLink_transmit failed");}/* Enter RX */if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success){System_abort("EasyLink_receiveAsync failed");} }我觉得我加入的这个事件可能有些问题,请大神指导
xudong qin1:
回复 readlove1 readlove1:
/** Copyright (c) 2015-2016, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//***** Includes *****/ #include <xdc/std.h> #include <xdc/runtime/System.h>#include "ConcentratorRadioTask.h"#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Event.h> #include <driverlib/aon_batmon.h>/* Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h>/* Board Header files */ #include "Board.h"#include "easylink/EasyLink.h" #include "RadioProtocol.h"/***** Defines *****/ #define CONCENTRATORRADIO_TASK_STACK_SIZE 1024 #define CONCENTRATORRADIO_TASK_PRIORITY3#define RADIO_EVENT_ALL0xFFFFFFFF #define RADIO_EVENT_VALID_PACKET_RECEIVED(uint32_t)(1 << 0) #define RADIO_EVENT_INVALID_PACKET_RECEIVED (uint32_t)(1 << 1)#define CONCENTRATORRADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160)#define CONCENTRATOR_ACTIVITY_LED Board_LED0/***** Type declarations *****/ //add by me--begin enum NodeRadioOperationStatus {NodeRadioStatus_Success,NodeRadioStatus_Failed,NodeRadioStatus_FailedNotConnected, }; struct RadioOperation {EasyLink_TxPacket easyLinkTxPacket;uint8_t retriesDone;uint8_t maxNumberOfRetries;uint32_t ackTimeoutMs;enum NodeRadioOperationStatus result; }; //add by me --end/***** Variable declarations *****/ static Task_Params concentratorRadioTaskParams; Task_Struct concentratorRadioTask; /* not static so you can see in ROV */ static uint8_t concentratorRadioTaskStack[CONCENTRATORRADIO_TASK_STACK_SIZE]; Event_Struct radioOperationEvent;/* not static so you can see in ROV */ static Event_Handle radioOperationEventHandle;//add by me--begin static struct DualModeSensorPacket dmSensorPacket; static struct RadioOperation currentRadioOperation; Event_Struct OperationEvent;/* not static so you can see in ROV */ static Event_Handle OperationEventHandle; //add by me --endstatic ConcentratorRadio_PacketReceivedCallback packetReceivedCallback; static union ConcentratorPacket latestRxPacket; static EasyLink_TxPacket txPacket; static struct AckPacket ackPacket; static uint8_t concentratorAddress; static int8_t latestRssi;/***** Prototypes *****/ static void concentratorRadioTaskFunction(UArg arg0, UArg arg1); static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status); static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket); static void sendAck(uint8_t latestSourceAddress); static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs); void buttonCallback(PIN_Handle handle, PIN_Id pinId);static void TxcontrolTaskFunction(UArg arg0, UArg arg1); /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState;//add by me--begin /***** Defines *****/ #define TXCONTROL_TASK_STACK_SIZE 1024 #define TXCONTROL_TASK_PRIORITY2static Task_Params TxcontrolTaskParams; Task_Struct TxcontrolTask;/* not static so you can see in ROV */ static uint8_t TxcontrolTaskStack[TXCONTROL_TASK_STACK_SIZE];#define NODERADIO_MAX_RETRIES 2 #define NORERADIO_ACK_TIMEOUT_TIME_MS (160) static PIN_Handle buttonPinHandle; static PIN_State buttonPinState; static uint32_t prevTicks; //static uint8_t txevents= 0; //add by me--end/* Configure LED Pin */PIN_Config ledPinTable[] = {CONCENTRATOR_ACTIVITY_LED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by meBoard_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by meBoard_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,//add by mePIN_TERMINATE }; //add by me --begin PIN_Config buttonPinTable[] = {Board_BUTTON0| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON1| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON2| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON3| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,Board_BUTTON4| PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,PIN_TERMINATE }; //add by me--end/***** Function definitions *****/ void ConcentratorRadioTask_init(void) {/* Open LED pins */ledPinHandle = PIN_open(&ledPinState, ledPinTable);if (!ledPinHandle){System_abort("Error initializing board 3.3V domain pins\n");}buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);if (!buttonPinHandle){System_abort("Error initializing button pins\n");}/* Create event used internally for state changes */Event_Params eventParam;Event_Params_init(&eventParam);Event_construct(&radioOperationEvent, &eventParam);radioOperationEventHandle = Event_handle(&radioOperationEvent);Event_construct(&OperationEvent, &eventParam);OperationEventHandle = Event_handle(&OperationEvent);/* Create the concentrator radio protocol task */Task_Params_init(&concentratorRadioTaskParams);concentratorRadioTaskParams.stackSize = CONCENTRATORRADIO_TASK_STACK_SIZE;concentratorRadioTaskParams.priority = CONCENTRATORRADIO_TASK_PRIORITY;concentratorRadioTaskParams.stack = &concentratorRadioTaskStack;Task_construct(&concentratorRadioTask, concentratorRadioTaskFunction, &concentratorRadioTaskParams, NULL);/* Create the concentrator radio protocol task */Task_Params_init(&TxcontrolTaskParams);TxcontrolTaskParams.stackSize = TXCONTROL_TASK_STACK_SIZE;TxcontrolTaskParams.priority = TXCONTROL_TASK_PRIORITY;TxcontrolTaskParams.stack = &TxcontrolTaskStack;Task_construct(&TxcontrolTask, TxcontrolTaskFunction, &TxcontrolTaskParams, NULL); }void ConcentratorRadioTask_registerPacketReceivedCallback(ConcentratorRadio_PacketReceivedCallback callback) {packetReceivedCallback = callback; }static void concentratorRadioTaskFunction(UArg arg0, UArg arg1) {/* Initialize EasyLink */if(EasyLink_init(RADIO_EASYLINK_MODULATION) != EasyLink_Status_Success) {System_abort("EasyLink_init failed");}/* Set frequency */if(EasyLink_setFrequency(RADIO_FREQUENCY) != EasyLink_Status_Success) {System_abort("EasyLink_setFrequency failed");}/* Set concentrator address */;concentratorAddress = RADIO_CONCENTRATOR_ADDRESS;EasyLink_enableRxAddrFilter(&concentratorAddress, 1, 1);/* Set up Ack packet */ackPacket.header.sourceAddress = concentratorAddress;ackPacket.header.packetType = RADIO_PACKET_TYPE_ACK_PACKET;/* Enter receive */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}while (1) {uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER);/* If valid packet received */if(events & RADIO_EVENT_VALID_PACKET_RECEIVED) {/* Send ack packet */sendAck(latestRxPacket.header.sourceAddress);/* Call packet received callback */notifyPacketReceived(&latestRxPacket);/* Go back to RX */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}/* toggle Activity LED */PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED,!PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED));}/* If invalid packet received */if(events & RADIO_EVENT_INVALID_PACKET_RECEIVED) {/* Go back to RX */if(EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success) {System_abort("EasyLink_receiveAsync failed");}}} }static void TxcontrolTaskFunction(UArg arg0, UArg arg1){/* Setup ADC sensor packet */// dmSensorPacket.header.sourceAddress = RADIO_CONCENTRATOR_ADDRESS;dmSensorPacket.header.sourceAddress =1;dmSensorPacket.header.packetType = RADIO_PACKET_TYPE_DM_SENSOR_PACKET;/* Initialise previous Tick count used to calculate uptime for the TLM beacon */prevTicks = Clock_getTicks();dmSensorPacket.batt = AONBatMonBatteryVoltageGet();dmSensorPacket.button = !PIN_getInputValue(Board_BUTTON0);dmSensorPacket.time100MiliSec=prevTicks;/* Setup callback for button pins */if (PIN_registerIntCb(buttonPinHandle, &buttonCallback) != 0){System_abort("Error registering button callback function");}while(1){uint32_t txevents = Event_pend(OperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER);if(txevents & RADIO_EVENT_VALID_PACKET_RECEIVED){sendDmPacket(dmSensorPacket, NODERADIO_MAX_RETRIES, NORERADIO_ACK_TIMEOUT_TIME_MS);/* toggle Activity LED */PIN_setOutputValue(ledPinHandle, CONCENTRATOR_ACTIVITY_LED,!PIN_getOutputValue(CONCENTRATOR_ACTIVITY_LED));//txevents=0;}} }static void sendAck(uint8_t latestSourceAddress) {/* Set destinationAdress, but use EasyLink layers destination adress capability */txPacket.dstAddr[0] = latestSourceAddress;/* Copy ACK packet to payload, skipping the destination adress byte.* Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */memcpy(txPacket.payload, &ackPacket.header, sizeof(ackPacket));txPacket.len = sizeof(ackPacket);/* Send packet*/if (EasyLink_transmit(&txPacket) != EasyLink_Status_Success){System_abort("EasyLink_transmit failed");} }static void notifyPacketReceived(union ConcentratorPacket* latestRxPacket) {if (packetReceivedCallback){packetReceivedCallback(latestRxPacket, latestRssi);} }static void rxDoneCallback(EasyLink_RxPacket * rxPacket, EasyLink_Status status) {union ConcentratorPacket* tmpRxPacket;/* If we received a packet successfully */if (status == EasyLink_Status_Success){/* Save the latest RSSI, which is later sent to the receive callback */latestRssi = (int8_t)rxPacket->rssi;/* Check that this is a valid packet */tmpRxPacket = (union ConcentratorPacket*)(rxPacket->payload);/* If this is a known packet */if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_ADC_SENSOR_PACKET){/* Save packet */memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct AdcSensorPacket));/* Signal packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);}else if (tmpRxPacket->header.packetType == RADIO_PACKET_TYPE_DM_SENSOR_PACKET){/* Save packet */memcpy((void*)&latestRxPacket, &rxPacket->payload, sizeof(struct DualModeSensorPacket));/* Signal packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);}else{/* Signal invalid packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED);}}else{/* Signal invalid packet received */Event_post(radioOperationEventHandle, RADIO_EVENT_INVALID_PACKET_RECEIVED);} }void buttonCallback(PIN_Handle handle, PIN_Id pinId) {/* Debounce logic, only toggle if the button is still pushed (low) */// CPUdelay(8000*50);if (PIN_getInputValue(Board_BUTTON0) == 0){Event_post(OperationEventHandle, RADIO_EVENT_VALID_PACKET_RECEIVED);// txevents=1;PIN_setOutputValue(ledPinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));}if (PIN_getInputValue(Board_BUTTON1) == 0){PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));}if (PIN_getInputValue(Board_BUTTON2) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}if (PIN_getInputValue(Board_BUTTON3) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}if (PIN_getInputValue(Board_BUTTON4) == 0){PIN_setOutputValue(ledPinHandle, Board_LED3,!PIN_getOutputValue(Board_LED3));}}static void sendDmPacket(struct DualModeSensorPacket sensorPacket, uint8_t maxNumberOfRetries, uint32_t ackTimeoutMs) {/* Set destination address in EasyLink API */currentRadioOperation.easyLinkTxPacket.dstAddr[0] = 0;/* Copy ADC packet to payload* Note that the EasyLink API will implcitily both add the length byte and the destination address byte. */memcpy(currentRadioOperation.easyLinkTxPacket.payload, ((uint8_t*)&dmSensorPacket), sizeof(struct DualModeSensorPacket));currentRadioOperation.easyLinkTxPacket.len = sizeof(struct DualModeSensorPacket);/* Setup retries */currentRadioOperation.maxNumberOfRetries = maxNumberOfRetries;currentRadioOperation.ackTimeoutMs = ackTimeoutMs;currentRadioOperation.retriesDone = 0;EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(ackTimeoutMs));/* Send packet*/if (EasyLink_transmit(¤tRadioOperation.easyLinkTxPacket) != EasyLink_Status_Success){System_abort("EasyLink_transmit failed");}/* Enter RX */if (EasyLink_receiveAsync(rxDoneCallback, 0) != EasyLink_Status_Success){System_abort("EasyLink_receiveAsync failed");} }是这一个,上一个是无法接收信号,已改
readlove1 readlove1:
回复 xudong qin1:
问题解决了?
xudong qin1:
回复 readlove1 readlove1:
没有解决,第二个上传的程序是我现在的问题,按键操作发送信号,会有发送失败EasyLink_transmit failed弹出在窗口,是天线冲突的问题吗?怎么解决呢?
readlove1 readlove1:
回复 xudong qin1:
收发不可同步
xudong qin1:
回复 readlove1 readlove1:
我试过用互斥信号量来解决,没有作用,还有什么方式来解决同步问题呢?
readlove1 readlove1:
回复 xudong qin1:
你问下技术支持,回复快点。
xudong qin1:
回复 readlove1 readlove1:
怎么问技术支持啊,求指导
readlove1 readlove1:
回复 xudong qin1:
你用这个芯片,应该有供应商与你们公司合作吧。供应商那边一般有技术支持的,打电话问问。
TI中文支持网
