wip
This commit is contained in:
parent
48c0a9f33d
commit
e0b680d48b
|
@ -107,8 +107,9 @@ void Error_Handler(void);
|
|||
#define MEMS_RESET_Pin GPIO_PIN_4
|
||||
#define MEMS_RESET_GPIO_Port GPIOB
|
||||
|
||||
#define PME_ON HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET )
|
||||
#define PME_OFF HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET )
|
||||
#define PME_ON HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET )
|
||||
#define PME_OFF HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET )
|
||||
#define PME_TOGGLE HAL_GPIO_TogglePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
|||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stddef.h>
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "yunhorn_sts_prd_conf.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
@ -80,6 +80,31 @@ typedef enum
|
|||
CFG_SEQ_Task_LoRaStoreContextEvent,
|
||||
CFG_SEQ_Task_LoRaStopJoinEvent,
|
||||
/* USER CODE BEGIN CFG_SEQ_Task_Id_t */
|
||||
CFG_SEQ_Task_YunhornSTSEventRFAC, /* RFAC */
|
||||
|
||||
#ifdef STS_O6
|
||||
CFG_SEQ_Task_YunhornSTSEventP1, /* REEDSWITCH, IO */
|
||||
CFG_SEQ_Task_YunhornSTSEventP2, /* MOTION */
|
||||
CFG_SEQ_Task_YunhornSTSEventP3, /* LAMP BAR LED */
|
||||
#endif
|
||||
#ifdef STS_R1
|
||||
CFG_SEQ_Task_YunhornSTSEventP4, /* TOF RANGE */
|
||||
#endif
|
||||
#ifdef STS_P2
|
||||
CFG_SEQ_Task_YunhornSTSEventP5, /* TOF IN-OUT */
|
||||
#endif
|
||||
#ifdef STS_R4
|
||||
CFG_SEQ_Task_YunhornSTSEventP6, /* SOAP LEVEL */
|
||||
#endif
|
||||
#ifdef STS_E2
|
||||
CFG_SEQ_Task_YunhornSTSEventP7, /* IAQ */
|
||||
#endif
|
||||
#ifdef STS_M1
|
||||
CFG_SEQ_Task_YunhornSTSEventP8, /* ETR, PULSE COUNT */
|
||||
#endif
|
||||
#ifdef MODBUS_RS485
|
||||
STS_YunhornSTSEventPIORS485_Process, /* RS485 MODBUS RTU */
|
||||
#endif
|
||||
|
||||
/* USER CODE END CFG_SEQ_Task_Id_t */
|
||||
CFG_SEQ_Task_NBR
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
/* External variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
uint8_t outbuf[128]={0x0};
|
||||
extern volatile uint8_t *sts_ac_code;
|
||||
extern volatile uint32_t rfac_timer;
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -237,6 +239,45 @@ static void OnRxTimerLedEvent(void *context);
|
|||
*/
|
||||
static void OnJoinTimerLedEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief STS Lamp Bar timer callback function
|
||||
* @param context ptr of Lamp Bar LED context
|
||||
*/
|
||||
static void OnYunhornSTSLampBarColorTimerEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief SYS occupancy, door lock, motion duration check timer callback function
|
||||
* @param context ptr of duration check context
|
||||
*/
|
||||
static void OnYunhornSTSDurationCheckTimerEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Occupancy RSS WakeUP timer callback function
|
||||
* @param context ptr of STS RSS WakeUp context
|
||||
*/
|
||||
|
||||
static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context);
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Heart beat timer callback function
|
||||
* @param context ptr of context
|
||||
*/
|
||||
|
||||
static void OnYunhornSTSHeartBeatTimerEvent(void *context);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Heart Beat Periodicity Chagne function
|
||||
* @param duration of periodicty in ms (1/1000 sec)
|
||||
*/
|
||||
static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity);
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS AC Code handle Process
|
||||
* @param void
|
||||
*/
|
||||
static void STS_YUNHORN_RFAC_HANDLE_PROCESS(void);
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
@ -305,6 +346,7 @@ static UTIL_TIMER_Object_t TxTimer;
|
|||
*/
|
||||
static UTIL_TIMER_Object_t WakeUpScanTimer;
|
||||
|
||||
static UTIL_TIMER_Object_t YunhornSTSHeartBeatTimer;
|
||||
|
||||
/**
|
||||
* @brief Tx Timer period
|
||||
|
@ -1107,3 +1149,126 @@ static void OnRestoreContextRequest(void *nvm, uint32_t nvm_size)
|
|||
/* USER CODE END OnRestoreContextRequest_Last */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Occupancy RSS WakeUP timer callback function, act as sampling process
|
||||
* @param context ptr of STS RSS WakeUp context
|
||||
*/
|
||||
static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context)
|
||||
{
|
||||
#if 0
|
||||
if ((sts_work_mode == STS_RSS_MODE)||(sts_work_mode == STS_DUAL_MODE)||(sts_work_mode == STS_UNI_MODE))
|
||||
{
|
||||
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0);
|
||||
|
||||
if ((sts_rss_result_changed_flag == 1) || (sts_fall_rising_detected_result_changed_flag == 1))
|
||||
{
|
||||
//SendTxData();
|
||||
sts_rss_result_changed_flag = 0;
|
||||
sts_fall_rising_detected_result_changed_flag = 0;
|
||||
|
||||
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
|
||||
//if ((last_sts_rss_result ==STS_RESULT_NO_MOTION)&& (sts_rss_result==STS_RESULT_MOTION))
|
||||
{
|
||||
//OnSensor3StateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Sensor Heart Beat Timer callback function
|
||||
* @param context ptr of STS Sampling Check context
|
||||
*/
|
||||
static void OnYunhornSTSHeartBeatTimerEvent(void *context)
|
||||
{
|
||||
//heart_beat_timer = 1;
|
||||
//UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
|
||||
AppData.Port = YUNHORN_STS_P2_LORA_APP_HTBT_PORT;
|
||||
AppData.BufferSize = 2;
|
||||
AppData.Buffer[0]=0x80;
|
||||
AppData.Buffer[1]=0x63; //TODO XXX change to battery level %
|
||||
|
||||
LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
|
||||
if(LORAMAC_HANDLER_SUCCESS == status) APP_LOG(TS_OFF, VLEVEL_L, "\nHeart-beat Sent out \r\n");
|
||||
|
||||
if ((sts_ac_code[0]==0x0) && (sts_ac_code[19]==0x0)) /* simple validation of non-empty ac code */
|
||||
{
|
||||
/* RFAC Challenge */
|
||||
if (rfac_timer < (STS_BURN_IN_RFAC+3)) {
|
||||
rfac_timer ++;
|
||||
}
|
||||
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
|
||||
}
|
||||
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Sensor Live Heart Beat Periodicity/interval Change callback function
|
||||
* @param context ptr of STS Live Heart Beat context
|
||||
* YL x x x
|
||||
* */
|
||||
|
||||
static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
|
||||
{
|
||||
/* USER CODE BEGIN OnTxPeriodicityChanged_1 */
|
||||
|
||||
/* USER CODE END OnTxPeriodicityChanged_1 */
|
||||
|
||||
if (periodicity == 0)
|
||||
{
|
||||
/* Revert to application default periodicity */
|
||||
periodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms
|
||||
}
|
||||
|
||||
/* Update timer periodicity */
|
||||
|
||||
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
|
||||
UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, periodicity);
|
||||
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
||||
|
||||
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */
|
||||
APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 );
|
||||
/* USER CODE END OnTxPeriodicityChanged_2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Yunhorn STS Sensor Sampling Periodicity/interval Change callback function
|
||||
* @param context ptr of STS RSS WakeUp context
|
||||
*/
|
||||
|
||||
static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity)
|
||||
{
|
||||
/* USER CODE BEGIN OnTxPeriodicityChanged_1 */
|
||||
|
||||
/* USER CODE END OnTxPeriodicityChanged_1 */
|
||||
|
||||
if (periodicity == 0)
|
||||
{
|
||||
/* Revert to application default periodicity */
|
||||
periodicity = APP_TX_DUTYCYCLE;
|
||||
}
|
||||
|
||||
/* Update timer periodicity */
|
||||
|
||||
#if defined(STS_O6)||defined(STS_O7)
|
||||
UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer);
|
||||
UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, periodicity);
|
||||
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
|
||||
APP_LOG(TS_OFF, VLEVEL_M,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
|
||||
#else
|
||||
#ifdef STS_E2
|
||||
UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer);
|
||||
UTIL_TIMER_SetPeriod(&YunhornSTSSamplingCheckTimer, periodicity);
|
||||
UTIL_TIMER_Start(&YunhornSTSSamplingCheckTimer);
|
||||
APP_LOG(TS_OFF, VLEVEL_M,"**************** SamplingPeriodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */
|
||||
|
||||
/* USER CODE END OnTxPeriodicityChanged_2 */
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.548833444" name="Debug" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug">
|
||||
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.548833444" name="Debug" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug">
|
||||
<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.548833444." name="/" resourcePath="">
|
||||
<toolChain id="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug.1245189394" name="MCU ARM GCC" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug">
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu.1668122417" name="MCU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu" useByScannerDiscovery="true" value="STM32WLE5CCUx" valueType="string"/>
|
||||
|
@ -76,6 +76,12 @@
|
|||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1944207685" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.1421055350" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32WLE5CCUX_FLASH.ld}" valueType="string"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags.108089525" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value=":libSTM32Cryptographic_CM4.a"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.additionalobjs.1376873273" name="Additional object files" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.additionalobjs" valueType="userObjs">
|
||||
<listOptionValue builtIn="false" value="../../../../../../../Middlewares/ST/STM32_Cryptographic/lib"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.796162615" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
|
@ -168,6 +174,19 @@
|
|||
</tool>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1749026972" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.1425112380" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32WLE5CCUX_FLASH.ld}" valueType="string"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.additionalobjs.2070807673" name="Additional object files" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.additionalobjs" valueType="userObjs"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags.74061769" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="-z noexecstack"/>
|
||||
<listOptionValue builtIn="false" value="-Wunused-but-set-variable"/>
|
||||
<listOptionValue builtIn="false" value="-Wunused-variable"/>
|
||||
</option>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.fshort.1815009447" name="(-fshort-enums)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.fshort" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries.1112753374" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries" valueType="libs">
|
||||
<listOptionValue builtIn="false" value=":libSTM32Cryptographic_CM4.a"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories.1621778628" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value="../../../../../../../Middlewares/ST/STM32_Cryptographic/lib"/>
|
||||
</option>
|
||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.715223353" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
|
|
|
@ -72,7 +72,7 @@ main-build: WLE5CC_NODE_STS.elf secondary-outputs
|
|||
|
||||
# Tool invocations
|
||||
WLE5CC_NODE_STS.elf WLE5CC_NODE_STS.map: $(OBJS) $(USER_OBJS) D:\ONEDRIVE\STM32WLV13\Projects\NUCLEO-WL55JC\Applications\LoRaWAN\WLE5CC_NODE_STS\STM32CubeIDE\STM32WLE5CCUX_FLASH.ld makefile objects.list $(OPTIONAL_TOOL_DEPS)
|
||||
arm-none-eabi-gcc -o "WLE5CC_NODE_STS.elf" @"objects.list" $(USER_OBJS) $(LIBS) -mcpu=cortex-m4 -T"D:\ONEDRIVE\STM32WLV13\Projects\NUCLEO-WL55JC\Applications\LoRaWAN\WLE5CC_NODE_STS\STM32CubeIDE\STM32WLE5CCUX_FLASH.ld" --specs=nosys.specs -Wl,-Map="WLE5CC_NODE_STS.map" -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
|
||||
arm-none-eabi-gcc -o "WLE5CC_NODE_STS.elf" @"objects.list" $(USER_OBJS) $(LIBS) -mcpu=cortex-m4 -T"D:\ONEDRIVE\STM32WLV13\Projects\NUCLEO-WL55JC\Applications\LoRaWAN\WLE5CC_NODE_STS\STM32CubeIDE\STM32WLE5CCUX_FLASH.ld" --specs=nosys.specs -Wl,-Map="WLE5CC_NODE_STS.map" -Wl,--gc-sections -static -L../../../../../../../Middlewares/ST/STM32_Cryptographic/lib -z noexecstack -Wunused-but-set-variable -Wunused-variable -fshort-enums --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
|
||||
@echo 'Finished building target: $@'
|
||||
@echo ' '
|
||||
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
USER_OBJS :=
|
||||
|
||||
LIBS :=
|
||||
LIBS := -l:libSTM32Cryptographic_CM4.a
|
||||
|
||||
|
|
|
@ -50,10 +50,6 @@
|
|||
/* ########################## Product Selection ##############################
|
||||
* @brief This is the list of Yunhorn STS products to be used in ALL product config
|
||||
*/
|
||||
|
||||
#define YUNHORN_STS_USER_APP_CTRL_PORT 2U
|
||||
#define YUNHORN_STS_USER_APP_CTRL_REPLY_PORT 1U
|
||||
|
||||
#ifdef YUNHORN_STS_R1_ENABLED
|
||||
#define YUNHORN_STS_R1_LORA_APP_DATA_PORT 57U
|
||||
#define YUNHORN_STS_R1_LORA_APP_HTBT_PORT 58U
|
||||
|
@ -103,34 +99,35 @@
|
|||
//#define YUNHORN_STS_M10_LORA_APP_HTBT_PORT 9U
|
||||
|
||||
#ifdef STS_P2
|
||||
#define YUNHORN_STS_P2_LORA_APP_DATA_PORT 106U
|
||||
#define YUNHORN_STS_P2_LORA_APP_HTBT_PORT 107U
|
||||
#define YUNHORN_STS_P2_LORA_APP_DATA_PORT 106U
|
||||
#define YUNHORN_STS_P2_LORA_APP_HTBT_PORT 107U
|
||||
#define YUNHORN_STS_USER_APP_CTRL_PORT 2U
|
||||
#define YUNHORN_STS_USER_APP_CTRL_REPLY_PORT 1U
|
||||
#define YUNHORN_STS_PRD_STRING "STS_P2"
|
||||
|
||||
#define sts_mtmcode1 0U
|
||||
#define sts_mtmcode2 106U
|
||||
#define sts_hardware_ver 1U
|
||||
#define sts_version 1U
|
||||
#define sts_senddataport (YUNHORN_STS_P2_LORA_APP_DATA_PORT)
|
||||
#define sts_sendhtbtport (YUNHORN_STS_P2_LORA_APP_HTBT_PORT)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define YUNHORN_STS_PRD_STRING "STS_P2"
|
||||
/* General Settings */
|
||||
#define MajorVer 24U
|
||||
#define MinorVer 9U
|
||||
#define SubMinorVer 9U
|
||||
#define SubMinorVer 14U
|
||||
#define FirmwareVersion 3U
|
||||
#define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U
|
||||
#define YUNHORN_STS_AC_CODE_SIZE 20U
|
||||
|
||||
#define STS_NVM_CFG_SIZE 32U
|
||||
#define STS_CFG_PCFG_SIZE 28U
|
||||
#define STS_CFG_PCFG_SIZE 20U
|
||||
#define STS_CFG_CMD_SIZE 30U
|
||||
#define STS_CFG_CMD_SHORT_LEN 8U
|
||||
#define STS_MODE_COLOR_CMD_LEN 5U
|
||||
|
||||
#define STS_R0_NVM_CFG_SIZE 16U
|
||||
#define STS_R0_CFG_CMD_SIZE 12U
|
||||
#define CFG_CMD_TOF_SIMPLE_SIZE (STS_R0_CFG_CMD_SIZE)
|
||||
|
||||
#ifdef YUNHORN_STS_R1_ENABLED
|
||||
#define sts_mtmcode1 0U
|
||||
|
|
|
@ -57,70 +57,6 @@ enum p_cmd_order{
|
|||
P_WORK_MODE, // #4 work mode
|
||||
P_NET_COLOR // #5 cloud net color
|
||||
};
|
||||
#if (defined(YUNHORN_STS_M7_ENABLED) || defined(YUNHORN_STS_O6_ENABLED))
|
||||
enum sts_sensor_result_t {
|
||||
STS_RESULT_NO_MOTION = 0,
|
||||
STS_RESULT_MOTION,
|
||||
STS_RESULT_NO_WAVE,
|
||||
STS_RESULT_WAVE,
|
||||
STS_RESULT_NO_PRESENCE,
|
||||
STS_RESULT_PRESENCE,
|
||||
STS_RESULT_WATER_LEAKAGE_YES,
|
||||
STS_RESULT_WATER_LEAKAGE_NO,
|
||||
STS_RESULT_SOAP_LEVEL_ABOVE,
|
||||
STS_RESULT_SOAP_LEVEL_BELOW
|
||||
};
|
||||
enum RSS_CFG_order{
|
||||
// FOR SIMPLE CONFIG .... 8 BYTES
|
||||
RSS_CFG_START_M_H=0,
|
||||
RSS_CFG_START_M_L,
|
||||
|
||||
RSS_CFG_LENGTH_M_H,
|
||||
RSS_CFG_LENGTH_M_L,
|
||||
|
||||
RSS_CFG_THRESHOLD_H,
|
||||
RSS_CFG_THRESHOLD_L,
|
||||
|
||||
RSS_CFG_RECEIVER_GAIN_H,
|
||||
RSS_CFG_RECEIVER_GAIN_L,
|
||||
// FOR SIMPLE CONFIG .... 8 BYTES
|
||||
|
||||
RSS_CFG_PROFILE,
|
||||
|
||||
RSS_CFG_RATE_TRACKING_H,
|
||||
RSS_CFG_RATE_TRACKING_L,
|
||||
|
||||
RSS_CFG_RATE_PRESENCE_H,
|
||||
RSS_CFG_RATE_PRESENCE_L,
|
||||
|
||||
RSS_CFG_HWAAS_H,
|
||||
RSS_CFG_HWAAS_L,
|
||||
|
||||
RSS_CFG_NBR_REMOVED_PC,
|
||||
|
||||
RSS_CFG_ITE_DEVIATION_H,
|
||||
RSS_CFG_ITE_DEVIATION_L,
|
||||
|
||||
RSS_CFG_ITE_FAST_CUTOFF_H,
|
||||
RSS_CFG_ITE_FAST_CUTOFF_L,
|
||||
|
||||
RSS_CFG_ITE_SLOW_CUTOFF_H,
|
||||
RSS_CFG_ITE_SLOW_CUTOFF_L,
|
||||
|
||||
RSS_CFG_ITR_TIME_H,
|
||||
RSS_CFG_ITR_TIME_L,
|
||||
|
||||
RSS_CFG_ITR_WEIGHT_H,
|
||||
RSS_CFG_ITR_WEIGHT_L,
|
||||
|
||||
RSS_CFG_OUTPUT_TIME_H,
|
||||
RSS_CFG_OUTPUT_TIME_L,
|
||||
|
||||
RSS_CFG_DOWNSAMPLING_FACTOR,
|
||||
|
||||
RSS_CFG_POWER_MODE
|
||||
};
|
||||
#endif
|
||||
|
||||
//"P 0 0 "+"1 2 3 1 2 3 1 2 3 1 2"
|
||||
// P
|
||||
|
@ -128,113 +64,6 @@ enum RSS_CFG_order{
|
|||
// P 1 0 SENSOR HEAD 0, VERSION 0
|
||||
// P 1 0 1 2 SENSOR HEAD 0, VERSION 0, VALUE 12, 1*10+2
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
enum sts_ctrl_cmd_type {
|
||||
STS_CTRL_CMD_TYPE_DUTYCYCLE_LEVEL_CHANGE,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L0X=0x00,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L1X, //0X01
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L2X, //0X02
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L3X, //0X03
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L4X, //0X04
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_VL53L5X, //0X05
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_MV_ADXL345, //0X06
|
||||
STS_CTRL_CMD_MEMS_TUNE_MV_ADXL365, //0X07
|
||||
STS_CTRL_CMD_MEMS_TUNE_MV_ADXL362, //0X08
|
||||
STS_CTRL_CMD_MEMS_TUNE_MV_ADXL110X, //0X09
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_FMCW_TI16X,
|
||||
STS_CTRL_CMD_MEMS_TUNE_FMCW_TI68X,
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_PCR_A11X,
|
||||
STS_CTRL_CMD_MEMS_TUNE_PCR_A12X,
|
||||
|
||||
STS_CTRL_CMD_PRESENCE_SETTING,
|
||||
STS_CTRL_CMD_PRESENCE_TUNE_LED_COLOR,
|
||||
STS_CTRL_CMD_PRESENCE_TUNE_WORK_MODE,
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_SMOKING_MUSIC,
|
||||
STS_CTRL_CMD_MEMS_TUNE_SMOKING_ENABLE,
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_WATER_FLOW_DN,
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_DIGITAL_RELAY,
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_FAN_CONTROL,
|
||||
STS_CTRL_CMD_MEMS_TUNE_VENTILATION_FAN_SPEED,
|
||||
STS_CTRL_CMD_MEMS_TUNE_VENTILATION_FAN_SWING,
|
||||
|
||||
|
||||
STS_CTRL_CMD_MEMS_TUNE_DEVICE_COMPONENT
|
||||
}; // sensor_mems_type
|
||||
|
||||
enum sts_ctrl_cmd_tune_para{
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_RANGE_START=0,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_RANGE_END,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_THRESHOLD,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_GAIN,
|
||||
STS_CTRL_CMD_MEMS_TUNE_TOF_MAX_DISTANCE
|
||||
}; // sensor_mems_tof_tune_type
|
||||
#endif
|
||||
|
||||
#if (defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R1_ENABLED) || defined(YUNHORN_STS_R2_ENABLED) || defined(YUNHORN_STS_R5_ENABLED))
|
||||
typedef struct
|
||||
{
|
||||
uint16_t distance_mm; /*Default distance sensor measured distance in mm, min=0mm, max=2500mm. */
|
||||
uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */
|
||||
|
||||
uint8_t on_off_event; /* 1: liquid sensed, 0: no liquid sensed */
|
||||
uint8_t measure_tech; /* 0: capacit, 1:dTof, 2: ultrasonic */
|
||||
|
||||
uint8_t distance_mm_h; /*MSB */
|
||||
uint8_t distance_mm_l; /*LSB max=255 mm for short range measure */
|
||||
uint16_t distance1_mm; /* Additional #1 distance sensor */
|
||||
uint16_t distance2_mm; /* Additional #2 distance sensor */
|
||||
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
} STS_R0_SensorDataTypeDef;
|
||||
#endif
|
||||
|
||||
#if (defined(YUNHORN_STS_O0_ENABLED) || defined(YUNHORN_STS_O1_ENABLED) || defined(YUNHORN_STS_O2_ENABLED) || defined(YUNHORN_STS_O3_ENABLED) || defined(YUNHORN_STS_O4_ENABLED) || defined(YUNHORN_STS_O5_ENABLED)|| defined(YUNHORN_STS_O6_ENABLED))
|
||||
typedef struct
|
||||
{
|
||||
uint8_t lamp_bar_color; /*measured color ID, 0,1,2,3,4,5,6,7,8,9 */
|
||||
uint8_t workmode; /*work mode, 0,1,2,3,4*/
|
||||
uint8_t state_sensor1_on_off; /* reedswitch or hall element 0: open, 1: closed */
|
||||
uint8_t state_sensor2_on_off; /* pcr_sensor_on_off; 1: occupancy, 0: no occupancy */
|
||||
uint8_t state_sensor3_on_off; /* urinal_sensor_on_off urinal sensor state */
|
||||
uint8_t state_sensor4_on_off; /* reserved_sensor_on_off sensor state */
|
||||
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
uint8_t sts_service_mask; /* sts service mask */
|
||||
} STS_OO_SensorDataTypeDef;
|
||||
#endif
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
typedef struct
|
||||
{
|
||||
float start_m;
|
||||
float length_m;
|
||||
uint8_t acc_profile;
|
||||
uint8_t hwaas;
|
||||
uint8_t downsampling;
|
||||
float sweep_average;
|
||||
float gain;
|
||||
float threshold;
|
||||
float data_output_time;
|
||||
} distance_measure_cfg_t;
|
||||
|
||||
#define DEFAULT_START_M_2 (0.2f)
|
||||
#define DEFAULT_LENGTH_M_2 (1.4f)
|
||||
#define DEFAULT_UPDATE_RATE_2 (10)
|
||||
#define DEFAULT_POWER_SAVE_MODE_2 ACC_POWER_SAVE_MODE_SLEEP
|
||||
#define DEFAULT_DETECTION_THRESHOLD_2 (2.0f)
|
||||
#define DEFAULT_NBR_REMOVED_PC_2 (0)
|
||||
#define DEFAULT_ZONE_LENGTH (0.4f) //default 0.4 unit(meter)
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -242,224 +71,7 @@ typedef struct
|
|||
uint8_t SleepStatus;
|
||||
} STS_PRESENCE_SENSOR_Event_Status_t;
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
|
||||
typedef struct STS_OO_RSS_SensorTuneDataTypeDef
|
||||
{
|
||||
uint8_t default_workmode;
|
||||
uint8_t default_lamp_bar_color;
|
||||
|
||||
float default_profile; //---[4] (4) // 1,2,3,4,5
|
||||
|
||||
float default_start_m; //[08](0.80f) //default 0.2 unit(meter) [1]
|
||||
float default_length_m; //[20](2.00f) //default 2.5
|
||||
float default_zone_length_m; //---[04](0.4f) almost fixed, no need to change
|
||||
|
||||
float default_update_rate_wake_up; //---[02](2.0f) //default 80 unit(hz)
|
||||
float default_update_rate_tracking; //[10](10.0f) //default 80 unit(hz) [7]
|
||||
float default_update_rate_presence; //[65](65.0F) //(65.0f) //default 80 unit(hz)
|
||||
float default_hwaas; //[63](63) //default 10 unit(hz)
|
||||
|
||||
float default_threshold; //[15](1.5f) //default 1.5 level float [3]
|
||||
|
||||
float default_nbr_removed_pc; //(0) //default (0-2)
|
||||
float default_power_save_mode; // 0-4
|
||||
|
||||
//filters
|
||||
float default_inter_frame_deviation_time_const; //[05](0.5f) //default 0.5 unit(seconds) [6]
|
||||
float default_inter_frame_fast_cutoff; //[10](10.0f) //default 20.0 unit(hz) [8]
|
||||
float default_inter_frame_slow_cutoff; //[001](0.01f) //(0.01f) 0.2 hz unit(hz) [9]
|
||||
float default_intra_frame_time_const; //[00](00) //default 0.0 unit(seconds)
|
||||
float default_intra_frame_weight; //[06](00) //default 0.6
|
||||
float default_output_time_const; //[05](0.5f) //default 0.5 unit(seconds) [5]
|
||||
//filters
|
||||
|
||||
float default_downsampling_factor; //[2](2) //default 1
|
||||
float default_receiver_gain; //[45](0.45f) //default 0.9 gain mdB [4]
|
||||
} STS_OO_RSS_SensorTuneDataTypeDef;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(YUNHORN_STS_M0_ENABLED) || defined(YUNHORN_STS_M1_ENABLED) || defined(YUNHORN_STS_M2_ENABLED) || defined(YUNHORN_STS_M5_ENABLED))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t distance_mm; /*measured distance in mm, min=0mm, max=2500mm. */
|
||||
uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */
|
||||
|
||||
/* leakage detection */
|
||||
uint8_t leakage_event; /* 1: leakage detected, 0: no leakage detected */
|
||||
uint8_t leakage_cable_position; /* distance level 0-255 from starting point to length of cable */
|
||||
uint8_t leakage_measure_mode; /* 0: point, 1: cable/distance/level */
|
||||
|
||||
/* closestool clogging detection */
|
||||
uint8_t clogging_state; /* 0: no clogging, 1: clogging */
|
||||
uint8_t clogging_duration_level; /* 0-255 duration level time in min. */
|
||||
uint16_t clogging_level_distance_mm; /* from measure point to measured clogging level, in mm*/
|
||||
|
||||
/* water flow measure */
|
||||
uint16_t water_pulse_count; /* water flow count within counting interval 0-255 */
|
||||
uint8_t water_pipe_diameter_dn; /* DN number DN20--4", DN25--6", DN30--8" */
|
||||
uint8_t water_count_interval; /* in minutes 10 min by default */
|
||||
|
||||
/* power relay */
|
||||
uint8_t break_on_off; /* 0: off, 1: on */
|
||||
uint8_t channel_num_mask; /* 0000 0000 = 0x00, 0xff, 0-7, 8 channels max */
|
||||
|
||||
/* DI, DO digital input output */
|
||||
|
||||
uint8_t di_do_channel_mask; /* 0000 0000 = 0x00, 0xff, 0-7, 8 channels max */
|
||||
|
||||
/* Vibration sensor */
|
||||
uint8_t vibration_on_off; /* 0: off, 1: on */
|
||||
uint8_t vibration_threshold_level; /* 0 -255 */
|
||||
|
||||
uint16_t vb_x_freq; /* max vibration freq in x axis */
|
||||
uint16_t vb_y_freq; /* max vibration freq in y axis */
|
||||
uint16_t vb_z_freq; /* max vibration freq in z axis */
|
||||
|
||||
uint16_t vb_x_rms; /* max vibration rms in x axis */
|
||||
uint16_t vb_y_rms; /* max vibration rms in y axis */
|
||||
uint16_t vb_z_rms; /* max vibration rms in z axis */
|
||||
|
||||
|
||||
/* ventilation fan */
|
||||
uint8_t swing_state; /* 1: swing, 0: no swing */
|
||||
uint8_t speed_level; /* 0: off, speed 1, 2, 3 min max , 4:local remote control released */
|
||||
|
||||
|
||||
uint8_t distance_mm_h; /*MSB */
|
||||
uint8_t distance_mm_l; /*LSB max=255 mm for short range measure */
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
} STS_M0_SensorDataTypeDef;
|
||||
|
||||
#endif
|
||||
#ifdef YUNHORN_STS_O1_ENABLED
|
||||
typedef enum
|
||||
{
|
||||
REED_SWITCH_PIN_RESET = 0U,
|
||||
REED_SWITCH_PIN_SET
|
||||
} REED_SWITCH_State;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DOOR_CONTACT_PIN_RESET = 0U,
|
||||
DOOR_CONTACT_PIN_SET
|
||||
} DOOR_CONTACT_State;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DRY_CONTACT_PIN_RESET = 0U,
|
||||
DRY_CONTACT_PIN_SET
|
||||
} DRY_CONTACT_State;
|
||||
#endif
|
||||
#ifdef YUNHORN_STS_M1_ENABLED
|
||||
typedef enum
|
||||
{
|
||||
WATER_LEAKAGE_PIN_RESET = 0U,
|
||||
WATER_LEAKAGE_PIN_SET
|
||||
} WATER_LEAKAGE_State;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HALL_ELEMENT_PIN_RESET = 0U,
|
||||
HALL_ELEMENT_PIN_SET
|
||||
} HALL_ELEMENT_State;
|
||||
#endif
|
||||
|
||||
#if (defined(YUNHORN_STS_E0_ENABLED) || defined(YUNHORN_STS_E1_ENABLED) || defined(YUNHORN_STS_E2_ENABLED) || defined(YUNHORN_STS_E3_ENABLED) || defined(YUNHORN_STS_E4_ENABLED) || defined(YUNHORN_STS_E5_ENABLED) || defined(YUNHORN_STS_E6_ENABLED) || defined(YUNHORN_STS_E7_ENABLED))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float pressure; /*!< in mbar */
|
||||
float temperature; /*!< in degC - 40C ~ 125C , 0.05 C */
|
||||
float humidity; /*!< in % 0-100 RH% */
|
||||
float distance; /*!< in mm */
|
||||
int16_t co2_ppm; /*!< 400 - 5200 ppm */
|
||||
int16_t tvoc_ppb; /*!< 0 - 60000 ppb */
|
||||
uint32_t latitude; /*!< latitude converted to binary */
|
||||
uint32_t longitude ; /*!< longitude converted to binary */
|
||||
uint16_t altitudeGps; /*!< in m */
|
||||
uint16_t altitudeBar ; /*!< in m * 10 */
|
||||
|
||||
float nh3_ppb; /* NH3 */
|
||||
float h2s_ppb; /* H2S */
|
||||
float ch2o_ppb; /* CH2O */
|
||||
float no2_ppb; /* NO2 */
|
||||
float o3_ugm3; /* O3 ug/m3 */
|
||||
float battery;
|
||||
uint16_t co2_ugm3; /* ug/m3 */
|
||||
uint16_t tvoc_ppb2; /* TVOC */
|
||||
uint16_t pm_dot5_ugm3;
|
||||
uint16_t pm_1_ugm3;
|
||||
uint16_t pm_2dot5_ugm3;
|
||||
uint16_t pm_10_ugm3;
|
||||
/* FOR CIGGARATE SMOKING DETECTION */
|
||||
uint16_t mq2; /* combined smoking sensor */
|
||||
uint16_t co; /* CO */
|
||||
uint8_t iaq; /* IAQ index following EPD standards, HKSAR */
|
||||
|
||||
uint8_t symbol;
|
||||
uint8_t temperature1;
|
||||
uint8_t temperature2;
|
||||
uint8_t humidity1;
|
||||
uint8_t humidity2;
|
||||
uint8_t nh31;
|
||||
uint8_t nh32;
|
||||
uint8_t h2s1;
|
||||
uint8_t h2s2;
|
||||
uint8_t battery1;
|
||||
uint8_t battery2;
|
||||
uint8_t ch2o1;
|
||||
uint8_t ch2o2;
|
||||
|
||||
uint8_t co21;
|
||||
uint8_t co22;
|
||||
|
||||
uint8_t tvoc1;
|
||||
uint8_t tvoc2;
|
||||
|
||||
uint8_t pm251;
|
||||
uint8_t pm252;
|
||||
|
||||
uint8_t pm101;
|
||||
uint8_t pm102;
|
||||
|
||||
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
} STS_E0_SensorDataTypeDef;
|
||||
#endif
|
||||
|
||||
#if (defined(YUNHORN_STS_P0_ENABLED) || defined(YUNHORN_STS_P1_ENABLED) || defined(YUNHORN_STS_P2_ENABLED) || defined(YUNHORN_STS_P3_ENABLED))
|
||||
typedef struct
|
||||
{
|
||||
uint8_t people_count_num; /*measured people number in area, max 30 */
|
||||
|
||||
/* bi-direction */
|
||||
uint16_t people_in_num; /* people in out count in given duration */
|
||||
uint16_t people_out_num; /* people in out count in given duration */
|
||||
uint16_t people_in_out_interval; /* people in out count interval level */
|
||||
|
||||
/* occupancy */
|
||||
uint8_t people_in_out_state_; /* people in or leave state 0: leave, 1: stay */
|
||||
|
||||
/* queueing */
|
||||
uint8_t workmode; /* 0-5, 0:tst, 1:sensor reset, 2:power on, 3: power off */
|
||||
uint8_t tune_param1_left_x_m; /* left range in meter 0.5 - 9.9, 1.5 */
|
||||
uint8_t tune_param2_right_x_m; /* right range in meter 0.5 - 9.9 , 1.5 */
|
||||
uint8_t tune_param1_far_y_m; /* far range in meter 2.5 - 9.9, 6.0*/
|
||||
uint8_t tune_param1_top_z_m; /* top range in meter 0.5 - 9.9, 3.0 */
|
||||
uint8_t tune_param1_height_m; /* installation height in meter 0.5 - 9.9, 2.0 */
|
||||
uint8_t tune_param1_tilt_degree; /* tilt up/down in degree 0 - 45, 15 */
|
||||
|
||||
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
|
||||
uint8_t dutycycletimelevel; /* level=0,255 */
|
||||
} STS_P0_SensorDataTypeDef;
|
||||
|
||||
#endif
|
||||
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
|
@ -485,29 +97,55 @@ typedef struct
|
|||
// 0 --- 10 11 12 -- 39 40 41 42 43 44-63
|
||||
// LEN P RSS FALL_DETECTION AC_CODE
|
||||
enum nvm_order {
|
||||
NVM_MTM1=0,
|
||||
NVM_MTM2,
|
||||
NVM_VER,
|
||||
NVM_HWV,
|
||||
NVM_PERIODICITY,
|
||||
NVM_UNIT,
|
||||
NVM_SAMPLING,
|
||||
NVM_S_UNIT,
|
||||
NVM_WORK_MODE,
|
||||
NVM_SERVICE_MASK,
|
||||
NVM_RESERVE01, //10
|
||||
NVM_LEN, //11, 32=0x20
|
||||
NVM_CFG_START, //12, p[0] bytes for configs,
|
||||
//13, p[1]
|
||||
//14, p[2]
|
||||
// ...
|
||||
//39, P[27]
|
||||
NVM_FALL_DETECTION_ACC_THRESHOLD=40, //40
|
||||
NVM_FALL_DETECTION_DEPTH_THRESHOLD, //41
|
||||
NVM_FALL_DETECTION_RESERVE, //42
|
||||
NVM_OCCUPANCY_OVERTIME_THRESHOLD, //43
|
||||
NVM_AC_CODE_START=44 //STORED, NO UPLOAD
|
||||
//63, 20 bytes for AC code
|
||||
NVM_MTM1=0, // 0
|
||||
NVM_MTM2, // 1
|
||||
NVM_VER, // 2
|
||||
NVM_HWV, // 3
|
||||
NVM_PERIODICITY, // 4
|
||||
NVM_UNIT, // 5
|
||||
NVM_SAMPLING, // 6
|
||||
NVM_S_UNIT, // 7
|
||||
NVM_WORK_MODE, // 8
|
||||
NVM_SERVICE_MASK, // 9
|
||||
NVM_IOC_MASK, //10
|
||||
NVM_LEN, //11, 32=0x20
|
||||
NVM_CFG_START=12, //12, p[0] bytes for configs,
|
||||
//13, p[1]
|
||||
//14, p[2]
|
||||
//15, p[3]
|
||||
//16, p[4]
|
||||
//17, p[5]
|
||||
//18, p[6]
|
||||
//19, p[7]
|
||||
//20, p[8]
|
||||
//21, p[9]
|
||||
//22, p[10]
|
||||
//23, p[11]
|
||||
//24, p[12]
|
||||
//25, p[13]
|
||||
//26, p[14]
|
||||
//27, p[15]
|
||||
//28, p[16]
|
||||
//29, p[17]
|
||||
//30, p[18]
|
||||
NVM_CFG_START_END=31, //31, p[19]
|
||||
NVM_RESERVE02, //32
|
||||
NVM_RESERVE03, //33
|
||||
NVM_SENSOR_INSTALL_HEIGHT, //34
|
||||
NVM_ALARM_PARAMETER05, //35
|
||||
NVM_ALARM_MUTE_RESET_TIMER, //36
|
||||
NVM_ALARM_LAMP_BAR_FLASHING_COLOR, //37
|
||||
NVM_OCCUPANCY_OVERTIME_THRESHOLD, //38
|
||||
|
||||
NVM_MOTIONLESS_DURATION_THRESHOLD, //39
|
||||
NVM_UNCONSCIOUS_LEVEL_THRESHOLD, //40
|
||||
|
||||
NVM_FALL_DETECTION_ACC_THRESHOLD, //41
|
||||
NVM_FALL_DETECTION_DEPTH_THRESHOLD, //42
|
||||
NVM_FALL_CONFIRM_THRESHOLD, //43
|
||||
|
||||
NVM_AC_CODE_START=44 //STORED, NO UPLOAD
|
||||
//63, 20 bytes for AC code
|
||||
};
|
||||
|
||||
typedef struct sts_cfg_nvm {
|
||||
|
@ -517,20 +155,39 @@ typedef struct sts_cfg_nvm {
|
|||
uint8_t hardware_ver;
|
||||
uint8_t periodicity; //count of uplink duty cycle duration high {99}
|
||||
uint8_t unit; // uplink time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours
|
||||
uint8_t sampling; // heart-beat interval or count of sampling duty cycle duration high {99}
|
||||
uint8_t s_unit; // Heart-beat interval or sampling time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours
|
||||
uint8_t sampling; //count of sampling duty cycle duration high {99}
|
||||
uint8_t s_unit; // sampling time unit of duty cycle duration, in 'S', 'M','H' seconds, minutes, hours
|
||||
uint8_t work_mode;
|
||||
uint8_t sts_service_mask;
|
||||
uint8_t reseve01;
|
||||
uint8_t sts_ioc_mask; // I/O Control mask enable all 0xFF, Disable all 0x00 0b0000 0000
|
||||
uint8_t length; // length of following parameters except AC CODE(20bytes)
|
||||
uint8_t p[STS_CFG_PCFG_SIZE];
|
||||
uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2
|
||||
|
||||
uint8_t reserve02;
|
||||
uint8_t reserve03;
|
||||
uint8_t sensor_install_height_in_10cm;
|
||||
uint8_t alarm_parameter05;
|
||||
uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec
|
||||
uint8_t alarm_lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
|
||||
uint8_t occupancy_overtime_threshold_in_10min; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min
|
||||
|
||||
uint8_t motionless_duration_threshold_in_min; // 10(0x0A) min (2 min.) motionless_duration_threshold_in_min
|
||||
uint8_t unconscious_or_motionless_level_threshold; // 0 - 9 motion level *128
|
||||
|
||||
uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2
|
||||
uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm
|
||||
uint8_t fall_detection_reserve;
|
||||
uint8_t occupancy_overtime_threshold; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min
|
||||
uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded
|
||||
uint8_t fall_confirm_threshold_in_10sec; // 0-60(0x3C) Sec, or 3*10(0x03) sec default falldown_confirm_threshold_in_10sec
|
||||
|
||||
uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded
|
||||
} sts_cfg_nvm_t;
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define STS_SERVICE_MASK_L0 (0) // Service normal , no mask off
|
||||
#define STS_SERVICE_MASK_L1 (1) // service mask level 1, sensing data upload in silence mode, node appearance silence (no LED, No display, no sound, no vibration)
|
||||
#define STS_SERVICE_MASK_L2 (2) // service mask level 2, NO sensing data upload (event or periodicity)
|
||||
|
@ -569,21 +226,6 @@ void STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE(void);
|
|||
void STS_SENSOR_NVM_CFG_SIMPLE(void);
|
||||
void STS_SENSOR_NVM_CFG(void);
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
void STS_PRESENCE_SENSOR_Read(STS_OO_SensorDataTypeDef *o6_data);
|
||||
void STS_PRESENCE_SENSOR_Prepare_Send_Data(void);
|
||||
|
||||
void STS_PRESENCE_SENSOR_Init(void);
|
||||
void STS_PRESENCE_SENSOR_RSS_Init(void);
|
||||
void STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init(void);
|
||||
void STS_PRESENCE_SENSOR_TOF_Init(void);
|
||||
#endif
|
||||
|
||||
#ifdef YUNHORN_STS_O5_ENABLED
|
||||
|
||||
void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data);
|
||||
|
||||
#endif
|
||||
void STS_YunhornSTSEventP1_Process(void);
|
||||
void STS_YunhornSTSEventP2_Process(void);
|
||||
void STS_YunhornSTSEventP3_Process(void);
|
||||
|
@ -602,28 +244,6 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8
|
|||
uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID);
|
||||
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
int sts_presence_rss_presence_detection(void);
|
||||
int sts_distance_rss_detector_distance(void);
|
||||
int acc_example_detector_distance(int argc, char *argv[]);
|
||||
int acc_example_service_sparse(int argc, char *argv[]);
|
||||
int acc_example_detector_distance_recorded(int argc, char *argv[]);
|
||||
int sts_presence_rss_bring_up_test(uint8_t *rss_self_test_result);
|
||||
int acc_ref_app_tank_level(int argc, char *argv[]);
|
||||
#endif
|
||||
/*
|
||||
void STS_MOTION_SENSOR_Disable_Wake_Up_Detection(void);
|
||||
|
||||
int32_t STS_MOTION_SENSOR_Set_Wake_Up_Threshold(uint8_t Threshold);
|
||||
int32_t STS_MOTION_SENSOR_Set_Wake_Up_Duration(uint8_t Duration);
|
||||
int32_t STS_MOTION_SENSOR_Enable_Inactivity_Detection(STS_MOTION_SENSOR_IntPin_t IntPin);
|
||||
int32_t STS_MOTION_SENSOR_Disable_Inactivity_Detection(void);
|
||||
int32_t STS_MOTION_SENSOR_Set_Sleep_Duration(uint8_t Duration);
|
||||
|
||||
void STS_MOTION_SENSOR_Get_Event_Status(STS_MOTION_SENSOR_Event_Status_t *Status);
|
||||
void STS_MOTION_SENSOR_Enable_Wake_Up_Detection(void);
|
||||
void STS_MOTION_SENSOR_Initialization(void);
|
||||
*/
|
||||
|
||||
void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_size);
|
||||
void STS_SENSOR_Function_Test_Process(void);
|
||||
|
|
|
@ -71,7 +71,7 @@ uint32_t sts_hmac_sha1(const uint8_t *key, int key_length, const uint8_t *messag
|
|||
sizeof(Computed_Tag_SHA1), /* Expected authentication tag size */
|
||||
&computed_size); /* Generated tag size */
|
||||
|
||||
memcpy(hmac_result->hmac_tag, Computed_Tag_SHA1, sizeof(Computed_Tag_SHA1));
|
||||
UTIL_MEM_cpy_8(hmac_result->hmac_tag, Computed_Tag_SHA1, sizeof(Computed_Tag_SHA1));
|
||||
hmac_result->hmac_tag_size = computed_size;
|
||||
|
||||
return retval;
|
||||
|
|
|
@ -34,18 +34,20 @@
|
|||
#include "yunhorn_sts_prd_conf.h"
|
||||
#include "yunhorn_sts_sensors.h"
|
||||
#include "sts_cmox_hmac_sha.h"
|
||||
|
||||
#include "flash_if.h"
|
||||
#include "lora_app.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
volatile sts_cfg_nvm_t sts_cfg_nvm;
|
||||
volatile uint8_t sts_ac_code[20];
|
||||
volatile uint8_t sts_service_mask;
|
||||
volatile uint8_t sts_work_mode;
|
||||
volatile uint32_t rfac_timer;
|
||||
volatile uint16_t sts_sensor_install_height;
|
||||
volatile uint8_t sensor_data_ready;
|
||||
volatile sts_cfg_nvm_t sts_cfg_nvm={0x0};
|
||||
volatile uint8_t sts_ac_code[20]={0x0};
|
||||
volatile uint8_t sts_service_mask=STS_SERVICE_MASK_L0;
|
||||
volatile uint8_t sts_work_mode=4;
|
||||
volatile uint32_t rfac_timer=0;
|
||||
volatile uint16_t sts_sensor_install_height=3000;
|
||||
volatile uint8_t sensor_data_ready=0;
|
||||
static uint8_t outbuf[128]={0x0};
|
||||
extern volatile hmac_result_t hmac_result;
|
||||
|
||||
#if 0
|
||||
volatile uint8_t sts_reed_hall_result, last_sts_reed_hall_result,sts_reed_hall_changed_flag;
|
||||
volatile uint32_t event_start_time, event_stop_time;
|
||||
volatile uint8_t sts_soap_level_state;
|
||||
|
@ -56,10 +58,10 @@ volatile uint8_t sts_reed_hall_changed_flag = 0;
|
|||
volatile uint8_t sts_reed_hall_result =0;
|
||||
volatile uint8_t sts_water_leakage_result=0;
|
||||
volatile uint8_t sts_water_leakage_changed_flag=0;
|
||||
|
||||
#ifdef YUNHORN_STS_O5_ENABLED
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if (defined(YUNHORN_STS_O6_ENABLED) && defined(USE_ACCONEER_A111))
|
||||
extern volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config;
|
||||
extern volatile uint8_t sts_rss_result, sts_rss_2nd_result;
|
||||
|
@ -129,29 +131,30 @@ extern volatile float sts_presence_rss_distance;
|
|||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
#if (defined(YUNHORN_STS_O6_ENABLED) && defined(USE_ACCONEER_A111))
|
||||
|
||||
#endif
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/* initiated by AUTO RESPOND PARSE PROCESS */
|
||||
void STS_YunhornAuthenticationCode_Process(void)
|
||||
{
|
||||
if ((sts_ac_code[0] == 0x00) && (sts_ac_code[19]== 0x0)) {
|
||||
APP_LOG(TS_OFF,VLEVEL_M, "Initial AC CODE blank... \r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sts_service_mask = (sts_hmac_verify()!= 0)? STS_SERVICE_MASK_L2:STS_SERVICE_MASK_L0;
|
||||
if (sts_service_mask == STS_SERVICE_MASK_L2) {
|
||||
if (sts_hmac_verify() != 0)
|
||||
{
|
||||
sts_service_mask = STS_SERVICE_MASK_L2;
|
||||
sts_ac_code[0] = 0x0;
|
||||
sts_ac_code[19]= 0x0;
|
||||
} else {
|
||||
sts_service_mask = STS_SERVICE_MASK_L0;
|
||||
}
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "STS_SERVICE_MASK:%d \r\n",sts_service_mask);
|
||||
}
|
||||
|
||||
/* initiated by Heart-beat timer */
|
||||
void STS_YunhornSTSEventRFAC_Process(void)
|
||||
{
|
||||
if ((sts_ac_code[0] ==0x0)&& (sts_ac_code[19]== 0x0))
|
||||
|
@ -164,14 +167,16 @@ void STS_YunhornSTSEventRFAC_Process(void)
|
|||
if ((rfac_timer > (STS_BURN_IN_RFAC + 2)))
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n -------------------Verify RFAC Success or Not\r\n");
|
||||
sts_service_mask = (sts_hmac_verify()!= 0)? STS_SERVICE_MASK_L2:STS_SERVICE_MASK_L0;
|
||||
if (sts_service_mask == STS_SERVICE_MASK_L2) {
|
||||
if (sts_hmac_verify() != 0)
|
||||
{
|
||||
sts_service_mask = STS_SERVICE_MASK_L2;
|
||||
sts_ac_code[0] = 0x0;
|
||||
sts_ac_code[19] = 0x0;
|
||||
sts_ac_code[19]= 0x0;
|
||||
} else {
|
||||
sts_service_mask = STS_SERVICE_MASK_L0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -332,7 +337,9 @@ void STS_YunhornSTSEventP4_Process(void)
|
|||
*/
|
||||
void STS_YunhornSTSEventP5_Process(void)
|
||||
{
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n P5 Testing Process\r\n");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -386,10 +393,9 @@ void STS_YunhornSTSEventP6_Process(void)
|
|||
*/
|
||||
void STS_YunhornSTSEventP7_Process(void)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n P7 Testing Process\r\n");
|
||||
STS_SENSOR_Power_ON(0);
|
||||
|
||||
STS_SENSOR_Power_OFF(0);
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n P7 Testing Process\r\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -414,64 +420,21 @@ void STS_YunhornSTSEventPIORS485_Process(void)
|
|||
}
|
||||
|
||||
|
||||
void STS_Combined_Status_Processing(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void STS_SENSOR_Power_ON(uint8_t cnt)
|
||||
{
|
||||
switch (cnt) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
default:
|
||||
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
}
|
||||
|
||||
PME_ON;
|
||||
}
|
||||
void STS_SENSOR_Power_OFF(uint8_t cnt)
|
||||
{
|
||||
switch (cnt) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
default:
|
||||
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
}
|
||||
PME_OFF;
|
||||
}
|
||||
|
||||
void STS_SENSOR_MEMS_Reset(uint8_t cnt)
|
||||
{
|
||||
switch (cnt) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
HAL_GPIO_TogglePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PME_TOGGLE;
|
||||
}
|
||||
|
||||
|
||||
void STS_SENSOR_NVM_CFG(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void STS_SENSOR_NVM_CFG_SIMPLE(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if defined(YUNHORN_STS_O5_ENABLED)
|
||||
void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data)
|
||||
|
@ -486,6 +449,10 @@ void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data)
|
|||
|
||||
void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size)
|
||||
{
|
||||
|
||||
}
|
||||
// following to be fill up
|
||||
#ifndef STS_P2
|
||||
uint8_t pbuf[128]={0x0}, i=0, pbuf_size=parse_buffer_size&0x7F;
|
||||
uint8_t invalid_flag = 1;
|
||||
UTIL_MEM_cpy_8((void*)pbuf,(void*)parse_buffer, pbuf_size); /* 127 BYTES MAX */
|
||||
|
@ -840,11 +807,14 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size)
|
|||
} //END OF SWITCH TVL_BUF_P_MEMS_NO
|
||||
//END OF PARAMETER CONFIG
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_size)
|
||||
{
|
||||
uint8_t i=0, mems_ver, invalid_flag=1;
|
||||
uint8_t i=0, tlv_buf[128]={0x0};
|
||||
memset((void*)outbuf,0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)tlv_buf,(void*)parse_buffer, parse_buffer_size&0x7F); /* 127 BYTES MAX */
|
||||
|
||||
|
@ -860,12 +830,13 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
{
|
||||
case 'H': /* "YZH": BOARD SOFT RESET, REVIVE */
|
||||
//BOARD REVIVE
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t *)"!YunHorn STS Revive!");
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t *)"!YunHorn STS Revive!");
|
||||
HAL_Delay(5000);
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n");
|
||||
HAL_Delay(3000);
|
||||
__set_FAULTMASK(1);
|
||||
OnSystemReset();
|
||||
NVIC_SystemReset();
|
||||
//OnSystemReset();
|
||||
break;
|
||||
case 'S': /* "YZS": Self Function Testing */
|
||||
STS_SENSOR_Function_Test_Process();
|
||||
|
@ -880,7 +851,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
outbuf[i++] = (uint8_t) sts_mtmcode2;
|
||||
outbuf[i++] = (uint8_t) sts_version;
|
||||
outbuf[i++] = (uint8_t) (0x41+ deviceClass); //translate to 'A','B','C'
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
break;
|
||||
case 'D': /* "YZD": Distance/Install height Measure */
|
||||
STS_SENSOR_Distance_Test_Process();
|
||||
|
@ -897,14 +868,14 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
outbuf[i++] = (uint8_t)(sts_sensor_install_height>>8)&0xFF;
|
||||
outbuf[i++] = (uint8_t)(sts_sensor_install_height)&0xFF;
|
||||
#endif
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
break;
|
||||
case 'M': /* "YZM": Mask level */
|
||||
i = 0;
|
||||
outbuf[i++] = (uint8_t)'M';
|
||||
outbuf[i++] = (uint8_t)sts_service_mask;
|
||||
outbuf[i++] = (uint8_t)sts_work_mode;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -951,7 +922,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) {
|
||||
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]);
|
||||
}
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
break;
|
||||
case 'T':
|
||||
|
@ -978,7 +949,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
outbuf[i++] = (uint8_t) localtime.tm_min;
|
||||
outbuf[i++] = (uint8_t) localtime.tm_sec;
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -1004,9 +975,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
|
||||
// 2024-07-31
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,tlv_buf_size);
|
||||
i = tlv_buf_size;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
|
@ -1020,9 +991,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
PME_OFF;
|
||||
// 2024-07-31
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,tlv_buf_size);
|
||||
i = tlv_buf_size;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
|
@ -1037,9 +1008,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
PME_ON;
|
||||
// 2024-07-31
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,tlv_buf_size);
|
||||
i = tlv_buf_size;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
|
@ -1068,10 +1039,10 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
#endif
|
||||
// 2024-07-31
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,tlv_buf_size);
|
||||
i = tlv_buf_size;
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
// Save config to NVM
|
||||
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
|
||||
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
|
||||
|
@ -1118,10 +1089,10 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
#endif
|
||||
// 2024-07-31
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf,tlv_buf_size);
|
||||
i = tlv_buf_size;
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
// Save config to NVM
|
||||
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
|
||||
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
|
||||
|
@ -1145,19 +1116,21 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
break; /* End Sampling/HeartBeat interval */
|
||||
default:
|
||||
/* illegal CFG_CMD2*/
|
||||
braek;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/* 111111111111111111111111111111111111111111111111111111111111111111111 */
|
||||
case 'P':
|
||||
switch ((char)tlv_buf[CFG_CMD3])
|
||||
{
|
||||
}
|
||||
|
||||
/* TODO XXX FOR NON STS-P2 */
|
||||
USER_APP_Parse_CMD_P(tlv_buf, parse_buffer_size);
|
||||
|
||||
/* TODO XXX FOR NON STS-P2 */
|
||||
|
||||
break;
|
||||
/* 111111111111111111111111111111111111111111111111111111111111111111111 */
|
||||
case 'A':
|
||||
if (((char)tlv_buf[CFG_CMD1] == 'A') && ((char)tlv_buf[CFG_CMD2] == 'C') && (tlv_buf_size == (YUNHORN_STS_AC_CODE_SIZE+2))) // BEGIN OF *** BOARD LEVEL AUTHORIZATION CODE
|
||||
if (((char)tlv_buf[CFG_CMD1] == 'A') && ((char)tlv_buf[CFG_CMD2] == 'C') && (parse_buffer_size == (YUNHORN_STS_AC_CODE_SIZE+2))) // BEGIN OF *** BOARD LEVEL AUTHORIZATION CODE
|
||||
{
|
||||
// 'AC'+ AC_CODE(20bytes)
|
||||
//UTIL_MEM_cpy_8(sts_ac_code, tlv_buf+2,YUNHORN_STS_AC_CODE_SIZE);
|
||||
|
@ -1167,7 +1140,8 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
sts_ac_code[j] = (uint8_t) tlv_buf[2+j];
|
||||
}
|
||||
|
||||
STS_YUNHORN_RFAC_HANDLE_PROCESS();
|
||||
//STS_YUNHORN_RFAC_HANDLE_PROCESS();
|
||||
STS_YunhornAuthenticationCode_Process();
|
||||
|
||||
if ((hmac_result.ac_pass == 1U))
|
||||
{
|
||||
|
@ -1191,8 +1165,9 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
|
||||
i=0;
|
||||
UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf));
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, tlv_buf_size);
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, parse_buffer_size);
|
||||
i = parse_buffer_size;
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
break;
|
||||
|
@ -1273,418 +1248,13 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
|
|||
*
|
||||
*/
|
||||
|
||||
if (((char)tlv_buf[CFG_CMD1] == 'Y') && (tlv_buf_size <=5)) // BEGIN OF *** BOARD LEVEL CONTROL OR REPORT
|
||||
{
|
||||
switch ((char)tlv_buf[CFG_CMD2])
|
||||
{
|
||||
case 'Z': //"YZ"
|
||||
if ((char)tlv_buf[CFG_CMD3] == 'H') { //BOARD SOFT RESET, REVIVE "YZH"
|
||||
//BOARD REVIVE
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 20, (uint8_t *)"!YunHorn STS Revive!");
|
||||
HAL_Delay(5000);
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Yunhorn STS Node Revive ... \r\n");
|
||||
HAL_Delay(3000);
|
||||
|
||||
OnSystemReset();
|
||||
|
||||
} else if ((char)tlv_buf[CFG_CMD3] == 'S') { // Self Function Testing "YZS"
|
||||
i=0;
|
||||
memset((void*)outbuf,0x0,sizeof(outbuf));
|
||||
|
||||
STS_SENSOR_Function_Test_Process();
|
||||
|
||||
HAL_Delay(5000);
|
||||
i=21;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
} else if ((char)tlv_buf[CFG_CMD3] == 'C') { // Lora-WAN Class "YZC" LORAWAN CLASS A/B/C
|
||||
|
||||
DeviceClass_t deviceClass = CLASS_A;
|
||||
LmHandlerGetCurrentClass( &deviceClass );
|
||||
i=0;
|
||||
outbuf[i++] = (uint8_t) 'L';
|
||||
outbuf[i++] = (uint8_t) sts_mtmcode1;
|
||||
outbuf[i++] = (uint8_t) sts_mtmcode2;
|
||||
outbuf[i++] = (uint8_t) sts_version;
|
||||
outbuf[i++] = (uint8_t) (0x41+ deviceClass); //translate to 'A','B','C'
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else if ((char)tlv_buf[CFG_CMD3] == 'D') { // Distance Measure "YZD"
|
||||
i=0;
|
||||
outbuf[i++] = (uint8_t) 'Y';
|
||||
outbuf[i++] = (uint8_t) 'Z';
|
||||
outbuf[i++] = (uint8_t) 'D';
|
||||
//STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, outbuf);
|
||||
|
||||
STS_SENSOR_Distance_Test_Process();
|
||||
|
||||
i=0;
|
||||
memset((void*)outbuf,0x0,sizeof(outbuf));
|
||||
outbuf[i++] = (uint8_t)'D';
|
||||
outbuf[i++] = (uint8_t)sts_mtmcode1;
|
||||
outbuf[i++] = (uint8_t)sts_mtmcode2;
|
||||
outbuf[i++] = (uint8_t)sts_version;
|
||||
outbuf[i++] = (uint8_t)sts_hardware_ver;
|
||||
outbuf[i++] = (uint8_t)(99*((GetBatteryLevel()/254)&0xff));
|
||||
#ifdef STS_O6_ENABLED
|
||||
outbuf[i++] = (uint8_t)0x04; //length of following data
|
||||
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/1000)%10+0x30)&0xff;
|
||||
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/100)%10+0x30)&0xff;
|
||||
outbuf[i++] = (uint8_t) ((((uint16_t)sts_distance_rss_distance)/10)%10+0x30)&0xff;
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_distance_rss_distance)%10+0x30)&0xff;
|
||||
#endif
|
||||
#if (defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R1_ENABLED))
|
||||
#ifdef TOF_1
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[0])/100)&0xff;
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[0])%100)&0xff;
|
||||
#endif
|
||||
#ifdef TOF_2
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[1])/100)&0xff;
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[1])%100)&0xff;
|
||||
#endif
|
||||
|
||||
#ifdef TOF_3
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[2])/100)&0xff;
|
||||
outbuf[i++] = (uint8_t) (((uint16_t)sts_tof_distance_data[2])%100)&0xff;
|
||||
#endif
|
||||
#endif
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'M': //"YM"
|
||||
if ((char)tlv_buf[CFG_CMD3] >= '0' && (char)tlv_buf[CFG_CMD3]<='9') // Service Mask "YZM"
|
||||
{
|
||||
sts_service_mask = (uint8_t)(tlv_buf[CFG_CMD3]-0x30)&0xFF;
|
||||
sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask;
|
||||
outbuf[i++] = (uint8_t) 'Y';
|
||||
outbuf[i++] = (uint8_t) 'M';
|
||||
outbuf[i++] = (uint8_t) (sts_service_mask+0x30);
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
APP_LOG(TS_OFF, VLEVEL_L, ">>>>>>>>>>>>>>>>>>>>> Mask = [ %02x ] \r\n", sts_service_mask);
|
||||
OnStoreSTSCFGContextRequest();
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
if (sts_service_mask != STS_SERVICE_MASK_L0) STS_Lamp_Bar_Set_Dark();
|
||||
STS_Combined_Status_Processing();
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 'V': //"YV"
|
||||
if ((char)tlv_buf[CFG_CMD3] == 'H') { // "YVH" REPORT FIRMWARE VERSION "YVH"
|
||||
// FIRMWARE VERSION REPORT
|
||||
outbuf[i++] = (uint8_t) 'V';
|
||||
outbuf[i++] = (uint8_t) sts_mtmcode1;
|
||||
outbuf[i++] = (uint8_t) sts_mtmcode2;
|
||||
outbuf[i++] = (uint8_t) sts_version;
|
||||
outbuf[i++] = (uint8_t) FirmwareVersion;
|
||||
outbuf[i++] = (uint8_t) MajorVer;
|
||||
outbuf[i++] = (uint8_t) MinorVer;
|
||||
outbuf[i++] = (uint8_t) SubMinorVer;
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
//APP_LOG(TS_OFF, VLEVEL_L, "###### YUNHORN Report Version [ %X ] \r\n", outbuf);
|
||||
}
|
||||
else
|
||||
if ((char)tlv_buf[CFG_CMD3] == 'C') { // "YVC" REPORT NVM STORED CONFIG PARAMETERS "YVC"
|
||||
|
||||
uint8_t cfg_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]="";
|
||||
OnRestoreSTSCFGContextRequest((uint8_t *)cfg_in_nvm);
|
||||
i=0;
|
||||
memset((void*)outbuf,0x0,sizeof(outbuf));
|
||||
|
||||
outbuf[i++] = (uint8_t) 'C';
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM1]; //MTM Code
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_MTM2]; //MTM Code
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_VER]; //STS Version
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_HWV]; //STS Version
|
||||
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_PERIODICITY]); //UPLINK Periodicity
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_UNIT]; //UPLINK Periodicity unit
|
||||
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_SAMPLING]); //Heart-beat or SAMPLING Periodicity
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_S_UNIT]; //Heart-beat or SAMPLING Periodicity unit
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_WORK_MODE]; // STS WORK MODE
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_SERVICE_MASK]; //service mask
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_RESERVE01]; //service mask
|
||||
outbuf[i++] = (uint8_t) cfg_in_nvm[NVM_LEN]; //length of following cfg value
|
||||
|
||||
for (uint8_t j=0; j < cfg_in_nvm[NVM_LEN]; j++) {
|
||||
outbuf[i++] = (uint8_t) (cfg_in_nvm[NVM_CFG_START+j]);
|
||||
}
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
break;
|
||||
// "YO#","YF#","YH#","YD##L" ##={0,9} L={S,M,H}
|
||||
case 'O':
|
||||
// TODO # of modules
|
||||
if (((uint8_t)(tlv_buf[CFG_CMD3]-0x30) >= 0) && ((uint8_t)tlv_buf[CFG_CMD3]-0x30) <=9)
|
||||
{
|
||||
STS_SENSOR_Power_ON((uint8_t)(tlv_buf[CFG_CMD3]-0x30));
|
||||
i=0;
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
// TODO # of modules
|
||||
if (((uint8_t)(tlv_buf[CFG_CMD3]-0x30) >= 0) && ((uint8_t)tlv_buf[CFG_CMD3]-0x30) <=9) {
|
||||
STS_SENSOR_Power_OFF((tlv_buf[CFG_CMD3]-0x30));
|
||||
i=0;
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
// TODO # of modules
|
||||
if (((uint8_t)(tlv_buf[CFG_CMD3]-0x30) >= 0) && ((uint8_t)tlv_buf[CFG_CMD3]-0x30) <=9) {
|
||||
STS_SENSOR_MEMS_Reset((tlv_buf[CFG_CMD3]-0x30));
|
||||
i=0;
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'D': // regular uploading message interval
|
||||
if ((((char)tlv_buf[CFG_CMD3] >= '0') && ((char)tlv_buf[CFG_CMD3] <='9')
|
||||
&& ((char)tlv_buf[CFG_CMD4] >='0') && ((char)tlv_buf[CFG_CMD4] <='9')) &&
|
||||
(((char)tlv_buf[CFG_CMD5] == 'M' || ((char)tlv_buf[CFG_CMD5] =='H') ||((char)tlv_buf[CFG_CMD5] =='S'))))
|
||||
{
|
||||
uint32_t periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30);
|
||||
|
||||
if ((char)tlv_buf[CFG_CMD5] == 'M') {
|
||||
periodicity_length *= 60;
|
||||
} else if ((char)tlv_buf[CFG_CMD5] == 'H') {
|
||||
periodicity_length *= 3600;
|
||||
}
|
||||
TxPeriodicity = periodicity_length*1000; //translate to 1000ms=1s
|
||||
//HeartBeatPeriodicity = TxPeriodicity; 2024-05-22, fix issue of heart-beat interval mis-changed by Tx Interval
|
||||
|
||||
OnTxPeriodicityChanged(TxPeriodicity);
|
||||
i = 0;
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5];
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
// Save config to NVM
|
||||
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
|
||||
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
|
||||
sts_cfg_nvm.version = (uint8_t)sts_version;
|
||||
sts_cfg_nvm.hardware_ver = (uint8_t)sts_hardware_ver;
|
||||
sts_cfg_nvm.periodicity = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+(tlv_buf[CFG_CMD4]-0x30));
|
||||
sts_cfg_nvm.unit = (uint8_t)tlv_buf[CFG_CMD5];
|
||||
sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode;
|
||||
sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask;
|
||||
|
||||
OnStoreSTSCFGContextRequest();
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "###### YUNHORN Periodicity Changed to [ %d ] Seconds\r\n", periodicity_length);
|
||||
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
break;
|
||||
case 'S': // SAMPLING INTERVAL OR DURATION
|
||||
if ((((char)tlv_buf[CFG_CMD3] >= '0') && ((char)tlv_buf[CFG_CMD3] <='9')
|
||||
&& ((char)tlv_buf[CFG_CMD4] >='0') && ((char)tlv_buf[CFG_CMD4] <='9')) &&
|
||||
(((char)tlv_buf[CFG_CMD5] == 'M' || ((char)tlv_buf[CFG_CMD5] =='H') ||((char)tlv_buf[CFG_CMD5] =='S'))))
|
||||
{
|
||||
uint32_t heart_beat_or_sampling_periodicity_length = (tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30);
|
||||
|
||||
if ((char)tlv_buf[CFG_CMD5] == 'M') {
|
||||
heart_beat_or_sampling_periodicity_length *= 60;
|
||||
} else if ((char)tlv_buf[CFG_CMD5] == 'H') {
|
||||
heart_beat_or_sampling_periodicity_length *= 3600;
|
||||
}
|
||||
|
||||
#ifdef YUNHORN_STS_E0_ENABLED
|
||||
SamplingPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s
|
||||
OnYunhornSTSSamplingPeriodicityChanged(SamplingPeriodicity);
|
||||
#endif
|
||||
#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)
|
||||
HeartBeatPeriodicity = heart_beat_or_sampling_periodicity_length*1000; //translate to 1000ms=1s
|
||||
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
|
||||
#endif
|
||||
i = 0;
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD1];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD2];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD3];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD4];
|
||||
outbuf[i++] = (uint8_t) tlv_buf[CFG_CMD5];
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
// Save config to NVM
|
||||
sts_cfg_nvm.mtmcode1 = (uint8_t)sts_mtmcode1;
|
||||
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
|
||||
sts_cfg_nvm.version = (uint8_t)sts_version;
|
||||
sts_cfg_nvm.hardware_ver = (uint8_t)sts_hardware_ver;
|
||||
sts_cfg_nvm.sampling = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+(tlv_buf[CFG_CMD4]-0x30));
|
||||
sts_cfg_nvm.s_unit = (uint8_t)tlv_buf[CFG_CMD5];
|
||||
sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode;
|
||||
sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask;
|
||||
|
||||
OnStoreSTSCFGContextRequest();
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "###### YUNHORN Sampling Or Heart-Beat Interval Changed to [ %d ] Seconds\r\n", heart_beat_or_sampling_periodicity_length);
|
||||
|
||||
} else {
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
break;
|
||||
} // END OF switch switch ((char)tlv_buf[CFG_CMD2])
|
||||
} // end of if END OF *** BOARD LEVEL CONTROL OR REPORT
|
||||
else if (((char)tlv_buf[CFG_CMD1] == 'P') && (tlv_buf_size >= 3)) // BEGIN OF PARAMETER CONFIG
|
||||
{
|
||||
/*
|
||||
* YUNHORN STS PRODUCT SUBMODULE, MEMS OR SENSOR HEAD LEVEL PARAMETER TUNING SECTION
|
||||
*/
|
||||
|
||||
//i = P_MEM_CFG; //start of parameter
|
||||
|
||||
switch ((char)tlv_buf[CFG_CMD2]) //BEGIN OF SWITCH TVL_BUF_P_MEMS_NO
|
||||
{ //#1 No. of MEMS components
|
||||
//default first sensor head or MEMS component, default 1 sensor heads
|
||||
case '0': //default sensor head or MEMS component
|
||||
case '1': //first sensor head or MEMS component
|
||||
|
||||
mems_ver = (uint8_t)(tlv_buf[CFG_CMD3]-0x30);
|
||||
|
||||
uint8_t j=0;
|
||||
if (mems_ver == sts_version)
|
||||
{ // Firmware version or Variation of MEMS/component
|
||||
if (tlv_buf_size >= CFG_CMD_TOF_SIMPLE_SIZE)
|
||||
{
|
||||
//Validation check
|
||||
invalid_flag = 0;
|
||||
|
||||
for (j =0; j < CFG_CMD_TOF_SIMPLE_SIZE; j++)
|
||||
{
|
||||
sts_cfg_nvm.p[j] = (uint8_t)((tlv_buf[CFG_CMD4+j] - 0x30)&0xff);
|
||||
APP_LOG(TS_OFF,VLEVEL_H,"\r\n tlv_buf %d = %02x cfg->p[%d]=%02x \r\n",
|
||||
j,tlv_buf[CFG_CMD4+j], j, sts_cfg_nvm.p[j]);
|
||||
}
|
||||
|
||||
|
||||
//STS_PRESENCE_SENSOR_NVM_CFG_SIMPLE();
|
||||
STS_SENSOR_NVM_CFG_SIMPLE();
|
||||
|
||||
i=0; // Step 1: Prepare status update message
|
||||
outbuf[i++] = (char) 'P';
|
||||
outbuf[i++] = sts_mtmcode1;
|
||||
outbuf[i++] = sts_mtmcode2;
|
||||
outbuf[i++] = sts_version;
|
||||
outbuf[i++] = sts_hardware_ver;
|
||||
|
||||
for (j=0; j < CFG_CMD_TOF_SIMPLE_SIZE; j++)
|
||||
{
|
||||
outbuf[i++] = (uint8_t)(sts_cfg_nvm.p[j]+0x30)&0xff;
|
||||
}
|
||||
//APP_LOG(TS_OFF, VLEVEL_H, "###### RSS Simple CFG=%s\r\n",outbuf);
|
||||
|
||||
// Step 2: Save valid config to NVM
|
||||
sts_cfg_nvm.mtmcode1 = sts_mtmcode1;
|
||||
sts_cfg_nvm.mtmcode2 = sts_mtmcode2;
|
||||
sts_cfg_nvm.version = sts_version;
|
||||
sts_cfg_nvm.hardware_ver = sts_hardware_ver;
|
||||
sts_cfg_nvm.work_mode = sts_work_mode;
|
||||
sts_cfg_nvm.sts_service_mask = sts_service_mask;
|
||||
sts_cfg_nvm.length = CFG_CMD_TOF_SIMPLE_SIZE;
|
||||
|
||||
OnStoreSTSCFGContextRequest();
|
||||
}
|
||||
|
||||
// Invalid parameters
|
||||
// Step 1/2: Prepare status update message
|
||||
if (invalid_flag == 1)
|
||||
{
|
||||
STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
//APP_LOG(TS_OFF, VLEVEL_L, "###### MTM VER Invalid or Mismatch\r\n");
|
||||
}
|
||||
|
||||
// Step 3: Upload status update message
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// for multiple sensor heads or MEMS components, TODO 2022-10-21 PARK HERE
|
||||
|
||||
case 2:
|
||||
#ifdef YUNHORN_STS_O2_ENABLED
|
||||
// for 2nd sensor heads such as 2x Presence radar, 2 reed-switch or hall elements
|
||||
#endif
|
||||
|
||||
break;
|
||||
default:
|
||||
// for multiple sensor heads or MEMS components, TODO 2022-10-21 PARK HERE
|
||||
//STS_SENSOR_Upload_Config_Invalid_Message();
|
||||
break;
|
||||
} //END OF SWITCH TVL_BUF_P_MEMS_NO
|
||||
|
||||
} //END OF PARAMETER CONFIG
|
||||
else if (((char)tlv_buf[CFG_CMD1] == 'A') && ((char)tlv_buf[CFG_CMD2] == 'C') && (tlv_buf_size == (YUNHORN_STS_AC_CODE_SIZE+2))) // BEGIN OF *** BOARD LEVEL AUTHORIZATION CODE
|
||||
{
|
||||
// 'AC'+ AC_CODE(20bytes)
|
||||
|
||||
for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++)
|
||||
{
|
||||
sts_ac_code[j] = (uint8_t) tlv_buf[2+j];
|
||||
}
|
||||
|
||||
STS_YUNHORN_RFAC_HANDLE_PROCESS();
|
||||
|
||||
if ((hmac_result.ac_pass == 1U))
|
||||
{
|
||||
for (uint8_t j=0; j < YUNHORN_STS_AC_CODE_SIZE; j++)
|
||||
{
|
||||
sts_cfg_nvm.ac[j] = sts_ac_code[j];
|
||||
}
|
||||
|
||||
sts_service_mask = STS_SERVICE_MASK_L0;
|
||||
|
||||
sts_cfg_nvm.sts_service_mask = sts_service_mask;
|
||||
OnStoreSTSCFGContextRequest();
|
||||
|
||||
|
||||
} else {
|
||||
sts_service_mask = STS_SERVICE_MASK_L2;
|
||||
|
||||
}
|
||||
|
||||
i=0;
|
||||
for (uint8_t j=0; j <(tlv_buf_size) ; j++) {
|
||||
outbuf[i++] = (uint8_t) tlv_buf[j];
|
||||
}
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
|
||||
} // END OF USER_APP_AUTO_RESPONDER_Parse
|
||||
} // END OF USER_APP_AUTO_RESPONDER_P_CMD
|
||||
|
||||
|
||||
void STS_SENSOR_Upload_Config_Invalid_Message(void)
|
||||
{
|
||||
if (sts_service_mask == STS_SERVICE_MASK_L0)
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, 5, (uint8_t *)"PVXXX");
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 5, (uint8_t *)"PVXXX");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1694,9 +1264,9 @@ void STS_SENSOR_Upload_Config_Invalid_Message(void)
|
|||
void OnStoreSTSCFGContextRequest(void)
|
||||
{
|
||||
/* USER CODE BEGIN OnStoreContextRequest_1 */
|
||||
uint8_t i=0,j=0,nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
|
||||
|
||||
#if (defined(YUNHORN_STS_O5_ENABLED) || defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R4_ENABLED) || defined(YUNHORN_STS_R5_ENABLED))
|
||||
uint8_t nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
|
||||
#if 0
|
||||
sts_cfg_nvm.length = STS_NVM_CFG_SIZE;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.mtmcode1;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.mtmcode2;
|
||||
|
@ -1708,7 +1278,7 @@ void OnStoreSTSCFGContextRequest(void)
|
|||
nvm_store_value[i++] = sts_cfg_nvm.s_unit;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.work_mode;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.sts_service_mask;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.reseve01;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.sts_ioc_mask;
|
||||
nvm_store_value[i++] = (uint8_t) STS_NVM_CFG_SIZE; //sts_cfg_nvm.length;
|
||||
|
||||
for (j = 0; j < STS_CFG_PCFG_SIZE; j++) {
|
||||
|
@ -1717,7 +1287,7 @@ void OnStoreSTSCFGContextRequest(void)
|
|||
|
||||
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.fall_detection_reserve;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.fall_confirm_threshold_in_10sec;
|
||||
nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold;
|
||||
if ((sts_cfg_nvm.ac[0]!=0x0) && (sts_cfg_nvm.ac[19]!=0x0)) {
|
||||
for (j = 0; j < YUNHORN_STS_AC_CODE_SIZE; j++) {
|
||||
|
@ -1725,12 +1295,14 @@ void OnStoreSTSCFGContextRequest(void)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* USER CODE END OnStoreContextRequest_1 */
|
||||
/* store nvm in flash */
|
||||
|
||||
UTIL_MEM_cpy_8((void*)nvm_store_value, (void *)&sts_cfg_nvm,YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
if (FLASH_IF_Erase(STS_CONFIG_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE) == FLASH_IF_OK)
|
||||
{
|
||||
FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
//FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)nvm_store_value, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
FLASH_IF_Write(STS_CONFIG_NVM_BASE_ADDRESS, (const void *)&sts_cfg_nvm, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1745,7 +1317,7 @@ void OnRestoreSTSCFGContextRequest(uint8_t *cfg_in_nvm)
|
|||
/* USER CODE BEGIN OnRestoreSTSCFGContextRequest_1 */
|
||||
|
||||
/* USER CODE END OnRestoreSTSCFGContextRequest_1 */
|
||||
UTIL_MEM_cpy_8(cfg_in_nvm, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
UTIL_MEM_cpy_8((void*)cfg_in_nvm, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
/* USER CODE BEGIN OnRestoreSTSCFGContextRequest_Last */
|
||||
|
||||
/* USER CODE END OnRestoreSTSCFGContextRequest_Last */
|
||||
|
@ -1761,7 +1333,7 @@ void STS_REBOOT_CONFIG_Init(void)
|
|||
UTIL_MEM_cpy_8(nvm_stored_value, (void *)STS_CONFIG_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
/* USER CODE BEGIN OnRestoreContextRequest_Last */
|
||||
|
||||
#if defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R4_ENABLED) || defined(YUNHORN_STS_R5_ENABLED)
|
||||
|
||||
if ((nvm_stored_value[NVM_MTM1] != sts_mtmcode1) || (nvm_stored_value[NVM_MTM2] != sts_mtmcode2) || (nvm_stored_value[NVM_VER] != sts_version))
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\nInitial Boot with Empty Config, Flash with default config....\r\n");
|
||||
|
@ -1770,6 +1342,7 @@ void STS_REBOOT_CONFIG_Init(void)
|
|||
HAL_Delay(1000);
|
||||
} else
|
||||
{
|
||||
#if 0
|
||||
sts_cfg_nvm.mtmcode1 = (uint8_t)nvm_stored_value[NVM_MTM1];
|
||||
sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_stored_value[NVM_MTM2];
|
||||
sts_cfg_nvm.version = (uint8_t)nvm_stored_value[NVM_VER];
|
||||
|
@ -1780,7 +1353,7 @@ void STS_REBOOT_CONFIG_Init(void)
|
|||
sts_cfg_nvm.s_unit = (uint8_t)(nvm_stored_value[NVM_S_UNIT]);
|
||||
sts_cfg_nvm.work_mode = (uint8_t)(nvm_stored_value[NVM_WORK_MODE]);
|
||||
sts_cfg_nvm.sts_service_mask = (uint8_t)(nvm_stored_value[NVM_SERVICE_MASK]);
|
||||
sts_cfg_nvm.reseve01 = (uint8_t)(nvm_stored_value[NVM_RESERVE01]);
|
||||
sts_cfg_nvm.sts_ioc_mask = (uint8_t)(nvm_stored_value[NVM_IOC_MASK]);
|
||||
sts_cfg_nvm.length = (uint8_t)(nvm_stored_value[NVM_LEN]&0x3F); //MAX 32 bytes
|
||||
|
||||
for (uint8_t j=0; j< sts_cfg_nvm.length; j++) {
|
||||
|
@ -1795,8 +1368,9 @@ void STS_REBOOT_CONFIG_Init(void)
|
|||
for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) {
|
||||
sts_cfg_nvm.ac[j] = (uint8_t)nvm_stored_value[NVM_AC_CODE_START +j];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
UTIL_MEM_cpy_8((void*) &sts_cfg_nvm, (void*)nvm_stored_value, YUNHORN_STS_MAX_NVM_CFG_SIZE);
|
||||
}
|
||||
|
||||
OnRestoreSTSCFGContextProcess();
|
||||
|
||||
|
@ -1814,33 +1388,35 @@ void OnRestoreSTSCFGContextProcess(void)
|
|||
periodicity *= 1;
|
||||
}
|
||||
periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit
|
||||
TxPeriodicity= periodicity*1000; // to ms
|
||||
|
||||
uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval
|
||||
//TxPeriodicity= periodicity*1000; // to ms
|
||||
|
||||
uint32_t sampling_heartbeat_periodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval
|
||||
if ((char)sts_cfg_nvm.s_unit =='M') {
|
||||
samplingperiodicity *= 60;
|
||||
sampling_heartbeat_periodicity *= 60;
|
||||
} else if ((char) sts_cfg_nvm.s_unit =='H') {
|
||||
samplingperiodicity *= 3600;
|
||||
sampling_heartbeat_periodicity *= 3600;
|
||||
} else if ((char) sts_cfg_nvm.s_unit =='S') {
|
||||
samplingperiodicity *= 1;
|
||||
sampling_heartbeat_periodicity *= 1;
|
||||
}
|
||||
|
||||
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
|
||||
{ // ensure it's not in production yet
|
||||
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
|
||||
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
|
||||
//OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); TODO XXXX
|
||||
} else
|
||||
{
|
||||
OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
|
||||
//OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
|
||||
OnTxPeriodicityChanged(periodicity*1000);
|
||||
//Heart-beat or Sampling interval
|
||||
samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit
|
||||
HeartBeatPeriodicity = samplingperiodicity*1000;
|
||||
sampling_heartbeat_periodicity = (sampling_heartbeat_periodicity > 0)? sampling_heartbeat_periodicity : 1; // in seconds unit
|
||||
sampling_heartbeat_periodicity = sampling_heartbeat_periodicity*1000;
|
||||
#if defined(YUNHORN_STS_O6_ENABLED) ||defined(YUNHORN_STS_O5_ENABLED)
|
||||
OnYunhornSTSSamplingPeriodicityChanged(HeartBeatPeriodicity); // in m-sec unit
|
||||
OnYunhornSTSSamplingPeriodicityChanged(sampling_heartbeat_periodicity); // in m-sec unit
|
||||
#endif
|
||||
|
||||
#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R4_ENABLED)
|
||||
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
|
||||
OnYunhornSTSHeartBeatPeriodicityChanged(sampling_heartbeat_periodicity);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1856,10 +1432,11 @@ void OnRestoreSTSCFGContextProcess(void)
|
|||
#endif
|
||||
|
||||
|
||||
for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++)
|
||||
{
|
||||
sts_ac_code[j] = sts_cfg_nvm.ac[j];
|
||||
}
|
||||
//for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++)
|
||||
//{
|
||||
// sts_ac_code[j] = sts_cfg_nvm.ac[j];
|
||||
//}
|
||||
UTIL_MEM_cpy_8((void*)sts_ac_code,(void*)sts_cfg_nvm.ac, YUNHORN_STS_AC_CODE_SIZE);
|
||||
|
||||
#ifdef YUNHORN_STS_O6_ENABLED
|
||||
if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length))
|
||||
|
@ -1955,7 +1532,7 @@ void STS_SENSOR_Function_Test_Process(void)
|
|||
memset((void*)outbuf,0x0,sizeof(outbuf));
|
||||
memcpy((void*)outbuf, tstbuf, i);
|
||||
|
||||
STS_SENSOR_Upload_Message(LORAWAN_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ extern "C" {
|
|||
#include "sys_app.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "VL53L1X_ULP_api.h"
|
||||
//#include "VL53L1X_ULP_api.h"
|
||||
//#include "53l1a2_ranging_sensor.h"
|
||||
#include "stm32wlxx_nucleo.h"
|
||||
|
||||
#include "VL53L1X_api.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
@ -210,7 +210,7 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps)
|
|||
/*********************************/
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"Range Mode =%d \r\n",range_mode);
|
||||
/* (Optional) Check if there is a VL53L1X sensor connected */
|
||||
status = VL53L1X_ULP_GetSensorId(dev, &sensor_id);
|
||||
status = VL53L1X_GetSensorId(dev, &sensor_id);
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"VL53L1X address =%X\r\n",sensor_id );
|
||||
if(status || (sensor_id != 0xEACC))
|
||||
{
|
||||
|
@ -218,7 +218,7 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps)
|
|||
return status;
|
||||
}
|
||||
/* (Mandatory) Init VL53L1X sensor */
|
||||
status = VL53L1X_ULP_SensorInit(dev);
|
||||
status = VL53L1X_SensorInit(dev);
|
||||
if(status)
|
||||
{
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"VL53L1X ultra low power Loading failed\n");
|
||||
|
@ -230,26 +230,28 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps)
|
|||
/* Sensor configuration */
|
||||
/*********************************/
|
||||
/* (Optional) Program sensor to raise an interrupt ONLY below 300mm */
|
||||
status = VL53L1X_ULP_SetInterruptConfiguration(dev, distance_threshold_mm, 1); //i_distance_threshold_mm
|
||||
//status = VL53L1X_SetInterruptConfiguration(dev, distance_threshold_mm, 1); //i_distance_threshold_mm
|
||||
status = VL53L1X_SetDistanceThreshold(dev, distance_threshold_mm,distance_threshold_mm, 0,1); //i_distance_threshold_mm
|
||||
/* (Optional) Program a 10Hz ranging frequency */
|
||||
status = VL53L1X_ULP_SetInterMeasurementInMs(dev, inter_measurement_ms); // range_interval_ms
|
||||
status = VL53L1X_SetInterMeasurementInMs(dev, inter_measurement_ms); // range_interval_ms
|
||||
/* Increase the macro timing. This is equivalent as increasing the integration time */
|
||||
status = VL53L1X_ULP_SetMacroTiming(dev, macro_timing); // micro_timing_ms
|
||||
//status = VL53L1X_SetMacroTiming(dev, macro_timing); // micro_timing_ms
|
||||
status = VL53L1X_SetTimingBudgetInMs(dev, macro_timing);
|
||||
/* Enable all the SPADS */
|
||||
status = VL53L1X_ULP_SetROI(dev, roi_width); // SPADS { 1 -- 16 }
|
||||
status = VL53L1X_SetROI(dev, roi_width, roi_width); // SPADS { 1 -- 16 }
|
||||
|
||||
if(range_mode != STS_TOF_LOW_POWER_RANGE)
|
||||
{
|
||||
/* Example for robust and short distance measurements. Max distance reduced
|
||||
* but very low number of false-positives */
|
||||
status |= VL53L1X_ULP_SetSigmaThreshold(dev, sigma_mm);
|
||||
status |= VL53L1X_ULP_SetSignalThreshold(dev, signal_kcps);
|
||||
status |= VL53L1X_SetSigmaThreshold(dev, sigma_mm);
|
||||
status |= VL53L1X_SetSignalThreshold(dev, signal_kcps);
|
||||
}
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
status = VL53L1X_ULP_StartRanging(dev);
|
||||
status = VL53L1X_StartRanging(dev);
|
||||
if(status)
|
||||
{
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"VL53L1X_ULP_StartRanging failed with status %u\n", status);
|
||||
|
@ -265,9 +267,9 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps)
|
|||
if(IsInterruptDetected(dev))
|
||||
{
|
||||
/* (Mandatory) Clear HW interrupt to restart measurements */
|
||||
VL53L1X_ULP_ClearInterrupt(dev);
|
||||
VL53L1X_ClearInterrupt(dev);
|
||||
/* Dump debug data */
|
||||
status = VL53L1X_ULP_DumpDebugData(dev, &measurement_status,
|
||||
status = VL53L1X_DumpDebugData(dev, &measurement_status,
|
||||
&estimated_distance_mm, &r_sigma_mm, &r_signal_kcps, &r_ambient_kcps);
|
||||
*ranged_distance = estimated_distance_mm;
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"Target detected! Interrupt raised by sensor, Distance =%d mm \r\n", estimated_distance_mm );
|
||||
|
@ -275,7 +277,7 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps)
|
|||
}
|
||||
}
|
||||
|
||||
status = VL53L1X_ULP_StopRanging(dev);
|
||||
status = VL53L1X_StopRanging(dev);
|
||||
APP_LOG(TS_OFF,VLEVEL_L,"End of VL53L1X ultra low power demo\n");
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -1,419 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file : part of VL53L1X ULP and : dual licensed,
|
||||
* either 'STMicroelectronics
|
||||
* Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document : strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, VL53L1X ULP may be distributed under the terms of
|
||||
* 'BSD 3-clause "New" or "Revised" License', in which case the following
|
||||
* provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions 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 the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file VL53L1X api.h
|
||||
* @brief Functions definition
|
||||
*/
|
||||
|
||||
#ifndef VL53L1X_ULP_API_H_
|
||||
#define VL53L1X_ULP_API_H_
|
||||
|
||||
#include "VL53L1X_ULP_platform.h"
|
||||
|
||||
#define VL53L1X_ULP_VERSION "1.0.0"
|
||||
|
||||
/**
|
||||
* @brief Error types.
|
||||
*/
|
||||
|
||||
#define VL53L1X_ULP_ERROR_NONE ((uint8_t)0U)
|
||||
#define VL53L1X_ULP_ERROR_INVALID_ARGUMENT ((uint8_t)254U)
|
||||
#define VL53L1X_ULP_ERROR_TIMEOUT ((uint8_t)255U)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Firmware addresses.
|
||||
*/
|
||||
|
||||
|
||||
#define VL53L1X_ULP_I2C_SLAVE__DEVICE_ADDRESS ((uint16_t)0x0001)
|
||||
#define VL53L1X_ULP_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND ((uint16_t)0x0008)
|
||||
#define VL53L1X_ULP_GPIO_HV_MUX__CTRL ((uint16_t)0x0030)
|
||||
#define VL53L1X_ULP_GPIO__TIO_HV_STATUS ((uint16_t)0x0031)
|
||||
#define VL53L1X_ULP_SYSTEM__INTERRUPT ((uint16_t)0x0046)
|
||||
#define VL53L1X_ULP_RANGE_CONFIG_A ((uint16_t)0x005E)
|
||||
#define VL53L1X_ULP_RANGE_CONFIG_B ((uint16_t)0x0061)
|
||||
#define VL53L1X_ULP_RANGE_CONFIG__SIGMA_THRESH ((uint16_t)0x0064)
|
||||
#define VL53L1X_ULP_MIN_COUNT_RATE_RTN_LIMIT_MCPS ((uint16_t)0x0066)
|
||||
#define VL53L1X_ULP_INTERMEASUREMENT_MS ((uint16_t)0x006C)
|
||||
#define VL53L1X_ULP_THRESH_HIGH ((uint16_t)0x0072)
|
||||
#define VL53L1X_ULP_THRESH_LOW ((uint16_t)0x0074)
|
||||
#define VL53L1X_ULP_POWER_GO1 ((uint16_t)0x0083)
|
||||
#define VL53L1X_ULP_FIRMWARE_ENABLE ((uint16_t)0x0085)
|
||||
#define VL53L1X_ULP_SYSTEM__INTERRUPT_CLEAR ((uint16_t)0x0086)
|
||||
#define VL53L1X_ULP_SYSTEM_START ((uint16_t)0x0087)
|
||||
#define VL53L1X_ULP_RESULT__RANGE_STATUS ((uint16_t)0x0089)
|
||||
#define VL53L1X_ULP_RESULT__SPAD_NB ((uint16_t)0x008C)
|
||||
#define VL53L1X_ULP_RESULT__SIGNAL_RATE ((uint16_t)0x008E)
|
||||
#define VL53L1X_ULP_RESULT__AMBIENT_RATE ((uint16_t)0x0090)
|
||||
#define VL53L1X_ULP_RESULT__SIGMA ((uint16_t)0x0092)
|
||||
#define VL53L1X_ULP_RESULT__DISTANCE ((uint16_t)0x0096)
|
||||
#define VL53L1X_ULP_RESULT__OSC_CALIBRATE_VAL ((uint16_t)0x00DE)
|
||||
#define VL53L1X_ULP_FIRMWARE__SYSTEM_STATUS ((uint16_t)0x00E5)
|
||||
#define VL53L1X_ULP_IDENTIFICATION__MODEL_ID ((uint16_t)0x010F)
|
||||
|
||||
/**
|
||||
* @brief Functions definitions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function is used to get the sensor id of VL53L1X. The sensor id
|
||||
* should be 0xEACC.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) *p_id : Sensor id.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetSensorId(
|
||||
uint16_t dev,
|
||||
uint16_t *p_id);
|
||||
|
||||
/**
|
||||
* @brief This function sets a new I2C address to a sensor. It can be used for
|
||||
* example when multiple sensors share the same I2C bus.
|
||||
* @param (uint16_t) dev : Device to update.
|
||||
* @param (uint8_t) new_address : New I2C address.
|
||||
* @return (uint8_t) status : 0 if I2C address has been correctly
|
||||
* programmed.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetI2CAddress(
|
||||
uint16_t dev,
|
||||
uint8_t new_address);
|
||||
|
||||
/**
|
||||
* @brief This function is used to initialize the sensor.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @return (uint8_t) status : 0 if init is OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SensorInit(
|
||||
uint16_t dev);
|
||||
|
||||
/**
|
||||
* @brief This function check if a new data is available by polling a dedicated
|
||||
* register.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint8_t) *p_is_data_ready : Pointer containing a flag to know if a
|
||||
* data is ready : 0 = no data ready, 1 = data ready.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_CheckForDataReady(
|
||||
uint16_t dev,
|
||||
uint8_t *p_is_data_ready);
|
||||
|
||||
/**
|
||||
* @brief This function clears the interrupt. It needs to be called after a
|
||||
* ranging data reading to arm the interrupt for the next data ready event.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_ClearInterrupt(
|
||||
uint16_t dev);
|
||||
|
||||
/**
|
||||
* @brief This function starts a ranging session for only one measurement.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_StartRangingSingleShot(
|
||||
uint16_t dev);
|
||||
|
||||
/**
|
||||
* @brief This function starts a ranging session. A manual clear interrupt has
|
||||
* to be done to restart the next measurement.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_StartRanging(
|
||||
uint16_t dev);
|
||||
|
||||
/**
|
||||
* @brief This function stops the ranging in progress.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_StopRanging(
|
||||
uint16_t dev);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to dump the debug data (estimated distance,
|
||||
* measurement status, etc). It is particularly useful to tune the device for a
|
||||
* specific application. The function can be used when a new measurement is
|
||||
* ready, after clearing the interrupt.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint8_t) *p_measurement_status : Measurement status. A value equal to
|
||||
* 0 means that the estimated distance should be close to the reality.
|
||||
* @param (uint16_t) *p_estimated_distance_mm : Estimated target distance in mm.
|
||||
* @param (uint8_t) *p_sigma_mm : Estimated measurements std deviation in mm.
|
||||
* @param (uint16_t) *p_signal_kcps : Estimated signal rate of the target in kcps.
|
||||
* @param (uint16_t) *p_signal_mm : Ambient noise from external light in kcps.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_DumpDebugData(
|
||||
uint16_t dev,
|
||||
uint8_t *p_measurement_status,
|
||||
uint16_t *p_estimated_distance_mm,
|
||||
uint16_t *p_sigma_mm,
|
||||
uint16_t *p_signal_kcps,
|
||||
uint16_t *p_ambient_kcps);
|
||||
|
||||
/**
|
||||
* @brief Macro timing is equivalent to integration time. A high value increases
|
||||
* the maximum ranging distance and accuracy, but it also increase the power
|
||||
* consumption. This function is used to program a new value.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) macro_timing : Macro timing value. Value needs to be
|
||||
* between 1 and 255. Default is 1 (lowest power consumption).
|
||||
* @return (uint8_t) status : 0 if OK, or 254 if macro timing is invalid.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetMacroTiming(
|
||||
uint16_t dev,
|
||||
uint16_t macro_timing);
|
||||
|
||||
/**
|
||||
* @brief Macro timing is equivalent to integration time. A high value increases
|
||||
* the maximum ranging distance and accuracy, but it also increase the power
|
||||
* consumption. This function is used to get the programmed value.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) *p_macro_timing : Programmed macro timing value.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetMacroTiming(
|
||||
uint16_t dev,
|
||||
uint16_t *p_macro_timing);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to program the time between 2
|
||||
* consecutive measurements.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint32_t) inter_measurement_ms : Time in milliseconds between 2
|
||||
* measurements. Min value is 20ms and max is 60000ms. Default is 100ms.
|
||||
* @return (uint8_t) status : 0 if OK, or 254 if inter-measurement is invalid.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetInterMeasurementInMs(
|
||||
uint16_t dev,
|
||||
uint32_t inter_measurement_ms);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to get the programmed time between 2
|
||||
* consecutive measurements.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint32_t) *p_inter_measurement_ms : Time in milliseconds between 2
|
||||
* measurements.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetInterMeasurementInMs(
|
||||
uint16_t dev,
|
||||
uint32_t *p_inter_measurement_ms);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to change the number of SPADs enabled. The
|
||||
* VL53L1X uses by default a matrix of 256 SPADs which can be reduced. A
|
||||
* reduced number of SPADs reduces the power consumption, but is also reduces
|
||||
* the maximum ranging distance and accuracy. By default all SPADs are enabled
|
||||
* (max ranging distance).
|
||||
* IMPORTANT : Reducing the number of SPADs does't reduce the FOV.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint8_t) roi_width : Size of ROI. The minimum width is 4 (4x4=16
|
||||
* SPADs), and the maximum is 16 (16x16=256 SPADs).
|
||||
* @return (uint8_t) status : 0 if OK, or 254 if roi is invalid.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetROI(
|
||||
uint16_t dev,
|
||||
uint8_t roi_width);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to get the number of SPADs enabled. The
|
||||
* VL53L1X uses by default a matrix of 256 SPADs which can be reduced. A
|
||||
* reduced number of SPADs reduces the power consumption, but is also reduces
|
||||
* the maximum ranging distance and accuracy. By default all SPADs are enabled
|
||||
* (max ranging distance).
|
||||
* IMPORTANT : Reducing the number of SPADs does't reduce the FOV.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint8_t) *p_roi_width : Size of ROI.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetROI(
|
||||
uint16_t dev,
|
||||
uint8_t *p_roi_width);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to program the interrupt. There are 2
|
||||
* possible configurations :
|
||||
* - 1) Interrupt raised when a new measurement is ready, even if the distance
|
||||
* is wrong. It can be used to debug and tune the sensor.
|
||||
* - 2) Interrupt raised only when a target is detected. This is more for real
|
||||
* scene applications.
|
||||
* By default the sensor is programmed for the first case, it raises an
|
||||
* interrupt any new measurement is ready.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) distance_threshold_mm : Below this threshold, the
|
||||
* interrupt will be raised if the measurement is valid (status 0).
|
||||
* @param (uint8_t) enable_interrupt_only_below_threshold : If this flag is set
|
||||
* to 0, the sensor is programmed with the first configuration (raise an
|
||||
* interrupt when a new measurement is ready). Else, the sensor is programmed
|
||||
* to raise an interrupt ONLY when a valid distance below the threshold is
|
||||
* reported.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetInterruptConfiguration(
|
||||
uint16_t dev,
|
||||
uint16_t distance_threshold_mm,
|
||||
uint8_t enable_interrupt_only_below_threshold);
|
||||
|
||||
/**
|
||||
* @brief This function can be used to get the programmed the interrupt. There
|
||||
* are 2 possible configurations :
|
||||
* - 1) Interrupt raised when a new measurement is ready, even if the distance
|
||||
* is wrong. It can be used to debug and tune the sensor.
|
||||
* - 2) Interrupt raised only when a target is detected. This is more for real
|
||||
* scene applications.
|
||||
* By default the sensor is programmed for the first case, it raises an
|
||||
* interrupt any new measurement is ready.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) *p_distance_threshold_mm : Below this threshold, the
|
||||
* interrupt will be raised if the measurement is valid (status 0).
|
||||
* @param (uint8_t) *p_interrupt_enabled_only_below_threshold : If this flag is
|
||||
* set to 0, the sensor is programmed with the first configuration (raise an
|
||||
* interrupt when a new measurement is ready). Else, the sensor is programmed
|
||||
* to raise an interrupt ONLY when a valid distance below the threshold is
|
||||
* reported.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetInterruptConfiguration(
|
||||
uint16_t dev,
|
||||
uint16_t *p_distance_threshold_mm,
|
||||
uint8_t *p_interrupt_enabled_only_below_threshold);
|
||||
|
||||
/**
|
||||
* @brief This function sets a new signal threshold in kcps. If a
|
||||
* target has a lower signal as the programmed value, the measurement status in
|
||||
* debug value will be equal to 2.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) signal_kcps : New signal threshold in kcps. The default
|
||||
* value is 1500 kcps. Minimum is 1 kcps, and maximum is 16384 kcps.
|
||||
* @return (uint8_t) status : 0 if OK, or 254 if the threshold is not valid.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetSignalThreshold(
|
||||
uint16_t dev,
|
||||
uint16_t signal_kcps);
|
||||
|
||||
/**
|
||||
* @brief This function returns the current signal threshold in kcps. If a
|
||||
* target has a lower signal as the programmed value, the measurement status in
|
||||
* debug value will be equal to 2.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) *p_signal_kcps : Pointer of signal threshold in kcps.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetSignalThreshold(
|
||||
uint16_t dev,
|
||||
uint16_t *p_signal_kcps);
|
||||
|
||||
/**
|
||||
* @brief This function programs a new sigma threshold. The sigma corresponds to
|
||||
* the standard deviation of the returned pulse. If the computed sigma is above
|
||||
* the programmed value, the measurement status in debug value will be equal to
|
||||
* 1.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) sigma_mm : New sigma threshold in mm. The default value is
|
||||
* 45mm. Minimum is 1mm, and maximum is 16383mm.
|
||||
* @return (uint8_t) status : 0 if OK, or 254 if the threshold is not valid.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_SetSigmaThreshold(
|
||||
uint16_t dev,
|
||||
uint16_t sigma_mm);
|
||||
|
||||
/**
|
||||
* @brief This function gets the current sigma threshold. The sigma corresponds
|
||||
* to the standard deviation of the returned pulse. If the computed sigma is
|
||||
* above the programmed value, the measurement status in debug value will be
|
||||
* equal to 1.
|
||||
* @param (uint16_t) dev : Device address.
|
||||
* @param (uint16_t) *p_sigma_mm : Current sigma threshold in mm.
|
||||
* @return (uint8_t) status : 0 if OK.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_GetSigmaThreshold(
|
||||
uint16_t dev,
|
||||
uint16_t *p_sigma_mm);
|
||||
|
||||
#endif
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2021, STMicroelectronics - All Rights Reserved
|
||||
|
||||
This file : part of VL53L1X ULP and : dual licensed,
|
||||
either 'STMicroelectronics
|
||||
Proprietary license'
|
||||
or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
'STMicroelectronics Proprietary license'
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
terms at www.st.com/sla0081
|
||||
|
||||
STMicroelectronics confidential
|
||||
Reproduction and Communication of this document : strictly prohibited unless
|
||||
specifically authorized in writing by STMicroelectronics.
|
||||
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Alternatively, VL53L1X ULP may be distributed under the terms of
|
||||
'BSD 3-clause "New" or "Revised" License', in which case the following
|
||||
provisions apply instead of the ones mentioned above :
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
License terms: BSD 3-clause "New" or "Revised" License.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions 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 the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _VL53L1X_ULP_PLATFORM_H_
|
||||
#define _VL53L1X_ULP_PLATFORM_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read 32 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_RdDWord(uint16_t dev, uint16_t registerAddr, uint32_t *value);
|
||||
|
||||
/**
|
||||
* @brief Read 16 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_RdWord(uint16_t dev, uint16_t registerAddr, uint16_t *value);
|
||||
|
||||
/**
|
||||
* @brief Read 8 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_RdByte(uint16_t dev, uint16_t registerAddr, uint8_t *value);
|
||||
|
||||
/**
|
||||
* @brief Write 8 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_WrByte(uint16_t dev, uint16_t registerAddr, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Write 16 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_WrWord(uint16_t dev, uint16_t RegisterAdress, uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief Write 32 bits through I2C.
|
||||
*/
|
||||
|
||||
uint8_t VL53L1X_ULP_WrDWord(uint16_t dev, uint16_t RegisterAdress, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Wait during N milliseconds.
|
||||
*/
|
||||
|
||||
void VL53L1X_ULP_WaitMs(uint32_t TimeMs);
|
||||
|
||||
#endif // _VL53L1X_ULP_PLATFORM_H_
|
Loading…
Reference in New Issue