Exemplo n.º 1
0
int test_processSignal() {
	int linesRead = 0;
	LinkedList * signal = readFile("Michael_Williamson_Train.csv", 10, &linesRead);
	exportToC4_5Data(TrainDataStemFile, processSignal(signal), FALSE, FALSE);

	LinkedList * testData = readFile("Michael_Williamson_Test.csv", 10, &linesRead);
	exportToC4_5Data("cawax_test.data", processSignal(testData), TRUE, TRUE);
	freeLinkedList(signal);
	return 0;
}
Exemplo n.º 2
0
OCStackResult SetPlatformInfo()
{
    static const OCPlatformInfo platformInfo =
        {
            .platformID = "IoTivityZigbeeID",
            .manufacturerName = "IoTivity",
            .manufacturerUrl = "http://iotivity.org",
            .modelNumber = "T1000",
            .dateOfManufacture = "January 14th, 2015",
            .platformVersion = "0.9.2",
            .operatingSystemVersion = "7",
            .hardwareVersion = "0.5",
            .firmwareVersion = "0",
            .supportUrl = "http://iotivity.org",
            .systemTime = ""
        };

    return OCSetPlatformInfo(platformInfo);
}

OCStackResult SetDeviceInfo()
{
    static OCDeviceInfo deviceInfo =
        {
            .deviceName = "IoTivity/Zigbee Server Sample",
            .specVersion = "IoTivity/Zigbee Device Spec Version",
        };
    char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version");
    deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
    deviceInfo.dataModelVersions->value = dmv;
    char *dup = OICStrdup("oic.wk.d");
    deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
    deviceInfo.types->value = dup;
    return OCSetDeviceInfo(deviceInfo);
}

bool processSignal(bool set)
{
    static sig_atomic_t signal = 0;
    if (set)
    {
        signal = 1;
    }

    return signal == 1;
}

void processCancel(int signal)
{
    if(signal == SIGINT)
    {
        processSignal(true);
    }
}
Exemplo n.º 3
0
OCStackResult SetPlatformInfo()
{
    static const OCPlatformInfo platformInfo =
        {
            .platformID = "IoTivityZigbeeID",
            .manufacturerName = "IoTivity",
            .manufacturerUrl = "http://iotivity.org",
            .modelNumber = "T1000",
            .dateOfManufacture = "January 14th, 2015",
            .platformVersion = "0.9.2",
            .operatingSystemVersion = "7",
            .hardwareVersion = "0.5",
            .firmwareVersion = "0",
            .supportUrl = "http://iotivity.org",
            .systemTime = ""
        };

    return OCSetPlatformInfo(platformInfo);
}

OCStackResult SetDeviceInfo()
{
    static const OCDeviceInfo deviceInfo =
        {
            .deviceName = "IoTivity/Zigbee Server Sample"
        };

    return OCSetDeviceInfo(deviceInfo);
}

bool processSignal(bool set)
{
    static sig_atomic_t signal = 0;
    if (set)
    {
        signal = 1;
    }

    return signal == 1;
}

void processCancel(int signal)
{
    if(signal == SIGINT)
    {
        processSignal(true);
    }
}
Exemplo n.º 4
0
void CNetConnection::processCommand(ireon::net::commandId id, CData& data, netAddress fromAddress)
{
    if (fromAddress.m_type == netAddress::atInternalAddress)
        CLog::instance()->log(CLog::msgFlagNetwork,CLog::msgLvlDebug,_("Received internal packet. Id = %d.\n"),id);
    else
        CLog::instance()->log(CLog::msgFlagNetwork,CLog::msgLvlDebug,_("Received packet. Id = %d.\n"),id);

    if( !processSignal(id, fromAddress, data) )
    {
        if (fromAddress.m_type == netAddress::atExternalAddress)
        {
            CData response;
            response.wrt((ireon::net::commandId) ireon::net::rcCommandNotFound);
            response << id;
            write(response);
        }
        CLog::instance()->log(CLog::msgLvlError,_("Can't process packet. Contents:\n"));
        CLog::instance()->dump(CLog::msgLvlError,data.data(),data.length());
    }
    return;
};
Exemplo n.º 5
0
/** 
 * Function called by a wiringPi thread at each data pin value change 
 * La fonction wiringPiISR est une fonction permettant de définir un code d'interruption, en l'occurence RCSwitch::handleInterrupt
 * Ce code met l'exécution du programme principal (RFReceptHandler.main) en attente à chaque besoin d'interruption recensé par la librairie wiringPi
 * Ainsi, à chaque interruption telle que définie, la librairie wiringPi gère : 
 *    - La mise en attente du code principal (RFReceptHandler.main) : le processeur est libéré pour exécuter autre chose, ici le code d'interruption
 *    - L'exécution du code d'interruption (RCSwitch::handleInterrupt)
 *    - La réactivation du code principal, là où il en était précédemment
 * 	Au final, on en déduit que aucune invocation de processSignal mettant à jour le code du signal recu ne sera perdu par RFReceptHandler.main ;
 *  RFReceptHandler.main consommera alors le code signal recu et le remettra à 0.
 */
