示例#1
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwSpecialCommand(CAbstractPeer& peer, const char **pkt)
{
	int debugCommand = 0;
	eCommWebErrorCodes retCode = cwErrSuccess;
	do
	{
		if(!skipInt(pkt, &debugCommand))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}
		switch(debugCommand)
		{
		case 0:
			restartSystem();
			break;

		case 1:
			if(!skipInt(pkt, &debugCommand))
			{
				retCode = cwErrInvalidCommandParams;
				break;
			}
			deviceDeleteLog(debugCommand);
			break;
		}
	}while(false);
	reply_cwReplyToCommand(peer, retCode);

}
示例#2
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwSetGenericDeviceParams(CAbstractPeer& peer, const char **pkt)
{
	int i = 0, sequence = 0;
	int devID;
	bool deserialized = false;
	eCommWebErrorCodes retCode = cwErrInvalidDeviceID;

	do
	{
		if(!skipInt(pkt, &devID))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}

		for(i=0; i < g_activeDevices.count(); i++)
		{
			if(devID == g_activeDevices[i]->m_ID)
			{
				//LOG_I("found dev");
				if(g_activeDevices[i]->deserialize(pkt))
				{
					//LOG_I("deserialized");
					retCode = cwErrSuccess;

					if(!skipInt(pkt, &sequence))
						retCode = cwErrInvalidCommandParams;

					g_activeDevices[i]->isSavedToDisk  =
							deviceWriteToDisk(g_activeDevices[i]);
				}
				else
				{
					retCode = cwErrInvalidCommandParams;
				}
				break;
			}
		}
	}
	while(false);

	reply_cwReplyToCommand(peer, retCode, cwSetGenericDeviceParams, sequence);

	if(retCode == cwErrSuccess)
	{
		broadcastDeviceInfo(gConnectedPeers, g_activeDevices[i], &peer);
	}
}
示例#3
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwGetDevicesOfType(CAbstractPeer& peer, const char **pkt)
{
	int i = 0, numDevs = 0, sizePkt = 0, j, len, k, devType;

	if (!skipInt(pkt, &devType))
	{
		LOG_E( "Cannot get Pkt Type");
	}

	for(; i < g_activeDevices.count(); i++)
	{
		if(devType == g_activeDevices[i]->m_deviceType)
		{
			++numDevs;
		}
	}
	sizePkt = m_snprintf(g_devScrapBuffer, sizeof(g_devScrapBuffer),
				"%d;%d;%d;", cwReplyDevicesOfType, devType, numDevs);

	for(i=0; i < g_activeDevices.count(); i++)
	{
		if(devType == g_activeDevices[i]->m_deviceType)
		{
			sizePkt += g_activeDevices[i]->serialize(g_devScrapBuffer + sizePkt,
										sizeof(g_devScrapBuffer) - sizePkt);
		}
	}

	peer.sendToPeer((const char*)g_devScrapBuffer, sizePkt);
}
示例#4
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool cwReceivePacket(CAbstractPeer& peer, const char* pkt)
{
	bool retVal = false;

	int pktId;

	if (!skipInt(&pkt, &pktId))
	{
		LOG_E( "Cannot get Pkt ID");
	}
	else
	{
		LOG_D( "Received Pkt ID: %d", pktId);

		if(pktId >=  cwMaxId)
		{
			LOG_E( "Bad pkt ID rx: %d", pktId);
		}
		else
		{
			retVal = gCWHandlers[pktId](peer, &pkt);
		}
	}
	return retVal;
}
示例#5
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwPrintDebugInformation(CAbstractPeer& peer, const char **pkt)
{
	int debugCommand = 0;
	eCommWebErrorCodes retCode = cwErrSuccess;
	do
	{
		if(!skipInt(pkt, &debugCommand))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}

		switch(debugCommand)
		{
		case 0:
			LOG_I("DBG: heap %d", system_get_free_heap_size());
			break;

		case 1:
			NetUtils::debugPrintTcpList();
			break;
		}
	}while(false);
	reply_cwReplyToCommand(peer, retCode);
}
示例#6
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwGetGenericDeviceLogs(CAbstractPeer& peer, const char **pkt)
{
	int sizePkt = 0, devId, fromTime, decimation, numEntries, i, entriesWritten = 0;
	uint32_t entriesRead = 0;

	bool printHeader = true;

	if (!skipInt(pkt, &devId) ||
		!skipInt(pkt, &fromTime) ||
		!skipInt(pkt, &decimation) ||
		!skipInt(pkt, &numEntries)
	)
	{
		LOG_E( "Invalid pkg");
	}
	else
	{
		for(i=0; i < g_activeDevices.count(); i++)
		{
			if(devId == g_activeDevices[i]->m_ID)
			{
				sizePkt = m_snprintf(g_devScrapBuffer, sizeof(g_devScrapBuffer),
							"%d;%d;%d;", cwReplyGenericDeviceLogs,
							g_activeDevices[i]->m_deviceType, devId);

				do
				{
					sizePkt += deviceReadLog(devId, fromTime, decimation,
											 (char*)(g_devScrapBuffer + sizePkt), sizeof(g_devScrapBuffer) - sizePkt,
											 numEntries, printHeader, entriesWritten, entriesRead);

					fromTime = (fromTime/8192 + 1)*8192;
				}
				while( numEntries > entriesWritten && SystemClock.now(eTZ_UTC).toUnixTime() > fromTime);

				//LOG_I("cwGetGenericDeviceLogs %s", g_devScrapBuffer);
				peer.sendToPeer((const char*)g_devScrapBuffer, sizePkt);
				break;
			}
		}
	}
}
示例#7
0
    void skipNumber(const char *&c){
      if((*c == '+') || (*c == '-'))
        ++c;

      skipInt(c);

      if(*c == '.')
        ++c;

      skipInt(c);

      if(*c == 'e')
        ++c;

      if((*c == '+') || (*c == '-'))
        ++c;

      skipInt(c);

      if(*c == 'f')
        ++c;
    }
