void set_bus_dir(char * bscan_state,struct bus * mybus, int dir) { while( mybus!=NULL ) { set_pin_dir(bscan_state,mybus->pin_name,dir); mybus=mybus->next; } }
/* central command parser */ void Commands() { char c = toRS232Buf[0]; usbprog.datatogl = 0; int pin,value; int j; for(j=0;j<8;j++) toUSBBuf[j]=0; if((toRS232Buf[1]>=0x31) && (toRS232Buf[1]<=0x39)) pin=(uint8_t)toRS232Buf[1]-0x30; if(toRS232Buf[1]=='A')pin=10; if(toRS232Buf[1]=='B')pin=11; if(toRS232Buf[2]==0x31)value=1; else value=0; toUSBBuf[0]=c; toUSBBuf[1]=toRS232Buf[2]; USBBuf_i=2; switch(c) { /* case PORT_DIRECTION: //WASTE!!! set_direction((uint8_t)toRS232Buf[1]); break; case PORT_SET: // WASTE!!! set_port(pin, (uint8_t)toRS232Buf[2]); break; */ case PORT_GET: USBBuf_i=8; uint8_t port = PINB; if((port & BIT(IO1))) toUSBBuf[0] = 0x31; else toUSBBuf[0] = 0x30; if((port & BIT(IO2))) toUSBBuf[1] = 0x31; else toUSBBuf[1] = 0x30; if((port & BIT(IO3))) toUSBBuf[2] = 0x31; else toUSBBuf[2] = 0x30; if((port & BIT(IO4))) toUSBBuf[3] = 0x31; else toUSBBuf[3] = 0x30; if((port & BIT(IO5))) toUSBBuf[4] = 0x31; else toUSBBuf[4] = 0x30; if((port & BIT(IO6))) toUSBBuf[5] = 0x31; else toUSBBuf[5] = 0x30; if((port & BIT(IO7))) toUSBBuf[6] = 0x31; else toUSBBuf[6] = 0x30; if((port & BIT(IO8))) toUSBBuf[7] = 0x31; else toUSBBuf[7] = 0x30; break; case PORT_SETPIN: set_pin(pin,value); USBBuf_i=0; break; case PORT_SETPINDIR: set_pin_dir(pin,value); USBBuf_i=0; break; case PORT_GETPIN: if(get_pin(pin)==1) toUSBBuf[1] = 0x31; else toUSBBuf[1] = 0x30; break; default: // unkown command toUSBBuf[0]='x'; USBBuf_i=0; } //USBNWrite(TXC2,FLUSH); for(j=0;j<USBBuf_i;j++){ USBNWrite(TXD2,toUSBBuf[j]); } rs232_send(); USBBuf_i = 0; }