char *dhb10_com(char *myConfigStr)
{
  memset(dhb10_reply, 0, DHB10_LEN);
  char *reply = dhb10_reply;
  #ifdef ARLO_DEBUG
    //dprint(term, "dhb10_com(%s, ", myConfigStr);
  #endif
  
  if(!ard_opened) drive_open();

  int ca = 0, cta = 0;
  
  //fdserial_txChar(ard_dhb10_arlo, '\r');

  #ifdef HALF_DUPLEX
    print("dhb10_com.c before fdserial_rxFlush(ard_dhb10_arlo); \n");
  #endif  

  fdserial_rxFlush(ard_dhb10_arlo);

  #ifdef HALF_DUPLEX
    print("dhb10_com.c after fdserial_rxFlush(ard_dhb10_arlo); \n");
  #endif  

  int i = 0;
  
  while(1) 
  {
    fdserial_txChar(ard_dhb10_arlo, myConfigStr[i]);
    if((myConfigStr[i] == '\r') || (myConfigStr[i] == 0)) break;
    i++;
  }
  if((i == 0) && (myConfigStr[i] == '\r'))
  {
    return 0;
  }    
  #ifdef ARLO_DEBUG
    //dprint(term, "i = %d\n", i);
  #endif  
  i = 0;
  #ifdef ARLO_DEBUG
    for(int i = 0; i < 32; i++)                                    // 32 Needs #define
    {
      if(myConfigStr[i] == '\r')
      {
        dprint(term, "\\r\n");
        break;
      }        
      else if(myConfigStr[i] >= ' ' && myConfigStr[i] <= 'z')
      {
        writeChar(term, myConfigStr[i]);
      } 
      else
      {
        dprint(term, "[%d]", myConfigStr[i]);
      } 
    }         
  #endif 

  i = 0;
  int t = CNT;
  int dt = CLKFREQ;
  while(1)
  {
    cta = fdserial_rxCount(ard_dhb10_arlo);
    if(cta)
    {
      ca = readChar(ard_dhb10_arlo);
      dhb10_reply[i] = ca;
      #ifdef ARLO_DEBUG
        if(ca == '\r')
        {
          dprint(term, "[\\r]\n");
        }        
        else if(ca >= ' ' && ca <= 'z')
        {
          writeChar(term, ca);
        } 
        else
        {
          dprint(term, "[%d]", ca);
        } 
      #endif  
      if(dhb10_reply[i] == '\r')
      {
        reply = dhb10_reply;
        break;
      }  
      i++;
    }
    if(CNT - t > dt)
    {
      #ifdef ARLO_DEBUG
        dprint(term, "Error, no reply from DHB-10!\n");
      #endif
      strcpy(reply, "Error, no reply from DHB-10!\n");
      break;
    }  
  }
  return reply;    
}
Ejemplo n.º 2
0
void main()
{
  badge_setup();
  simpleterm_close();
  ir_start();
  ee_wipe();
  
  // Connection to host routine (FORCE CONNECTION TO HOST)
  port = fdserial_open(31, 30, 0, 115200);
  char_size(SMALL);
  cursor(2, 4);
  display("Connecting...");
  while(1)
  {
    dprint(port, "Propeller\n");
    pause(1000);  // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout
    if (fdserial_rxCount(port) == 0)
    {
      continue;
    }      
    else if (fdserial_rxCount(port) < 5)
    {
      fdserial_rxFlush(port);
      continue;
    }
    else dscan(port, "%s", handshake);
    // Attempt handshake and listen to response
    if (strcmp(handshake, "H0st") == 0)
    {
      break;
    }      
  }
  clear();
  
  while(1)
  {
    rgb(L, OFF);
    rgb(R, OFF);
        
    char_size(BIG);
    cursor(0, 0);
    display("HOTSPOT!");
    char_size(SMALL);
    cursor(4, 5);
    display("Start an");
    cursor(1, 6);
    display("interaction to");
    cursor(0, 7);
    display("upload your data");
    
    memset(&their, 0, sizeof(info));
    
    int t = CNT;
    int dt = CLKFREQ * 2;
    
    if (check_inbox() == 1)
    {
      clear();
      message_get(&their);
      ir_send(&my);
      
      char_size(SMALL);
      cursor(2, 2);
      display("Receiving...");
      
      while(1)
      {
        if (CNT - t > dt)
        {
          clear();
          char_size(SMALL);
          cursor(5, 2);
          display("ERROR!");
          cursor(0, 5);
          display("Please try again");
          dprint(port, "txBegin\n");  
          dprint(port, "Timeout\n");
          ee_wipe();
          clear_inbox();
          pause(2000);
          clear();
          break;
        }
        if (check_inbox() == 1)
        {
          t = CNT;
          message_get(&their);
          if(!strcmp(their.name, "txDone"))
          {
            char_size(SMALL);
            cursor(0, 5);
            display("Upload complete");
            dprint(port, "txBegin\n");
            ee_uploadContacts(port);
            ee_wipe();
            clear_inbox();
            pause(1000);
            clear();
            break;
          }
          ee_save(&their);
          dprint(port, "Name: %s\n", their.name);
          dprint(port, "Email: %s\n", their.email);       
        }
      }        
    }      
  }    
}  
void main()
{
  badge_setup();
  simpleterm_close();
  contacts_clearAll();
  preserve_header();
  CLKLIMIT = CLKFREQ * 2;
  
  // Connection to host routine (FORCE CONNECTION TO HOST)
  port = fdserial_open(31, 30, 0, 115200);
  text_size(SMALL);
  cursor(2, 4);
  oledprint("Connecting...");
  spkr = talk_run(9, 10);                    // Start talk process
  while(1)
  {
    dprint(port, "Propeller\n");
    pause(1000);  // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout
    if (fdserial_rxCount(port) == 0)
    {
      continue;
    }      
    else if (fdserial_rxCount(port) < 5)
    {
      fdserial_rxFlush(port);
      continue;
    }
    else dscan(port, "%s", handshake);
    // Attempt handshake and listen to response
    if (strcmp(handshake, "H0st") == 0)
    {
      break;
    }      
  }

  clear();
  
  talk_say(spkr, "heloa");
  while(1)
  {
    rgb(L, OFF);
    rgb(R, OFF);
    
    text_size(LARGE);
    cursor(0, 0);
    oledprint("HOTSPOT!");
    text_size(SMALL);
    cursor(4, 5);
    oledprint("Start an");
    cursor(1, 6);
    oledprint("interaction to");
    cursor(0, 7);
    oledprint("upload your data");
    
    char their_id[7];
    memset(&their_id, 0, 7);
    
    int t = CNT;
    char i_type[5];
    
    irscan("%s%s", their_id, i_type);
    
    if (strlen(their_id) > 0)
    {
      clear();
      eeprint("%s,%u,%s\n", their_id, 0, "INFO");
      irprint("%s\n%s\n", "htspt1", "DUMP");
      
      text_size(SMALL);
      cursor(2, 2);
      oledprint("Receiving...");
      
      while(1)
      {
        char b[128];
        memset(&b, 0, 128);
        irscan("%s", b);
        
        if (CNT - t > CLKLIMIT)
        {
          clear();
          text_size(LARGE);
          cursor(0, 0);
          oledprint(" ERROR");
          text_size(SMALL);
          cursor(0, 6);
          oledprint("Please try again");
          dprint(port, "txBegin\n");  
          dprint(port, "Timeout\n");
          contacts_clearAll();
          preserve_header();
          talk_say(spkr, "oops;/trae,-ugen");
          pause(2000);
          clear();
          break;
        }
        if (strlen(b) > 0)
        {
          t = CNT;
          if(!strcmp(b, "irDone"))
          {
            clear();
            text_size(LARGE);
            cursor(0, 0);
            oledprint("SUCCESS");
            text_size(SMALL);
            cursor(0, 6);
            oledprint("Upload complete");
            talk_say(spkr, "oakay;</aem,dun");
            dprint(port, "txBegin\n");
            upload_contacts(port);
            contacts_clearAll();
            preserve_header();
            pause(1000);
            clear();
            break;
          }
          save_contact(b); 
        }
      }        
    }      
  }    
}