mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-16 15:08:15 +08:00
修复代码错误
This commit is contained in:
@@ -48,7 +48,7 @@ static mico_thread_t easylink_thread_handler = NULL;
|
||||
static bool easylink_thread_force_exit = false;
|
||||
|
||||
static mico_config_source_t source = CONFIG_BY_NONE;
|
||||
static bool easylink_with_softap = false;
|
||||
|
||||
/******************************************************
|
||||
* Function Definitions
|
||||
******************************************************/
|
||||
@@ -99,20 +99,7 @@ static void easylink_complete_cb( network_InitTypeDef_st *nwkpara, system_contex
|
||||
}
|
||||
return;
|
||||
}
|
||||
#ifdef MICO_EASYLINK_AND_SOFTAP_ENABLED
|
||||
void easylink_uap_success(uint32_t id)
|
||||
{
|
||||
if (easylink_with_softap == false)
|
||||
return;
|
||||
|
||||
system_log("sofapt configured");
|
||||
easylinkIndentifier = id;
|
||||
easylink_success = true;
|
||||
micoWlanSuspendSoftAP();
|
||||
mico_rtos_set_semaphore( &easylink_sem );
|
||||
}
|
||||
|
||||
#endif
|
||||
/* MiCO callback when EasyLink is finished step 2, return extra data
|
||||
data format: [AuthData#Identifier]<localIp/netMask/gateWay/dnsServer>
|
||||
Auth data: Provide to application, application will decide if this is a proter configuration for currnet device
|
||||
@@ -123,7 +110,7 @@ static void easylink_extra_data_cb( int datalen, char* data, system_context_t *
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
int index;
|
||||
uint32_t ipInfoCount;
|
||||
uint32_t *identifier, ipInfoCount;
|
||||
char *debugString;
|
||||
struct in_addr ipv4_addr;
|
||||
|
||||
@@ -145,7 +132,9 @@ static void easylink_extra_data_cb( int datalen, char* data, system_context_t *
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* Read identifier */
|
||||
memcpy(&easylinkIndentifier, &data[index], 4);
|
||||
identifier = (uint32_t *) &data[index];
|
||||
easylinkIndentifier = *identifier;
|
||||
|
||||
/* Identifier: 1 x uint32_t or Identifier/localIp/netMask/gateWay/dnsServer: 5 x uint32_t */
|
||||
ipInfoCount = (datalen - index) / sizeof(uint32_t);
|
||||
require_action( ipInfoCount >= 1, exit, err = kParamErr );
|
||||
@@ -159,13 +148,13 @@ static void easylink_extra_data_cb( int datalen, char* data, system_context_t *
|
||||
} else
|
||||
{ //Use static ip address
|
||||
inContext->flashContentInRam.micoSystemConfig.dhcpEnable = false;
|
||||
memcpy(&ipv4_addr.s_addr, &data[index+4], 4);
|
||||
ipv4_addr.s_addr = *(identifier+1);
|
||||
strcpy( (char *) inContext->micoStatus.localIp, inet_ntoa( ipv4_addr ) );
|
||||
memcpy(&ipv4_addr.s_addr, &data[index+8], 4);
|
||||
ipv4_addr.s_addr = *(identifier+2);
|
||||
strcpy( (char *) inContext->micoStatus.netMask, inet_ntoa( ipv4_addr ) );
|
||||
memcpy(&ipv4_addr.s_addr, &data[index+12], 4);
|
||||
ipv4_addr.s_addr = *(identifier+3);
|
||||
strcpy( (char *) inContext->micoStatus.gateWay, inet_ntoa( ipv4_addr ) );
|
||||
memcpy(&ipv4_addr.s_addr, &data[index+16], 4);
|
||||
ipv4_addr.s_addr = *(identifier+4);
|
||||
strcpy( (char *) inContext->micoStatus.dnsServer, inet_ntoa( ipv4_addr ) );
|
||||
|
||||
system_log("Get auth info: %s, EasyLink identifier: %lx, local IP info:%s %s %s %s ", data, easylinkIndentifier, inContext->flashContentInRam.micoSystemConfig.localIp,
|
||||
@@ -208,24 +197,9 @@ static void easylink_thread( uint32_t arg )
|
||||
restart:
|
||||
mico_system_delegate_config_will_start( );
|
||||
system_log("Start easylink combo mode");
|
||||
#ifdef MICO_EASYLINK_AND_SOFTAP_ENABLED
|
||||
if (easylink_with_softap == true) {
|
||||
char wifi_ssid[32];
|
||||
sprintf( wifi_ssid, "EasyLink_%c%c%c%c%c%c",
|
||||
context->micoStatus.mac[9], context->micoStatus.mac[10], context->micoStatus.mac[12],
|
||||
context->micoStatus.mac[13], context->micoStatus.mac[15], context->micoStatus.mac[16]);
|
||||
|
||||
system_log("Enable softap %s in easylink", wifi_ssid);
|
||||
OpenEasylink_softap( EasyLink_TimeOut / 1000, wifi_ssid, NULL, 6 );
|
||||
/* Start config server */
|
||||
config_server_start( );
|
||||
easylink_bonjour_start( Soft_AP, 0, context );
|
||||
} else
|
||||
#endif
|
||||
micoWlanStartEasyLinkPlus( EasyLink_TimeOut / 1000 );
|
||||
|
||||
while( mico_rtos_get_semaphore( &easylink_sem, 0 ) == kNoErr );
|
||||
err = mico_rtos_get_semaphore( &easylink_sem, EasyLink_TimeOut );
|
||||
err = mico_rtos_get_semaphore( &easylink_sem, MICO_WAIT_FOREVER );
|
||||
|
||||
/* Easylink force exit by user, clean and exit */
|
||||
if( err != kNoErr && easylink_thread_force_exit )
|
||||
@@ -296,7 +270,7 @@ exit:
|
||||
mico_rtos_delete_thread( NULL );
|
||||
}
|
||||
|
||||
OSStatus mico_easylink( mico_Context_t * const in_context, mico_bool_t enable, mico_bool_t softap )
|
||||
OSStatus mico_easylink( mico_Context_t * const in_context, mico_bool_t enable )
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
@@ -313,10 +287,6 @@ OSStatus mico_easylink( mico_Context_t * const in_context, mico_bool_t enable, m
|
||||
}
|
||||
|
||||
if ( enable == MICO_TRUE ) {
|
||||
if (softap == MICO_TRUE)
|
||||
easylink_with_softap = true;
|
||||
else
|
||||
easylink_with_softap = false;
|
||||
err = mico_rtos_create_thread( &easylink_thread_handler, MICO_APPLICATION_PRIORITY, "EASYLINK", easylink_thread,
|
||||
0x1000, (mico_thread_arg_t) in_context );
|
||||
require_noerr_string( err, exit, "ERROR: Unable to start the EasyLink thread." );
|
||||
|
||||
@@ -84,20 +84,6 @@ WEAK void mico_system_delegate_config_recv_ssid ( char *ssid, char *key )
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK mico_connect_fail_config_t mico_system_delegate_config_result( mico_config_source_t source, uint8_t result )
|
||||
{
|
||||
//system_log( "Configed by %d", source );
|
||||
UNUSED_PARAMETER(source);
|
||||
if(MICO_FALSE == result)
|
||||
{
|
||||
return RESTART_EASYLINK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EXIT_EASYLINK;
|
||||
}
|
||||
}
|
||||
|
||||
WEAK void mico_system_delegate_config_success( mico_config_source_t source )
|
||||
{
|
||||
//system_log( "Configed by %d", source );
|
||||
@@ -105,19 +91,6 @@ WEAK void mico_system_delegate_config_success( mico_config_source_t source )
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK void mico_system_delegate_easylink_timeout( system_context_t *context )
|
||||
{
|
||||
/* so roll back to previous settings (if it has) and connect */
|
||||
if ( context->flashContentInRam.micoSystemConfig.configured != unConfigured ) {
|
||||
MICOReadConfiguration( context );
|
||||
system_connect_wifi_normal( context );
|
||||
}
|
||||
else {
|
||||
/*module should power down in default setting*/
|
||||
micoWlanPowerOff();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WEAK OSStatus mico_system_delegate_config_recv_auth_data(char * anthData )
|
||||
{
|
||||
|
||||
@@ -56,7 +56,6 @@ static mico_thread_t easylink_monitor_thread_handler = NULL;
|
||||
static bool easylink_thread_force_exit = false;
|
||||
|
||||
static mico_config_source_t source = CONFIG_BY_NONE;
|
||||
static mico_connect_fail_config_t connect_fail_config = EXIT_EASYLINK;
|
||||
|
||||
/******************************************************
|
||||
* Function Definitions
|
||||
@@ -275,32 +274,33 @@ restart:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
source = (source == CONFIG_BY_NONE) ? CONFIG_BY_MONITOR : source;
|
||||
/*SSID or Password is not correct, module cannot connect to wlan, so restart EasyLink again*/
|
||||
require_noerr_action_string( err, restart, micoWlanSuspend(), "Re-start easylink combo mode" );
|
||||
|
||||
/* Easylink connect result */
|
||||
if ( err != kNoErr )
|
||||
{
|
||||
connect_fail_config = mico_system_delegate_config_result( source, MICO_FALSE );
|
||||
if ( RESTART_EASYLINK == connect_fail_config )
|
||||
{
|
||||
system_log("Re-start easylink combo mode");
|
||||
micoWlanSuspend( );
|
||||
goto restart;
|
||||
} else {
|
||||
system_log("exit easylink combo mode");
|
||||
micoWlanSuspendStation( );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mico_system_delegate_config_result( source, MICO_TRUE );
|
||||
mico_easylink_monitor_delegate_connect_success( source );
|
||||
}
|
||||
/* Start bonjour service for new device discovery */
|
||||
err = easylink_bonjour_start( Station, easylink_id, context );
|
||||
require_noerr( err, exit );
|
||||
SetTimer( 60 * 1000, easylink_remove_bonjour );
|
||||
|
||||
source = (source == CONFIG_BY_NONE) ? CONFIG_BY_MONITOR : source;
|
||||
mico_system_delegate_config_success( source );
|
||||
mico_easylink_monitor_delegate_connect_success( source );
|
||||
|
||||
goto exit;
|
||||
}
|
||||
else /* EasyLink failed */
|
||||
{
|
||||
mico_system_delegate_easylink_timeout( context );
|
||||
/* so roll back to previous settings (if it has) and connect */
|
||||
if ( context->flashContentInRam.micoSystemConfig.configured != unConfigured ) {
|
||||
system_log("Roll back to previous settings");
|
||||
MICOReadConfiguration( context );
|
||||
system_connect_wifi_normal( context );
|
||||
}
|
||||
else {
|
||||
/*module should power down in default setting*/
|
||||
system_log("Wi-Fi power off");
|
||||
micoWlanPowerOff();
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -348,7 +348,7 @@ OSStatus mico_easylink_monitor_save_result( network_InitTypeDef_st *nwkpara )
|
||||
|
||||
OSStatus mico_easylink_monitor_with_easylink( mico_Context_t * const in_context, mico_bool_t enable )
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
require_action( in_context, exit, err = kNotPreparedErr );
|
||||
|
||||
|
||||
@@ -127,9 +127,7 @@ OSStatus ConfigIncommingJsonMessageUAP( int fd, const uint8_t *input, size_t siz
|
||||
|
||||
easylink_success = true;
|
||||
if( easylink_sem ) mico_rtos_set_semaphore( &easylink_sem );
|
||||
#ifdef MICO_EASYLINK_AND_SOFTAP_ENABLED
|
||||
easylink_uap_success(easylinkIndentifier);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
if ( input_str ) free( input_str );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user