Skip to content

Commit

Permalink
merge 3288_dev to master
Browse files Browse the repository at this point in the history
  • Loading branch information
haibo344 committed Mar 6, 2015
2 parents d070f76 + 0155585 commit c4f2c34
Show file tree
Hide file tree
Showing 119 changed files with 74,441 additions and 5,116 deletions.
69 changes: 69 additions & 0 deletions Demos/COM.WECHAT.LED/MICOAppDefine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
******************************************************************************
* @file MICOAppDefine.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This file create a TCP listener thread, accept every TCP client
* connection and create thread for them.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MXCHIP Inc. SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2014 MXCHIP Inc.</center></h2>
******************************************************************************
*/


#ifndef __MICOAPPDEFINE_H
#define __MICOAPPDEFINE_H

#include "Common.h"
#include "MicoVirtualDeviceDef.h"


#define APP_INFO "mxchipWNet Wechat Demo based on MICO OS"

#define FIRMWARE_REVISION "MICO_WECHAT_LED_1_0"
#define MANUFACTURER "MXCHIP Inc."
#define SERIAL_NUMBER "20150305"
#define PROTOCOL "com.wechat.led"


/* Wi-Fi configuration mode */
//#define MICO_CONFIG_MODE CONFIG_MODE_EASYLINK_PLUS
#define MICO_CONFIG_MODE CONFIG_MODE_AIRKISS

/*User provided configurations*/
#define CONFIGURATION_VERSION 0x00000003 // if default configuration is changed, update this number
#define LOCAL_PORT 8080
#define BONJOUR_SERVICE "_easylink._tcp.local."

/* product type */
#define DEFAULT_PRODUCT_ID "f2889664"
#define DEFAULT_PRODUCT_KEY "fc7773f7-9199-4999-8bac-803ec949c61f"
#define DEFAULT_ROM_VERSION "v0.0.1"

/*Application's configuration stores in flash*/
typedef struct
{
uint32_t configDataVer; // config param update number
uint32_t localServerPort; // for bonjour service port

virtual_device_config_t virtualDevConfig; //virtual device settings
} application_config_t;

/*Running status*/
typedef struct _current_app_status_t {
virtual_device_status_t virtualDevStatus; //virtual device status
} current_app_status_t;


#endif

59 changes: 59 additions & 0 deletions Demos/COM.WECHAT.LED/MICOAppEntrance.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
******************************************************************************
* @file MICOAppEntrance.c
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief Mico application entrance, addd user application functons and threads.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MXCHIP Inc. SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2014 MXCHIP Inc.</center></h2>
******************************************************************************
*/

#include "MICODefine.h"
#include "MICOAppDefine.h"
#include "MicoPlatform.h"

#include "MicoVirtualDevice.h"

#define app_log(M, ...) custom_log("APP", M, ##__VA_ARGS__)
#define app_log_trace() custom_log_trace("APP")


/* MICO system callback: Restore default configuration provided by application */
void appRestoreDefault_callback(mico_Context_t *inContext)
{
inContext->flashContentInRam.appConfig.configDataVer = CONFIGURATION_VERSION;
inContext->flashContentInRam.appConfig.localServerPort = LOCAL_PORT;

// restore virtual device config
MVDRestoreDefault(inContext);
}

OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
app_log_trace();
OSStatus err = kNoErr;

require_action(inContext, exit, err = kParamErr);

/*Bonjour for service searching*/
if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true)
MICOStartBonjourService( Station, inContext );

/* start virtual device for communication (usart <==> cloud)*/
err = MVDInit(inContext);
require_noerr_action( err, exit, app_log("ERROR: virtual device start failed!") );

exit:
return err;
}
136 changes: 136 additions & 0 deletions Demos/COM.WECHAT.LED/MICOBonjour.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
******************************************************************************
* @file MICOBonjour.c
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief Zero-configuration protocol compatiable with Bonjour from Apple
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MXCHIP Inc. SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2014 MXCHIP Inc.</center></h2>
******************************************************************************
*/

#include "MicoDefine.h"
#include "platform.h"
#include "MICONotificationCenter.h"

#include "MDNSUtils.h"
#include "StringUtils.h"

static int _bonjourStarted = false;

void BonjourNotify_WifiStatusHandler( WiFiEvent event, mico_Context_t * const inContext )
{
(void)inContext;
switch (event) {
case NOTIFY_STATION_UP:
suspend_bonjour_service(false);
break;
case NOTIFY_STATION_DOWN:
break;
default:
break;
}
return;
}

void BonjourNotify_SYSWillPoerOffHandler( mico_Context_t * const inContext)
{
(void)inContext;
if(_bonjourStarted == true){
suspend_bonjour_service(true);
}
}

OSStatus MICOStartBonjourService( WiFi_Interface interface, mico_Context_t * const inContext )
{
char *temp_txt= NULL;
char *temp_txt2;
OSStatus err;
net_para_st para;
bonjour_init_t init;

temp_txt = malloc(500);
require_action(temp_txt, exit, err = kNoMemoryErr);

memset(&init, 0x0, sizeof(bonjour_init_t));

micoWlanGetIPStatus(&para, Station);

init.service_name = BONJOUR_SERVICE;

/* name#xxxxxx.local. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.host_name = (char*)__strdup(temp_txt);

/* name#xxxxxx. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.instance_name = (char*)__strdup(temp_txt);

init.service_port = inContext->flashContentInRam.appConfig.localServerPort;
init.interface = interface;

temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac);
sprintf(temp_txt, "MAC=%s.", temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION);
sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION);
sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(MicoGetVer());
sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(MODEL);
sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(PROTOCOL);
sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2);
free(temp_txt2);

temp_txt2 = __strdup_trans_dot(MANUFACTURER);
sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2);
free(temp_txt2);

sprintf(temp_txt, "%sSeed=%u.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed);
init.txt_record = (char*)__strdup(temp_txt);

bonjour_service_init(init);

free(init.host_name);
free(init.instance_name);
free(init.txt_record);

err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)BonjourNotify_WifiStatusHandler );
require_noerr( err, exit );
err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)BonjourNotify_SYSWillPoerOffHandler );
require_noerr( err, exit );

start_bonjour_service();
_bonjourStarted = true;

exit:
if(temp_txt) free(temp_txt);
return err;
}
Loading

0 comments on commit c4f2c34

Please sign in to comment.