Browse Source

修改功能按键不退出低功耗,由上位机负责退出

bfysop-v2
mr.zhangsan 1 year ago
parent
commit
c8c350267f
  1. 77
      source/app/app_config.c
  2. 4
      source/app/app_config.h
  3. 4
      source/app/main.c
  4. 1
      source/app/main.h
  5. 3
      source/app/task_btn.c
  6. 46
      source/app/task_low_power.c
  7. 32
      source/app/task_low_power.h
  8. 34
      source/app/task_rs485.c

77
source/app/app_config.c

@ -83,12 +83,8 @@ void L3_reg_reset(void)
}
//sop板默认不需要授权、未授权
//授权标志由主控板通过协议传递
// R.auth_flag = (0<<4) | 0;
R.auth_flag = (0<<4) | 0x01;
//设置led灯状态
L3_led_init();
R.auth_flag = (0<<4) | 0;
// R.auth_flag = (0<<4) | 0x01;
//从机ID
R.slave_id = 0x01;
@ -99,18 +95,14 @@ void L3_reg_reset(void)
//功能按键按下状态
R.func_btn = 0;
//设置led灯状态
L3_led_clear();
//nfc编号
R.nfc.nfc_no[0] = 0;
R.nfc.nfc_no[1] = 0;
L3_nfc_clear();
//4路RFID编号
for(i=0; i<4; i++)
{
R.rfids[i].rfid_no[0] = 0;
R.rfids[i].rfid_no[1] = 0;
R.rfids[i].rssi = 0;
R.rfids[i].ant = 0;
};
L3_rfid_clear();
//for test
// R.slave_id = 0x01;
@ -126,6 +118,33 @@ void L3_reg_reset(void)
// };
}
void L3_led_clear(void)
{
//设置led灯状态
for(i=0; i<LED_BTN_NUM; i++)
{
R.led_status[i] = BLED0_OFF;
}
R.led_status[0] = BLED0_ON;
}
void L3_nfc_clear(void)
{
R.nfc.nfc_no[0] = 0;
R.nfc.nfc_no[1] = 0;
}
void L3_rfid_clear(void)
{
for(i=0; i<4; i++)
{
R.rfids[i].rfid_no[0] = 0;
R.rfids[i].rfid_no[1] = 0;
R.rfids[i].rssi = 0;
R.rfids[i].ant = 0;
};
}
void L3_reg_init(void)
{
L3_reg_reset();
@ -159,7 +178,8 @@ U8 L3_find_rfid_table(U16 rfidno)
{
for(i=0; i<LED_BTN_NUM; i++)
{
if(rfidno == R.rfid_table[i]){
if(rfidno == R.rfid_table[i])
{
return i;
}
}
@ -168,24 +188,11 @@ U8 L3_find_rfid_table(U16 rfidno)
void L3_set_power_mode(U8 mode)
{
if(R.power_mode == POWER_NORMAL)
{
if(mode == POWER_LOW)
{
//除了功能按键,所有灯全灭
L3_led_init();
}
}
// if(R.power_mode == POWER_NORMAL)
// {
// if(mode == POWER_LOW)
// {
// }
// }
R.power_mode = mode;
}
void L3_led_init(void)
{
//设置led灯状态
for(i=0; i<LED_BTN_NUM; i++)
{
R.led_status[i] = BLED0_OFF;
}
R.led_status[0] = BLED0_ON;
}

4
source/app/app_config.h

@ -100,7 +100,9 @@ extern void L3_reg_2_iap(void);
extern void L3_iap_2_reg(void);
extern void L3_reg_reset(void);
extern void L3_reg_init(void);
extern void L3_led_init(void);
extern void L3_led_clear(void);
extern void L3_nfc_clear(void);
extern void L3_rfid_clear(void);
extern void L3_set_power_mode(U8 mode);
extern U8 L3_find_rfid_table(U16 rfidno);
extern U8 L3_new_rfid(U16 rfidno, U8 rssi, U8 ant);

4
source/app/main.c

@ -118,6 +118,7 @@ void L0_task_init()
L3_task_bled_init();
L3_task_btn_init();
L3_task_auth_init();
L3_task_low_power_init();
// L3_task_adc_init(0);
// L3_task_adc_init(1);
@ -181,6 +182,9 @@ void main(void)
// //10s认证过期
L3_task_auth_handler(&_s_task_auth);
//低功耗模式
L3_task_low_power_handler(&_s_task_low_power);
//NFC协议处理
L3_task_nfc_handler(&_s_task_nfc);

1
source/app/main.h

@ -61,6 +61,7 @@
#include "../app/task_bled.h"
#include "../app/task_btn.h"
#include "../app/task_nfc_auth.h"
#include "../app/task_low_power.h"
//////////////////////////////////////////////////////////////////

3
source/app/task_btn.c

@ -45,8 +45,9 @@ void L3_task_btn_handler(S_TASK_BTN *s)
{
//设置功能按键按下
R.func_btn = 1;
//此处代码注释掉:因为低功耗由上位机处理
//功能键按下退出低功耗模式
L3_set_power_mode(POWER_NORMAL);
//L3_set_power_mode(POWER_NORMAL);
}
else
{

46
source/app/task_low_power.c

@ -0,0 +1,46 @@
////////////////////////////////////////////////////////////////////////////
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
///-------------------------------------------------------------------------
/// @file bsp_drv.c
/// @brief bsp @ driver config
///-------------------------------------------------------------------------
/// @version 1.0
/// @author CC
/// @date 20180331
/// @note cc_AS_stc02
//////////////////////////////////////////////////////////////////////////////
#include "task_low_power.h"
#include "../app/app_config.h"
#include "../bsp/bsp_config.h"
#include "../msp/uart0.h"
S_TASK_LOW_POWER _s_task_low_power;
void L3_task_low_power_init(void)
{
L1_task_init(&_s_task_low_power.task);
L3_task_s_go(_s_task_low_power,D_task_init);
}
#define D_task_LOW_POWER_SET 0x50
void L3_task_low_power_handler(S_TASK_LOW_POWER *s)
{
TTSS_Task_init()
L2_task_go(D_task_LOW_POWER_SET);
TTSS_Task_step(D_task_LOW_POWER_SET)
if(R.power_mode == POWER_LOW)
{
//除了功能按键,所有灯全灭
L3_led_clear();
}
L2_task_go_Tdelay(D_task_LOW_POWER_SET,D_Tdelay_1s);
TTSS_Task_end();
}

32
source/app/task_low_power.h

@ -0,0 +1,32 @@
////////////////////////////////////////////////////////////////////////////
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
///-------------------------------------------------------------------------
/// @file bsp_drv.h
/// @brief bsp @ driver config
///-------------------------------------------------------------------------
/// @version 1.0
/// @author CC
/// @date 20180331
/// @note cc_AS_stc02
//////////////////////////////////////////////////////////////////////////////
#ifndef _APP_TASK_LOW_POWER_H
#define _APP_TASK_LOW_POWER_H
#include "../ctask/task.h"
#include "../clib/clib.h"
typedef struct _s_task_low_power
{
TS_task task;
}S_TASK_LOW_POWER;
extern S_TASK_LOW_POWER _s_task_low_power;
extern void L3_task_low_power_init(void);
extern void L3_task_low_power_handler(S_TASK_LOW_POWER *s);
#endif // #ifndef _APP_TASK_LOW_POWER_H

34
source/app/task_rs485.c

@ -21,6 +21,7 @@ TPC_RS485 tpc_rs485;
TPC_RS485_ACK tpc_rs485_ack;
static U8 acklen = 0;
static U8 i = 0;
U16 setLedStatus = 0;
U8 constructor_rs485_ack();
@ -59,14 +60,29 @@ void L3_task_rs485_handler(S_TASK_RS485 *s)
//读取
if(tpc_rs485.cmd == 0x10)
{
//buf[0] 是否需要授权标志、低功耗模式
//1.buf[0]高4位是否需要授权标志
R.auth_flag &= 0x0F;
R.auth_flag |= tpc_rs485.buf[0] & 0xF0;
//2.buf[0]低四位是否进入低功耗模式
// R.low_power_mode = tpc_rs485.buf[0] & 0x0F;
L3_set_power_mode(tpc_rs485.buf[0] & 0x0F);
//buf[1-2], rfid映射
//TODO 上位机发过来的rfid编号如何处理
//3.buf[1-2], rfid映射
//TODO 上位机发过来的rfid编号如何处理
setLedStatus = (U16)tpc_rs485.buf[1] << 8 | tpc_rs485.buf[2];
if(setLedStatus != 0x00)
{
//0位是功能按键,常亮,不提供设置功能
for(i=1;i<LED_BTN_NUM;i++)
{
//不处理0,只处理1的情况(代表其他端产生了sop中的节点,比如平板上触发谈话等)
if((setLedStatus >> i) & 0x0001)
{
R.led_status[i] = LED0_ON;
}
}
}
//构造响应包,并且返回
acklen = constructor_rs485_ack();
@ -124,16 +140,8 @@ U8 constructor_rs485_ack()
//清0资源
R.func_btn = 0;
R.nfc.nfc_no[0] = 0x00;
R.nfc.nfc_no[1] = 0x00;
R.rfids[0].rfid_no[0] = 0x00;
R.rfids[0].rfid_no[1] = 0x00;
R.rfids[1].rfid_no[0] = 0x00;
R.rfids[1].rfid_no[1] = 0x00;
R.rfids[2].rfid_no[0] = 0x00;
R.rfids[2].rfid_no[1] = 0x00;
R.rfids[3].rfid_no[0] = 0x00;
R.rfids[3].rfid_no[1] = 0x00;
L3_nfc_clear();
L3_rfid_clear();
return 5 + num + 1;
}

Loading…
Cancel
Save