-
Notifications
You must be signed in to change notification settings - Fork 0
/
shm_power_view.c
58 lines (54 loc) · 2.01 KB
/
shm_power_view.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// shm_power_view.c : Total Power Monitor
//
// Author : Seiji Kameno
// Created: 2013/12/23
//
#include "shm_VDIF.inc"
#include <stdlib.h>
#include <cpgplot.h>
#include <math.h>
main(
int argc, // Number of Arguments
char **argv ) // Pointer to Arguments
{
int shrd_param_id; // Shared Memory ID
struct SHM_PARAM *param_ptr; // Pointer to the Shared Param
struct sembuf sops; // Semaphore for data area
int IFindex;
int index;
float bitPower[MAX_NIF][POWER_TIME_NUM]; // Power Monitor Data
float tempPower[POWER_TIME_NUM]; // Buffer
char pg_text[256]; // Text to plot
char xlabel[64]; // X-axis label
//------------------------------------------ Access to the SHARED MEMORY
//------- SHARED PARAMETERS --------
if(shm_access(
SHM_PARAM_KEY, // ACCESS KEY
sizeof(struct SHM_PARAM), // SIZE OF SHM
&shrd_param_id, // SHM ID
¶m_ptr) != -1){ // Pointer to the SHM
printf("PowerView: Succeeded to access the shared parameter [%d]!\n", param_ptr->shrd_param_id);
}
memset(bitPower, 0, param_ptr->num_st* POWER_TIME_NUM* sizeof(float));
//------------------------------------------ K5 Header and Data
setvbuf(stdout, (char *)NULL, _IONBF, 0); // Disable stdout cache
cpgbeg(1, argv[1], 1, 1);
while(param_ptr->validity & ACTIVE){
cpgbbuf();
sprintf(xlabel, "Elapsed Time [sec]\0"); cpg_setup(xlabel);
if( param_ptr->validity & (FINISH + ABSFIN) ){ break; }
//-------- Wait for Semaphore
sops.sem_num = (ushort)SEM_POWER; sops.sem_op = (short)-1; sops.sem_flg = (short)0;
semop( param_ptr->sem_data_id, &sops, 1);
//-------- Plot Power Monitor
for(IFindex=0; IFindex<param_ptr->num_st; IFindex++){
memcpy(tempPower, bitPower[IFindex], POWER_TIME_NUM*sizeof(float));
bitPower[IFindex][0] = 10.0* log10(param_ptr->power[IFindex]);
memcpy(&bitPower[IFindex][1], tempPower, (POWER_TIME_NUM-1)*sizeof(float));
}
cpg_power(param_ptr, bitPower);
}
cpgend();
//------------------------------------------ RELEASE the SHM
return(0);
}