void Server_Registered_Appliance(int nSock)
{
	char *pszRecv=NULL;
	char szQuery[200];
	char szAppliance[25];
	int nFlatNo;
	int nApNo;
	pszRecv=Receive_Message(nSock);
	printf("%s\n",pszRecv);
	sscanf(pszRecv,"%d %s %d",&nFlatNo,szAppliance,&nApNo);
	sprintf(szQuery,"update Registered_Appliances set Appliance%d='%s' where FlatNo=%d ",nApNo,szAppliance,nFlatNo);
	printf("%s\n",szQuery);
	MYSQL *con = mysql_init(NULL);
	if(con == NULL) 
	{
	      fprintf(stderr, "%s\n", mysql_error(con));		    
	      //exit(1);
	}
	if(mysql_real_connect(con, "localhost", "root", "labh","rll", 0, NULL, 0) == NULL) 
  	{
      		finish_with_error(con);
		return;
  	} 
	if (mysql_query(con, szQuery)) 
	{
      		finish_with_error(con);
  	}
	sprintf(szQuery,"update Appliance_Status set Appliance%dState=0 where FlatNo=%d ",nApNo,nFlatNo);
	if (mysql_query(con, szQuery)) 
	{
      		finish_with_error(con);
  	}
}
Example #2
0
/*! \brief Command handler for the data received from QTouch Studio
 * \note This function should be called in the main loop after
 * measure_sensors to process the data received from QTOuch Studio.
 */
void QDebug_ProcessCommands(void)
{
	uint8_t CommandID;

	if (Receive_Message() == 0) {
		return;
	}

	/* Handle the commands */
	CommandID = GetChar();

	switch (CommandID) {
	case QT_CMD_DUMMY:
		break;

	case QT_CMD_SET_SUBS:
		Set_Subscriptions();
		break;

	case QT_CMD_SET_GLOBAL_CONFIG:
		Set_Global_Config();
		Set_Measurement_Period();
		break;

	case QT_CMD_SET_CH_CONFIG:
		Set_Channel_Config();
		break;
	}

	RX_Buffer[0] = 0;
	RX_index = 0;
}
void FamilyMember_Login(int nsock)
{
	char szUserName[10];
	char szPassword[15];
	char szBuf[nSize];
	char *pszBuf;
	int nResult=bZero;
	int nFlatNo;
	char *getpass(const char* prompt);
	printf("Admin_Login func %d\n",nsock);
	printf("Enter your Family  User Name\n");
	__fpurge(stdin);
	fgets(szUserName,15,stdin);

	printf("Enter your Family password\n");
	__fpurge(stdin);
	sprintf(szPassword,"%s",getpass("enter:"));
	szUserName[strlen(szUserName)-1]='\0';
	sprintf(szBuf,"%s %s %d",szUserName,szPassword,nFlatNo);
	printf("%s\n",szBuf);
	Send_Message(nsock,szBuf);
	pszBuf=Receive_Message(nsock);
	nResult=atoi(pszBuf);
	if(nResult==bOne)
	{
		printf("success change\n");
	}
	else 
	{
		printf("failed\n");
	}
}
Example #4
0
/**
 * @brief Application task
 * @ingroup TApp_API 
 */
