le mesh data transmission problem

Discussions around product based on ARM Cortex M0+ core.
This forum will be discontinued soon.

Moderator: nferre

alexsandy
Posts: 3
Joined: Tue Oct 06, 2015 9:38 am

le mesh data transmission problem

Wed Nov 25, 2015 2:57 pm

hi every one,
i had been trying to implement lw mesh and transfer data from one node to another. i am implementing the stack like that the node address and the data are given through the one of the node controller uart and that node identifies the node address given through uart and transmits the data to the respective node i am trying this to accomplish from past few days but didnt achieve i am attaching the code i had tried below.

please tell me where i went wrong...thanking you.....




/*- Includes ---------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "hal.h"
#include "phy.h"
#include "sys.h"
#include "nwk.h"
#include "sysTimer.h"
#include "halBoard.h"
#include "halUart.h"

/*- Definitions ------------------------------------------------------------*/
#ifdef NWK_ENABLE_SECURITY
#define APP_BUFFER_SIZE (NWK_MAX_PAYLOAD_SIZE - NWK_SECURITY_MIC_SIZE)
#else
#define APP_BUFFER_SIZE NWK_MAX_PAYLOAD_SIZE
#endif

/*- Types ------------------------------------------------------------------*/
typedef enum AppState_t
{
APP_STATE_INITIAL,
APP_STATE_IDLE,
} AppState_t;

/*- Prototypes -------------------------------------------------------------*/
static void appSendData(uint16_t addr, uint8_t *data, uint8_t size);

/*- Variables --------------------------------------------------------------*/
static AppState_t appState = APP_STATE_INITIAL;
static SYS_Timer_t appTimer;
static NWK_DataReq_t appDataReq;
static bool appDataReqBusy = false;
static uint8_t appDataReqBuffer[APP_BUFFER_SIZE];
static uint8_t appUartBuffer[APP_BUFFER_SIZE];
static uint8_t appUartBufferPtr = 0;

/*- Implementations --------------------------------------------------------*/

/*************************************************************************//**
*****************************************************************************/
static void appDataConf(NWK_DataReq_t *req)
{
appDataReqBusy = false;
(void)req;
}

/*************************************************************************//**
*****************************************************************************/
static void appSendData(uint16_t addr, uint8_t *data, uint8_t size)
{
if (appDataReqBusy || 0 == size)
return;

memcpy(appDataReqBuffer, data, size);

appDataReq.dstAddr = addr;
appDataReq.dstEndpoint = APP_ENDPOINT;
appDataReq.srcEndpoint = APP_ENDPOINT;
appDataReq.options = NWK_OPT_ENABLE_SECURITY;
appDataReq.data = appDataReqBuffer;
appDataReq.size = size;
appDataReq.confirm = appDataConf;
NWK_DataReq(&appDataReq);

appUartBufferPtr = 0;
appDataReqBusy = true;
}
void str_split(char *str, char splitstr[][20])
{
int line=0,cpos=0;
while (*str){
if (*str == ' ' ) { str++; continue;}
if (*str == '\r') {splitstr[line][cpos] = '\0'; break;}
if ((*str == ',') || ( *str == ':')){
splitstr[line++][cpos] = '\0';
cpos = 0;
}
else {
splitstr[line][cpos++] = *str;
}
str++;
}

}

/*************************************************************************//**
*****************************************************************************/
char data_rcvd[2][20];
char str[30];

void HAL_UartBytesReceived(uint16_t bytes){
static char *temp = str;
uint16_t i;
for (i = 0; i < bytes; i++)
{
uint8_t byte = HAL_UartReadByte();
*temp++ = byte;
if(byte=='#'){
str_split(str,data_rcvd);
uint32_t nod_addr = atoi(data_rcvd[0]);
appSendData(nod_addr,data_rcvd[1],strlen(data_rcvd[1]));
temp=str;
}
}


}


/*************************************************************************//**
*****************************************************************************/
static void appTimerHandler(SYS_Timer_t *timer)
{

(void)timer;
}

