[315] | 1 | // Prediction mouvement d'etoiles entre un tour et le suivant...
|
---|
| 2 | // si TS -> TS + dT, H -> H + dT, dT=dH
|
---|
| 3 | //
|
---|
| 4 | // dz = - cos phi sin az dH (check sign)
|
---|
| 5 | // daz = (sin phi - cos az cotg z cos phi) dH (check sign)
|
---|
| 6 | //
|
---|
| 7 | // free parameters = period + phase
|
---|
| 8 |
|
---|
| 9 | #define DIODE_UNUSED_1 3
|
---|
| 10 | #define DIODE_UNUSED_2 7
|
---|
| 11 |
|
---|
| 12 | #include <math.h>
|
---|
| 13 | #include "ssthandler.h"
|
---|
| 14 |
|
---|
| 15 | SSTHandler::SSTHandler()
|
---|
| 16 | {
|
---|
| 17 | diodeHistLength = nb_per_block*2+10;
|
---|
| 18 | diodeT = new int[diodeHistLength*nb_photo_diodes];
|
---|
| 19 | starHistLength = 300;
|
---|
| 20 | stars = new (vector<star>[starHistLength]);
|
---|
| 21 | lastBlkNum = -1;
|
---|
| 22 |
|
---|
| 23 | Has2Bars(false);
|
---|
| 24 | prcTodo=0;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | SSTHandler::SSTHandler(SSTHandler const& x)
|
---|
| 28 | {
|
---|
| 29 | diodeHistLength = x.diodeHistLength;
|
---|
| 30 | diodeT = new int[diodeHistLength*nb_photo_diodes];
|
---|
| 31 | memcpy(diodeT, x.diodeT, diodeHistLength*nb_photo_diodes);
|
---|
| 32 | starHistLength = x.starHistLength;
|
---|
| 33 | stars = new (vector<star>[starHistLength]);
|
---|
| 34 | for (int i=0; i<starHistLength; i++)
|
---|
| 35 | stars[i] = x.stars[i];
|
---|
| 36 |
|
---|
| 37 | prcTodo = x.prcTodo;
|
---|
| 38 | has2bars = x.has2bars;
|
---|
| 39 | elecOffset = x.elecOffset;
|
---|
| 40 | lastBlkNum = x.lastBlkNum;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | SSTHandler& SSTHandler::operator = (SSTHandler const& x) {
|
---|
| 44 | delete[] stars;
|
---|
| 45 | delete[] diodeT;
|
---|
| 46 | diodeHistLength = x.diodeHistLength;
|
---|
| 47 | diodeT = new int[diodeHistLength*nb_photo_diodes];
|
---|
| 48 | memcpy(diodeT, x.diodeT, diodeHistLength*nb_photo_diodes);
|
---|
| 49 | starHistLength = x.starHistLength;
|
---|
| 50 | stars = new (vector<star>[starHistLength]);
|
---|
| 51 | for (int i=0; i<starHistLength; i++)
|
---|
| 52 | stars[i] = x.stars[i];
|
---|
| 53 |
|
---|
| 54 | prcTodo = x.prcTodo;
|
---|
| 55 | has2bars = x.has2bars;
|
---|
| 56 | elecOffset = x.elecOffset;
|
---|
| 57 | lastBlkNum = x.lastBlkNum;
|
---|
| 58 |
|
---|
| 59 | return *this;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | SSTHandler::~SSTHandler()
|
---|
| 63 | {
|
---|
| 64 | delete[] stars;
|
---|
| 65 | delete[] diodeT;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | void SSTHandler::NeedProcess(int prcMask)
|
---|
| 69 | {
|
---|
| 70 | prcTodo |= prcMask;
|
---|
| 71 | if (prcTodo & findAxis) prcTodo |= findPeriod;
|
---|
| 72 | if (prcTodo & findPeriod) prcTodo |= findStars;
|
---|
| 73 | if (prcTodo & findStars) prcTodo |= rmveOffset;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void SSTHandler::Has2Bars(bool has, int eo)
|
---|
| 77 | {
|
---|
| 78 | has2bars = has;
|
---|
| 79 | elecOffset = eo;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | void SSTHandler::ProcessBlock(block_type_sst* blk)
|
---|
| 83 | {
|
---|
| 84 | lastBlkNum = numero_block(blk);
|
---|
| 85 | for (int i = 0; i<nb_per_block*2; i++) {
|
---|
| 86 | DecodeTMBlock(blk, i, diodeRaw[i]);
|
---|
| 87 | }
|
---|
| 88 | if (prcTodo & rmveOffset) {
|
---|
| 89 | RemoveOffset();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | void SSTHandler::DecodeTMBlock(block_type_sst* blk, int i, int* diod)
|
---|
| 96 | {
|
---|
| 97 | int j; // 0-5 : numero du bloc de 8 diodes
|
---|
| 98 | int k; // 0-2 : indice du bloc de 4 bits (une diode = 12 bits = 3 blocs de 4 bits)
|
---|
| 99 | int l; // 0-7 : indice de la diode dans son bloc (8 diodes * 4 bits = 1 mot de 32 bits)
|
---|
| 100 |
|
---|
| 101 | // numero de la diode (0-47) = j*8+l;
|
---|
| 102 | // indice dans le bloc sst du mot de 32 bits (0-17) = j*3+k;
|
---|
| 103 | // indice dans mot de 32 bits du premier bit utile = 28-4*l;
|
---|
| 104 |
|
---|
| 105 | for (j=0; j<48; j++) diod[j] = 0;
|
---|
| 106 |
|
---|
| 107 | for (j=0; j<6; j++)
|
---|
| 108 | for (k=0; k<3; k++)
|
---|
| 109 | for (l=0; l<8; l++) {
|
---|
| 110 | long word = blk->sst[i][j*3+k];
|
---|
| 111 | word = (word >> (28-4*l)) & 0xF;
|
---|
| 112 | //printf("diode %d mot %d valeur %d\n", j*8+l, k, word);
|
---|
| 113 | diod[j*8+l] = (diod[j*8+l] << 4) + word;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | void SSTHandler::RemoveOffset()
|
---|
| 119 | {
|
---|
| 120 | int j0 = diodeHistLength-(nb_per_block*2);
|
---|
| 121 |
|
---|
| 122 | // Decalage vers la gauche de la taille d'un bloc
|
---|
| 123 | memcpy(diodeT, diodeT + (nb_per_block*2)*nb_photo_diodes, j0*nb_photo_diodes);
|
---|
| 124 |
|
---|
| 125 | for (int j=0; j<nb_per_block*2; j++) {
|
---|
| 126 | // suppression des positions non utilisees. 3 et 7 ?
|
---|
| 127 | for (int i=0; i<DIODE_UNUSED_1; i++)
|
---|
| 128 | diode(j+j0,i) = diodeRaw[j][i];
|
---|
| 129 | for (int i=DIODE_UNUSED_1; i<46; i++)
|
---|
| 130 | diode(j+j0,i) = diodeRaw[j][ i<DIODE_UNUSED_2-1 ? i+1 : i+2 ];
|
---|
| 131 |
|
---|
| 132 | // calcul d'un fond sur la rangee. Moyenne clippee.
|
---|
| 133 | float m = 0; float sig = 1.e10;
|
---|
| 134 | for (int k=0; k<2; k++) {
|
---|
| 135 | float s=0; float s2=0; int n=0;
|
---|
| 136 | for (int i=0; i<46; i++) {
|
---|
| 137 | if (fabs(diode(j+j0,i)-m)<3*sig+1) {
|
---|
| 138 | s += diode(j+j0,i); s2 += diode(j+j0,i)*diode(j+j0,i); n++;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | if (n>0) {
|
---|
| 142 | m = s/n; sig = sqrt(s2/n - m*m);
|
---|
| 143 | } else {
|
---|
| 144 | m = 0; break;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | for (int i=0; i<46; i++)
|
---|
| 148 | diode(j+j0,i) -= m;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | int SSTHandler::getRawSignal(int imesure, int idiode) // for last block
|
---|
| 153 | {
|
---|
| 154 | if (imesure<0 || imesure>=nb_per_block*2 || idiode<0 || idiode>=48) return -99999;
|
---|
| 155 | return diodeRaw[imesure][idiode];
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | int SSTHandler::getSignal(int imesure, int idiode) // for last block
|
---|
| 159 | {
|
---|
| 160 | int j0 = diodeHistLength-(nb_per_block*2);
|
---|
| 161 | if (imesure+j0<0 || imesure>=nb_per_block*2 ||
|
---|
| 162 | idiode<0 || idiode>=nb_photo_diodes) return -99999;
|
---|
| 163 | return diode(imesure+j0, idiode);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 |
|
---|