static void app_task(void)
{
    /**
     * To start NLME Reset procedure when application starts up
     */
    if (target_auto_start == true)
    {
        target_auto_start = false;
        node_status = ALL_IN_ONE_START;
        ch_ag_enabled = false;
        nlme_reset_request(true);
        return;
    }
    else 
    {
        if(node_status != IDLE)
            return;    
        if (Receive_Message() == 0)
            return;
            /**
             * To send out QTouch Studio commands over air 
             * to Touch Remote  
             */  
            vendor_data_request(0, PROFILE_ID_VENDOR_DATA,
                                NWKC_VENDOR_IDENTIFIER, RF4CE_RX_Buffer[2], RF4CE_RX_Buffer,
                                TXO_UNICAST | TXO_DST_ADDR_IEEE | TXO_ACK_REQ | TXO_SEC_REQ | TXO_MULTI_CH | TXO_CH_NOT_SPEC | TXO_VEND_SPEC);  
                
    }/*end of else*/
       
}
Example #5
0
void server_menu(int nSock)
{
	char *pszChoice;
	int nChoice;
	int oChoice=bZero;
	printf("****************\n");
	while(1)
	{
		pszChoice=Receive_Message(nSock);
		nChoice=atoi(pszChoice);
		switch(nChoice)
		{
			case ADMIN:
				printf("you enter as a admin\n");
				Server_Admin_Login(nSock);
				break;
			case FLATE_OWNER:
				printf("you enter as a  owner\\ family\n");
				oChoice=atoi(Receive_Message(nSock));
				if(oChoice==1)
				{
					printf("you enter as a flat owner\n");
					Server_FlatOwner_Login(nSock);
				}
				else if(oChoice==2)
				{
					printf("you enter as a family Member\n");
					Server_FamilyMember_Login(nSock);
				}
				else
				printf("Wrong choice \n");
			
				break;

			case EXIT:
				printf("you exit from apps\n");
				return;
			
		}
	}
}
void Delete_Account(int nSock)
{	
	int nFlatNo;
	char szSend[15];
	char *pszRecv;
	printf("in Delete_Account fun %u\n",nSock);
	printf("Enter FlatNo\n");
	scanf("%d",&nFlatNo);
	sprintf(szSend,"%d",nFlatNo);
	Send_Message(nSock,szSend);
	pszRecv=Receive_Message(nSock);
	if(!strcmp(pszRecv,"1"))
		printf("Delete FlatNo %d successfully\n",nFlatNo);
	else
		printf("deletion is unsuccessfully\n");
}
void Server_Admin_Login(int nSock)
{

	int nResult=bZero;
	char *pszBuf;
	char szUserName[10];
	char szPassword[15];
	struct login admin;
	struct login admin1;
	FILE *pFilePointer;
	//	printf("++++++++++++++=\n");
	pFilePointer=fopen("Admin.txt","rb");
	pszBuf=Receive_Message(nSock);
//	if(recv(nSock,pszBuf,sizeof(pszBuf),bZero)==0)
//		printf("recv Failed\n");
	//printf(pszBuf);
//		printf("******************\n");
	sscanf(pszBuf,"%s %s",szUserName,szPassword);
	fread(&admin1,sizeof(struct login),bOne,pFilePointer);
	if(!strncmp(szUserName,admin1.strUserName,10) && !strncmp(szPassword,admin1.strUserPassword,15))
	{
		nResult=bOne;
	}
	fclose(pFilePointer);
	if(nResult==bOne)
	{
		Send_Message(nSock,"1");
		Server_Admin_Menu(nSock);
		printf("******************\n");
	}
	else
	{
		printf("******************\n");
		Send_Message(nSock,"0");
		Server_Admin_Login(nSock);
	}
//	printf("nResult==%d\n",nResult);
}
void FlatOwner_Login(int nsock)
{
	char szUserName[10];
	char szPassword[15];
	int nFlatNo=bZero;
	char szBuf[nSize];
	char *pszBuf;
	int nResult=bZero;
//	struct login admin;
	printf("FlatOwner_Login func %d\n",nsock);
	printf("Enter your User Name\n");
	__fpurge(stdin);
	fgets(szUserName,10,stdin);
	printf("Enter your password\n");
	__fpurge(stdin);
	fgets(szPassword,15,stdin);
	printf("Enter your FlatNo\n");
	__fpurge(stdin);
	scanf("%d",&nFlatNo);
	szUserName[strlen(szUserName)-1]='\0';
	szPassword[strlen(szPassword)-1]='\0';
	sprintf(szBuf,"%s %s %d",szUserName,szPassword,nFlatNo);
	printf("%s\n",szBuf);
	//send(nsock,szBuf,sizeof(szBuf),bZero);
	Send_Message(nsock,szBuf);
	pszBuf=Receive_Message(nsock);
	nResult=atoi(pszBuf);
	if(nResult==bOne)
	{
		printf("login success\n");
		FlatOwner_Menu(nFlatNo,nsock);
	}
	else 
	{
		printf("login failed\n");
		FlatOwner_Login(nsock);
	}
}
/*! \brief Command handler for the data received from QTouch Studio
 * \note This function should be called in the main loop after
 * measure_sensors to process the data received from QTOuch Studio.
 */
