revised RFAC process

This commit is contained in:
Yunhorn 2024-09-25 12:01:09 +08:00
parent dd4ed806e9
commit f8900ae912
6 changed files with 46 additions and 276 deletions

View File

@ -418,7 +418,9 @@ void LoRaWAN_Init(void)
/* USER CODE BEGIN LoRaWAN_Init_LV */
uint32_t feature_version = 0UL;
/* USER CODE END LoRaWAN_Init_LV */
APP_LOG(TS_OFF, VLEVEL_M, "\n\n# YUNHORN SMARTOILETS: MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\n",
(uint8_t)sts_mtmcode1, (uint8_t)sts_mtmcode2,(uint8_t)sts_hardware_ver,(uint8_t)FirmwareVersion,
(uint8_t)MajorVer,(uint8_t)MinorVer,(uint8_t)SubMinorVer);
/* USER CODE BEGIN LoRaWAN_Init_1 */
/* Get LoRaWAN APP version*/
@ -1316,8 +1318,25 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
{
// UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer);
#if 1
uint8_t appHeartBeatDataPort, appHeartBeatBufferSize, appHeartBeatDataBuffer[32];
if ((rfac_timer <(STS_BURN_IN_RFAC+3))&&(sts_cfg_nvm.ac[0]==0x0)&&(sts_cfg_nvm.ac[19]==0x0))
{
//APP_LOG(TS_OFF, VLEVEL_M, "\n\n RFAC_TIMER = %d\n\n", rfac_timer);
//STS_YunhornSTSEventRFAC_Process();
// the following doesn't executed
#if 1
//APP_LOG(TS_OFF, VLEVEL_M, "\n Start send RFAC request \n");
appHeartBeatBufferSize = 4;
UTIL_MEM_cpy_8((uint8_t*)appHeartBeatDataBuffer,"RFAC",4);
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer);
#endif
rfac_timer ++;
} else { // normal heart-beat process
#if 1
#ifdef STS_P2
appHeartBeatDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT;
#elif defined(STS_R1)
@ -1333,23 +1352,11 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
appHeartBeatDataBuffer[1]=(uint8_t)(SYS_GetBatteryLevel()/100); //TODO XXX change to battery level in mV
STS_SENSOR_Upload_Message(appHeartBeatDataPort, appHeartBeatBufferSize, (uint8_t*)appHeartBeatDataBuffer);
#endif
if (rfac_timer <20)
{
STS_YunhornSTSEventRFAC_Process();
rfac_timer ++;
}
#if 0
if ((sts_cfg_nvm.ac[0]==0x0) && (sts_cfg_nvm.ac[19]==0x0)) /* simple validation of non-empty ac code */
{
/* RFAC Challenge */
if (rfac_timer < (STS_BURN_IN_RFAC+3)) {
rfac_timer ++;
}
APP_LOG(TS_OFF, VLEVEL_M, "\n Start send RFAC request \n");
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 4, (uint8_t*)"RFAC");
}
#endif
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
}

View File

@ -31,7 +31,7 @@ typedef struct {
uint8_t ac_pass;
} hmac_result_t;
void STS_HMAC_TESTING(void);
uint32_t sts_hmac_sha1(const uint8_t *Key, int key_length, const uint8_t *Message, int message_length, hmac_result_t *hmac_result);
uint32_t sts_hmac_verify(void);

View File

@ -43,12 +43,12 @@ uint32_t sts_hmac_verify(void)
ret = sts_hmac_sha1((const uint8_t *) mKey, sizeof(mKey), (const uint8_t*)(uid+4), 4, &hmac_result);
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
APP_LOG(TS_OFF, VLEVEL_M, "\n STS_AC_CODE \n");
//APP_LOG(TS_OFF, VLEVEL_M, "\n STS_AC_CODE \n");
for (uint8_t k=0; k<sizeof(sts_ac_code); k++)
APP_LOG(TS_OFF, VLEVEL_M, "%02d : AC: %02x\t HMAC_TAG:%02x\n", k, sts_ac_code[k], hmac_result.hmac_tag[k]);
//for (uint8_t k=0; k<sizeof(sts_ac_code); k++)
//APP_LOG(TS_OFF, VLEVEL_M, "%02d : AC: %02x\t HMAC_TAG:%02x\n", k, sts_ac_code[k], hmac_result.hmac_tag[k]);
APP_LOG(TS_OFF, VLEVEL_M, "\n STS_AC_CODE \n");
//APP_LOG(TS_OFF, VLEVEL_M, "\n STS_AC_CODE \n");
hmac_result.ac_pass = (ret == 0x0)?1U:0U;