/*************************************************************************//**
*****************************************************************************/
static bool appDataInd(NWK_DataInd_t *ind)
{
for (uint8_t i = 0; i < ind->size; i++)
HAL_UartWriteByte(ind->data);
return true;
}

/*************************************************************************//**
*****************************************************************************/
static void appInit(void)
{
NWK_SetAddr(APP_ADDR);
NWK_SetPanId(APP_PANID);
PHY_SetChannel(APP_CHANNEL);
#ifdef PHY_AT86RF212
PHY_SetBand(APP_BAND);
PHY_SetModulation(APP_MODULATION);
#endif
PHY_SetRxState(true);

NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

HAL_BoardInit();

appTimer.interval = APP_FLUSH_TIMER_INTERVAL;
appTimer.mode = SYS_TIMER_INTERVAL_MODE;

}

/*************************************************************************//**
*****************************************************************************/
static void APP_TaskHandler(void)
{
switch (appState)
{
case APP_STATE_INITIAL:
{
appInit();
appState = APP_STATE_IDLE;
} break;

case APP_STATE_IDLE:
break;

default:
break;
}
}

/*************************************************************************//**
*****************************************************************************/
int main(void)
{
SYS_Init();
HAL_UartInit(38400);
while (1)
{
SYS_TaskHandler();
HAL_UartTaskHandler();
APP_TaskHandler();
}
}

sarlacii
Posts: 68
Joined: Mon Jan 26, 2015 2:33 pm

Re: le mesh data transmission problem

Wed Nov 25, 2015 4:08 pm

Woo, that's a whole lot of code... and so I'm guessing most folk will tell you that they don't know where you went wrong. You'll have to trouble-shoot it from a high level yourself, and then ask for specific help on a particular issue.

Go well.
alexsandy
Posts: 3
Joined: Tue Oct 06, 2015 9:38 am

Re: le mesh data transmission problem

Fri Nov 27, 2015 7:42 am

i was trying to communicate between three nodes in that say one node is main controller and the other two are node controllers and i was sending the data from main controller uart terminal along with the address of the node to which node the data should transfer say if i am thinking to communicate to node 2 i am sending the data like 2,ab1# i.e 2 states the nodes address ab1 means 1st data and # means end of data but the problem i was facing is randomly i was getting data and some of the data was missing.

this is a bit of code i initialized in appsenddata function:

void str_split(char* str, char splitstr[][20])
{
int line=0,cpos=0;
while (*str)
{
if (*str == ' ' )
{
str++;
continue;
}
if (*str == '#')
{
splitstr[line][cpos] = '\0';
break;
}
if ((*str == ',') || ( *str == ':'))
{
splitstr[line++][cpos] = '\0';
cpos = 0;
}
else
{
splitstr[line][cpos++] = *str;
}
str++;
}

}
int strlength(char* str1)
{
int i=0;
for (i=0;str1!='\0';i++);
return i;
}


and this is the code i am handling through HAL_UartBytesReceived function:

char data_rcvd[3][20];
char g_str[30];
char nod_add[2];
char data1[10];
int test_cnt=0;
int test_cnt1=0;

void HAL_UartBytesReceived(uint16_t bytes)
{
static char* temp = g_str;
uint16_t i;
for (i = 0; i < bytes; i++)
{
uint8_t byte = HAL_UartReadByte();
if(byte =='\0')
return;
g_str[test_cnt++]= byte;
//if(byte=='#'){
if(strlength(g_str)==6)
{
test_cnt1++;
str_split(g_str,data_rcvd);
nod_add[0] = g_str[0];
nod_add[1] = '\0';
data1[0] = g_str[2];
data1[1]= g_str[3];
data1[2]= g_str[4];
data1[3]= g_str[5];
data1[5]= '\0';
uint32_t nod_addr = atoi(nod_add);
appSendData(nod_addr, data1, strlength(data1));
test_cnt = 0;
for(uint16_t j=0; j<10; j++)
{
g_str[j]='\0';
data1[j]='\0';
}
temp = g_str;
}
}
}

can anyone help me where i was went wrong.thanking you......

Return to “SAM D20 Cortex-M0+ MCU”

Who is online

Users browsing this forum: No registered users and 1 guest