示例#8
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwSetWiFiParams(CAbstractPeer& peer, const char **pkt)
{
	int forceScan = 0; //force set new settings even if wifi network already set=> system reboot
	int op = 0; //set or forget
	eCommWebErrorCodes retCode = cwErrSuccess;
	do
	{
		if(!skipInt(pkt, &forceScan))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}

//...

	}while(false);
	reply_cwReplyToCommand(peer, retCode);
}
示例#9
0
    void property::skip(bitstream& stream, sendprop* prop) {
        switch (prop->getType()) {
            // Skip over Integer
            case sendprop::T_Int:
                skipInt(stream, prop);
                break;

            // Skip over Float
            case sendprop::T_Float:
                skipFloat(stream, prop);
                break;

            // Skip over 3D Vector
            case sendprop::T_Vector:
                skipVector(stream, prop);
                break;

            // Skip 2D Vector
            case sendprop::T_VectorXY:
                skipVectorXY(stream, prop);
                break;

            // Skip String
            case sendprop::T_String:
                skipString(stream);
                break;

            // Skip Array
            case sendprop::T_Array:
                skipArray(stream, prop);
                break;

            // Skip 64 bit Integer
            case sendprop::T_Int64:
                skipInt64(stream, prop);
                break;

            default:
                BOOST_THROW_EXCEPTION( propertyInvalidType()
                    << (EArgT<1, uint32_t>::info(prop->getType()))
                );
                break;
        }
    }
示例#10
0
文件: commWeb.cpp 项目: ADiea/HA-8266
bool handle_cwStartWiFiScan(CAbstractPeer& peer, const char **pkt)
{
	int secTimeout = 0;//, forceScan = 0;
	eCommWebErrorCodes retCode = cwErrSuccess;
	do
	{
		if(!skipInt(pkt, &secTimeout))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}
		/*if(!skipInt(pkt, &forceScan))
		{
			retCode = cwErrInvalidCommandParams;
			break;
		}*/

		if(eLoginOK != Login.startWiFiScan(&peer))
			retCode = cwErrUnknown;

	}while(false);
	reply_cwReplyToCommand(peer, retCode);
}
/**
 * Parse the Population element and return the stored value
 * @param str Pointer to a string structure
 * @return Returns the integer value or -1 on failure. Population should never be negative.
 **/
