“线程:CC3120, 测试”中讨论的其它部件
您好,
我目前正在使用由 MSP432和 CC3120设备组成的定制无线网络。 该系统从一个 MSP432/CC3120发送数据,并在另一个 MSP432/CC3120接收数据。 我正在使用 WiFi SDK 来实现这一目标。
发送节点 使用 SL_Send 和 SL_Recv 命令向接收节点传输恒定数据流。 在发送节点进入 LPM3.5和接收节点进入 AP 模式之前,此过程将在设定的时间内进行。
在发送循环期间,所有操作都完美无缺,但在完成该过程时似乎存在问题。
在查看接收节点的终端时,我注意到进程完成后会弹出一个错误。 这将显示“[错误]-致命错误:检测到驱动程序中止。”。 我知道这是 来自 SimpleLinkFatalErrorEventHandler(),但我不知道为什么。
发生这种情况时,最后一个收到的数据包末尾的部分字节将被切断,设备将变得无响应。 我试图重置 NWP,因为我在另一个论坛帖子中看到了类似的问题,但这似乎给我带来了另一个错误,同时也打印了相同的内容。
下面是主操作循环的代码以及用于启动和重置 NWP 的代码。 错误首先抛出在 sensorNetDataRecv()内,然后在 restartNWP()内再次发生。
在发送节点与接收节点创建的 AP 断开连接的同时,使用 SL_Recv()调用是否会导致错误? 我尝试了一系列调试,结果各不相同。 例如,在 SimpleLinkFatalErrorEventHandler()内添加 usleep(1000000)可让 sensorNetDataRecv()函数按预期返回,但当 NWP 尝试再次启动时,它将抛出各种不同的错误。
我愿意分享任何有助于进一步解决此问题的代码。 请提前感谢您的帮助。
格雷格
/* Start up the NWP */ void startupNWP(void) { int ret; /* Turn NWP on */ ret = sl_Start(NULL, NULL, NULL); if(ret < 0) { /* Handle Error */ UART_PRINT("sl_start failed - %d\n", ret); } /* sl_Start returns on success the role that device started on */ app_CB.Role =ret; /* disable the soft-roaming */ //cmdSoftRoamingDisablecallback(); /* Unregister mDNS services */ ret = sl_NetAppMDNSUnRegisterService(0, 0, 0); if(ret < 0) { /* Handle Error */ UART_PRINT("sl_NetAppMDNSUnRegisterService failed - %d\n", ret); } } /* Reset the NWP */ void restartNWP(void) { int ret; sl_Stop(0); sleep(3); ret = sl_Start(0, 0, 0); if(ret < 0) { /* Handle Error */ UART_PRINT("sl_start failed - %d\n", ret); } } void * mainThread(void *arg) { int32_t ret; wakeup_flag = 0; wakeup_count = 0; pthread_attr_t pAttrs_spawn; struct sched_param priParam; struct timespec ts = {0}; /* Initializes the SPI interface to the Network Processor and peripheral SPI (if defined in the board file) */ SPI_init(); GPIO_init(); /* Init Application variables */ ret = initAppVariables(); /* Init Terminal UART */ InitTerm(); /* initialize the realtime clock */ clock_settime(CLOCK_REALTIME, &ts); /* Switch off all LEDs on boards */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF); GPIO_write(Board_GPIO_LED1, Board_GPIO_LED_OFF); GPIO_write(Board_GPIO_LED2, Board_GPIO_LED_OFF); /* Create the sl_Task internal spawn thread */ pthread_attr_init(&pAttrs_spawn); priParam.sched_priority = SPAWN_TASK_PRIORITY; ret = pthread_attr_setschedparam(&pAttrs_spawn, &priParam); ret |= pthread_attr_setstacksize(&pAttrs_spawn, TASK_STACK_SIZE); /* The SimpleLink host driver architecture mandate spawn thread to be created prior to calling Sl_start (turning the NWP on). */ /* The purpose of this thread is to handle asynchronous events sent from the NWP. * Every event is classified and later handled by the Host driver event handlers. */ ret = pthread_create(&gSpawn_thread, &pAttrs_spawn, sl_Task, NULL); if(ret < 0) { /* Handle Error */ UART_PRINT("Network Terminal - Unable to create spawn thread \n"); return(NULL); } /* Run NWP Startup Sequence */ startupNWP(); /* Output device information to the UART terminal */ dbg = 1; // Debug mode on/off if (dbg) { ClearTerm(); ret = DisplayAppBanner(APPLICATION_NAME, APPLICATION_VERSION); if(ret < 0) { /* Handle Error */ UART_PRINT( "Network Terminal - Unable to retrieve device information \n"); return(NULL); } } /* Parse MAC address for network functions */ setNodeNum(); /* * Coordinator Operation Loop * * This loop occurs infinitely once the coordinator is turned on and operational. * It begins by polling for whether the SensorNet needs to turn on to * collect data. If the SensorNet needs to turn on, it then asks for the * number of SMs. * */ while(1) { /* Enter AP Mode */ ret = cmdWlanStartApCallback(); if (ret < 0) { if (dbg) UART_PRINT("\n\r[wlan ap start] : Unable to configure AP role.\n\r"); } /* Wait for SM Requests */ ret = cdWakeupMode(); if (ret < 0) { if (dbg) UART_PRINT("Failed to wakeup SMs. Hanging Program."); while(1) { } } /* If SMs are staying awake, keep AP up */ putch('a'); // CH signal: entering data collection /* Wait for connection to AP */ if(dbg) { UART_PRINT("\n\n\rReady to Receive Packets!\n\r"); UART_PRINT("Waiting for connection...\n\r"); } while (1) { ret = GET_STATUS_BIT(app_CB.Status, STATUS_BIT_CONNECTION); if (ret) { /* Receive Packets */ if(dbg) { UART_PRINT("Connection established\n\r"); } putch('c'); // CH Signal: Receiving packets ret = sensorNetDataRecv(); // calls sl_Recv on loop /* Return Message */ if(dbg) UART_PRINT("Done Collecting Data. Returning to Request Polling\n"); /* Reset NWP */ restartNWP(); /* Reset Memory */ wakeup_count = 0; wakeup_flag = 0; sem_post(&pollSem); break; } } } }