void RCSwitch::handleInterrupt() 
{
	static unsigned int 	duration;
	static unsigned long 	lastTime;
	static unsigned int 	repeatCount;

	long time = micros();
	duration = time - lastTime;
	
	// Todo : il faudrait faire une hasmap duration --> 0 et 1 high-->low encoding. Ca permettrait de mieux valider le signal
	if (duration > 2750) 
	{    
		if (duration > RCSwitch::timings[0] - 100 /*&& duration < RCSwitch::timings[0] + 200*/)
		{
			repeatCount++;
			changeCount--; // pour ramener changeCount à l'index 0 si début signal, ou au dernier bit recu afin d'analyser correctement le signal

			if (repeatCount == 2)  // ça signifie qu'on a recu au moins 1 fois le signal : verrou de début et verrou de fin
			{
				RCSwitch::timings[changeCount+1] = duration;
				if (!processSignal(changeCount)) {}
				repeatCount = 0;
			}
		}
		changeCount = 0; // réinitialisation d'une réception
	} 
	else if (changeCount >= RCSWITCH_MAX_CHANGES ) // on a atteint le nombre maximum de changements high-->low
	{
		changeCount = 0;
		repeatCount = 0;
	}
	else if (duration < 50) // peu de chance que ce soit un signal correct
	{
		changeCount = 0;
		repeatCount = 0;
	}
	
	RCSwitch::timings[changeCount++] = duration;	
	lastTime = time;  
}
Exemplo n.º 6
0
int main()
{
    OIC_LOG(INFO, TAG, "Initializing IoTivity...");
    OCStackResult result = OCInit(NULL, 0, OC_SERVER);
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
        return -1;
    }

    result = SetPlatformInfo();
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
        goto IotivityStop;
    }

    result  = SetDeviceInfo();
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
        goto IotivityStop;
    }

    result  = OCStartPresence(0);
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
        goto IotivityStop;
    }

    // PIStartPlugin
    PIPlugin* plugin = NULL;
    OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
    result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
        goto IotivityStop;
    }

    if (signal(SIGINT, processCancel) == SIG_ERR)
    {
        OIC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
    }
    else
    {
        OIC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
        // Loop until sigint
        while (!processSignal(false) && result == OC_STACK_OK)
        {
            result = OCProcess();
            if (result != OC_STACK_OK)
            {
                OIC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
                break;
            }

            result = PIProcess(plugin);
            if (result != OC_STACK_OK)
            {
                OIC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
            }
        }
    }

    OIC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
    result = PIStopPlugin(plugin);
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
    }
    OIC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
    // OCStop
IotivityStop:
    OIC_LOG(INFO, TAG, "Stopping IoTivity...");
    result = OCStop();
    if (result != OC_STACK_OK)
    {
        OIC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
        return 0;
    }

    OIC_LOG(INFO, TAG, "Application Completed Successfully");
    return 0;
}
void processIRSignal()
{
    LONG downTime = irDurationCounter10us;
    irDurationCounter10us = 0;
    //int value = 0;
    //printf("c:%d/%d\r\n", upTime, downTime);
    //printf("c:%d\r\n", downTime);

    //if the downtime is different than the known terminator
    if (downTime < 45 || 70 < downTime)
    {
        //is it arounf 9 000 us?
        if (200 < downTime && downTime < 1000)
        {
            //was there a previously long pulse?
            if (upTime > 3500 && upTime <= 4500)
            {
                //that is filler, usually 41 000 us
                printDebug("F");
                irFillerOK = TRUE;
                return;
            }
            else
            {
                //this is the initial run
                //usually 9 000 us
                printDebug("S");
                resetIRHolders();
                irStartOK = TRUE;
            }
        }
            //hm, unknown downtime duration
        else
        {
            //printf("RD:u-%d,d-%d\r\n", upTime, downTime);
            resetIRHolders();
        }
    }
        //this fall between the boundaries of a IR Terminator
    else
    {
        //        if(!irStartOK)
        //        {
        //            //wtf, terminator OK but initial signal missing!
        //            printDebug("W");
        //        }
        //        if(!irInitialOK)
        //        {
        //            //wtf, terminator OK but initial signal missing!
        //            printDebug("L");
        //        }

        if (upTime > 10 && upTime <= 80)
        {
            processSignal(0);
        }
        else if (upTime > 80 && upTime <= 200)
        {
            processSignal(1);
        }
        else if (upTime > 200 && upTime <= 300)
        {
            //end of package, usually 2 240us
            //printf("N\r\n");
            if (irStartOK && irInitialOK && irFillerOK)
            {
                printDebug("E\r\n");
                //we have a command for processing
                processIRCommand = 1;

                if (offCommandSent() && stbActivationInProgress)
                {
                    //printf("%d%d", offCommandSent(), stbActivationInProgress);
                    //printf("!\r\n");
                    switchMonitorOn();
                }
            }
            else
            {
                if (justWoke && cmdCounter == -1)
                {
                    justWoke = FALSE;
                    //seems the initial headers were missed becasue of the sleep time
                    processIRCommand = 1;
                    //printf("!%d%d", offCommandSent(), stbActivationInProgress);
                    if (offCommandSent() && stbActivationInProgress)
                    {
                        switchMonitorOn();
                    }
                }
                else
                {
                    //printf("!%d%d%d\r\n", irStartOK, irInitialOK, irFillerOK);
                }
            }
        }
        else if (upTime > 300 && upTime <= 600)
        {
            //usually 4 450 us, start if IR package
            printDebug("I");
            irInitialOK = TRUE;
            //printf("%d,%d\r\n", upTime, downTime);
        }
        else
        {

            //unkown uptime when the downtime is ok
            //printf("RU:u-%d,d-%d\r\n", upTime, downTime);

            resetIRHolders();
        }
    }
}