This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi all, I´m trying to set diferent Osal events, but when I set the first event, I can´t set the other events, my idea is set the second event inside of different .c archive that is called by the first event:
In SampleApp.c
osal_set_event ( PUBLIC_task_id_contratador, EVENT_contratation_start); // event of contratador.c
In contratador.c
osal_set_event ( PUBLIC_task_id_comunicador, EVENT_comunication_start);
I would like to help you but do not understand your problem. Could you explain it more specifically?
Hi my problem is:
1. I have to active a OsalEvent (I´m using SampleApp of Zstack), I´m doing that using: osal_set_event ( PUBLIC_task_id_contratador, EVENT_contratation_start). This event is in contratador.c file.
2. Once I active this event, inside of the event I have to do something like that:
if (events & EVENT_contratation_start){
osal_set_event ( PUBLIC_task_id_comunicador, EVENT_comunication_start) // this event is in comunicador.c file
return ( events ^ EVENT_contratation_start);
}
3. Inside of comunicador.c file, I have to do a similar proccess.
Only the first event is set.
This is the problem.
This is because that your "osal_set_event ( PUBLIC_task_id_comunicador, EVENT_comunication_start) // this event is in comunicador.c file" in EVENT_contratation_start event will be reset right after "return ( events ^ EVENT_contratation_start);". Try to replace the following codes in your event.
if (events & EVENT_contratation_start){
osal_start_timerEX( PUBLIC_task_id_comunicador, EVENT_comunication_start, 500);
return ( events ^ EVENT_contratation_start);
}
Hi Yikai, so, I have to do that:
In SampleApp.c
osal_set_event ( PUBLIC_task_id_contratador, EVENT_contratation_start);
In contratador.c
if (events & EVENT_contratation_start){
osal_start_timerEX( PUBLIC_task_id_comunicador, EVENT_comunication_start, 500);
return ( events ^ EVENT_contratation_start);
}
And again in sampleApp.c if I want to do something with EVENT_contratation_start, I have to do:
SampleaApp.c
if (EVENT_contratation_start)==1{
HalLcdWriteString (" It Works ", HAL_LCD_LINE_1);
}else
{
HalLcdWriteString (" =( ", HAL_LCD_LINE_1);
}
Is correct???
It doesn´t work, any Idea?
According to TI osal infrastructure, all events should be handled insides SampleApp_ProcessEvent in SampleApp.c. How could you put your event handling in another C, which is contratador.c in your case? These fragment source codes are not sufficient for me to help you.
I want to do a process inside of different .c archives, for example:
in SampleApp.c, I want to active a osal event , and then, using the return ( events ^ EVENT_........................); active a process in SampleApp.c
Is posible???
What I have to change???
In Zip Archive is the code.7534.Yikai Code.zip
I just have a look at your attachment and your codes are just too erratic. I have no idea about your intention. Could you describe why you want to do that? Maybe we can find out another approach to do that.
I´m trying to do the first phase of a control aplication, I need to make pieces of code that can to be independent, I need to manage code like components.
The whole infrastructure of ZStack has already been broken down into components already. SimpleApp.c is the component for application and SampleApp_ProcessEvent is for application to handle events.
Is true, though I´m not sure how can I do to add code automatically. My idea is that the sw can change depending on the purpose of it, I want to make a software that allows for control over different applications, this sw has to add components when required by each application.
I still don't understand your intention. There is nothing wrong with the infrastructure of TI ZStack. I have looked at other ZStack implementation and all are similar. I would suggest you to study deeply into the documents and examples. Try to be familiar with and get used to TI ZStack.
Well, maybe is the way that I´m trying to work, please help me with this:
if ( keys & HAL_KEY_SW_4 )
{
SampleApp_SendPeriodicMessage();
}
uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
if ( events & EVENT_contratation_start )
{
HalLcdWriteString ("CONTRATANDO ", HAL_LCD_LINE_1);
SampleApp_ComPeriodicMessage( );
return ( events ^ EVENT_contratation_start);
}
if ( events & EVENT_comunication_start )
{
HalLcdWriteString ("COMUNICANDO", HAL_LCD_LINE_3);
return ( events ^ EVENT_comunication_start);
}
}
void SampleApp_SendPeriodicMessage(void )
{
if (SampleApp_NwkState == DEV_END_DEVICE){
osal_start_timerEx (SampleApp_TaskID, EVENT_contratation_start, 300);
}
}
void SampleApp_ComPeriodicMessage(void ){
osal_stop_timerEx (SampleApp_TaskID, EVENT_contratation_start);
osal_start_timerEx (SampleApp_TaskID, EVENT_comunication_start, 300);
}
I want to set diferent flags, but I'm not sure that's the right way...
After having a look at your code, I conjecture that it would work like the followings:
Once SW key 4 is pressed, it will trigger EVENT_contratation_start event after 300ms. Then, EVENT_comunication_start event will triggered after 300 ms once EVENT_contratation_start is triggered.
Is this the behavior you expected?
I have to set different events, in each event I present some message and calculate the value of different variables, later I send messages using AF_Data_Request...
You can do that in the source codes that you posted. Is there any further problem?
Yes, I just can set the first event, when I try to set the second event (Event_comunication_start), it is not activate.
What are your definition of EVENT_contratation_start and EVENT_comunication_start?
#define EVENT_comunication_start 0x0001
#define EVENT_contratation_start 0x0002
This events are defined in comunicador.h and contratador.h
I don't see any reason why it does not work. By the way, what do you mean Event_comunication_start is not activated? Do you want to attaced whole source code to me to analyze?
The code... Some things still in development.
/************************************************************************************************** Filename: SampleApp.c Revised: $Date: 2009-03-18 15:56:27 -0700 (Wed, 18 Mar 2009) $ Revision: $Revision: 19453 $ Description: Sample Application (no Profile). Copyright 2007 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software license agreement between the user who downloaded the software, his/her employer (which must be your employer) and Texas Instruments Incorporated (the "License"). You may not use this Software unless you agree to abide by the terms of the License. The License limits your use, and you acknowledge, that the Software may not be modified, copied or distributed unless embedded on a Texas Instruments microcontroller or used solely and exclusively in conjunction with a Texas Instruments radio frequency transceiver, which is integrated into your product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software, contact Texas Instruments Incorporated at www.TI.com. **************************************************************************************************/ /********************************************************************* This application isn't intended to do anything useful, it is intended to be a simple example of an application's structure. This application sends it's messages either as broadcast or broadcast filtered group messages. The other (more normal) message addressing is unicast. Most of the other sample applications are written to support the unicast message model. Key control: SW1: Sends a flash command to all devices in Group 1. SW2: Adds/Removes (toggles) this device in and out of Group 1. This will enable and disable the reception of the flash command. *********************************************************************/ /********************************************************************* * INCLUDES */ #include "OSAL.h" #include "ZGlobals.h" #include "AF.h" #include "aps_groups.h" #include "ZDApp.h" #include "SampleApp.h" #include "SampleAppHw.h" #include "OnBoard.h" #include "ZMAC.h" #include "stdlib.h" #include "math.h" /* HAL */ #include "hal_lcd.h" #include "hal_adc.h" #include "hal_led.h" #include "hal_key.h" /*MIDDLEWARE*/ #include "new_task.h" #include "Contratador.h" #include "Comunicador.h" #include "ComunicadorRemoto.h" #include "ContratadorRemoto.h" /********************************************************************* * MACROS */ /********************************************************************* * CONSTANTS */ /********************************************************************* * TYPEDEFS */ /********************************************************************* * GLOBAL VARIABLES */ // This list should be filled with Application specific Cluster IDs. const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] = { SAMPLEAPP_PERIODIC_CLUSTERID, SAMPLEAPP_FLASH_CLUSTERID }; const SimpleDescriptionFormat_t SampleApp_SimpleDesc = { SAMPLEAPP_ENDPOINT, // int Endpoint; SAMPLEAPP_PROFID, // uint16 AppProfId[2]; SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2]; SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4; SAMPLEAPP_FLAGS, // int AppFlags:4; SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; (cId_t *)SampleApp_ClusterList, // uint8 *pAppInClusterList; SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; (cId_t *)SampleApp_ClusterList // uint8 *pAppInClusterList; }; // This is the Endpoint/Interface description. It is defined here, but // filled-in in SampleApp_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t SampleApp_epDesc; /********************************************************************* * EXTERNAL VARIABLES */ /********************************************************************* * EXTERNAL FUNCTIONS */ /********************************************************************* * LOCAL VARIABLES */ uint8 SampleApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // SampleApp_Init() is called. devStates_t SampleApp_NwkState; uint8 SampleApp_TransID; // This is the unique message ID (counter) afAddrType_t SampleApp_Periodic_DstAddr; afAddrType_t SampleApp_Flash_DstAddr; aps_Group_t SampleApp_Group; uint8 SampleAppPeriodicCounter = 0; uint8 SampleAppFlashCounter = 0; int e, Ref, y, u, u1, e1, e2, eF, diagnostico; float q0, q1, q2; uint8 *publicacionPtr; uint16 publicacionMsgLen; uint8 *diMsgPtr, *diagMsgPtr; uint16 diMsgLen, diagMsgLen; /********************************************************************* * LOCAL FUNCTIONS */ void SampleApp_HandleKeys( uint8 shift, uint8 keys ); void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pckt ); void SampleApp_SendPeriodicMessage(void ); void SampleApp_ComPeriodicMessage(void ); void SampleApp_SendFlashMessage( uint16 flashTime ); void proccessMyPeriodicMessage( afIncomingMSGPacket_t *pkt ); /********************************************************************* * NETWORK LAYER CALLBACKS */ /********************************************************************* * PUBLIC FUNCTIONS */ /********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); #endif } /********************************************************************* * @fn SampleApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; // Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: SampleApp_MessageMSGCB( MSGpkt ); break; // Received whenever the device changes state in the network case ZDO_STATE_CHANGE: SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (SampleApp_NwkState == DEV_ZB_COORD) || (SampleApp_NwkState == DEV_ROUTER) || (SampleApp_NwkState == DEV_END_DEVICE) ) { // MENSAJE PERI�DICO, NO LO USAR� POR EL MOMENTO. /*osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );*/ } else { // Device is no longer in the network } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & EVENT_contratation_start ) { HalLcdWriteString (" ", HAL_LCD_LINE_1); delay(); HalLcdWriteString ("CONTRATANDO ", HAL_LCD_LINE_1); delay(); HalLcdWriteString (" ", HAL_LCD_LINE_1); int x1, y1, y; uint8 T[2]; /* T[0] = 2; T[1] = 4; T[2] = 6; T[3] = 8; T[4] = 10;*/ T[0] = (int)SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT; T[1] = (int)SAMPLEAPP_FLASH_DURATION; int n = 2; int hp = 0; int x= T[0]; for (int i= 0; i<n ; i++){ y = T[i + 1]; x1= x; y1= y; if( x==0 || y==0){ //HalLcdWriteStringValue ("h.Periodo:", hp, 16 , HAL_LCD_LINE_3); }else { while(x!=y) { if( x > y){ y = y + y1; hp = y; } else if( x < y ){ x = x + x1; hp = x; } } HalLcdWriteString (" ", HAL_LCD_LINE_1); delay(); HalLcdWriteStringValue ("h.Periodo:", hp, 16 , HAL_LCD_LINE_2); } x = hp; } // FINALIZA EL C�LCULO DEL HIPERPERIODO if (hp>0){ int N= 3; int p = 2; uint8 c[3]; c[0]=5; // mac c[1]=10; c[2]=40; uint8 T[3]; T[0]=20; T[1]=40; T[2]=80; float u = 0.0; for(int i = 0; i < N; i++) { u += ((float)c[i]/(float)T[i]); } float exp = N*(pow(2.0,1.0/(float)N) - 1.0); if ( u < exp){ HalLcdWriteString (" ", HAL_LCD_LINE_2); delay(); HalLcdWriteString ("GARANTIZADO", HAL_LCD_LINE_2); int u1 = (int)(u*1000); HalLcdWriteString (" ", HAL_LCD_LINE_2); delay(); HalLcdWriteStringValue ("u:", u1, 16 , HAL_LCD_LINE_2); } else{ HalLcdWriteString (" ", HAL_LCD_LINE_2); delay(); HalLcdWriteString ("NO GARANTIZADO", HAL_LCD_LINE_2); int u1 = (int)(u*1000); HalLcdWriteString (" ", HAL_LCD_LINE_2); delay(); HalLcdWriteStringValue ("u:", u1, 16 , HAL_LCD_LINE_2); } float w = 0.0; float sumatoria = 0.0; float w1 = c[p]; do{ sumatoria = 0; for(int j = 0; j < N; j++) { if ( j != p) { sumatoria += (ceil(w1/(float)T[j]))*c[j]; } } w= c[p] + sumatoria; w1 = (int)w; } while (w < w1 || w < T[p]); if (w == w1){ HalLcdWriteStringValue ("w1: ", (int)w1,16, HAL_LCD_LINE_3); SampleApp_ComPeriodicMessage(); } else if (w > T[p]){ HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); HalLcdWriteStringValue ("w: ", (int)w,16, HAL_LCD_LINE_3); SampleApp_ComPeriodicMessage(); } else { HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); HalLcdWriteString ("Vamos Mal ", HAL_LCD_LINE_3); } } return ( events ^ EVENT_contratation_start); } if ( events & EVENT_comunication_start ) { HalLcdWriteString ("", HAL_LCD_LINE_3); delay(); HalLcdWriteString ("COMUNICANDO", HAL_LCD_LINE_3); HalLedSet(HAL_LED_ALL, HAL_LED_MODE_ON); Ref = HalAdcRead(HAL_ADC_CHANNEL_7, HAL_ADC_RESOLUTION_12); // La entrada 7 es el potenci�metro y = HalAdcRead(HAL_ADC_CHANNEL_6, HAL_ADC_RESOLUTION_12) - 0x217; // La entrada 6 es el sistema e=Ref-y; // Hallo el error y lo divido en parte alta y baja para enviarlo. HalLcdWriteStringValue("Error:", e, 16, HAL_LCD_LINE_2); int eA2 = e & 0xFF00; int eA1 = eA2 >>8; int eA = eA1 & 0xFF; int eB = e & 0xFF; uint8 publicacion[3]; publicacion[0] = eA; publicacion[1] = eB; publicacionPtr = &publicacion[0]; // Puntero del buffer del dato a ser enviado publicacionMsgLen = 2; if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, publicacionMsgLen, publicacionPtr, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { HalLcdWriteString (" ", HAL_LCD_LINE_1); delay(); HalLcdWriteString ("Enviando msg ", HAL_LCD_LINE_1); delay(); HalLcdWriteString (" ", HAL_LCD_LINE_1); //osal_stop_timerEx (SampleApp_TaskID, EVENT_contratation_start); } else { // Error occurred in request to send. } // Clear event and return. return ( events ^ EVENT_comunication_start); } // Send a message out - This event is generated by a timer // (setup in SampleApp_Init()). if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { SampleApp_SendPeriodicMessage(); //osal_stop_timerEx (SampleApp_TaskID, EVENT_comunication_start); //osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT); //(SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } // Discard unknown events return 0; } /********************************************************************* * Event Generation Functions */ /********************************************************************* * @fn SampleApp_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ void SampleApp_HandleKeys( uint8 shift, uint8 keys ) { (void)shift; // Intentionally unreferenced parameter if ( keys & HAL_KEY_SW_1 ) { HalLcdWriteString ("jostick 1", HAL_LCD_LINE_2); SampleApp_SendPeriodicMessage(); /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ //SampleApp_SendFlashMessage( SAMPLEAPP_FLASH_DURATION ); } if ( keys & HAL_KEY_SW_2 ) { /* The Flashr Command is sent to Group 1. * This key toggles this device in and out of group 1. * If this device doesn't belong to group 1, this application * will not receive the Flash command sent to group 1. */ HalLcdWriteString ("jostick 2", HAL_LCD_LINE_2); aps_Group_t *grp; grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP ); if ( grp ) { // Remove from the group aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP ); } else { // Add to the flash group aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); } } if ( keys & HAL_KEY_SW_3 ) { HalLcdWriteString ("jostick 3", HAL_LCD_LINE_2); } if ( keys & HAL_KEY_SW_4 ) { HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); HalLcdWriteString ("Init Com ", HAL_LCD_LINE_3); HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); SampleApp_SendPeriodicMessage(); } if ( keys & HAL_KEY_SW_5 ) { HalLcdWriteString ("jostick 5 ", HAL_LCD_LINE_2); } } /********************************************************************* * LOCAL FUNCTIONS */ /********************************************************************* * @fn SampleApp_MessageMSGCB * * @brief Data message processor callback. This function processes * any incoming data - probably from other devices. So, based * on cluster ID, perform the intended action. * * @param none * * @return none */ void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { //uint16 flashTime; switch ( pkt->clusterId ) { case SAMPLEAPP_PERIODIC_CLUSTERID: if (SampleApp_NwkState == DEV_ZB_COORD){ uint16 valCO= ((uint32)pkt->cmd.Data[0]<<8) + (uint32)pkt->cmd.Data[1]; HalLcdWriteStringValue ("Error:", valCO, 16 , HAL_LCD_LINE_3); eF = valCO; q2 =0; q0=1.1714; q1= 0.7453; //q2=11.1111; //u = u1 + (q0*eF) - (q1*e1); u = u1 + (int)(0.096*e1); u = abs(u); // u = 1000; if (u>1023){ u = 1023; } else { if (u<0){ u=0; } } u1=u; e2=e1; e1=eF; //u = 120; T1CC1L = (uint8)(u >> 8); // Genera la Acci�n de control a trav�s del PWM, puerto p18, pin 11 T1CC1H = (uint8)u ; //HalLcdWriteStringValue("Control", u, 16, HAL_LCD_LINE_2); //HalLcdWriteValue((int)publicador, 16, HAL_LCD_LINE_1); //osal_set_event ( PUBLIC_task_id_comunicador_remoto, EVENT_remote_comunication_start); if (EVENT_remote_comunication_start == 1){ HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); HalLcdWriteString ("Com. Remot ", HAL_LCD_LINE_3); delay(); HalLcdWriteString (" ", HAL_LCD_LINE_3); delay(); HalLcdWriteString (" ", HAL_LCD_LINE_3); if ( 29>e) { diagnostico = 1; } if (30<=e & e<=59) { diagnostico = 2; } if (60<e & e<=79) { diagnostico = 3; } if (e>80) { diagnostico = 4; } //HalLcdWriteStringValue("Diagn:", diagnostico, 16, HAL_LCD_LINE_1); uint8 diagnosticoMsg[2]; diagnosticoMsg[0] = diagnostico; diagnosticoMsg[1] = e; diMsgPtr = &diagnosticoMsg[0]; // Puntero del buffer del dato a ser enviado diMsgLen = 2; SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, diagMsgLen, //AF_ACK_REQUEST diagMsgPtr, &SampleApp_TransID, AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { proccessMyPeriodicMessage( pkt ); } else { } } /*if ( AF_DataRequest( &SampleApp_Flash_DstAddr, &SampleApp_epDesc, SAMPLEAPP_FLASH_CLUSTERID, 1, publicador, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { //HalLcdWriteString ("Enviando msg ", HAL_LCD_LINE_2); HalLcdWriteString ("Broadcast ", HAL_LCD_LINE_2); } else { // Error occurred in request to send. } }*/ break; } } } /********************************************************************* * @fn SampleApp_SendPeriodicMessage * * @brief Send the periodic message. * * @param none * * @return none */ void SampleApp_SendPeriodicMessage(void ) { if (SampleApp_NwkState == DEV_END_DEVICE){ osal_start_timerEx (SampleApp_TaskID, EVENT_contratation_start, 300); //osal_set_event ( SampleApp_TaskID, EVENT_contratation_start ); } } void SampleApp_ComPeriodicMessage(void ){ osal_stop_timerEx (SampleApp_TaskID, EVENT_contratation_start); delay(); HalLcdWriteString (" ", HAL_LCD_LINE_1); delay(); HalLcdWriteString ("Com P M ", HAL_LCD_LINE_1); osal_set_event ( SampleApp_TaskID, EVENT_comunication_start ); osal_start_timerEx (SampleApp_TaskID, EVENT_comunication_start, 300); } /********************************************************************* * @fn SampleApp_SendFlashMessage * * @brief Send the flash message to group 1. * * @param flashTime - in milliseconds * * @return none */ /*void SampleApp_SendFlashMessage( uint16 flashTime ) { uint8 buffer[3]; buffer[0] = (uint8)(SampleAppFlashCounter++); buffer[1] = LO_UINT16( flashTime ); buffer[2] = HI_UINT16( flashTime ); if ( AF_DataRequest( &SampleApp_Flash_DstAddr, &SampleApp_epDesc, SAMPLEAPP_FLASH_CLUSTERID, 3, buffer, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { HalLcdWriteString ("Mensaje Flash ", HAL_LCD_LINE_2); } else { // Error occurred in request to send. } }*/ void proccessMyPeriodicMessage(afIncomingMSGPacket_t *pkt ) { //osal_start_timerEx (PUBLIC_task_id_contratador_remoto, EVENT_remote_contratation_start, 300); HalLedSet ( HAL_LED_ALL, HAL_LED_MODE_OFF ); delay(); HalLcdWriteString ("Com. Remot ", HAL_LCD_LINE_3); delay(); HalLcdWriteString ("Contra.R ", HAL_LCD_LINE_3); delay(); //if (SampleApp_NwkState == DEV_END_DEVICE){ HalLedBlink(HAL_LED_3, 100, 20, 1000); uint16 diagnosticoF = ((uint32)pkt->cmd.Data[0]); HalLcdWriteStringValue("Diagn:", diagnosticoF, 16, HAL_LCD_LINE_3); HalLedSet ( HAL_LED_ALL, HAL_LED_MODE_OFF ); if ( diagnosticoF == 1) { HalLedBlink(HAL_LED_1, 100, 50, 1000); HalLedBlink(HAL_LED_3, 100, 50, 1000); } if (diagnosticoF == 2) { HalLedBlink(HAL_LED_2, 100, 50, 1000); } if (diagnosticoF == 3) { HalLedBlink(HAL_LED_1, 100, 50, 1000); HalLedBlink(HAL_LED_2, 100, 50, 1000); } if (diagnosticoF == 4) { HalLedBlink(HAL_LED_ALL, 100, 50, 1000); } //} } /********************************************************************* *********************************************************************/
You only call SampleApp_ComPeriodicMessage when "if (w == w1) " and "if (w > T[p])". If these two rules are not meet, the EVENT_comunication_start won't be triggered. Could you set break points inside these two rules and make sure your code will call SampleApp_ComPeriodicMessage?