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
|
---|
22 | extern "C" {
|
---|
23 | void BAORadio_init();
|
---|
24 | void BAORadio_end();
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | // Une classe commande-executor, permettant d'enregistrer de
|
---|
29 | // nouvelles commandes a piapp
|
---|
30 | class BAORadioExecutor : public CmdExecutor {
|
---|
31 | public:
|
---|
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-- */
|
---|
39 | BAORadioExecutor::BAORadioExecutor()
|
---|
40 | {
|
---|
41 |
|
---|
42 | PIACmd * mpiac;
|
---|
43 | NamedObjMgr omg;
|
---|
44 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
45 |
|
---|
46 | // On enregistre deux nouvelles commandes
|
---|
47 | string hgrp = "BAORadioCmd";
|
---|
48 | // commande excmd1
|
---|
49 | string kw = "brrdfile";
|
---|
50 | string usage = "brrdfile: Lecture fichier AcqBAORadio \n" ;
|
---|
51 | usage += "Usage: brrdfile size fileName [objName] \n";
|
---|
52 | usage += " Defaut objName= data";
|
---|
53 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* --Methode-- */
|
---|
58 | BAORadioExecutor::~BAORadioExecutor()
|
---|
59 | {
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | static 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-- */
|
---|
76 | int BAORadioExecutor::Execute(string& kw, vector<string>& tokens, string&)
|
---|
77 | {
|
---|
78 |
|
---|
79 | NamedObjMgr omg;
|
---|
80 | if (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 | /*
|
---|
122 | else if (kw == "excmd2") {
|
---|
123 | }
|
---|
124 | */
|
---|
125 | return(0);
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | static BAORadioExecutor * baoradioex = NULL;
|
---|
130 | /* Nouvelle-Fonction */
|
---|
131 | void BAORadio_init()
|
---|
132 | {
|
---|
133 | // Fonction d'initialisation du module
|
---|
134 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
135 | if (baoradioex) delete baoradioex;
|
---|
136 | baoradioex = new BAORadioExecutor;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* Nouvelle-Fonction */
|
---|
140 | void BAORadio_end()
|
---|
141 | {
|
---|
142 | // Desactivation du module
|
---|
143 | if (baoradioex) delete baoradioex;
|
---|
144 | baoradioex = NULL;
|
---|
145 | }
|
---|
146 |
|
---|