Thread: calculate process mean with c programming to implement with contiki

  1. #1
    Registered User
    Join Date
    Aug 2014

    calculate process mean with c programming to implement with contiki

    Hi, I am starting to use contiki and learn c programming for my summer internship. I have to calculate the mean of the ongoing process of refrigerator power. I made the code like this

    #include <stdlib.h>
    #include <stdio.h>
    #include <homadeus/processes/fridge_process.h>
    #include <homadeus/devices/78M6610.h>
    #include <homadeus/utils/utils.h>
    float global_variable;
    int current_state = 0; //down =0, up =1
    float current_power = 0;
    int sample[n];
    float get_instant_power()
            double scaled_value = MAXIM_78M6610_SCALING_RESOLUTION_POWER_WATTS * maxim_78M6610_get_register_int24(MAXIM_78M6610_P);
            if (scaled_value>0)    return scaled_value;
            else return 0;
    float get_sum()
            float sum = 0;
             float mean;
                 for(int i=1; i<n ; i++){
                     sum +=sample[i];
    int get_current_state()
             current_power = get_instant_power();
                  if(current_power < 0) return 0;
                  else return 1; 
    PROCESS_THREAD(hmd_fridge_process, ev, data) 
               static struct etimer timer;
                    etimer_set(&timer, CLOCK_CONF_SECOND);
    How it gets the value of power is handled already. Every one second, it will display the power consumed (get_instant_power()). I don't know how to start and end the sample numbre. If I start by 1 then how should it be until? Also, is it possible if I store the power in array to accumulate?

  2. #2
    Registered User zub's Avatar
    Join Date
    May 2014
    First second: we get number1. sum = number1. numbers = 1. mean = sum / numbers.
    Next second: we get number2. sum = number1 + number2. numbers = 2. mean = sum / numbers.
    Third second: we get number3. sum = number1 + number2 + number3. numbers = 3. mean = sum / numbers.

    You see, it's simple. Every second you have to add the number to sum, to add 1 to counter and divide the sum by the counter.
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 01-19-2011, 01:24 PM
  2. Shell Programming - Process Table
    By simpatico_qa in forum C Programming
    Replies: 33
    Last Post: 06-05-2009, 01:23 PM
  3. Replies: 9
    Last Post: 11-12-2007, 02:29 PM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  5. How to implement WIN32 into C++ programming?
    By PsychoMantis in forum C++ Programming
    Replies: 2
    Last Post: 07-08-2002, 02:21 AM

Tags for this Thread