View File

@ -209,11 +209,7 @@ extern volatile float sts_presence_rss_distance;
/* initiated by AUTO RESPOND PARSE PROCESS */
void STS_YunhornAuthenticationCode_Process(void)
{
if ((sts_cfg_nvm.ac[0] == 0x00) && (sts_cfg_nvm.ac[19]== 0x0)) {
APP_LOG(TS_OFF,VLEVEL_M, "Initial AC CODE blank... \r\n");
return;
}
if (sts_hmac_verify() != 0)
if (sts_hmac_verify() != 0) //Mismatch position =0, Passed, else failed
{
sts_service_mask = STS_SERVICE_MASK_L2;
sts_cfg_nvm.ac[0] = 0x0;
@ -235,7 +231,7 @@ void STS_YunhornSTSEventRFAC_Process(void)
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, 4, (uint8_t*)"RFAC");
}
}
#if 0
#if 1
if ((rfac_timer > (STS_BURN_IN_RFAC + 3)))
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n -Verify RFAC Success or Not\r\n");
@ -1227,7 +1223,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
STS_YunhornAuthenticationCode_Process();
if ((hmac_result.ac_pass == 1U))
if ((hmac_result.ac_pass == 1U)) // good ac code
{
//UTIL_MEM_cpy_8(sts_cfg_nvm.ac, sts_ac_code,YUNHORN_STS_AC_CODE_SIZE);
@ -1244,7 +1240,8 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s
} else {
sts_service_mask = STS_SERVICE_MASK_L2;
sts_ac_code[0] =0x0;
sts_ac_code[19] =0x0;
}
i=0;
@ -1466,7 +1463,7 @@ void STS_REBOOT_CONFIG_Init(void)
}
}
STS_Show_STS_CFG_NVM((uint8_t*)nvm_store_value);
//STS_Show_STS_CFG_NVM((uint8_t*)nvm_store_value);
OnRestoreSTSCFGContextProcess();
/* USER CODE END OnRestoreContextRequest_Last */

View File