void QDebug_ProcessCommands(void)
{
	uint8_t CommandID;

	if (Receive_Message() == 0) {
		return;
	}

	/* Handle the commands */
	CommandID = GetChar();

	switch (CommandID) {
	case QT_CMD_DUMMY:
		break;

	case QT_CMD_SET_SUBS:
		Set_Subscriptions();
		break;

	case QT_CMD_SET_GLOBAL_CONFIG:
		Set_Global_Config();
		Set_Measurement_Period();
		break;

	case QT_CMD_SET_CH_CONFIG:
		Set_Channel_Config();
		break;

#if (DEF_TOUCH_QDEBUG_ENABLE_QM == 1)
	case QT_CMD_SET_QM_BURST_LENGTHS:
		Set_QM_Burst_Lengths();
		break;
#endif
	}

	RX_Buffer[0] = 0;
	RX_index = 0;
}
void Server_Create_FlatAccount(int nSock)
{
	char szQuery[200];
	char szBuf[200];
	char szUserName[10];
	char szPassword[15];
	char szFlatOwnerName[10];
	char szResidingDate[15];
	char szDetails[nSize];
	char *pszRecv=NULL;
	int nContactNo=bZero;
	int nMembers=bZero;
	int nResult=bZero;
	int nFlatNo,i,numrow;
	int num_fields=bZero;
	MYSQL_RES *result=NULL;
	MYSQL *con = mysql_init(NULL);
	if(con == NULL) 
	{
	      fprintf(stderr, "%s\n", mysql_error(con));
	      //exit(1);
	}


	printf("In func login %u\n",nSock);
	pszRecv=Receive_Message(nSock);
	nFlatNo=atoi(pszRecv);
	sprintf(szQuery,"select * from Login_Credentials where FlatNo=%d",nFlatNo);
//	printf("*******%s****\n",pszRecv);
	if(mysql_real_connect(con, "localhost", "root", "labh","rll", 0, NULL, 0) == NULL) 
	{
		finish_with_error(con);
		return;
	} 
	if (mysql_query(con, szQuery)) 
	{
		finish_with_error(con);
	}
	result = mysql_store_result(con);
	if (result == NULL) 
	{
		finish_with_error(con);
	}
  	//num_fields = mysql_num_fields(result);
  	numrow = mysql_num_rows(result);
 	if(numrow==0)
	{
  		Send_Message(nSock,"1");
		pszRecv=Receive_Message(nSock);
		sscanf(pszRecv,"%s %d %s %d ",szFlatOwnerName,&nContactNo,szResidingDate,&nMembers);
		sprintf(szQuery,"insert into Flat_Account values(%d,'%s','%d','%s',%d)",nFlatNo,szFlatOwnerName,nContactNo,szResidingDate,nMembers);
		printf("%s\n",szQuery);
		if (mysql_query(con, szQuery)) 
		{
			finish_with_error(con);
		}
		sprintf(szUserName,"%.2s%d",szFlatOwnerName,nContactNo%1000);
		srand(time(NULL));
		sprintf(szPassword,"%d",rand()%10000);
		sprintf(szBuf,"%s %s\n",szUserName,szPassword);
		sprintf(szQuery,"insert into Login_Credentials(FlatNo,FlatOwner,LoginName,LoginPwd) values(%d,'%s','%s','%s')",nFlatNo,szFlatOwnerName,szUserName,szPassword);
		printf("%s\n",szQuery);
		printf("%s\n",szBuf);
		if (mysql_query(con, szQuery)) 
		{
			finish_with_error(con);
		}
		sprintf(szQuery,"insert into Registered_Appliances (FlatNo) values (%d)",nFlatNo);
		if (mysql_query(con, szQuery)) 
		{
			finish_with_error(con);
		}
		sprintf(szQuery,"insert into Appliance_Status (FlatNo) values (%d)",nFlatNo);
		if (mysql_query(con, szQuery)) 
		{
			finish_with_error(con);
		}
		Send_Message(nSock,szBuf);


	}
  	else
  	{
		Send_Message(nSock,"0");
	 	Server_Create_FlatAccount(nSock);
	}
	printf("in create_flatacc fun %u\n",nSock);
	mysql_close(con);
}