Real2Virtual202111

٤Ƴ٤Ĥ
  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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
-
!
-
|
!
 
 
-
|
|
|
!
 
-
!
 
-
|
!
 
-
|
|
-
|
|
!
|
|
-
!
-
-
-
!
|
-
|
!
-
|
!
!
!
|
-
-
!
-
!
|
|
-
|
|
|
|
|
|
|
|
|
!
-
-
!
|
|
|
-
|
!
|
-
|
!
-
-
|
|
|
|
|
|
!
|
|
!
!
-
|
|
|
|
|
|
|
!
!
|
-
|
!
|
|
!
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
-
|
|
|
|
-
|
!
|
|
!
 
-
|
|
|
|
-
|
!
|
-
|
!
-
|
!
!
 
-
|
|
|
|
|
-
!
|
-
!
|
-
!
|
-
!
!
 
-
|
-
-
|
!
-
!
!
 
-
|
|
-
|
|
|
!
-
|
!
|
|
-
-
!
|
-
|
!
|
-
|
|
|
|
!
|
!
-
!
!
 
-
|
|
|
-
!
|
|
|
!
 
-
|
!
-
|
!
 
-
!
-
|
|
|
|
|
|
|
|
!
 
-
-
|
|
!
|
-
|
|
|
-
|
!
-
-
|
|
!
|
-
|
|
|
!
!
|
-
|
|
|
!
|
-
|
|
|
!
-
|
|
-
|
-
!
!
-
|
!
-
!
|
-
-
|
|
|
!
|
!
!
|
-
!
!
 
-
-
!
-
 
!
|
-
-
!
!
|
-
 
-
!
|
//#include "CommandBuffer.h"
#include "InBuffer.h"
//#include <string.h>
//CommandBuffer::ackReturned( int faceID);
 
unsigned char  setIthBit(unsigned char i, unsigned char x);
 
void InBuffer::setPortConf( unsigned char (*getfun)(void), void (*modefun)(unsigned char x)){
   getPort=getfun;
   setPortMode=modefun;
   setPortMode((unsigned char)0); /* input ... for sh7125 */
}
 
//void trg_putc(unsigned char c);
unsigned char setIthBit(unsigned char i, unsigned char x);
 
void InBuffer::setCommand(CommandBuffer *com){
    command=com;
}
 
void InBuffer::intrProcess(void){
   volatile unsigned char cx;
   volatile unsigned char i,j;
//   volatile unsigned char sbi; // p % 8 = p & 0x07... for access bs
//   volatile unsigned char sbj; // p/8 = p >>3... for access bits
//   volatile unsigned char cs;
   i=getPort();
   if(i==0) now=0;
   else now=1;
//  xputc(' '+i);
 
   if(status==0){ /* waiting */
      if(last==0 && now==1){  /* some thing was happen */
//          printf("f=%d\n",(int)((*this).faceID));
         /* start reading */
         status=1;
//        trg_puts("status 0->1 - ");trg_putc((*this).channelID+'0');trg_puts("\n");
//        (*this).sampleIntervalCounter=0;
         p=0;
         for(j=0;j<MaxBits;j++){
            bits[j]=0x00;
         }
      }
   }
   else
   if(status==1){ /* reading bits sequence */
//     if((*this).sampleIntervalCounter==0){
/**/
//         xputc(' '+i);
        bits[p]=now;
        p++;
/**/
/*
        if((*this).now!=0){
           sbj=(*this).p>>3;
           cs=(*this).bits[sbj];
           sbi=(*this).p & 0x07;
           cs=setIthBit(sbi,cs);
           (*this).bits[sbj]=cs;
 
        }
        (*this).p++;
        */
        if(p>=ReceiveBits){
//          xputs("\n\r");
          p=0;
          now=0;
          last=0;
          cx=decode();
          if(cx==0xff){
             status=0;
          }
          else
          if(cx==0x00){
             status=0;
          }
          else{
//             trg_puts("--");
//             trg_putc(cx);trg_puts("\n");
//                      xputc(cx); xputs("]n");
//                      xputs("bits=");
//                      for(j=0;j<ReceiveBits;j++) xputc('0'+bits[j]);
//                      xputs("\n\r");
//                      printf("cx=%d %c\n\r",0+cx,cx);
             status=2;
             cin=cx;
             parse(cx);
          }
        }
/*
     }
     else{
     }
     (*this).sampleIntervalCounter++;
     if((*this).sampleIntervalCounter>=(*this).sampleInterval){
        (*this).sampleIntervalCounter=0;
     }
     */
   }
   else
   if(status==2) {
       status=0;
   }
   last=now;
   return;
}
/*
unsigned char startWithForInBit(struct inbit *this, char *c){
  unsigned char p;
  p=0;
  while(c[p]!=0){
     if(c[p]!=(*this).inputBuffer[p]) return 0;
     p++;
  }
  return 1;
}
 
void shiftLeftForInBit(struct inbit *this, unsigned char i){
  unsigned j,k;
  k=0;
  for(j=i;j<(*this).cbp;j++){
     (*this).inputBuffer[k]=(*this).inputBuffer[j];
     k++;
  }
  (*this).cbp=(*this).cbp-i;
}
*/
unsigned char  setIthBit(unsigned char i, unsigned char x){
   unsigned char j;
   unsigned char mask;
   unsigned char r;
   mask=0x80;
   for(j=0;j<i;j++){
      mask=mask>>1;
   }
   r=x | mask;
   return r;
}
 
