InBuffer.cpp
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Real2Virtual202111]]
#code(c){{
//#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
終了行:
[[Real2Virtual202111]]
#code(c){{
//#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
ページ名: