Hi everyone,

Im helping with an open source package for dataloggers. So far my plan is
to based around a std module class, and use class extends for hardware
specific modules. So there are the modules, and each one has a bunch of
predefined datapoints, those datapoints have propertys. Below is the draft
class docs. Im wondering if anyone has some tips for a better code
structure for this sort of thing.

My specific questions are:

1. I probably need a class for datapoint, right? Module object stores an
array of datapoint objects.
2. but is there a js-like way in php to reference the method to do
something later, eg
  var dp_get_method = function() {xyz('abc')};
The problem is that i need to iterate the datapoint definitions in order to
get the value of each one, in a variety of ways specifed up front.
3. This structure doesnt seem resource efficient, carrying around multiple
instances of identical methods. Would it be better to use
module->dbsrc->read() instead of module->dbsrc_read(). Probably uses as
much ram that way too. Sometimes i still pine for the good old days of
preceedural.

Cheers guys


/**
 *  DATA-INPUT-MODULE
 *
 *  This class defines default module methods, used by all input modules.
 *
 *  Of the methods contained here, read_device is the only method that
should be custom per module.
 *  the rest are std methods.
 *
 *  In general theres four ways to use this:
 *    1. from cron:        process_device, done
 *    2. view current:     get_datapoints, done
 *    3. view realtime:    read_device, get_datapoints, done
 *    4. view historic:    get_datapoints(date), done
 *
 *     The Datapoint 'object'. Key/label is the db column name and unique
key for the dp.
 *        $this->datapoints['vbat']= array(
 *            'name'=>       "Battery voltage",
 *            'type'=>       'sampled',
//sampled,derived,computed
 *            'logfreq'=>    'periodic',
//none,periodic,daily,monthly,yearly
 *            'method'=>     'translate_register', //method name to get
values
 *            'argument'=>   'LSB([4101])/10',     //method arg to get
values
 *            'comment'=>    '(decimal) measured at controller terminals
accurate to +/-0.2V',
 *            'data'=>       array(
 *                        'current'=> array('date'=>'2013-08-01 12:22:01',
'value'=>28.8),
 *                        'day'=>   array(...),
 *                        'month'=> array(...),
 *                        'year'=>  array(...),
 *                      ),
 *            'unit'=>       'V',
 *            'order'=>      8,
 *        );
 *
 *
 *  Standard methods:
 *  ---------------------------------------------------------------
 *  SET_SETTING                Usage: $module->set_setting(key,val)
 *  GET_SETTINGS               Usage: $s= $module->get_settings()
 *
 *     Set module setting, self explanatory, used in the module
configuration file
 *     Returns an array of the module settings
 *
 *
 *  PROCESS_DEVICE             Usage: $module->process_device()
 *
 *     Calls read_dbase, read_device, calc_derived, then write_dbase
 *
 *
 *  READ_DBASE                 Usage: $module->read_dbase()
 *
 *     Gets stored data and populates datapoints, regardless of type.
 *     Gets the whole day to date,
 *     If mode is day, get an array of the entire days readings.
 *     If mode is month, year, etc, ditto.
 *
 *
 *  READ_DEVICE
 *     Usage: $module->read_device()
 *     This is the top level custom method to read the particular device.
 *     It just reads the device and populates sample type dp data only.
 *     In std module it is empty.
 *
 *
 *  CALC_DERIVED               Usage: $module->calc_derived()
 *
 *    From the already populated datapoints, creates needed derived dps.
 *    Hence must be run either after read_device, or alone it gets computed
types only.
 *
 *
 *  WRITE_DBASE                Usage: $module->write_dbase()
 *
 *     Stores all dps to the periodic database table, as well as the daily,
monthly, yearly agregations.
 *     Agregations work by each periodic, overwriting periodic values to
the single agregate record. Last one standing wins.
 *     Its not efficient but will better cope with eratic datalogger uptime.
 *
 *
 *  GET_DEFINITIONS            Usage: $dfns= $module->get_definitions()
 *  GET_DATAPOINT              Usage: $dps=  $module->get_datapoint(label)
 *  GET_DATAPOINTS             Usage: $dps=  $module->get_datapoints()
 *
 *    get_definitions just gets the dp definitions with no call to the
device or db.
 *    get_datapoint returns a single datapoint defn and value from the db
plus derivations
 *    get_datapoints returns all datapoint dfns and values from the db plus
derivations
 *    the last two call read_dbase and calc_derived as necessary
 *
 *
 *  @license:  GPLv3.
 *  @author:   zb 2013
 *  @revision: $Rev$
 *
 **/

-- 
-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
--- 
You received this message because you are subscribed to the Google Groups "NZ 
PHP Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to