source: Sophya/branches/Reza/AddOn/TAcq/baoradex.cc@ 3537

Last change on this file since 3537 was 3537, checked in by ansari, 17 years ago

Ajout du module AddOn/TAcq (programmes test pour acquisition BAORadio) ds cvs sophya (sous-repertoire AddOn/) , Reza 22/10/2008

  • Property svn:executable set to *
File size: 3.4 KB
RevLine 
[3537]1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <iostream>
6#include <math.h>
7
8#include <typeinfo>
9
10#include <vector>
11#include <string>
12
13#include "tvector.h"
14#include "piacmd.h"
15#include "nobjmgr.h"
16#include "pistdimgapp.h"
17
18
19// Module pour lire les fichiers generes par Monique pour Acq-BAORadio
20
21// Declaration de la fonction d'activation et de desactivation du module
22extern "C" {
23void BAORadio_init();
24void BAORadio_end();
25}
26
27
28// Une classe commande-executor, permettant d'enregistrer de
29// nouvelles commandes a piapp
30class BAORadioExecutor : public CmdExecutor {
31public:
32 BAORadioExecutor();
33 virtual ~BAORadioExecutor();
34 // Execute s'occupe de l'execution effective des commandes
35 virtual int Execute(string& keyw, vector<string>& args, string& toks);
36};
37
38/* --Methode-- */
39BAORadioExecutor::BAORadioExecutor()
40{
41
42PIACmd * mpiac;
43NamedObjMgr omg;
44mpiac = omg.GetImgApp()->CmdInterpreter();
45
46// On enregistre deux nouvelles commandes
47string hgrp = "BAORadioCmd";
48// commande excmd1
49string kw = "brrdfile";
50string usage = "brrdfile: Lecture fichier AcqBAORadio \n" ;
51usage += "Usage: brrdfile size fileName [objName] \n";
52usage += " Defaut objName= data";
53mpiac->RegisterCommand(kw, usage, this, hgrp);
54
55}
56
57/* --Methode-- */
58BAORadioExecutor::~BAORadioExecutor()
59{
60
61}
62
63
64static inline void bswap4(void* p)
65{
66 uint_4 tmp = *(uint_4*)p;
67 *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
68 ((tmp >> 8) & 0x0000FF00) |
69 ((tmp & 0x0000FF00) << 8) |
70 ((tmp & 0x000000FF) << 24);
71}
72
73
74
75/* --Methode-- */
76int BAORadioExecutor::Execute(string& kw, vector<string>& tokens, string&)
77{
78
79NamedObjMgr omg;
80if (kw == "brrdfile") {
81 if (tokens.size() < 2) {
82 cout << "Usage: brrdfile size fileName [objName]" << endl;
83 return(0);
84 }
85 sa_size_t sz = atoi(tokens[0].c_str());
86 string filename = tokens[1];
87 string objname = "data";
88 if (tokens.size() > 2) objname = tokens[2];
89
90 cout << " brrdfile : reading from file " << filename
91 << " Size=" << sz << endl;
92 TVector<int_2> data(sz);
93 TVector<r_8> ddata(sz);
94 FILE *fip = NULL;
95 fip = fopen(filename.c_str(),"rb");
96 if (fip == NULL) {
97 cout << " brrdfile : ERROR opening file" << endl;
98 return 1;
99 }
100 uint_1* buff = new uint_1[sz/4+1];
101 fread(buff, 1, (size_t)(sz), fip);
102 uint_4* first = (uint_4*)(buff);
103 uint_4* second = (uint_4*)(buff+4);
104 cout << " brrdfile, first uint_4= " << hex << (*first)
105 << " second= " << (*second) << dec << endl;
106 // uint_1* buff = (uint_1 *)buff4;
107 // for(sa_size_t ka=0; ka<sz/4; ka++) bswap4(buff4+ka);
108 for(sa_size_t ka=0; ka<sz; ka+=4) {
109 if (ka>=sz-3) break;
110 for(sa_size_t kb=0; kb<4; kb++)
111 data(ka+kb) = (int_2)buff[ka+3-kb];
112 }
113// for(sa_size_t k=0; k<sz; k++) data(k) = (int_2)buff[k];
114 fclose(fip);
115 delete[] buff;
116 omg.AddObj(data, objname);
117 ddata = data;
118 objname += "_f";
119 omg.AddObj(ddata, objname);
120 }
121/*
122else if (kw == "excmd2") {
123 }
124*/
125return(0);
126
127}
128
129static BAORadioExecutor * baoradioex = NULL;
130/* Nouvelle-Fonction */
131void BAORadio_init()
132{
133// Fonction d'initialisation du module
134// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
135if (baoradioex) delete baoradioex;
136baoradioex = new BAORadioExecutor;
137}
138
139/* Nouvelle-Fonction */
140void BAORadio_end()
141{
142// Desactivation du module
143if (baoradioex) delete baoradioex;
144baoradioex = NULL;
145}
146
Note: See TracBrowser for help on using the repository browser.