Example #1
0
int test05(void)
{
    int n, s, light;
    
    char key;
    
    Init();

    StatusLED(XGN);
    
    FrontLED(ON);
    BackLED(ON, ON);
                                                                       
    //SerWrite("Begin...", 8);
    //SerWrite("Waiting for command... ", 23);

    SerRead(key, 1, 0);
    
    if (key == 'g')
    {
        SerWrite("Good Morning... Starting...", 27);
    }
    else
    {
        SerWrite("So... just start... ", 20);
    }
    
    while(1)
    {
        for (s=80; s<300; s+=10)
        {    
            SerWrite("Looping... ", 11);
            
            MotorDir(FWD, RWD);
            MotorSpeed(150,s);
        
            SerWrite("Sleep Now! ", 11);
            for (n=1; n< 100; n++)  Sleep(255);
        
            if (s > 200)
            {
                SerWrite("S>200 ", 6);
            
                s=80;
            }
                
        }
    }
    return 0;
}
Example #2
0
int main()
{
	uint16_t n;
	unsigned char direction=FWD,inv_direction=RWD;
	// ASURO initialisieren
	Init();
	
	//Text aus FLASH ausgeben
	SerPrint_p(PSTR("Hello World!\n"));

	//Puffer im SRAM für Kommandos
	uint8_t buff;
	
	StatusLED(OFF);//GREEN,RED,YELLOW,OFF

	while(1)
	{
		SerRead(&buff,1,0);

		if(buff=='1')
		{
			StatusLED(RED);
		}
		else if(buff=='2')
		{
			StatusLED(GREEN);
		}
		else if(buff=='3')
		{
			StatusLED(YELLOW);
		}
		// Fügen Sie hier die noch fehlenden Kommandos ein
		// Für das Martinshorn Kommando verwenden Sie bitte die Funktion Sound() der AsuroLib. Schauen Sie sich die Dokumentation dieser Funktion an.
		// Eine Iterations des Martinshorns soll so programmiert werden, dass für 500ms ein Ton mit einer Frequenz von 410Hz und dann für 500ms ein Ton mit einer Frequenz von 547Hz abgespielt wird.
		// Beide Töne sollen mit maximaler Amplitude abgespielt werden. Wiederholen Sie die Tonfolge 5x.
		
		
		
		
		else
		{
			StatusLED(OFF);
		}
	}	
	while(1);
	return 0;
}
Example #3
0
bool cSmartCardNagra::SetIFS(unsigned char size)
{
  unsigned char buf[5];
  // NAD, PCB, LEN
  buf[0]=0x21; buf[1]=0xC1; buf[2]=0x01;
  // Information Field size
  buf[3]=size; buf[4]=XorSum(buf,4);
  PRINTF(L_SC_INIT,"Setting IFS to 0x%02X",size);
  if(SerWrite(buf,5)!=5) {
    PRINTF(L_SC_ERROR,"failed to write IFS command");
    return false;
    }
  if(SerRead(buff,5,cardCfg.workTO)!=5 || XorSum(buff,5)) {
    PRINTF(L_SC_ERROR,"setting IFS to %02x failed",size);
    return false;
    }
  return true;
}
Example #4
0
bool cSmartCardNagra::DoBlkCmd(unsigned char cmd, int ilen, unsigned char res, int rlen, const unsigned char *data)
{
  /*
  here we build the command related to the protocol T1 for ROM142 or T14 for ROM181
  the only different that i know is the command length byte msg[4], this msg[4]+=1 by a ROM181 smartcard (_nighti_)
  one example for the cmd$C0
  T14 protocol:       01 A0 CA 00 00 03 C0 00 06 91
  T1  protocol: 21 00 08 A0 CA 00 00 02 C0 00 06 87
  */
  unsigned char msg[MAX_LEN+16];
  static char nagra_head[] = { 0xA0,0xCA,0x00,0x00 };

  memset(msg,0,sizeof(msg));
  int c=0;
  if(!isT14Nagra) {
    msg[c++]=0x21;
    msg[c++]=block; block^=0x40;
    msg[c++]=ilen+6;
    }
  else {
    msg[c++]=0x01;
    }
  memcpy(msg+c,nagra_head,sizeof(nagra_head)); c+=sizeof(nagra_head);
  msg[c]=ilen;
  msg[c+1]=cmd;
  int dlen=ilen-2;
  if(dlen<0) {
    PRINTF(L_SC_ERROR,"invalid data length encountered");
    return false;
    }
  msg[c+2]=dlen;
  if(isT14Nagra) msg[c]++;
  c+=3;
  if(data && dlen>0) { memcpy(msg+c,data,dlen); c+=dlen; }
  msg[c++]=rlen;
  msg[c]=XorSum(msg,c); c++;

  if(SerWrite(msg,c)==c) {
    LDUMP(L_CORE_SC,msg,c,"NAGRA: <-");
    cCondWait::SleepMs(10);
    if(SerRead(buff,3,cardCfg.workTO)!=3) {
      PRINTF(L_SC_ERROR,"reading back reply failed");
      return false;
      }
    int xlen=buff[2]+1;
    if(SerRead(buff+3,xlen,cardCfg.workTO)!=xlen) {
      PRINTF(L_SC_ERROR,"reading back information block failed");
      return false;
      }
    xlen+=3;
    if(XorSum(buff,xlen)) {
      PRINTF(L_SC_ERROR,"checksum failed");
      return false;
      }
    LDUMP(L_CORE_SC,buff,xlen,"NAGRA: ->");

    if(buff[3]!=res) {
      PRINTF(L_SC_ERROR,"result not expected (%02X != %02X)",buff[3],res);
      return false;
      }
    if(buff[2]-2!=rlen) {
      PRINTF(L_SC_ERROR,"result length not expected (%d != %d)",buff[2]-2,rlen);
      return false;
      }
    memcpy(sb,&buff[3+rlen],2);
    LDUMP(L_CORE_SC,sb,2,"NAGRA: ->");
    cCondWait::SleepMs(10);
    return true;
    }
  return false;
}