Source file: /~heha/mb-iwp/Energiemessung/VIPsys3/vipsys3.zip/src/tabdata.h

#pragma once
/*======================================================================*
 * Optimized measurement data transfer in table form			*
 * heha, 100807								*
 * This is a C++ header file, not intended to be used with C		*
 *======================================================================*/

#include <windows.h>
// This concept doesn't rely on STRING_ESCxx definitions in "analyzer.h"
// but uses its own record description arrays

// Column (low nibble)	0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
// Column's meaning	1i 2i 3i Si 1a 2a 3a Sa 1p 2p 3p Sp *i -  -  -
// 1,2,3 = phases, S = sum of phases
// *: special column: N = Null (current only), D = between phases (voltage only)
//    colspan of {1i-2i-3i-Si} (frequency), colspan of {1i-2i-3i} (second aux value)
// i = instanteous, a = average (default time = 15 min), p = peak (in average interval)

// Row (high nibble)	0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
// Row's measurement	-  f  I  U  P  S  Q  d  c  t  W  X  Y  a  -  -
// Uncommon symbols:
// d = distortion (THD), c  = cos phi (power factor), t = tan phi
// X = apparent energy/work (not measured by VIP System3 / MK3, therefore, not used)
// Y = reactive energy/work (kvarh)
// a = auxiliary values (from Black Box, two values, one in Column 4i, one in Colspan {1i-2i-3i})
union VALUEINFO{
 DWORD u;
 struct{
  BYTE valcode;	// column (1..14) and row (1..12) of requested value, see above
  BYTE tariff;	// number of tariff band (0..4)
  BYTE valsize;	// [return] size (low-nibble) and fixed exponent (high-nibble) of value
  BYTE count;	// [return] number of VALUELOC locations / column out of U1-2, U2-3, U3-1
 };
};

union VALUELOC{
 DWORD u;
 struct{
  BYTE n;	// [return] <n> of ESC mn or ESC M (zero), 0..15
  BYTE record;	// [return] number of records to be read to reach the offset + LOWNIBBLE(info.valsize)
  WORD offset;	// [return] number of bytes from start of record
 };
};

struct VALUE{	// for extracting a value out of the data
 VALUEINFO info;
 VALUELOC loc;
};

struct VALUE3{
 VALUEINFO info;
 VALUELOC loc[3];// three possible positions before optimizing
 void locate();	// finds up to three occurences of desired value.
		// <info.valcode> and <info.tariff> must be initialized.
		// Returns the filled <loc> array, and updates <info.valsize> and <info.count>
		// Check <info.count> whether this function succeeded!
		// Iterate through all 256*5 possible combinations to get all measures.
};

struct ESCM{
 BYTE *data[16];
 UINT len[16];	// needed length for data, i.e. allocated length
 bool valid;	// TODO: some form of locking mechanism between threads is required!
 bool makebuffers(VALUE val[], unsigned len);	// cleans buffers with len=0
 int readall(int(*sendrecv)(const char*,int,char*,int)) const;
 bool extract(const VALUE*, char[10]) const;
// double extract();
};
Detected encoding: ASCII (7 bit)2