@ -355,7 +355,7 @@ void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_
void STS_TOF_VL53LX_PeopleCounting_Process_Init(void)
{
APP_LOG(TS_OFF, VLEVEL_M,"############### TOF VL53LX_ PEOPLE COUNTING PROCESS INITIALIZATION\r\n");
APP_LOG(TS_OFF, VLEVEL_L,"\n\n# YUNHORN STS-P2 PEOPLE COUNTING PROCESS #\r\n");
sts_tof_vl53lx_peoplecount_init();
}
@ -389,9 +389,9 @@ int sts_tof_vl53lx_peoplecount_init(void)
/* Initialize all configured peripherals */
APP_LOG(TS_OFF, VLEVEL_L,"XNUCLEO53L1A1_Init Start .......... \r\n");
//APP_LOG(TS_OFF, VLEVEL_H,"XNUCLEO53L1A1_Init Start .......... \r\n");
status = XNUCLEO53L1A1_Init();
APP_LOG(TS_OFF, VLEVEL_L,"XNUCLEO53L1A1_Init Status : %X\n", status);
//APP_LOG(TS_OFF, VLEVEL_H,"XNUCLEO53L1A1_Init Status : %X\n", status);
status = XNUCLEO53L1A1_ResetId(XNUCLEO53L1A1_DEV_CENTER, 0); // Reset ToF sensor
@ -401,11 +401,11 @@ int sts_tof_vl53lx_peoplecount_init(void)
// Those basic I2C read functions can be used to check your own I2C functions */
status = VL53L1_RdByte(dev, 0x010F, &byteData);
APP_LOG(TS_OFF, VLEVEL_L,"VL53L1X Model_ID: %X\n", byteData);
//APP_LOG(TS_OFF, VLEVEL_H,"VL53L1X Model_ID: %X\n", byteData);
status = VL53L1_RdByte(dev, 0x0110, &byteData);
APP_LOG(TS_OFF, VLEVEL_L,"VL53L1X Module_Type: %X\n", byteData);
//APP_LOG(TS_OFF, VLEVEL_H,"VL53L1X Module_Type: %X\n", byteData);
status = VL53L1_RdWord(dev, 0x010F, &wordData);
APP_LOG(TS_OFF, VLEVEL_L,"VL53L1X: %X\n", wordData);
//APP_LOG(TS_OFF, VLEVEL_H,"VL53L1X: %X\n", wordData);
sensor_id = wordData;
wordData = 0;
while (sensorState == 0) {
@ -413,11 +413,11 @@ int sts_tof_vl53lx_peoplecount_init(void)
HAL_Delay(2);
wordData ++;
if (wordData > 8000) {
APP_LOG(TS_OFF, VLEVEL_L,"\n\n ***Failed to boot Chip***\n\n\n");
APP_LOG(TS_OFF, VLEVEL_H,"\n\n ***Failed to boot Chip***\n\n\n");
return status;
}
}
APP_LOG(TS_OFF, VLEVEL_L,"\nChip booted\n\n");
//APP_LOG(TS_OFF, VLEVEL_H,"\nChip booted\n\n");
/* Initialize and configure the device according to people counting need */
status = VL53L1X_SensorInit(dev);
@ -428,14 +428,14 @@ int sts_tof_vl53lx_peoplecount_init(void)
center[0]=ppc_cfg[sts_distance_mode].front_zone_center;
center[1]=ppc_cfg[sts_distance_mode].back_zone_center;
if (status != 0) {
APP_LOG(TS_OFF, VLEVEL_L,"Initialization or configuration of the device\n");
APP_LOG(TS_OFF, VLEVEL_H,"Initialization or configuration of the device\n");
return (-1);
}
APP_LOG(TS_OFF, VLEVEL_L,"\n\nStart counting people with profile : %s...\n\n", PROFILE_STRING);
//APP_LOG(TS_OFF, VLEVEL_H,"\n\nStart counting people with profile : %s...\n\n", PROFILE_STRING);
status = VL53L1X_StartRanging(dev); /* This function has to be called to enable the ranging */
if (status != 0) {
APP_LOG(TS_OFF, VLEVEL_L,"Error in start ranging\n");
APP_LOG(TS_OFF, VLEVEL_H,"Error in start ranging\n");
return (-1);
}
return 0;

View File