unsigned char getIthBit(unsigned char i,unsigned char x){
   unsigned char j;
   unsigned char mask;
   unsigned char r;
   mask=0x80;
   for(j=0;j<i;j++){
      mask=mask>>1;
   }
   r=x & mask;
   if(r==0x00){
      return r;
   }
   else{
      return 0x01;
   }
}
 
void printHexChar(char c){
    int ch,cl;
    ch=c;
    ch=ch>>4;
    cl=c & 0x0f;
    if(ch<10)
//    printf("%d",ch);
        xputd(ch);
    else
//    printf("%c",ch-10+'a');
        xputd(ch-10+'a');
    if(cl<10)
//    printf("%d",cl);
        xputd(cl);
    else
//    printf("%c",cl-10+'a');
        xputd(cl-10+'a');
}
 
void printHexArray(int size, char x[]){
    int i;
//    unsigned int ch,cl;
    for(i=0;i<size;i++){
        printHexChar(x[i]);
    }
//    printf("\n");
    xputs("\n");
}
 
unsigned char InBuffer::decode(void){
  volatile unsigned char startp;
  volatile unsigned char c,i;
//  volatile unsigned char sbi;
//  volatile unsigned char sbj;
//  volatile unsigned char cs;
//  unsigned char s[3];
 
//  trg_putHexArray((*this).bits,MaxBits);
//  printHexArray(bitsParChar,(*this).bits);
  startp=sampleInterval>>1;
  startp=startp+sampleInterval;
  c=0x00;
  for(i=0;i<8;i++){
//     trg_puts(" startp=");hex2str(startp,s);trg_puts(s);trg_puts("\n");
     c=c<<1;
     /* */
     if(bits[startp]==1){
       c=c|0x01;
     }
     /* */
     /*
     sbi=startp & 0x07;
     sbj=startp >> 3;
     cs=(*this).bits[sbj];
     c=c|getIthBit(sbi,cs);
     */
     startp=startp+sampleInterval;
  }
//  printf("decode c="); printHexChar(c); printf("\n");
  return c;
}
 
unsigned char InBuffer::getChar(void){
  unsigned char rtn;
  if(status==0) return 0x00;
  if(status==1) return 0x00;
//  trg_puts(" getChar"); trg_putc((*this).cin); trg_puts("\n");
  rtn=cin;
  status=0;
  cin=0;
  return rtn;
}
 
void InBuffer::setStatus( unsigned char s){
  status=s;
}
unsigned char InBuffer::getStatus(void){
  return status;
}
 
//void parseForInBit(struct inbit *this, unsigned char c);
 
InBuffer::InBuffer(unsigned char id, CommandBuffer *com ){
  faceID=id;
  sampleInterval=SampleInterval0*SampleIntForDecode0;
  sampleIntForDecode=SampleIntForDecode0;
  status=2;
  setConnected((unsigned char)0);
  cin=0;
  command=com;
    cbp=0;
}
 
void InBuffer::parse( unsigned char c){
//   unsigned char cx;
//   unsigned char p;
//   unsigned char s[3];
   CommandBuffer *com;
   com=command;
//  printf("face-%d char:%c is inputed.\n\r",faceID, c);
//   trg_puts("parseForInBit-1-");trg_putc(c); trg_puts("\n");
//   hex2str(c,s);
//   trg_puts(" codeHex="); trg_puts(s); trg_puts("\n");
   if(cbp>MaxInterFaceStrLen) {
      cbp=0;
   }
   if(cbp==0){
       if(c=='p'){
           cbp++;
             return;
       }
       else
       if(c=='a'){
           cbp=0;
           (*com).ackReturned(faceID);
           return;
       }
   }
   else
   if(cbp==1){
       inlen=h2i1(c);
         cbp++;
         return;
   }
     else
     if(cbp==2){
         inlen=inlen*16+h2i1(c);
         cbp++;
         return;
     }
   else{
      inputBuffer[cbp-3]=c;
      cbp++;
      if(inlen<cbp-3){
          inputBuffer[cbp-2]=0;
  //          returnAck();
          return;
      }
            if(inlen> cbp-3){
                   return;
            }
//   trg_puts("parseForInBit-2"); trg_putc(c); trg_puts("\n");
      inputBuffer[cbp-3]=0;
      int clen=xstrlen(inputBuffer);
      while(1){
         if(((*com).putQueue)(faceID, inputBuffer,clen)==1){
            cbp=0;
            returnAck();
            return;
         }
         wait(100);
      }
   }
 
//   trg_puts("parseForInBit-3");;trg_putc(c); trg_puts("\n");
 
}
 
void InBuffer::returnAck(void){
//    (*command).putChar(faceID,'a');
}
int InBuffer::getNextDoorDirection(void){
    return nextDoorDirection;
}
 
unsigned char InBuffer::getConnected(void){
//  printf("face-%d getConnected=%d\n\r",(int)faceID,(int)connected);   
    return connected;
}
 
void InBuffer::setConnected(unsigned char x){
    connected=x;
//  printf("face-%d setConnected=%d\n\r",(int)faceID,(int)x);
}
 

Counter: 50, today: 1, yesterday: 0

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS