2026-09-04 21:08:56 +08:00
# include "ext_relay.h"
2026-09-04 20:09:04 +08:00
# include "relay.h"
# include "main.h"
# include "network.h"
# include "24c02.h"
# include "feed_scale.h"
# include "proto.h"
# include <string.h>
/* <20> <> <EFBFBD> <EFBFBD> ִ<EFBFBD> к<EFBFBD> ״̬<D7B4> ϱ <EFBFBD> <CFB1> <EFBFBD> ־ */
volatile uint8_t relay_report_pending = 0 ;
volatile uint32_t relay_report_tick = 0 ;
/* <20> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> ο <D7B6> <CEBF> <EFBFBD> :
0 : <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
1 : <EFBFBD> Ѷ <EFBFBD> <EFBFBD> <EFBFBD> , <EFBFBD> ȴ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȶ <EFBFBD>
2 : <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѷ <EFBFBD> , <EFBFBD> ѷ <EFBFBD> <EFBFBD> <EFBFBD> response <EFBFBD> <EFBFBD> status , <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
*/
volatile uint8_t relay_cmd_stage = 0 ;
volatile uint32_t relay_cmd_tick = 0 ;
volatile uint8_t relay_cmd_ch = 0 ;
volatile GPIO_PinState relay_cmd_fb_before = GPIO_PIN_RESET ;
char relay_cmd_id [ 20 ] = { 0 } ;
/* <20> <> <EFBFBD> м̵<D0BC> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ӧ״̬<D7B4> <CCAC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ѭ<EFBFBD> <D1AD> ÿ<EFBFBD> ֵ<EFBFBD> <D6B5> <EFBFBD> */
void relayCmdProcess ( void )
{
GPIO_PinState fb_after ;
uint8_t ch = relay_cmd_ch ;
if ( relay_cmd_stage = = 0 ) return ;
if ( relay_cmd_stage = = 1 ) {
/* <20> ȴ<EFBFBD> <C8B4> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ·<EFBFBD> ȶ<EFBFBD> */
if ( HAL_GetTick ( ) - relay_cmd_tick < 100 ) return ;
fb_after = relayReadFb ( ch ) ;
if ( RELAY_FB_ENABLE ) {
if ( MqttInfoStr . Relay_State [ ch ] ) {
if ( relay_cmd_fb_before = = FB_INACTIVE & & fb_after = = FB_ACTIVE ) {
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : SW%d <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " , ch ) ;
NET_publish_response ( relay_cmd_id , 1 , " OK " ) ;
} else {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : SW%d δ<> Ӹ<EFBFBD> <D3B8> ػ<EFBFBD> <D8BB> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> Ͽ<EFBFBD> " , ch ) ;
NET_publish_response ( relay_cmd_id , 0 , " Load unpowered / relay failure ! " ) ;
}
} else {
if ( relay_cmd_fb_before = = FB_ACTIVE & & fb_after = = FB_INACTIVE ) {
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : SW%d <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " , ch ) ;
NET_publish_response ( relay_cmd_id , 1 , " OK " ) ;
} else {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : SW%d δ<> Ӹ<EFBFBD> <D3B8> ػ<EFBFBD> <D8BB> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> Ͽ<EFBFBD> " , ch ) ;
NET_publish_response ( relay_cmd_id , 0 , " Load unpowered / relay failure ! " ) ;
}
}
} else {
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : SW%d <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " , ch ) ;
NET_publish_response ( relay_cmd_id , 1 , " OK " ) ;
}
/* <20> ο <EFBFBD> APP1: <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <D3A6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ϱ <EFBFBD> һ <EFBFBD> <D2BB> ȫ״̬, <20> <> ƽ ̨ˢ<CCA8> ¿<EFBFBD> <C2BF> <EFBFBD> ״̬ */
relayStatueUpdata ( ) ;
relay_cmd_stage = 0 ;
return ;
}
}
void relayInit ( void )
{
GPIO_InitTypeDef g = { 0 } ;
__HAL_RCC_GPIOA_CLK_ENABLE ( ) ;
__HAL_RCC_GPIOB_CLK_ENABLE ( ) ;
__HAL_RCC_GPIOC_CLK_ENABLE ( ) ;
/* 4 ·<> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ų<EFBFBD> ʼ <EFBFBD> <CABC> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , Ĭ<> ϵ͵<CFB5> ƽ <EFBFBD> ͷ<EFBFBD> */
g . Mode = GPIO_MODE_OUTPUT_PP ;
g . Pull = GPIO_NOPULL ;
g . Speed = GPIO_SPEED_FREQ_LOW ;
g . Pin = Relay1_Pin ; HAL_GPIO_Init ( Relay1_Port , & g ) ;
g . Pin = Relay2_Pin ; HAL_GPIO_Init ( Relay2_Port , & g ) ;
g . Pin = Relay3_Pin ; HAL_GPIO_Init ( Relay3_Port , & g ) ;
g . Pin = Relay4_Pin ; HAL_GPIO_Init ( Relay4_Port , & g ) ;
/* 4 ·<> <C2B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> */
g . Mode = GPIO_MODE_INPUT ;
g . Pull = GPIO_PULLUP ;
g . Pin = Relay1_FB_Pin ; HAL_GPIO_Init ( Relay1_FB_Port , & g ) ;
g . Pin = Relay2_FB_Pin ; HAL_GPIO_Init ( Relay2_FB_Port , & g ) ;
g . Pin = Relay3_FB_Pin ; HAL_GPIO_Init ( Relay3_FB_Port , & g ) ;
g . Pin = Relay4_FB_Pin ; HAL_GPIO_Init ( Relay4_FB_Port , & g ) ;
/* <20> <> <EFBFBD> <EFBFBD> GPIO Ĭ<> <C4AC> ȫ<EFBFBD> <C8AB> OFF<46> <46> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӡ<EFBFBD> <D3A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> ״̬ʱ<CCAC> <CAB1> ͳһ <CDB3> <D2BB> ӡһ <D3A1> Σ<EFBFBD> */
Relay1_OFF ;
Relay2_OFF ;
Relay3_OFF ;
Relay4_OFF ;
}
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӳɹ<D3B3> <C9B9> <EFBFBD> , <20> <> EEPROM <20> ָ<EFBFBD> <D6B8> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> ״̬<D7B4> <CCAC> <EFBFBD> ϵ<EFBFBD> <CFB5> <EFBFBD> <EFBFBD> 䣩<EFBFBD> <E4A3A9>
* <EFBFBD> <EFBFBD> ģ ʽ ( <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> · <EFBFBD> ̵ <EFBFBD> <EFBFBD> <EFBFBD> ) : <EFBFBD> <EFBFBD> · ȫ <EFBFBD> <EFBFBD> <EFBFBD> ָ <EFBFBD> <EFBFBD> <EFBFBD>
* <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ͷ ι ģ ʽ : <EFBFBD> ̵ <EFBFBD> <EFBFBD> <EFBFBD> 1 <EFBFBD> <EFBFBD> Ͷ ι ͨ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ָ <EFBFBD> <EFBFBD> <EFBFBD> ǿ <EFBFBD> ƹ ر գ <EFBFBD> <EFBFBD> <EFBFBD> ֹ <EFBFBD> ϵ <EFBFBD> <EFBFBD> <EFBFBD> Ͷ <EFBFBD> <EFBFBD> <EFBFBD> ˷ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
void relayRestoreState ( void )
{
if ( ! g_feed_scale_on ) {
if ( MqttInfoStr . Relay_State [ 1 ] ) { Relay1_ON ; log_info ( " SW1:<3A> <> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
else { Relay1_OFF ; log_info ( " SW1:<3A> أ<EFBFBD> <D8A3> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
} else {
MqttInfoStr . Relay_State [ 1 ] = 0 ;
Relay1_OFF ; log_info ( " SW1:<3A> أ<EFBFBD> <D8A3> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> Ͷι <CDB6> <CEB9> ȫ<EFBFBD> <C8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
}
if ( MqttInfoStr . Relay_State [ 2 ] ) { Relay2_ON ; log_info ( " SW2:<3A> <> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
else { Relay2_OFF ; log_info ( " SW2:<3A> أ<EFBFBD> <D8A3> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
if ( MqttInfoStr . Relay_State [ 3 ] ) { Relay3_ON ; log_info ( " SW3:<3A> <> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
else { Relay3_OFF ; log_info ( " SW3:<3A> أ<EFBFBD> <D8A3> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
if ( MqttInfoStr . Relay_State [ 4 ] ) { Relay4_ON ; log_info ( " SW4:<3A> <> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
else { Relay4_OFF ; log_info ( " SW4:<3A> أ<EFBFBD> <D8A3> ָ<EFBFBD> <D6B8> <EFBFBD> " ) ; }
}
/* <20> <> ȡָ<C8A1> <D6B8> <EFBFBD> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ԭʼ <D4AD> <CABC> ƽ */
GPIO_PinState relayReadFb ( uint8_t ch )
{
switch ( ch ) {
case 1 : return HAL_GPIO_ReadPin ( Relay1_FB_Port , Relay1_FB_Pin ) ;
case 2 : return HAL_GPIO_ReadPin ( Relay2_FB_Port , Relay2_FB_Pin ) ;
case 3 : return HAL_GPIO_ReadPin ( Relay3_FB_Port , Relay3_FB_Pin ) ;
case 4 : return HAL_GPIO_ReadPin ( Relay4_FB_Port , Relay4_FB_Pin ) ;
default : return GPIO_PIN_RESET ;
}
}
/* <20> <> <EFBFBD> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬: ֻд GPIO <20> <> Relay_State, <20> <> <EFBFBD> <EFBFBD> EEPROM/<2F> <> <EFBFBD> <EFBFBD> */
void relaySet ( uint8_t ch , uint8_t on )
{
2026-09-04 21:08:56 +08:00
if ( ch < 1 | | ch > 8 ) return ;
2026-09-04 20:09:04 +08:00
MqttInfoStr . Relay_State [ ch ] = on ? 1 : 0 ;
switch ( ch ) {
case 1 : if ( on ) Relay1_ON ; else Relay1_OFF ; break ;
case 2 : if ( on ) Relay2_ON ; else Relay2_OFF ; break ;
case 3 : if ( on ) Relay3_ON ; else Relay3_OFF ; break ;
case 4 : if ( on ) Relay4_ON ; else Relay4_OFF ; break ;
}
}
/* <20> <> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> ״̬<D7B4> ϱ <EFBFBD> : <20> <> <EFBFBD> <EFBFBD> ѭ<EFBFBD> <D1AD> <EFBFBD> <EFBFBD> <EFBFBD> relay_report_pending <20> <> <EFBFBD> <EFBFBD> ʱͳһ <CDB3> ϱ <EFBFBD> */
void relayRequestReport ( void )
{
relay_report_tick = HAL_GetTick ( ) ;
relay_report_pending = 1 ;
}
/* <20> ϱ <EFBFBD> <CFB1> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> ǰ״̬<D7B4> <CCAC> MQTTƽ ̨ */
void relayStatueUpdata ( void )
{
/* <20> <> ƽ ̨<C6BD> <CCA8> ģ<EFBFBD> <C4A3> <EFBFBD> ֶΣ<D6B6> weight=ʣ<> <CAA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> )<29> <> zero=<3D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (ȥƤ)<29> <> onceWt=<3D> <> <EFBFBD> <EFBFBD> Ͷ<EFBFBD> <CDB6> <EFBFBD> <EFBFBD> */
/* sw1 <20> <> feeding <20> <> <EFBFBD> ϱ <EFBFBD> <CFB1> ̵<EFBFBD> <CCB5> <EFBFBD> 1 ״̬<D7B4> <CCAC> ƽ ̨<C6BD> <CCA8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ض<EFBFBD> <D8B6> <EFBFBD> ͬ<EFBFBD> <CDAC> ˢ<EFBFBD> <CBA2> */
NET_publish_status (
MqttInfoStr . Relay_State [ 1 ] ? 1 : 0 ,
MqttInfoStr . Relay_State [ 1 ] ? 1 : 0 ,
MqttInfoStr . Relay_State [ 2 ] ? 1 : 0 ,
MqttInfoStr . Relay_State [ 3 ] ? 1 : 0 ,
MqttInfoStr . Relay_State [ 4 ] ? 1 : 0 ,
( float ) feedScaleGetZero ( ) / 10.0f ,
( float ) feedScaleGetOnceWeight ( ) / 10.0f ,
( float ) feedScaleGetWeight ( ) / 10.0f ) ;
}
/* <20> <> JSON <20> <> <EFBFBD> <EFBFBD> <EFBFBD> н<EFBFBD> <D0BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> ִ<EEB2A2> У <EFBFBD> ȡֵͳһ <CDB3> <D2BB> proto ģ<> 飬<EFBFBD> <E9A3AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ<EFBFBD> <CEBB> */
void relayAction ( uint8_t * data )
{
char * p ;
char CmdId [ 20 ] = { 0 } ;
uint8_t ch = 0 ;
GPIO_PinState fb_before ;
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : %.80s " , data ) ;
/* ֧<> <D6A7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> id <20> <> ʽ <EFBFBD> <CABD> "id":"xxx" <20> <> "id":xxx */
if ( ! proto_get_id ( ( char * ) data , CmdId , sizeof ( CmdId ) ) ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : id <20> <> <EFBFBD> <EFBFBD> ʧ<EFBFBD> <CAA7> " ) ;
return ;
}
if ( strstr ( ( char * ) data , " \" sw " ) ) {
char swkey [ 4 ] ;
int on = 0 ;
p = strstr ( ( char * ) data , " \" sw " ) ;
ch = p [ 3 ] - ' 0 ' ;
/* sw1 <20> <> feeding ָ<> <D6B8> <EFBFBD> <EFBFBD> Ч, <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ƽ ̵<C6BC> <CCB5> <EFBFBD> 1 */
if ( ch < 1 | | ch > 4 ) { log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : sw <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ч<EFBFBD> <D0A7> <EFBFBD> <EFBFBD> ֧<EFBFBD> <D6A7> sw1~sw4 " ) ; return ; }
swkey [ 0 ] = ' s ' ; swkey [ 1 ] = ' w ' ; swkey [ 2 ] = ( char ) ( ' 0 ' + ch ) ; swkey [ 3 ] = ' \0 ' ;
if ( ! proto_get_bool ( ( char * ) data , swkey , & on ) ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : sw%d ֵ<> <D6B5> Ч " , ch ) ;
NET_publish_response ( CmdId , 0 , " bad sw value " ) ;
return ;
}
/* <20> <> <EFBFBD> Ƽ ̵<C6BC> <CCB5> <EFBFBD> ǰ<EFBFBD> ȶ<EFBFBD> ȡ<EFBFBD> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƽ */
2026-09-04 21:08:56 +08:00
/* sw5~sw8: 485 <20> <> չ<EFBFBD> ̵<EFBFBD> <CCB5> <EFBFBD> <EFBFBD> <EFBFBD> (<28> 첽<EFBFBD> ·<EFBFBD> , Ӧ<> <D3A6> <EFBFBD> <EFBFBD> ext_relay_process <20> <> <EFBFBD> <EFBFBD> ) */
if ( ch > = 5 ) {
ext_relay_cmd ( ( uint8_t ) ( ch - 4 ) , ( uint8_t ) on , CmdId ) ;
return ;
}
2026-09-04 20:09:04 +08:00
fb_before = relayReadFb ( ch ) ;
if ( g_feed_scale_on ) {
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Զ<EFBFBD> Ͷι ģʽ <C4A3> ¼̵<C2BC> <CCB5> <EFBFBD> 1 <20> <> <EFBFBD> <EFBFBD> feeding ָ<> <D6B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , sw1 ֱ<> Ӻ<EFBFBD> <D3BA> <EFBFBD> */
if ( ch = = 1 ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> <> <EFBFBD> <EFBFBD> Ͷι ģʽ <C4A3> º<EFBFBD> <C2BA> <EFBFBD> sw1<77> <31> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> feeding ָ<> <D6B8> " ) ;
NET_publish_response ( CmdId , 0 , " sw1 disabled, use feeding " ) ;
return ;
}
}
relaySet ( ch , ( uint8_t ) on ) ;
log_info ( " > SW%d %s " , ch , on ? " <EFBFBD> <EFBFBD> " : " <EFBFBD> <EFBFBD> " ) ;
} else if ( strstr ( ( char * ) data , " \" feeding \" " ) ) {
/* ι <> <CEB9> /Ͷι ָ<CEB9> <D6B8> : body.feeding.value=true <20> <> <EFBFBD> <EFBFBD> , value=false ֹͣ */
int value_true = 0 ;
if ( ! proto_get_bool ( ( char * ) data , " feeding " , & value_true ) ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : feeding ֵ<> <D6B5> Ч " ) ;
NET_publish_response ( CmdId , 0 , " bad feeding value " ) ;
return ;
}
ch = 1 ;
fb_before = relayReadFb ( ch ) ;
if ( ! g_feed_scale_on ) {
if ( value_true ) {
relaySet ( 1 , 1 ) ;
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> ֶ<EFBFBD> Ͷι <CDB6> <CEB9> <EFBFBD> <EFBFBD> <EFBFBD> ӣ<DEB3> " ) ;
} else {
relaySet ( 1 , 0 ) ;
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> ֶ<EFBFBD> Ͷι <CDB6> أ<EFBFBD> <D8A3> ӣ<DEB3> " ) ;
}
} else {
if ( value_true ) {
/* <20> ״<EFBFBD> <D7B4> ϵ<EFBFBD> <CFB5> <EFBFBD> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> Ч<EFBFBD> <D0A7> <EFBFBD> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ͷι */
if ( feedScaleGetWeight ( ) = = 0 ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> ܾ<EFBFBD> <DCBE> <EFBFBD> <EFBFBD> <EFBFBD> Ͷι <CDB6> <CEB9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> δ<EFBFBD> <CEB4> <EFBFBD> <EFBFBD> " ) ;
NET_publish_response ( CmdId , 0 , " weight not ready " ) ;
return ;
}
/* <20> <> <EFBFBD> <EFBFBD> ʹ <EFBFBD> ñ<EFBFBD> <C3B1> <EFBFBD> ָ<EFBFBD> <D6B8> <EFBFBD> <EFBFBD> Я<EFBFBD> <D0AF> <EFBFBD> <EFBFBD> onceWt, <20> <> <EFBFBD> <EFBFBD> ʹ <EFBFBD> <CAB9> EEPROM <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ */
uint16_t once_wt_100g = 0 ;
proto_get_kg100 ( ( char * ) data , " onceWt " , & once_wt_100g ) ;
if ( once_wt_100g = = 0 ) {
once_wt_100g = feedScaleGetOnceWeight ( ) ;
} else {
feedScaleSetOnceWeight ( once_wt_100g ) ;
}
if ( once_wt_100g = = 0 ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> <> onceWt <20> <> <EFBFBD> <EFBFBD> Ͷι <CDB6> <CEB9> <EFBFBD> <EFBFBD> <EFBFBD> Ѻ<EFBFBD> <D1BA> <EFBFBD> " ) ;
NET_publish_response ( CmdId , 0 , " no onceWt " ) ;
return ;
}
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> <> ʼ Ͷι <CDB6> <CEB9> onceWt=%.1fKG " , ( float ) once_wt_100g / 10.0f ) ;
feedScaleStart ( once_wt_100g ) ;
} else {
log_info ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : ֹͣͶι " ) ;
feedScaleStop ( ) ;
}
}
} else if ( proto_locate ( ( char * ) data , " onceWt " ) ) {
if ( ! g_feed_scale_on ) {
/* <20> <EFBFBD> ģʽ <C4A3> <CABD> <EFBFBD> <EFBFBD> <DEB5> <EFBFBD> Ͷι <CDB6> <CEB9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܾ<EFBFBD> <DCBE> <EFBFBD> <EFBFBD> <EFBFBD> */
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> ܾ<EFBFBD> <DCBE> <EFBFBD> <EFBFBD> <EFBFBD> onceWt<57> <74> <EFBFBD> ӣ<DEB3> " ) ;
NET_publish_response ( CmdId , 0 , " no scale on this device " ) ;
return ;
} else {
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> õ<EFBFBD> <C3B5> <EFBFBD> Ͷι <CDB6> <CEB9> , <20> ־û<D6BE> <C3BB> <EFBFBD> EEPROM */
uint16_t once_wt_100g = 0 ;
proto_get_kg100 ( ( char * ) data , " onceWt " , & once_wt_100g ) ;
if ( once_wt_100g = = 0 | | once_wt_100g > 5000 ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : onceWt <20> <> Ч " ) ;
NET_publish_response ( CmdId , 0 , " invalid onceWt " ) ;
return ;
}
feedScaleSetOnceWeight ( once_wt_100g ) ;
NET_publish_response ( CmdId , 1 , " OK " ) ;
relayStatueUpdata ( ) ;
return ;
}
} else if ( proto_locate ( ( char * ) data , " zero " ) ) {
if ( ! g_feed_scale_on ) {
/* <20> <EFBFBD> ģʽ <C4A3> <CABD> <EFBFBD> <EFBFBD> ȥƤ/<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܾ<EFBFBD> <DCBE> <EFBFBD> <EFBFBD> <EFBFBD> */
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : <20> ܾ<EFBFBD> <DCBE> <EFBFBD> <EFBFBD> <EFBFBD> zero<72> <6F> <EFBFBD> ӣ<DEB3> " ) ;
NET_publish_response ( CmdId , 0 , " no scale on this device " ) ;
return ;
} else {
/* ƽ ̨<C6BD> ·<EFBFBD> <C2B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> /ȥƤֵ<C6A4> <D6B5> ֱ<EFBFBD> ӽ<EFBFBD> <D3BD> <EFBFBD> value <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
uint16_t zero_100g = 0 ;
proto_get_kg100 ( ( char * ) data , " zero " , & zero_100g ) ;
if ( zero_100g = = 0 | | zero_100g > 5000 ) {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : zero <20> <> Ч " ) ;
NET_publish_response ( CmdId , 0 , " invalid zero " ) ;
return ;
}
feedScaleSetZero ( zero_100g ) ;
NET_publish_response ( CmdId , 1 , " OK " ) ;
relayStatueUpdata ( ) ;
return ;
}
} else {
log_warn ( " > <20> ̵<EFBFBD> <CCB5> <EFBFBD> : δָ֪<D6AA> <EFBFBD> <EEA3A8> sw/feeding/zero<72> <6F> " ) ;
return ;
}
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ̵<EFBFBD> <CCB5> <EFBFBD> ״̬<D7B4> <CCAC> EEPROM, <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ָ<EFBFBD> */
eepromWriteData ( 102 , & MqttInfoStr . Relay_State [ 0 ] , 7 ) ;
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <D3A6> <EFBFBD> <EFBFBD> */
relay_cmd_stage = 1 ;
relay_cmd_tick = HAL_GetTick ( ) ;
relay_cmd_ch = ch ;
relay_cmd_fb_before = fb_before ;
memset ( relay_cmd_id , 0 , sizeof ( relay_cmd_id ) ) ;
memcpy ( relay_cmd_id , CmdId , sizeof ( relay_cmd_id ) - 1 ) ;
}