int extractPopulation( pstring str )
{
	char *temp = NULL;
	int pop = -1;
	int start = 0;
	int end = 0;

	/// These will be used specifically for the name data
	int ps = 0;
	int pe = 0;

	if (str == NULL ) {
		return -1;
	}

	skipWhiteSpace(str);

	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate opening brace\n");
		return -1;
	}

	/// Skip past the curly brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip opening brace\n");
		return -1;
	}

	/// Skip any additional whitespace
	skipWhiteSpace(str);

	/// Save the index
	start = str->index;

	/// This should skip any to either whitespace or a closing '}'
	end = skipAlpha( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the element id\n");
		return -1;
	}

	/// Copy the element id from the string
	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Copy from @d to @d failed\n", start, end);
		return -1;
	}

	/// If the element id is not "Population" then this is the wrong function
	if ( strcmp( temp, "Population") != 0 ) {
		printf("!!Element id is not \"Population\"\n");
		deallocate( temp, strlen(temp) + 1 );
		temp = NULL;
		return -1;
	}

	/// The buffer is no longer needed so free it
	deallocate(temp, strlen(temp) + 1);

	/// Skip to the end of the element id
	skipWhiteSpace( str );

	/// If it is not a closing brace then this is improperly formatted.
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate initial closing brace\n");
		return -1;
	}

	/// Skip the closing brace as well as any whitespace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip initial closing brace\n");
		return -1;
	}

	skipWhiteSpace( str );

	/// Copy the start index to store the data
	ps = str->index;

	/// The population data must be an integer
	pe = skipInt( str );

	if ( pe == -1 ) {
		printf("!!Failed to locate the end of the population data\n");
		return end;
	}

	/// The rest of this code is a check to ensure proper formatting except for the copy data
	skipWhiteSpace( str );

	/// If this is not an opening curly brace then fail
	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate the final opening brace\n");
		return -1;
	}

	/// Skip past the brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip the final opening brace\n");
		return -1;
	}
	
	skipWhiteSpace(str);

	/// If this is not a # indicating the closing brace then fail
	if ( !atChar( str, '#' ) ) {
		printf("!!Failed to locate the closing mark\n");		
		return -1;
	}

	/// Skip past the # but save the start
	start = skipLength( str, 1 );

	if ( start == -1 ) {
		printf("!!Failed to skip closing mark\n");
		return start;
	}

	end = skipAlpha( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the closing element id\n");
		return end;
	}
	
	temp = copyData( str, start, end );

#ifdef PATCHED
	if ( temp == NULL ) {
		return -1;
	}
#endif 

	if ( strcmp( temp, "Population") != 0 ) {
		printf("!!Invalid closing element id: @s\n", temp);
		deallocate(temp, strlen(temp)+1);
		return -1;
	}

	deallocate(temp, strlen(temp)+1);

	skipWhiteSpace( str );

	/// Check the final curly brace
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate final closing brace\n");
		return -1;
	}

	/// Skip past the closing brace
	skipLength( str, 1 );
		
	/// Copy the name element data
	temp = copyData( str, ps, pe );

	if ( temp == NULL ) {
		printf("!!Failed to copy population data\n");
		return -1;
	}

	pop = atoi( temp );

	deallocate( temp, strlen(temp) + 1 );

	return pop;
}
示例#12
0
bool loadSystemSettings()
{
	bool bRet = false;
	char *sysCfgStr = NULL, *saveSysCfgStr;

	int iValue;
	uint32_t uValue;
	char sBuffer[128];

	if(readFileFull(SYS_SETTINGS_FILE, &sysCfgStr))
	{
		saveSysCfgStr = sysCfgStr;
		if(FIRMWARE_VER_MAJOR == 1)
		{
			if(FIRMWARE_VER_MINOR == 0) /* for 01.00 */
			{
				do
				{
					if(!skipUint((const char**)&sysCfgStr, &gSysCfg.fwVerMinor ))
						break;

					if(!skipUint((const char**)&sysCfgStr, &gSysCfg.fwVerMajor))
						break;

					if(!skipInt((const char**)&sysCfgStr, (int*)&gSysCfg.wifiStationIsConfigured))
						break;
					gSysCfg.wifiStationIsConfigured = iValue;

					if(!skipString((const char**)&sysCfgStr, sBuffer, sizeof(sBuffer)))
						break;
					iValue = strlen(sBuffer);
					if(iValue < sizeof(sBuffer))
					{
						if(gSysCfg.wifiSSID)
							delete gSysCfg.wifiSSID;
						gSysCfg.wifiSSID = new char[iValue];
						memcpy(gSysCfg.wifiSSID, sBuffer, iValue);
						gSysCfg.wifiSSID[iValue - 1] = 0;
					}

					if(!skipString((const char**)&sysCfgStr, sBuffer, sizeof(sBuffer)))
						break;
					iValue = strlen(sBuffer);
					if(iValue < sizeof(sBuffer))
					{
						if(gSysCfg.wifiPwd)
							delete gSysCfg.wifiPwd;
						gSysCfg.wifiPwd = new char[iValue];
						memcpy(gSysCfg.wifiPwd, sBuffer, iValue);
						gSysCfg.wifiPwd[iValue - 1] = 0;
					}

					if(!skipUint((const char**)&sysCfgStr, &gSysCfg.dbgNumRestarts))
						break;

					if(!skipUint((const char**)&sysCfgStr, &gSysCfg.lastKnownTimeStamp))
						break;

					if(!skipInt((const char**)&sysCfgStr, (int*)&gSysCfg.timeZone))
						break;

					bRet = true;
				}while(0);
			}
		}
		if(saveSysCfgStr)
			delete saveSysCfgStr;
	}
	return bRet;
}