summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorFlorent Duchon2012-04-03 18:35:01 +0200
committerFlorent Duchon2012-04-03 19:34:39 +0200
commitacf4617c9f264dc5813abb4b305d8c1d76ad19b0 (patch)
treeccf5c8aac133d9bbee8a43fc7d09ffcee29be133 /digital
parent1fa4caab2da5558efddd4a5dc892da5dea28921b (diff)
digital/beacon: file restructuration (license header)
Diffstat (limited to 'digital')
-rw-r--r--digital/beacon/src/configuration.h161
-rw-r--r--digital/beacon/src/debug.h16
-rw-r--r--digital/beacon/src/main_simu.c2
-rw-r--r--digital/beacon/src/network.c377
-rw-r--r--digital/beacon/src/network.h55
-rw-r--r--digital/beacon/src/sensors.c153
-rw-r--r--digital/beacon/src/sensors.h45
-rw-r--r--digital/beacon/src/servo.c96
-rw-r--r--digital/beacon/src/servo.h46
9 files changed, 491 insertions, 460 deletions
diff --git a/digital/beacon/src/configuration.h b/digital/beacon/src/configuration.h
index edff9edf..5d42df85 100644
--- a/digital/beacon/src/configuration.h
+++ b/digital/beacon/src/configuration.h
@@ -2,61 +2,60 @@
#define _CONFIGURATION_H_
#include "apsCommon.h"
-//-----------------------------------------------
-// Disables board-specific peripherals support
-//-----------------------------------------------
-//#define APP_DISABLE_BSP 1
-#define APP_DISABLE_BSP 1
-
-//-----------------------------------------------
-// Includes board-specific peripherals support in application.
-//-----------------------------------------------
#include <BoardConfig.h>
+#include <usart.h>
-#define APP_INTERFACE_USART 0x01
-#define APP_INTERFACE_VCP 0x02
-#define APP_INTERFACE_SPI 0x03
-#define APP_INTERFACE_UART 0x04
-#define APP_INTERFACE_USBFIFO 0x05
-
-
-
-// Receive buffer size for USART.
-#define APP_USART_RX_BUFFER_SIZE 100
-// Transmit buffer size for USART.
-#define APP_USART_TX_BUFFER_SIZE 100
-
-#define AT25F2048 0x01
-#define AT45DB041 0x02
-#define AT25DF041A 0x03
-
-
-
-// Enables or disables APS Fragmentation support.
-#define APP_FRAGMENTATION 0
-//#define APP_FRAGMENTATION 1
-
-// Link failure detection functionality
-#define APP_DETECT_LINK_FAILURE 1
-//#define APP_DETECT_LINK_FAILURE 0
-
-// Enable this option if target board belongs to MNZB-EVBx family
-#define BSP_MNZB_EVB_SUPPORT 1
-//#define BSP_MNZB_EVB_SUPPORT 0
-
-// Defines primary serial interface type to be used by application.
-#define APP_INTERFACE APP_INTERFACE_USART
-
-// Defines USART interface name to be used by application.
-#define APP_USART_CHANNEL USART_CHANNEL_1
-
-
-
+/*----------------------------------------------- */
+/* Disables board-specific peripherals support */
+/*----------------------------------------------- */
+#define APP_DISABLE_BSP 1
-#define APP_JOINING_INDICATION_PERIOD 500L // Period of blinking during starting network
-#define APP_ENDPOINT 1 // Endpoint will be useed
-#define APP_PROFILE_ID 1 // Profile Id will be used
-#define APP_CLUSTER_ID 1 // Cluster Id will be used
+#define AC_FREQ 8000000
+
+/* ----------------------------------------------------------- */
+/* USART CONFIGURATION */
+/* ----------------------------------------------------------- */
+#define APP_INTERFACE_USART 0x01
+#define APP_INTERFACE_VCP 0x02
+#define APP_INTERFACE_SPI 0x03
+#define APP_INTERFACE_UART 0x04
+#define APP_INTERFACE_USBFIFO 0x05
+#define APP_USART_RX_BUFFER_SIZE 100 /* Receive buffer size for USART. */
+#define APP_USART_TX_BUFFER_SIZE 100 /* Transmit buffer size for USART */
+#define APP_INTERFACE APP_INTERFACE_USART /* Defines primary serial interface type to be used by application */
+#define APP_USART_CHANNEL USART_CHANNEL_1 /* Defines USART interface name to be used by application.*/
+
+/* ----------------------------------------------------------- */
+/* TWI CONFIGURATION */
+/* ----------------------------------------------------------- */
+#define AC_BEACON_TWI_ADDRESS 10 /* TWI address */
+#define AC_TWI_DRIVER HARD /* Driver to implement TWI: HARD, SOFT, or USI. */
+#define AC_TWI_NO_INTERRUPT 0 /* Do not use interrupts. */
+#define AC_TWI_FREQ 100000 /* TWI frequency, should really be 100 kHz. */
+#define AC_TWI_SLAVE_ENABLE 1 /* Enable slave part. */
+#define AC_TWI_MASTER_ENABLE 0 /* Enable master part. */
+#define AC_TWI_SLAVE_POLLED 1 /* Use polled slave mode: received data is stored in a buffer which can be polled using twi_slave_poll. */
+#undef AC_TWI_SLAVE_RECV /* Slave reception callback to be defined by the user when not in polled mode. */
+#define AC_TWI_PULL_UP 0 /* Use internal pull up. */
+#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 /* Slave reception buffer size. */
+#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 16 /* Slave transmission buffer size. */
+
+
+/* ----------------------------------------------------------- */
+/* ZIGBEE CONFIGURATION */
+/* ----------------------------------------------------------- */
+#define AT25F2048 0x01
+#define AT45DB041 0x02
+#define AT25DF041A 0x03
+
+
+
+#define APP_FRAGMENTATION 0 /* Enables or disables APS Fragmentation support. */
+#define APP_DETECT_LINK_FAILURE 1 /* Enable or disable link failure detection */
+#define APP_ENDPOINT 1 /* Endpoint will be useed */
+#define APP_PROFILE_ID 1 /* Profile Id will be used */
+#define APP_CLUSTER_ID 1 /* Cluster Id will be used */
+#define APP_JOINING_INDICATION_PERIOD 500L /* Period of blinking during starting network */
@@ -83,7 +82,7 @@
// formed (for the coordinator) or joined (for a router or an end device). For a
// router or an end device the parameter can equal 0 allowing them to join the
// first suitable network that they discover.
-#define CS_EXT_PANID 0xAAAAAAAAAAAAAAAALL
+#define CS_EXT_PANID 0xAAAAAAAAAAAA1337LL
// 64-bit Unique Identifier (UID) determining the device extended address. If this
// value is 0 stack will try to read hardware UID from external UID or EEPROM chip.
@@ -136,7 +135,7 @@
// The parameter determines how many routers the device can have as children. Note
// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT -
// CS_MAX_CHILDREN_ROUTER_AMOUNT.
-#define CS_MAX_CHILDREN_ROUTER_AMOUNT 2
+#define CS_MAX_CHILDREN_ROUTER_AMOUNT 0
// Network depht limits amount of hops that packet may travel in the network.
// Actual maximum number of hops is network depth multiplied by 2.
@@ -154,7 +153,33 @@
// perform any checkings of the network depth, neither when joining a network nor
// when accepting other nodes as children. This allows forming long chains of
// devices across considerable distances.
-#define CS_MAX_NETWORK_DEPTH 6
+#define CS_MAX_NETWORK_DEPTH 1
+
+// Maximum amount of records in the Neighbor Table.
+//
+// The parameter determines the size of the neighbor table which is used to store
+// beacon responses from nearby devices. The parameter puts an upper bound over the
+// amount of child devices possible for the node.
+#define CS_NEIB_TABLE_SIZE 10
+
+// Maximum amount of records in the network Route Table.
+//
+// The parameter sets the maximum number of records that can be kept in the NWK
+// route table. The table is used by NWK to store information about established
+// routes. Each table entry specifies the next-hop short address for a route from
+// the current node to a given destination node. The table is being filled
+// automatically during route discovery. An entry is added when a route is
+// discovered.
+#define CS_ROUTE_TABLE_SIZE 8
+
+// The parameter specifies the TX power of the transceiver device, is measured in
+// dBm(s). After the node has entered the network the value can only be changed via
+// the ZDO_SetTxPowerReq() function.
+//
+// Value range: depends on the hardware. Transmit power must be in the range from
+// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit
+// power must be in the range from -11 to 11 dBm.
+#define CS_RF_TX_POWER 3
//-----------------------------------------------
//STANDARD_SECURITY_MODE
@@ -223,32 +248,6 @@
#define CS_APS_SECURITY_TIMEOUT_PERIOD 10000
#endif
-// Maximum amount of records in the Neighbor Table.
-//
-// The parameter determines the size of the neighbor table which is used to store
-// beacon responses from nearby devices. The parameter puts an upper bound over the
-// amount of child devices possible for the node.
-#define CS_NEIB_TABLE_SIZE 10
-
-// Maximum amount of records in the network Route Table.
-//
-// The parameter sets the maximum number of records that can be kept in the NWK
-// route table. The table is used by NWK to store information about established
-// routes. Each table entry specifies the next-hop short address for a route from
-// the current node to a given destination node. The table is being filled
-// automatically during route discovery. An entry is added when a route is
-// discovered.
-#define CS_ROUTE_TABLE_SIZE 8
-
-// The parameter specifies the TX power of the transceiver device, is measured in
-// dBm(s). After the node has entered the network the value can only be changed via
-// the ZDO_SetTxPowerReq() function.
-//
-// Value range: depends on the hardware. Transmit power must be in the range from
-// -17 to 3 dBm for AT86RF231, AT86RF230 and AT86RF230B. For AT86RF212 transmit
-// power must be in the range from -11 to 11 dBm.
-#define CS_RF_TX_POWER 3
-
//-----------------------------------------------
//APP_FRAGMENTATION == 1
//-----------------------------------------------
diff --git a/digital/beacon/src/debug.h b/digital/beacon/src/debug.h
index ab166fe9..3e79501d 100644
--- a/digital/beacon/src/debug.h
+++ b/digital/beacon/src/debug.h
@@ -26,7 +26,15 @@
#define _DEBUG_H
#include <stdio.h>
+#include "configuration.h"
+#define OPEN_USART HAL_OpenUsart
+#define CLOSE_USART HAL_CloseUsart
+#define WRITE_USART HAL_WriteUsart
+#define READ_USART HAL_ReadUsart
+#define USART_CHANNEL APP_USART_CHANNEL
+
+
// #define DEBUG_POSITION_ENABLE
// #define DEBUG_UPDATE_ENABLE
// #define DEBUG_RECOVERY_ENABLE
@@ -71,4 +79,12 @@
#define DEBUG_TRUST(f,s...) ((void)0)
#endif
+/* This function initializes the USART interface for debugging on avr */
+void initSerialInterface(void);
+
+/* RX USART Callback */
+void usartRXCallback(uint16_t bytesToRead);
+
+/* This function sends data string via the USART interface */
+void uprintf(char *format, ...);
#endif
diff --git a/digital/beacon/src/main_simu.c b/digital/beacon/src/main_simu.c
index b3191d90..706b360b 100644
--- a/digital/beacon/src/main_simu.c
+++ b/digital/beacon/src/main_simu.c
@@ -1,4 +1,4 @@
-/* beacon.c */
+/* main_simu.c */
/* Beacon Simulator Interface. {{{
*
* Copyright (C) 2011 Florent Duchon
diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c
index 787abfb7..8e0fbaa0 100644
--- a/digital/beacon/src/network.c
+++ b/digital/beacon/src/network.c
@@ -1,51 +1,57 @@
+/* network.c */
+/* Beacon network management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#include <types.h>
#include <configServer.h>
#include <zdo.h>
-// #include <peer2peer.h>
+#include "configuration.h"
#include "network.h"
-// #include <serialInterface.h>
+#include "debug.h"
+#include "led.h"
+// Endpoint parameters
+static SimpleDescriptor_t simpleDescriptor = { APP_ENDPOINT, APP_PROFILE_ID, 1, 1, 0, 0 , NULL, 0, NULL };
+static APS_RegisterEndpointReq_t endpointParams;
+static ZDO_StartNetworkReq_t networkParams; // request params for ZDO_StartNetworkReq
+APS_DataReq_t config;
-#define APP_DETECT_LINK_FAILURE 1
// Network related variables
-AppMessageBuffer_t buf_to_send;
-
+AppMessageBuffer_t zigbit_tx_buffer;
extern AppState_t appState;
extern DeviceType_t deviceType;
-// extern HAL_UsartDescriptor_t appUsartDescriptor;
-// extern uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE];
-
-
-static ZDO_StartNetworkReq_t networkParams; // request params for ZDO_StartNetworkReq
-APS_DataReq_t test;
-
-// Endpoint parameters
-static SimpleDescriptor_t simpleDescriptor = { APP_ENDPOINT, APP_PROFILE_ID, 1, 1, 0, 0 , NULL, 0, NULL };
-static APS_RegisterEndpointReq_t endpointParams;
-
-#if APP_DETECT_LINK_FAILURE == 1
static uint8_t retryCounter = 0; // Data sending retries counter
// Leave request, used for router to leave the network when communication was interrupted
static ZDO_ZdpReq_t leaveReq;
-static void leaveNetwork(void);
-static void zdpLeaveResp(ZDO_ZdpResp_t *zdpResp);
-#endif // APP_DETECT_LINK_FAILURE
-
-uint16_t petite_adresse = 0;
-int lost_packet = 0;
-extern int jack;
-/**************************************************************************//**
- \brief Intializes network parameters.
- \param none.
- \return none.
-******************************************************************************/
-void initNetwork(void)
+/* This function intializes network parameters */
+void network_init(void)
{
if(deviceType == DEVICE_TYPE_COORDINATOR)
{
@@ -54,56 +60,43 @@ void initNetwork(void)
}
if(deviceType == DEVICE_TYPE_END_DEVICE)
{
- _delay_ms(2000);
bool rx_on_idle = false;
- CS_WriteParameter(CS_RX_ON_WHEN_IDLE_ID, &rx_on_idle);
-
+ CS_WriteParameter(CS_RX_ON_WHEN_IDLE_ID, &rx_on_idle);
}
/*False = random ID */
+ /* True = static short address */
bool unique_addr = true;
CS_WriteParameter(CS_NWK_UNIQUE_ADDR_ID,&unique_addr);
-
-// uint16_t nwkAddr=1;
-// CS_WriteParameter(CS_NWK_ADDR_ID, &nwkAddr);
+
+ uint16_t nwkAddr=CS_NWK_ADDR;
+ CS_WriteParameter(CS_NWK_ADDR_ID, &nwkAddr);
// Set the deviceType value to Config Server
CS_WriteParameter(CS_DEVICE_TYPE_ID, &deviceType);
- /* Neighbor table size - The size of neighbor table an ED can have */
- int neighbor_table_size = 10;
- CS_WriteParameter(CS_NEIB_TABLE_SIZE_ID, &neighbor_table_size);
-
- /* Max children amount -Maximum number of children that a given device (coordinator or router) may have */
- int max_children = 8;
- CS_WriteParameter(CS_MAX_CHILDREN_AMOUNT_ID, &max_children);
-
- /* Max router children amount - Maximum number of routers among the children of one device */
- int max_children_router = 2;
- CS_WriteParameter(CS_MAX_CHILDREN_ROUTER_AMOUNT_ID, &max_children_router);
-
- CS_WriteParameter(CS_EXT_PANID_ID,&(char){"0xAAAAAAAAAAAAAAAALL"});
-
appState = APP_NETWORK_JOINING_STATE;
}
-/**************************************************************************//**
- \brief ZDO_StartNetwork primitive confirmation callback.
+/* This function starts the network according to the defined configuraiton*/
+void network_start(void)
+{
+ /* Activate the network status led blink */
+ led_start_blink();
+
+ networkParams.ZDO_StartNetworkConf = ZDO_StartNetworkConf;
+ // start network
+ ZDO_StartNetworkReq(&networkParams);
+}
+
- \param confirmInfo - confirmation parametrs.
- \return none.
-******************************************************************************/
+/* ZDO_StartNetwork primitive confirmation callback */
void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t* confirmInfo)
{
if (confirmInfo->status == ZDO_SUCCESS_STATUS)
{
-#if APP_DETECT_LINK_FAILURE == 1
retryCounter = 0;
-#endif // APP_DETECT_LINK_FAILURE
-
- PORTD=0b00100000;
- petite_adresse = confirmInfo->shortAddr;
appState = APP_NETWORK_JOINED_STATE;
@@ -114,207 +107,171 @@ void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t* confirmInfo)
APS_RegisterEndpointReq(&endpointParams);
// Configure the message structure
- test.dstAddrMode = APS_SHORT_ADDRESS; // Short addressing mode
- test.dstAddress.shortAddress = 0x0000; // Destination address
- test.profileId = APP_PROFILE_ID; // Profile ID
- test.dstEndpoint = APP_ENDPOINT; // Desctination endpoint
- test.clusterId = APP_CLUSTER_ID; // Desctination cluster ID
- test.srcEndpoint = APP_ENDPOINT; // Source endpoint
- test.asdu = &buf_to_send.message; // application message pointer
- test.asduLength = 3 + sizeof(buf_to_send.message.messageId); // actual application message length
- test.txOptions.acknowledgedTransmission = 0; // Acknowledged transmission enabled
- test.radius = 0; // Use maximal possible radius
- test.APS_DataConf = APS_DataConf; // Confirm handler Z
+ config.dstAddrMode = APS_SHORT_ADDRESS; // Short addressing mode
+#ifdef TYPE_COOR
+ config.dstAddress.shortAddress = BROADCAST_ADDR_ALL; // Destination address
+#else
+ config.dstAddress.shortAddress = 0x0000; // Destination address
+#endif
+ config.profileId = APP_PROFILE_ID; // Profile ID
+ config.dstEndpoint = APP_ENDPOINT; // Desctination endpoint
+ 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.txOptions.acknowledgedTransmission = 0; // Acknowledged transmission enabled
+ config.radius = 0; // Use maximal possible radius
+ config.APS_DataConf = APS_DataConf; // Confirm handler Z
+
+ /* Stop the network status led blink */
+ led_stop_blink();
}
else
{
- PORTD=0b01000000;
+ uprintf("CONNECTION FAILED. confirmInfo->status = %x\n\r",confirmInfo->status);
}
SYS_PostTask(APL_TASK_ID);
}
-/**************************************************************************//**
- \brief Starts network.
- \param none.
- \return none.
-******************************************************************************/
-void startNetwork(void)
-{
- networkParams.ZDO_StartNetworkConf = ZDO_StartNetworkConf;
- // start network
- ZDO_StartNetworkReq(&networkParams);
-}
-
-
-/**************************************************************************//**
- \brief Update network status event handler.
- \param nwkParams - new network parameters.
- \return none.
-******************************************************************************/
+/* Update network status event handler */
void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams)
{
- switch (nwkParams->status)
- {
- case ZDO_NETWORK_STARTED_STATUS:
- break;
-
- case ZDO_NETWORK_LOST_STATUS:
- {
- APS_UnregisterEndpointReq_t unregEndpoint;
-
- unregEndpoint.endpoint = endpointParams.simpleDescriptor->endpoint;
- APS_UnregisterEndpointReq(&unregEndpoint);
-
- // try to rejoin the network
- appState = APP_NETWORK_JOINING_STATE;
- SYS_PostTask(APL_TASK_ID);
- break;
- }
-
- case ZDO_NWK_UPDATE_STATUS:
- break;
-
- default:
- break;
- }
+ switch (nwkParams->status)
+ {
+ case ZDO_NETWORK_STARTED_STATUS:
+ break;
+ case ZDO_NETWORK_LOST_STATUS:
+ {
+ APS_UnregisterEndpointReq_t unregEndpoint;
+ unregEndpoint.endpoint = endpointParams.simpleDescriptor->endpoint;
+ APS_UnregisterEndpointReq(&unregEndpoint);
+ // try to rejoin the network
+ appState = APP_NETWORK_JOINING_STATE;
+ SYS_PostTask(APL_TASK_ID);
+ break;
+ }
+ case ZDO_NWK_UPDATE_STATUS:
+ break;
+ default:
+ break;
+ }
}
-/**************************************************************************//**
- \brief Handler of aps data sent confirmation.
- \param confInfo - confirmation info
- \return none.
-******************************************************************************/
+/* brief Handler of aps data sent confirmation */
void APS_DataConf(APS_DataConf_t* confInfo)
{
if (APS_SUCCESS_STATUS != confInfo->status)
{
-#if APP_DETECT_LINK_FAILURE == 1
retryCounter++;
- if(retryCounter>3)
- {
- lost_packet++;
- }
if (MAX_RETRIES_BEFORE_REJOIN == retryCounter)
{
- leaveNetwork();
+ network_leave();
}
else
-#endif // APP_DETECT_LINK_FAILURE
{
// Data not delivered, resend.
- send_data();
+// send_data();
}
return;
}
-#if APP_DETECT_LINK_FAILURE == 1
retryCounter = 0;
-#endif // APP_DETECT_LINK_FAILURE
}
-
-/**************************************************************************//**
- \brief APS data indication handler.
-
- \param indData - received data pointer.
- \return none.
-******************************************************************************/
-int received_event=0;
-int beacon_number = 0;
-int angle_received = 0;
+/* APS data indication handler */
void APS_DataIndication(APS_DataInd_t* indData)
{
AppMessage_t *appMessage = (AppMessage_t *) indData->asdu;
// Data received indication
- received_event++;
-
switch(appMessage->data[0])
{
- case 42: // COMMANDE JACK
+ case 0x42: // COMMANDE JACK
// jack = appMessage->data[2];
break;
- case 43: // Update ANGLE
- beacon_number = appMessage->data[1];
- angle_received = appMessage->data[2];
- update_position(beacon_number,angle_received);
+ case 0x43: // Update ANGLE
+// beacon_number = appMessage->data[1];
+// angle_received = appMessage->data[2];
+// update_position(beacon_number,angle_received);
+ break;
+ default:
+ uprintf("Unknown data type received = %x\r\n",appMessage->data[0]);
break;
}
-
- /*if(appMessage->data[0]==0x55)
- {
- sprintf(usartTxBuffer,"Trame recue from %d ==> Lost packet = %d\r\n\0",appMessage->data[1],appMessage->data[2]);
- WRITE_USART(&appUsartDescriptor,usartTxBuffer,strlen(usartTxBuffer));
- }
- else
- {
-
- }*/
}
-#if APP_DETECT_LINK_FAILURE == 1
-/**************************************************************************//**
- * \brief Leave network.
- *
- * \param none.
- * \return none.
- ******************************************************************************/
- static void leaveNetwork(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);
-
- leaveReq.ZDO_ZdpResp = zdpLeaveResp;
- leaveReq.reqCluster = MGMT_LEAVE_CLID;
- leaveReq.dstAddrMode = EXT_ADDR_MODE;
- leaveReq.dstExtAddr = 0;
- zdpLeaveReq->deviceAddr = 0;
- zdpLeaveReq->rejoin = 0;
- zdpLeaveReq->removeChildren = 1;
- zdpLeaveReq->reserved = 0;
- ZDO_ZdpReq(&leaveReq);
- }
+/* Leave network */
+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);
+
+ leaveReq.ZDO_ZdpResp = zdpLeaveResp;
+ leaveReq.reqCluster = MGMT_LEAVE_CLID;
+ leaveReq.dstAddrMode = EXT_ADDR_MODE;
+ leaveReq.dstExtAddr = 0;
+ zdpLeaveReq->deviceAddr = 0;
+ zdpLeaveReq->rejoin = 0;
+ zdpLeaveReq->removeChildren = 1;
+ zdpLeaveReq->reserved = 0;
+ ZDO_ZdpReq(&leaveReq);
+}
- /**************************************************************************//**
- * \brief Leave network response.
- *
- * \param zdpResp - response data
- * \return none.
- ******************************************************************************/
- static void zdpLeaveResp(ZDO_ZdpResp_t *zdpResp)
- {
-
- // Try to rejoin the network
- appState = APP_NETWORK_JOINING_STATE;
- SYS_PostTask(APL_TASK_ID);
-
- (void)zdpResp;
- }
- #endif // APP_DETECT_LINK_FAILURE
-
-void send_data(void)
+
+/* Leave network response */
+void zdpLeaveResp(ZDO_ZdpResp_t *zdpResp)
{
-// PORTD ^= (1<<7);
- buf_to_send.message.data[0]=0x55;
- buf_to_send.message.data[1]=petite_adresse;
- buf_to_send.message.data[2]=lost_packet;
- APS_DataReq(&test);
-// PORTD ^= (1<<7);
+ // Try to rejoin the network
+ appState = APP_NETWORK_JOINING_STATE;
+ SYS_PostTask(APL_TASK_ID);
+
+ (void)zdpResp;
+}
+
+
+void send_data(uint8_t type, uint8_t data)
+{
+ zigbit_tx_buffer.message.data[0]=type;
+ zigbit_tx_buffer.message.data[1]=data;
+ APS_DataReq(&config);
}
void send_angle(int angle_degree)
{
- buf_to_send.message.data[0]=0x43;
- buf_to_send.message.data[1]=petite_adresse;
- buf_to_send.message.data[2]=angle_degree;
+// zigbit_tx_buffer.message.data[0]=0x43;
+// zigbit_tx_buffer.message.data[1]=beacon_id;
+// zigbit_tx_buffer.message.data[2]=angle_degree;
+}
+
+
+
+/* Wakeup event handler (dummy) */
+void ZDO_WakeUpInd(void)
+{
}
+
+/* Stub for ZDO Binding Indication */
+void ZDO_BindIndication(ZDO_BindInd_t *bindInd)
+{
+ (void)bindInd;
+}
+
+/* Stub for ZDO Unbinding Indication */
+void ZDO_UnbindIndication(ZDO_UnbindInd_t *unbindInd)
+{
+ (void)unbindInd;
+}
+
+
+
+
\ No newline at end of file
diff --git a/digital/beacon/src/network.h b/digital/beacon/src/network.h
index c9734df4..aec22c03 100644
--- a/digital/beacon/src/network.h
+++ b/digital/beacon/src/network.h
@@ -1,23 +1,33 @@
-/**************************************************************************//**
- \file Peer2Peer.h
-
- \brief Peer-2-peer sample application header file.
-
- \author
- Atmel Corporation: http://www.atmel.com \n
- Support email: avr@atmel.com
-
- Copyright (c) 2008 , Atmel Corporation. All rights reserved.
- Licensed under Atmel's Limited License Agreement (BitCloudTM).
-
- \internal
- History:
- 14.10.09 A. Taradov - Added FIFO for received packets
-******************************************************************************/
+/* network.h */
+/* Beacon network management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
#ifndef _NETWORK_H
#define _NETWORK_H
+#include <zdo.h>
+
// #define MAX_RETRIES_BEFORE_REJOIN 6
// typedef struct
@@ -48,10 +58,17 @@ typedef struct
void APS_DataIndication(APS_DataInd_t* dataInd);
void APS_DataConf(APS_DataConf_t* confInfo);
void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t* confirmInfo);
-void initNetwork(void);
-void startNetwork(void);
-void send_data(void);
+void ZDO_UnbindIndication(ZDO_UnbindInd_t *unbindInd);
+void ZDO_BindIndication(ZDO_BindInd_t *bindInd);
+void ZDO_WakeUpInd(void);
+
+void network_init(void);
+void network_start(void);
+void send_data(uint8_t type, uint8_t data);
void send_angle(int angle_degree);
+void network_leave(void);
+/* Leave network response */
+void zdpLeaveResp(ZDO_ZdpResp_t *zdpResp);
#endif // ifndef _NETWORK_H
diff --git a/digital/beacon/src/sensors.c b/digital/beacon/src/sensors.c
index 150da7fa..6b7a11bb 100644
--- a/digital/beacon/src/sensors.c
+++ b/digital/beacon/src/sensors.c
@@ -1,127 +1,74 @@
+/* sensors.c */
+/* Beacon sensors management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#include <types.h>
-// #include <zdo.h>
-// #include <peer2peer.h>
#include <irq.h>
#include "sensors.h"
-// #include <network.h>
-// #include <serialInterface.h>
-// #include <stdio.h>
-// #include <debug.h>
-
-/* External variables */
-// extern APS_DataReq_t test;
-// extern HAL_UsartDescriptor_t appUsartDescriptor;
-// extern uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE];
-// extern unsigned int top_tour;
-// extern unsigned int last_tour_time;
-// extern int activation_asserv;
-// extern int nb_top;
-// extern long last_seen_laser;
-
-int consigne_motor_ms = 100;
-int security_ils = 1;
-int old_top_tour = 0;
-long angle = 0;
-unsigned int status_temps_tour = 0;
-unsigned int top_laser;
-unsigned int counter_top_tour;
/********************************************************/
-void init_sensors(void)
-{
-// HAL_RegisterIrq(IRQ_7,IRQ_RISING_EDGE,irq_laser);
-}
-
-void init_ILS(void)
-{
- PORTE = (1<<PE6);
- HAL_RegisterIrq(IRQ_6,IRQ_RISING_EDGE,irq_ILS);
- PORTE = (1<<PE6);
- HAL_EnableIrq(IRQ_6);
- PORTE = (1<<PE6);
-}
-void irq_ILS(void)
+/* This function initializes the laser pin input and associated interrupt */
+void sensors_laser_init(void)
{
-// // HAL_DisableIrq(IRQ_6);
-// unsigned int temps_ms;
-// if(security_ils == 1)
-// {
-// PORTD=~PORTD;
-// security_ils = 0;
-// temps_ms = calcul_temps();
-// if(activation_asserv == 1)
-// {
-// regul_vitesse(temps_ms);
-// }
-// angle = last_seen_laser * 360 / counter_top_tour;
-// counter_top_tour = 0;
-//
-// // SYS_PostTask(APL_TASK_ID); //For angle sending
-// }
-// // HAL_EnableIrq(IRQ_6);
+ HAL_RegisterIrq(IRQ_7,IRQ_RISING_EDGE,sensors_laser_irq_vector);
}
-int calcul_temps()
-{
- long temps = 0;
-// temps = counter_top_tour; //nb de top
-// temps = temps * 128; //temps en us depuis le dernier tours
-// temps = temps / 1000; //temps en ms depuis le dernier tours
-// status_temps_tour = temps;
- return temps;
-}
-void regul_vitesse(int temps)
-{
- int diff = 0;
- int correction = 0;
+/* This function initializes the codewheel optical sensors and associated interrupt */
+void sensors_codewheel_init(void)
+{
+ /* Select external clock on rising edge for timer 3 */
+ TCCR3B |= (1<<CS30)|(1<<CS31)|(1<<CS32);
- diff = consigne_motor_ms - temps;
-
- correction = OCR3A - diff;
+ /* Use CTC mode */
+ TCCR3B |= (1<<WGM32);
- if(correction < 0)
- {
- OCR3A = 0;
- }
- else if(correction > 0xd5)
- {
- OCR3A = 0xd5;
- }
- else
- {
- OCR3A = correction;
- }
+ /* Define the compare value */
+ OCR3A = CODEWHEEL_CPR;
+
+ /* Enable Interrupts */
+ sei();
}
-void init_ic(void)
+/* This function returns the wheel position */
+int sensors_codewheel_get_value(void)
{
- TCCR3A|=(1<<COM3A1)|(1<<COM3A0);
- TCCR3B|=(1<<CS30)|(1<<ICNC3)|(1<<ICES3);
- TIMSK3|= (1<<ICIE3) | (1<<TOIE3);
- TIFR3|=(1<<ICF3);
- sei();
+ return TCNT3;
}
-void irq_laser(void)
+
+/* IRQ vector for Laser Interrupt */
+void sensors_laser_irq_vector(void)
{
-// HAL_DisableIrq(IRQ_7);
-// top_laser=top_tour;
-// nb_top++;
-// sprintf(usartTxBuffer,"%d\r\n",nb_top);
-// WRITE_USART(&appUsartDescriptor,usartTxBuffer,5);
-// // PORTD=~(PORTD);
-// // _delay_ms(50);
-// appState = APP_NETWORK_JOINED_STATE;
-// SYS_PostTask(APL_TASK_ID); // Execute next step
+ //calculate and send value
}
-void control_motor_ms(int value)
+/* IRQ vector for CodeWheel complete turn */
+ISR(TIMER3_OVF_vect)
{
-// activation_asserv = 1;
-// OCR3A = 0x60;
-// consigne_motor_ms = value;
+ //Top tour ++
}
diff --git a/digital/beacon/src/sensors.h b/digital/beacon/src/sensors.h
index 33e96daf..0f868d65 100644
--- a/digital/beacon/src/sensors.h
+++ b/digital/beacon/src/sensors.h
@@ -1,12 +1,43 @@
+/* sensors.h */
+/* Beacon sensors management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#ifndef _SENSORS_H
#define _SENSORS_H
-void init_ILS();
-void irq_laser(void);
-void irq_ILS(void);
-void init_sensors(void);
-int calcul_temps();
-void regul_vitesse(int temps);
-void control_motor_ms(int value);
+#define CODEWHEEL_CPR 500
+
+/* This function initializes the laser pin input and associated interrupt */
+void sensors_laser_init(void);
+
+/* This function initializes the codewheel optical sensors and associated interrupt */
+void sensors_codewheel_init(void);
+
+/* This function returns the wheel position */
+int sensors_codewheel_get_value(void);
+
+/* IRQ vector for Laser Interrupt */
+void sensors_laser_irq_vector(void);
#endif \ No newline at end of file
diff --git a/digital/beacon/src/servo.c b/digital/beacon/src/servo.c
index 42555cd7..7d7e5dc4 100644
--- a/digital/beacon/src/servo.c
+++ b/digital/beacon/src/servo.c
@@ -1,22 +1,38 @@
+/* servo.c */
+/* Beacon servomotor management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#include <types.h>
-// #include <zdo.h>
-// #include <peer2peer.h>
#include <irq.h>
-// #include <sensors.h>
-// #include <network.h>
-// #include <serialInterface.h>
-// #include <stdio.h>
#include "servo.h"
-// #include <debug.h>
-
-void init_timer_servo(void)
+/* This function initializes the timer used for servomotor signal generation */
+void SERVO_timer1_init(void)
{
//Fpwm = f_IO / (prescaler * (1 + TOP)) = 7200 Hz. */
-
-
OCR1B = 210;
OCR1A = 279;
@@ -46,33 +62,51 @@ void init_timer_servo(void)
}
-void increase_angle_servo_1(void)
+/* This function increase by one unit the angle of the defined servo */
+void SERVO_angle_increase(int servo_id)
{
- OCR1A++;
- //uprintf("Servo_1 : Angle increase = %d\r\n",OCR1A);
+ switch(servo_id)
+ {
+ case 1:
+ if(OCR1A < SERVO_1_ANGLE_MAX)
+ {
+ OCR1A++;
+ }
+ break;
+ case 2:
+ if(OCR1B < SERVO_2_ANGLE_MAX)
+ {
+ OCR1B++;
+ }
+ break;
+ default:
+ return;
+ }
}
-void decrease_angle_servo_1(void)
-{
- OCR1A--;
- //uprintf("Servo_1 : Angle decreased = %d\r\n",OCR1A);
-}
-void increase_angle_servo_2(void)
+/* This function decrease by one unit the angle of the defined servo */
+void SERVO_angle_decrease(int servo_id)
{
- OCR1B++;
- //uprintf("Servo_2 : Angle increased = %d\r\n",OCR1B);
+ switch(servo_id)
+ {
+ case 1:
+ if(OCR1A > SERVO_1_ANGLE_MIN)
+ {
+ OCR1A--;
+ }
+ break;
+ case 2:
+ if(OCR1B > SERVO_2_ANGLE_MIN)
+ {
+ OCR1B--;
+ }
+ break;
+ default:
+ return;
+ }
}
-void decrease_angle_servo_2(void)
-{
- OCR1B--;
- //uprintf("Servo_2 : Angle decreased = %d\r\n",OCR1B);
-}
-
-
-
-
SIGNAL (SIG_OVERFLOW1)
{
}
diff --git a/digital/beacon/src/servo.h b/digital/beacon/src/servo.h
index 5ca51117..52580575 100644
--- a/digital/beacon/src/servo.h
+++ b/digital/beacon/src/servo.h
@@ -1,14 +1,44 @@
+/* servo.h */
+/* Beacon servomotor management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
#ifndef _SERVO_H
#define _SERVO_H
-void init_timer_servo(void);
-uint8_t servo_get_high_time (uint8_t servo);
-void servo_set_high_time (uint8_t servo, uint8_t high_time);
-void servo_apbteam_init (void);
+#define SERVO_1_ANGLE_MIN 3000
+#define SERVO_1_ANGLE_MAX 3000
+#define SERVO_2_ANGLE_MIN 3000
+#define SERVO_2_ANGLE_MAX 3000
+
+
+/* This function initializes the timer used for servomotor signal generation */
+void SERVO_timer1_init(void);
+
+/* This function increase by one unit the angle of the defined servo */
+void SERVO_angle_increase(int servo_id);
-void increase_angle_servo_1(void);
-void decrease_angle_servo_1(void);
-void increase_angle_servo_2(void);
-void decrease_angle_servo_2(void);
+/* This function decrease by one unit the angle of the defined servo */
+void SERVO_angle_decrease(int servo_id);
#endif \ No newline at end of file