从一个进程启动Contiki进程

Start Contiki process from a process

我正在使用 contikiOS 和 C,我正在尝试创建将等待 10 秒然后打印温度的代码。然后它将启动一个不同的进程并每 1 秒记录一次温度。它会检查温度何时超过 28c 并打开 LED。

目前执行如下:

等待 10 秒, 打印温度, 等待 10 秒, 终止

这是我的代码:

#include "dev/light-sensor.h"
#include "dev/sht11-sensor.h"
#include "dev/leds.h"
#include <stdio.h> /* For printf() */


unsigned short d1(float f) // Integer part
{
  return((unsigned short)f);
}
unsigned short d2(float f) // Fractional part
{
  return(1000*(f-d1(f)));
}


/*---------------------------------------------------------------------------*/
PROCESS(alarm, "alarm");

/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
PROCESS(detect, "detect");
AUTOSTART_PROCESSES(&detect);
/*---------------------------------------------------------------------------*/




PROCESS_THREAD(detect, ev, data)
{

    static struct etimer timer;
    PROCESS_BEGIN();
    etimer_set(&timer, CLOCK_CONF_SECOND * 10);
    SENSORS_ACTIVATE(sht11_sensor);
    leds_off(LEDS_ALL);

    while (1) {
        if (!etimer_pending()) {
            break;
        }
        else {


            PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);

            float temp = 0.01*sht11_sensor.value(SHT11_SENSOR_TEMP) - 39.6;
            printf("\n%u.%03u C", d1(temp), d2(temp));

            if (temp > 28) {

                leds_on(LEDS_ALL);
                clock_wait(CLOCK_SECOND);


                leds_off(LEDS_ALL);

            }
            if (temp <= 28) {

                leds_off(LEDS_ALL);
            }


        }
        etimer_stop(&timer);

    }
    PROCESS_EXIT();
    PROCESS_START(&alarm, NULL);
    PROCESS_END();
}


/*---------------------------------------------------------------------------*/


PROCESS_THREAD(alarm, ev, data)
{

    static struct etimer timer1;
    PROCESS_BEGIN();
    etimer_set(&timer1, CLOCK_SECOND);
    SENSORS_ACTIVATE(sht11_sensor);
    leds_off(LEDS_ALL);
    while (1) {
        PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
        float temp = 0.01*sht11_sensor.value(SHT11_SENSOR_TEMP) - 39.6;
        printf("\n%u.%03u C", d1(temp), d2(temp));

        if (temp > 28) {

            leds_on(LEDS_ALL);
            clock_wait(CLOCK_SECOND);


            leds_off(LEDS_ALL);

        }
        if (temp <= 28) {

            leds_off(LEDS_ALL);
        }
        etimer_reset(&timer1);






    }

    PROCESS_END();
}





根据contiki wiki on processesprocess_start()方法是小写的。改变它,你的程序应该可以工作。