B3M38SPD seminar project - beehive monitor with LoRa reporting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spd-lorabees/Src/main.c

229 lines
7.1 KiB

7 years ago
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Generic lora driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
*/
/******************************************************************************
* @file main.c
* @author MCD Application Team
* @version V1.1.2
* @date 08-September-2017
* @brief this is the main!
7 years ago
******************************************************************************
7 years ago
* @attention
7 years ago
*
7 years ago
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
7 years ago
*
7 years ago
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
7 years ago
*
7 years ago
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 years ago
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
7 years ago
#include "hw.h"
#include "low_power.h"
#include "lora.h"
//#include "bsp.h"
#include "timeServer.h"
#include "vcom.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/*!
* CAYENNE_LPP is myDevices Application server.
*/
//#define CAYENNE_LPP
#define LPP_DATATYPE_DIGITAL_INPUT 0x0
#define LPP_DATATYPE_DIGITAL_OUTPUT 0x1
#define LPP_DATATYPE_HUMIDITY 0x68
#define LPP_DATATYPE_TEMPERATURE 0x67
#define LPP_DATATYPE_BAROMETER 0x73
#define LPP_APP_PORT 99
/*!
* Defines the application data transmission duty cycle. 5s, value in [ms].
*/
#define APP_TX_DUTYCYCLE 10000
/*!
* LoRaWAN Adaptive Data Rate
* @note Please note that when ADR is enabled the end-device should be static
*/
#define LORAWAN_ADR_ON 1
/*!
* LoRaWAN confirmed messages
*/
#define LORAWAN_CONFIRMED_MSG DISABLE
/*!
* LoRaWAN application port
* @note do not use 224. It is reserved for certification
*/
#define LORAWAN_APP_PORT 2
/*!
* Number of trials for the join request.
*/
#define JOINREQ_NBTRIALS 3
/* Private macro -------------------------------------------------------------*/
7 years ago
/* Private function prototypes -----------------------------------------------*/
7 years ago
/* call back when LoRa will transmit a frame*/
static void LoraTxData(lora_AppData_t *AppData, FunctionalState *IsTxConfirmed);
7 years ago
7 years ago
/* call back when LoRa has received a frame*/
static void LoraRxData(lora_AppData_t *AppData);
7 years ago
7 years ago
/* Private variables ---------------------------------------------------------*/
/* load call backs*/
static LoRaMainCallback_t LoRaMainCallbacks = {HW_GetBatteryLevel,
HW_GetUniqueId,
HW_GetRandomSeed,
LoraTxData,
LoraRxData};
/*!
* Specifies the state of the application LED
*/
static uint8_t AppLedStateOn = RESET;
#ifdef USE_B_L072Z_LRWAN1
/*!
* Timer to handle the application Tx Led to toggle
*/
static TimerEvent_t TxLedTimer;
static void OnTimerLedEvent( void );
#endif
/* !
*Initialises the Lora Parameters
*/
static LoRaParam_t LoRaParamInit = {TX_ON_TIMER,
APP_TX_DUTYCYCLE,
CLASS_A,
LORAWAN_ADR_ON,
DR_0,
LORAWAN_PUBLIC_NETWORK,
JOINREQ_NBTRIALS};
/* Private functions ---------------------------------------------------------*/
7 years ago
7 years ago
/**
* @brief Main program
* @param None
* @retval None
*/
7 years ago
int main(void)
{
7 years ago
/* STM32 HAL library initialization*/
HAL_Init();
7 years ago
7 years ago
/* Configure the system clock*/
SystemClock_Config();
7 years ago
7 years ago
/* Configure the debug mode*/
DBG_Init();
7 years ago
7 years ago
/* Configure the hardware*/
HW_Init();
7 years ago
7 years ago
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
7 years ago
7 years ago
/* Configure the Lora Stack*/
lora_Init(&LoRaMainCallbacks, &LoRaParamInit);
7 years ago
7 years ago
PRINTF("starting!!!\n\r");
7 years ago
7 years ago
/* main loop*/
while (1) {
/* run the LoRa class A state machine*/
lora_fsm();
7 years ago
7 years ago
DISABLE_IRQ();
/* if an interrupt has occurred after DISABLE_IRQ, it is kept pending
* and cortex will not enter low power anyway */
if (lora_getDeviceState() == DEVICE_STATE_SLEEP) {
#ifndef LOW_POWER_DISABLE
LowPower_Handler();
#endif
}
ENABLE_IRQ();
7 years ago
7 years ago
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
}
7 years ago
}
7 years ago
static void LoraTxData(lora_AppData_t *AppData, FunctionalState *IsTxConfirmed)
7 years ago
{
7 years ago
/* USER CODE BEGIN 3 */
7 years ago
7 years ago
AppData->Port = LORAWAN_APP_PORT;
7 years ago
7 years ago
//TODO
7 years ago
7 years ago
*IsTxConfirmed = LORAWAN_CONFIRMED_MSG;
7 years ago
7 years ago
AppData->BuffSize = 0;
7 years ago
7 years ago
/* USER CODE END 3 */
}
7 years ago
7 years ago
static void LoraRxData(lora_AppData_t *AppData)
7 years ago
{
7 years ago
/* USER CODE BEGIN 4 */
switch (AppData->Port) {
case LORAWAN_APP_PORT:
break;
case LPP_APP_PORT: {
break;
}
default:
break;
}
/* USER CODE END 4 */
7 years ago
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/