static int SetBaud( int baud_index, int *sync_point_p ) { int reply; /* storing data received from other machine */ int sync_point; sync_point = *sync_point_p; *sync_point_p += MAX_BAUD_SET_TICKS + 3*SYNC_SLOP; if( !Baud( baud_index ) ) return( FAIL ); /* sets up baud rate */ SyncPoint( sync_point ); ClearCom(); Wait( SYNC_SLOP ); SendByte( SDATA_HI ); reply = WaitByte( SYNC_SLOP * 2 ); if( reply != SDATA_HI ) { return( FAIL ); } /* now go the other way */ *sync_point_p += BaudTable[ baud_index ].full_test_ticks; #ifdef SERVER if( !SetBaudReceiver() ) return( FAIL ); if( !SetBaudSender() ) return( FAIL ); #else if( !SetBaudSender() ) return( FAIL ); if( !SetBaudReceiver() ) return( FAIL ); #endif return( SUCCESS ); }
// Initialise the Mind Control's ATmega168 microcontroller void Initialise(void) { cli(); // Set I/O pins DDRB = 0x10; PORTB = 0xCF; DDRC = 0x00; PORTC = 0xFF; DDRD = 0xE6; PORTD = 0x7D; // Set up timer 1 to generate an interrupt every 1 ms TCCR1A = 0x00; TCCR1B = (_BV(WGM12) | _BV(CS12)); OCR1A = 71; TIMSK1 = _BV(OCIE1A); // Set up the serial port with rx interrupt UBRR0 = 19; UCSR0B = (_BV(RXCIE0) | _BV(TXEN0) | _BV(RXEN0)); UCSR0C = (_BV(UCSZ00) | _BV(UCSZ01)); // Turn on interrupts sei(); LEDBothOff; PowerOnRobot(); ByteTx(CmdStart); Baud(Baud28800); ByteTx(CmdControl); ByteTx(CmdFull); }
bool SetSyncTime( void ) { if( MaxBaud != MIN_BAUD ) { if( !Baud( LOW_BAUD ) ) return( FAIL ); } #ifdef SERVER if( WaitByte( SEC(1)/10 ) != SDATA_HI ) { return( FAIL ); } #else SendByte( SDATA_HI ); #endif return( MarchToTheSameDrummer() ); }
static char *SetupModem( char *parm ) { char *start; unsigned wait; unsigned ch; int data; Baud( MaxBaud ); wait = SEC(3); while( *parm == ' ' && *parm == '\t' ) ++parm; if( *parm == '\0' ) return( NULL ); for( ;; ) { if( *parm == '(' ) { start = ++parm; for( ;; ) { ch = *parm; if( ch == '\0' ) goto done; ++parm; if( ch == ')' ) break; if( ch == '\\' ) { ch = *parm++; switch( ch ) { case '\0': return( TRP_ERR_invalid_modem_string ); case 'r': ch = '\r'; break; case 'n': ch = '\n'; break; } } data = WaitByte( wait ); if( data == SDATA_NO_DATA ) { if( wait != SEC(60) ) { wait = SEC(60); } else { return( TRP_ERR_timeout_on_modem_string ); } --parm; } else { wait = SEC(3); if( data != ch ) parm = start; } } } else { Wait( SEC(1)/5 ); for( ;; ) { ch = *parm; if( ch == '\0' ) goto done; if( ch == '(' ) break; ++parm; if( ch == '\\' ) { ch = *parm++; switch( ch ) { case '\0': return( TRP_ERR_invalid_modem_string ); case '`': Wait( 1 ); break; case '~': Wait( SEC(1) ); break; case 'r': SlowSend( '\r' ); Wait( SEC(1)/2 ); break; case 'n': SlowSend( '\n' ); break; default: SlowSend( ch ); break; } } else { SlowSend( ch ); } } } } done: #ifdef SERVER #define SEND_CHAR '=' #define EXPECT_CHAR '-' #else #define SEND_CHAR '-' #define EXPECT_CHAR '=' #endif wait = 1; for( ;; ) { data = WaitByte( wait ); if( data == EXPECT_CHAR ) break; if( data == SDATA_NO_DATA ) { if( wait != SEC(10) ) { wait = SEC(10); SendByte( SEND_CHAR ); } else { return( TRP_ERR_modem_failed_connection ); } } } if( wait != SEC(10) ) SendByte( SEND_CHAR ); return( NULL ); }
/*------------------------------------------------------*/ void LoadFromPc(char *p) { void InProg(void); int ReadPar(char *); char q[LINK_LEN],*r,*s,*ss[16]; int i,j,k; long y,z; lib *l; command *c,**cp; switch(*p) { case 'd': Lr=scanLLA(Lr,++p,null); if(!Lr) { j=0; switch(strscan(p,ss,',',16)) { case 2: j=atoi(ss[1]); case 1: if(l=FindLib(LinkAddrStr(ss[0]))) { copylib(l,Lr=makelib()); if(j) for(Lr->xc=Lr->x; --j && Lr->xc->next;) Lr->xc=Lr->xc->next; else Lr->x=Lr->xc=freecoord(Lr->x); Ungetch(REFRESH,0); } else puts_pc("!NOT_FOUND\r\n"); break; default: puts_pc("!SYNTAX\r\n"); break; } } break; case 'l': if(i=LinkAddrStr(++p)) { freelib(Lc); Lc=makelib(); Lc->ltype=LinkAddrType(i); Lc->n=LinkAddrN(i); } else InsertLib(&Lc); break; case 'M': if(sscanf(++p," %d,%04X,%04X,%s",&k,&i,&j,q)==4) { if(Mscan) /* znak, da je editor odprt ! */ if(Mscan->c->maxopt) { /* vrstica in obseg aktivna ? */ if(k) if(--k <= Mscan->c->maxopt) { Mscan->active = k; Refresh(); } break; } r=strchr(q,','); *r++=0; cp=NULL; if(!strcmp(q,"message")) cp=&CP; if(!strcmp(q,"gun")) cp=&GUN; if(!strcmp(q,"meteo")) cp=&METEO; if(!cp) break; /*......................................................................................*/ if(!*cp) new_command(cp); else{ c=*cp; do if(c->chk == j) *cp=c; else c=c->next; while(c != *cp); if((*cp)->chk != j) new_command(cp); } (*cp)->chk=j; c=*cp; s=(char *)c; i = sizeof(command) - sizeof(command *) - sizeof(int); while(i--) { sscanf(r,"%02X",&j); *s++ = j; ++r;++r; } c->chk *= -1; if(cp == &CP) Ungetch(GXM_MESSAGE_ID,0); if(cp == &GUN) Ungetch(GXM_GUN_ID,0); } break; case 'r': if(crest && (sscanf(++p," %ld %ld",&y,&z) == 2)) { add_coord(crest,0,y,z); crest->xc->refp=null; } else DeleteTask(DMRtimeout,RTC_task); break; case 'c': i=j=0; if(Lc) Lc=scanLLA(Lc,++p,eof); break; case 'g': if(Lc && (sscanf(++p," %s %d %d",q,&j,&k) == 3)) { for(i=0; Guns[i].name; ++i) if(!strcmp(Guns[i].name,q)) { Lc->gun=i; Lc->refd=j; Lc->powder=k; } } break; case 'a': if(Lc && (sscanf(++p,"%s %d",q,&j) == 2)) { for(i=0; Guns[Lc->gun].ammo[i]; ++i) if(!strcmp(Guns[Lc->gun].ammo[i],q)) { Lc->ammpcs[i]=j; r=strchr(p,'+'); s=strrchr(p,'+'); if(r) do Lc->ammpcs[i] += 0x1000; while(r++ != s); r=strchr(p,'-'); s=strrchr(p,'-'); if(r) do Lc->ammpcs[i] -= 0x1000; while(r++ != s); } } break; case 'p': if(sscanf(++p,"%d,%d",&i,&j) == 2) if(i<12 && j<4) { xyLCD(i,j); Ungetch(GXM_CURSOR_POS,0); } break; case 'm': LoadHexRec(p,'m',_MenuCode); break; case 'h': LoadHexRec(p,'h',_MenuHead); break; case 't': if(Lc) { ++p; ++p; Lc->txt=addtxt(Lc,p); } else LoadHexRec(p,'t',_TextCode); break; case 'T': if(sscanf(++p," %x %x",&i,&j)==2) { sprintf(q,"%04X\r\n",readTEMP(i,j)); puts_pc(q); } break; case 'f': if(ReadPar(++p)) break; i=strscan(p,ss,' ',16); if(i>=2) { sscanf(ss[0],"%lx",&eebott); sscanf(ss[1],"%lx",&eetop); if(eebott < (long)FLASHTOP) { puts_pc("!ILL_ADDRESS\r\n"); break; } if(eetop > (long)FLASHTOP+0x80000L) { puts_pc("!ILL_ADDRESS\r\n"); break; } if(i==3) { ss[2][8]=0; sprintf(pass,"%-8s",ss[2]); } if(CheckPass(&syspass)) { puts_pc("!NOT_ALLOWED\r\n"); break; } puts_pc("\7\r\nFLASH programming !!!\r\n"); wait(50); InProg(); puts_pc("Done\r\n"); } else puts_pc("!SYNTAX\r\n"); break; case 'b': k=sscanf(++p," %d %d",&i,&j); if(k) if(Baud(CHPC,i)) { if(k==2) Xonoff(j); break; } puts_pc("!SYNTAX\r\n"); break; case 'z': EnterZone(++p); break; case 'G': DeleteTask(ReadPc,RTC_task); Guns=ReadGunData(0,0,0,0,NULL); SetTask(ReadPc,0,RTC_task); break; default: puts_pc("!SYNTAX\r\n"); break; } }
CResetAttributes::ResetResult CTestResource::Reset(LogFunc *pfnLog, void *pfnLogparam) { String strReset; strReset.Format(_T("port(%s,%d) %s"),Serial(),Baud(),ResetString()); return CResetAttributes(strReset).Reset(pfnLog,pfnLogparam); }