@ -310,63 +310,6 @@ done:
return status;
}
#if 0
void VL53L1A1_EXTI_IOConfigure(int DevNo, int IntPriority, int SubPriority){
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = VL53L1A1_INTR_PIN_PUPD;
switch (DevNo ) {
case XNUCLEO53L1A1_DEV_CENTER:
case 'c':
VL53L1A1_GPIO1_C_CLK_ENABLE();
/*Configure GPIO pin : PA4 */
GPIO_InitStruct.Pin = VL53L1A1_GPIO1_C_GPIO_PIN;
XNUCLEO53L1A1_SetIntrStateId(1,XNUCLEO53L1A1_DEV_CENTER);
HAL_GPIO_Init(VL53L1A1_GPIO1_C_GPIO_PORT, &GPIO_InitStruct);
HAL_NVIC_SetPriority((IRQn_Type)VL53L1A1_GPIO1_C_GPIO_PIN, IntPriority, SubPriority);
break;
#if VL53L1A1_GPIO1_SHARED == 0
case XNUCLEO53L1A1_DEV_LEFT:
case 'l':
break;
case XNUCLEO53L1A1_DEV_RIGHT:
break;
#endif
}
}
void VL53L1A1_EXTI_IOUnconfigure(int DevNo){
switch (DevNo ) {
case XNUCLEO53L1A1_DEV_CENTER:
case 'c':
//XNUCLEO53L1A1_SetIntrStateId(0,XNUCLEO53L1A1_DEV_TOP);
HAL_GPIO_DeInit(VL53L1A1_GPIO1_C_GPIO_PORT, VL53L1A1_GPIO1_C_GPIO_PIN);
__HAL_GPIO_EXTI_CLEAR_IT(VL53L1A1_GPIO1_C_GPIO_PIN);
break;
#if VL53L1A1_GPIO1_SHARED == 0
case XNUCLEO53L1A1_DEV_LEFT:
case 'l':
// XNUCLEO53L1A1_SetIntrStateId(0,XNUCLEO53L1A1_DEV_LEFT);
HAL_GPIO_DeInit(VL53L1A1_GPIO1_L_GPIO_PORT, VL53L1A1_GPIO1_L_GPIO_PIN);
__HAL_GPIO_EXTI_CLEAR_IT(VL53L1A1_GPIO1_L_GPIO_PIN);
break;
case XNUCLEO53L1A1_DEV_RIGHT:
case 'r':
HAL_GPIO_DeInit(VL53L1A1_GPIO1_R_GPIO_PORT, VL53L1A1_GPIO1_R_GPIO_PIN);
__HAL_GPIO_EXTI_CLEAR_IT(VL53L1A1_GPIO1_R_GPIO_PIN);
//XNUCLEO53L1A1_SetIntrStateId(0,XNUCLEO53L1A1_DEV_RIGHT);
break;
#endif
}
}
#endif
/**
* Set all i2c expended gpio in one go
* @return i/o operation status
@ -426,183 +369,6 @@ static int _ExpanderWR(int I2cExpAddr, int index, uint8_t *data, int n_data) {
return status;
}
#if 0
/**
* @defgroup XNUCLEO53L1A1_7Segment 7 segment display
*
* macro use for human readable segment building
* @code
* --s0--
* s s
* 5 1
* --s6--
* s s
* 4 2
* --s3-- . s7 (dp)
* @endcode
*
* @{
*/
/** decimal point bit mapping* */
#define DP (1<<7)
//VL6180 shield
//#define S0 (1<<0)
//#define S1 (1<<1)
//#define S2 (1<<2)
//#define S3 (1<<3)
//#define S4 (1<<4)
//#define S5 (1<<5)
//#define S6 (1<<6)
/** sgement s0 bit mapping*/
#define S0 (1<<3)
/** sgement s1 bit mapping*/
#define S1 (1<<5)
/** sgement s2 bit mapping*/
#define S2 (1<<6)
/** sgement s3 bit mapping*/
#define S3 (1<<4)
/** sgement s4 bit mapping*/
#define S4 (1<<0)
/** sgement s5 bit mapping*/
#define S5 (1<<1)
/** sgement s6 bit mapping*/
#define S6 (1<<2)
/**
* build a character by defining the non lighted segment (not one and no DP)
*
* @param ... literal sum and or combine of any macro to define any segment #S0 .. #S6
*
* example '9' is all segment on but S4
* @code
* ['9']= NOT_7_NO_DP(S4),
* @endcode
*/
#define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
/**
* Ascii to 7 segment lookup table
*
* Most common character are supported and follow http://www.twyman.org.uk/Fonts/
* few extra special \@ ^~ ... etc are present for specific demo purpose
*/
static const uint8_t ascii_to_display_lut[256]={
[' ']= 0,
['-']= S6,
['_']= S3,
['=']= S3+S6,
['~']= S0+S3+S6, /* 3 h bar */
['^']= S0, /* use as top bar */
['?']= NOT_7_NO_DP(S5+S3+S2),
['*']= NOT_7_NO_DP(),
['[']= S0+S3+S4+S5,
[']']= S0+S3+S2+S1,
['@']= S0+S3,
['0']= NOT_7_NO_DP(S6),
['1']= S1+S2,
['2']= S0+S1+S6+S4+S3,
['3']= NOT_7_NO_DP(S4+S5),
['4']= S5+S1+S6+S2,
['5']= NOT_7_NO_DP(S1+S4),
['6']= NOT_7_NO_DP(S1),
['7']= S0+S1+S2,
['8']= NOT_7_NO_DP(0),
['9']= NOT_7_NO_DP(S4),
['a']= S2+ S3+ S4+ S6 ,
['b']= NOT_7_NO_DP(S0+S1),
['c']= S6+S4+S3,
['d']= NOT_7_NO_DP(S0+S5),
['e']= NOT_7_NO_DP(S2),
['f']= S6+S5+S4+S0, /* same as F */
['g']= NOT_7_NO_DP(S4), /* same as 9 */
['h']= S6+S5+S4+S2,
['i']= S4,
['j']= S1+S2+S3+S4,
['k']= S6+S5+S4+S2, /* a h */
['l']= S3+S4,
['m']= S0+S4+S2, /* same as */
['n']= S2+S4+S6,
['o']= S6+S4+S3+S2,
['p']= NOT_7_NO_DP(S3+S2), // same as P
['q']= S0+S1+S2+S5+S6,
['r']= S4+S6,
['s']= NOT_7_NO_DP(S1+S4),
['t']= NOT_7_NO_DP(S0+S1+S2),
['u']= S4+S3+S2+S5+S1, // U
['v']= S4+S3+S2, // is u but u use U
['w']= S1+S3+S5,
['x']= NOT_7_NO_DP(S0+S3), // similar to H
['y']= NOT_7_NO_DP(S0+S4),
['z']= S0+S1+S6+S4+S3, // same as 2
['A']= NOT_7_NO_DP(S3),
['B']= NOT_7_NO_DP(S0+S1), /* as b */
['C']= S0+S3+S4+S5, // same as [
['E']= NOT_7_NO_DP(S1+S2),
['F']= S6+S5+S4+S0,
['G']= NOT_7_NO_DP(S4), /* same as 9 */
['H']= NOT_7_NO_DP(S0+S3),
['I']= S1+S2,
['J']= S1+S2+S3+S4,
['K']= NOT_7_NO_DP(S0+S3), /* same as H */
['L']= S3+S4+S5,
['M']= S0+S4+S2, /* same as m*/
['N']= S2+S4+S6, /* same as n*/
['O']= NOT_7_NO_DP(S6),
['P']= NOT_7_NO_DP(S3+S2),
['Q']= NOT_7_NO_DP(S3+S2),
['R']= S4+S6,
['S']= NOT_7_NO_DP(S1+S4), /* sasme as 5 */
['T']= NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
['U']= NOT_7_NO_DP(S6+S0),
['V']= S4+S3+S2, // is u but u use U
['W']= S1+S3+S5,
['X']= NOT_7_NO_DP(S0+S3), // similar to H
['Y']= NOT_7_NO_DP(S0+S4),
['Z']= S0+S1+S6+S4+S3, // same as 2
};
#undef S0
#undef S1
#undef S2
#undef S3
#undef S4
#undef S5
#undef S6
#undef DP
#endif
/** @} */
#if 0
int XNUCLEO53L1A1_SetDisplayString(const char *str) {
int status;
uint32_t Segments;
int BitPos;
int i;
for( i=0; i<4 && str[i]!=0; i++){
Segments = (uint32_t)ascii_to_display_lut[(uint8_t)str[i]];
Segments =(~Segments)&0x7F;
BitPos=DisplayBitPos[i];
CurIOVal.u32 &=~(0x7F<<BitPos);
CurIOVal.u32 |= Segments<<BitPos;
}
/* clear unused digit */
for( ; i<4;i++){
BitPos=DisplayBitPos[i];
CurIOVal.u32 |=0x7F<<BitPos;
}
status = _ExpandersSetAllIO();
if( status ){
XNUCLEO53L1A1_ErrLog("Set i/o");
}
return status;
}
#endif
/**
*
* @} XNUCLEO53L1A1_top