From 57e774eee922780d6a584be72a8984d2a3711987 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:00:33 +0200 Subject: digital/beacon: broadcast reset API --- digital/beacon/src/network.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index fe413314..51cb1ea2 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -299,6 +299,9 @@ void APS_DataIndication(APS_DataInd_t* indData) /* New angle is avaiiable, update position */ // update_position(appMessage->data[NETWORK_MSG_ADDR_FIELD],appMessage->data[NETWORK_MSG_DATA_FIELD]); break; + case NETWORK_RESET: + reset_avr(); + break; default: uprintf("Unknown data type received = %x\r\n",appMessage->data[NETWORK_MSG_TYPE_FIELD]); break; -- cgit v1.2.3 From a55506ba721610388545ff868d291caffe95f49f Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:15:50 +0200 Subject: digital/beacon: Improve deconnection/reconnection state machine --- digital/beacon/src/network.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index 51cb1ea2..eb334a89 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -144,7 +144,6 @@ void network_leave(void) ZDO_MgmtLeaveReq_t *zdpLeaveReq = &leaveReq.req.reqPayload.mgmtLeaveReq; APS_UnregisterEndpointReq_t unregEndpoint; - appState = APP_NETWORK_LEAVING_STATE; unregEndpoint.endpoint = endpointParams.simpleDescriptor->endpoint; APS_UnregisterEndpointReq(&unregEndpoint); @@ -164,9 +163,6 @@ void network_leave(void) /* Leave network response */ void zdpLeaveResp(ZDO_ZdpResp_t *zdpResp) { - // Try to rejoin the network - appState = APP_NETWORK_JOIN_REQUEST; - (void)zdpResp; } @@ -199,11 +195,7 @@ void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams) break; case ZDO_NETWORK_LOST_STATUS: { - APS_UnregisterEndpointReq_t unregEndpoint; - unregEndpoint.endpoint = endpointParams.simpleDescriptor->endpoint; - APS_UnregisterEndpointReq(&unregEndpoint); - - // try to rejoin the network + network_leave(); appState = APP_NETWORK_JOIN_REQUEST; break; } @@ -269,6 +261,7 @@ void APS_DataConf(APS_DataConf_t* confInfo) if (MAX_RETRIES_BEFORE_REJOIN == retryCounter) { network_leave(); + appState = APP_NETWORK_JOIN_REQUEST; } else { -- cgit v1.2.3 From 130899fb27b2b841156d0e77376ef3142ba77d47 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:17:31 +0200 Subject: digital/beacon: angle is send only when device is connected to the network --- digital/beacon/src/network.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index eb334a89..6f184435 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -234,20 +234,25 @@ int8_t network_get_rssi(void) /* This function must be used to send data through zigbee network */ void network_send_data(TMessage_type type, uint16_t data) { - /* Message type*/ - zigbit_tx_buffer.message.data[NETWORK_MSG_TYPE_FIELD] = type; - /* Source address */ - zigbit_tx_buffer.message.data[NETWORK_MSG_ADDR_FIELD] = CS_NWK_ADDR; - - /* LSB Data */ - zigbit_tx_buffer.message.data[NETWORK_MSG_DATA_LSB_FIELD] = data; - - /* MSB Data */ - zigbit_tx_buffer.message.data[NETWORK_MSG_DATA_MSB_FIELD] = data >> 8; - - /* Bitcloud sending request */ - APS_DataReq(&config); + if(network_get_status() == APP_NETWORK_JOINED_STATE) + { + led_inverse(2); + /* Message type*/ + zigbit_tx_buffer.message.data[NETWORK_MSG_TYPE_FIELD] = type; + + /* Source address */ + zigbit_tx_buffer.message.data[NETWORK_MSG_ADDR_FIELD] = CS_NWK_ADDR; + + /* LSB Data */ + zigbit_tx_buffer.message.data[NETWORK_MSG_DATA_LSB_FIELD] = data; + + /* MSB Data */ + zigbit_tx_buffer.message.data[NETWORK_MSG_DATA_MSB_FIELD] = data >> 8; + + /* Bitcloud sending request */ + APS_DataReq(&config); + } } -- cgit v1.2.3 From 6828871a64e6b8e31f3b5d9069a62696832a3697 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:18:23 +0200 Subject: digital/beacon: fix issue when sending 4 bytes --- digital/beacon/src/network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index 6f184435..918ce3ad 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -120,7 +120,7 @@ void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t* confirmInfo) config.clusterId = APP_CLUSTER_ID; // Desctination cluster ID config.srcEndpoint = APP_ENDPOINT; // Source endpoint config.asdu = &zigbit_tx_buffer.message; // application message pointer - config.asduLength = 3 + sizeof(zigbit_tx_buffer.message.messageId); // actual application message length + config.asduLength = 4 + sizeof(zigbit_tx_buffer.message.messageId); // actual application message length config.txOptions.acknowledgedTransmission = 0; // Acknowledged transmission enabled config.radius = 0; // Use maximal possible radius config.APS_DataConf = APS_DataConf; // Confirm handler Z -- cgit v1.2.3 From a84e8b9345568775fdd0fa9716b7379f6def3dd5 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:19:50 +0200 Subject: digital/beacon: start/stop the motor using NETWORK_JACK_STATE --- digital/beacon/src/network.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index 918ce3ad..50b86d71 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -31,6 +31,7 @@ #include "debug_avr.h" #include "led.h" +#include "motor.h" // Endpoint parameters static SimpleDescriptor_t simpleDescriptor = { APP_ENDPOINT, APP_PROFILE_ID, 1, 1, 0, 0 , NULL, 0, NULL }; @@ -289,6 +290,7 @@ void APS_DataIndication(APS_DataInd_t* indData) switch(appMessage->data[NETWORK_MSG_TYPE_FIELD]) { case NETWORK_JACK_STATE: + motor_start_stop_control(); break; case NETWORK_OPPONENT_NUMBER: break; -- cgit v1.2.3 From 0a5ba20c1a69e82400cb2ecb4ab78bc589326c21 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 16 May 2012 17:21:26 +0200 Subject: digital/beacon: update the opponnent position when a angle is received --- digital/beacon/src/network.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'digital/beacon/src/network.c') diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index 50b86d71..bbcba4ec 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -30,8 +30,9 @@ #include "network.h" #include "debug_avr.h" #include "led.h" - #include "motor.h" +#include "position.h" +#include "misc.h" // Endpoint parameters static SimpleDescriptor_t simpleDescriptor = { APP_ENDPOINT, APP_PROFILE_ID, 1, 1, 0, 0 , NULL, 0, NULL }; @@ -283,7 +284,9 @@ void APS_DataConf(APS_DataConf_t* confInfo) /* APS data indication handler */ void APS_DataIndication(APS_DataInd_t* indData) { + uint8_t beacon = 0; uint16_t angle = 0; + uint16_t angle_id = 0; AppMessage_t *appMessage = (AppMessage_t *) indData->asdu; // Data received indication @@ -295,9 +298,21 @@ void APS_DataIndication(APS_DataInd_t* indData) case NETWORK_OPPONENT_NUMBER: break; case NETWORK_ANGLE_RAW: - angle = codewheel_convert_angle_raw2degrees((appMessage->data[NETWORK_MSG_DATA_MSB_FIELD]<<8) + appMessage->data[NETWORK_MSG_DATA_LSB_FIELD]); + + /* Beacon address */ + beacon = appMessage->data[NETWORK_MSG_ADDR_FIELD]; + + /* Angle ID */ + angle_id = appMessage->data[NETWORK_MSG_DATA_MSB_FIELD] >> 1; + + /* Angle value */ + angle = ((appMessage->data[NETWORK_MSG_DATA_MSB_FIELD]&0x01) << 8) + appMessage->data[NETWORK_MSG_DATA_LSB_FIELD]; + + /* For debug */ + uprintf("[%d] angle[%d] = %f\r\n",beacon,angle_id,codewheel_convert_angle_raw2degrees(angle)); + /* New angle is avaiiable, update position */ -// update_position(appMessage->data[NETWORK_MSG_ADDR_FIELD],appMessage->data[NETWORK_MSG_DATA_FIELD]); + update_position(beacon,angle_id,codewheel_convert_angle_raw2radians(angle)); break; case NETWORK_RESET: reset_avr(); -- cgit v1.2.3