This ZigBee project for a long time did not write, and now a little strange to this project, a lot of things do not understand. Today write a simple wireless send applet, has been a problem, the program calls Zstack in the Af_datarequest function, as follows
Af_datarequest ( &Coor_Addr, &App_epDesc,                APP_CLUSTERID_ADC, sizeof (Adc_value), (uint8 *) adc_value, &AppTransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
(Uint8 *) Adc_value for the address to send the data, must be a 8-bit unsigned pointer. Then I was very sad to write a structure adc_value, all the code is as follows.
VOID ADC (void) { adc_value *adc_value; adc_value->x=haladcread ( Hal_adc_channel_0,hal_adc_resolution_12); //calculates the value adc_value->y=haladcread (HAL_ADC_CHANNEL_1, Hal_adc_resolution_12);//Calculate numerical adc_value->z=haladcread (Hal_adc_channel_4,hal_adc_resolution_12); /Calculate numerical af_datarequest ( &Coor_Addr, &App_epDesc, //Sending Data app_clusterid_ adc, sizeof (Adc_value), (uint8 *) Adc_value, &AppTransID, AF_DISCV_ROUTE, af_ default_radius ); osal_start_timerex (apptaskid,app_adc_evt,5000); //set timer, loop send }
after compiling a warning, "the adc_value is used before it value is set", also did not care, download the program to the board, the data sent the first normal, the rest is all the wrong data, and the data values are all the same, Or the program went straight to the fly.
I was baffled, very depressed, but did not know where the problem. Then I found out where the problem was. I wonder if you crossing see what the problem is?
The first line of code Adc_value *adc_value; Only one pointer was declared, but no memory space was allocated, causing the problem. With the Java with the basic problem is ignored! This shows that I am not enough to study hard enough depth. The correct code is:
VOID ADC (void) { adc_value *adc_value; adc_value= (ADC_Value *) Osal_msg_allocate (sizeof (Adc_value)); adc_value->x=haladcread (hal_adc_channel_0,hal_adc_ Resolution_12); adc_value->y=haladcread (Hal_adc_channel_1,hal_adc_resolution_12);   ADC _value->z=haladcread (Hal_adc_channel_4,hal_adc_resolution_12); af_datarequest ( &Coor_ addr, &app_epdesc, APP_CLUSTERID_ADC, sizeof (Adc_value), (uint8 *) adc_value, &apptransid, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); osal_msg_deallocate (( uint8 *) adc_value); osal_start_timerex (apptaskid,app_adc_evt,5000); }
This article is from the "Flying Fish Technology" blog, please be sure to keep this source http://flyingfish.blog.51cto.com/9580339/1586077
Memory Management in ZigBee (a murder caused by a memory space)