Ejemplo n.º 1
0
string
Esp8266WiFiPhy::GetSoftAPMac(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CIPAPMAC_";
	// store
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CIPAPMAC\?\r\n");
		return "";
	}
	size_t from = 0;
	string stamac = StringUnescape(GetStringBetweenTokens(':','\r',m_lastATreply, from));

	dbgprintf("SoftAP MAC ADDRESS: <%s>\r\n", stamac.c_str());
	testprintf("Ended!\r\n");
	return stamac;
}
Ejemplo n.º 2
0
int8_t
Esp8266WiFiPhy::GetWiFiMode(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWMODE_";
	// stored?
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	//tail
	ATCommand += "\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWMODE\?\r\n");
		return -1;
	}

	// parsing
	char ch = m_lastATreply.at(m_lastATreply.find(":") + 1);
	dbgprintf("WiFi Mode: %c\r\n", ch);
	testprintf("Ended!\r\n");
	return (int8_t) (ch - '0');
}
Ejemplo n.º 3
0
void
Esp8266WiFiPhy::SetSoftAPMac(string mac_addr, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CIPAPMAC_";
	// store
	if (flashStore){
		// NB: DISABLED: WARNING!!! THIS CHANGES THE DEVICE PHYSICAL MAC ADDRESS!!
		// ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + StringEscape(mac_addr);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CIPAPMAC_xxx\r\n");
		return;
	}
	m_softAPInterfaceMac = mac_addr;
	testprintf("Ended!\r\n");
}
Ejemplo n.º 4
0
StationAccessPoint
Esp8266WiFiPhy::GetConnectedStationAP(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWJAP_";
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWJAP\?\r\n");
		return StationAccessPoint("","","");
	}

	size_t from = 0;
	string ssid = StringUnescape(GetStringBetweenTokens(':',',',m_lastATreply, from));
	string bssid = StringUnescape(GetStringBetweenTokens(',',',',m_lastATreply, from));
	string channel = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string rssi = GetStringBetweenTokens(',','\r',m_lastATreply, from);

	dbgprintf("AccessPoint: <%s>,<%s>,<%s>,<%s>\r\n", ssid.c_str(), bssid.c_str(), channel.c_str(), rssi.c_str());
	testprintf("Ended!\r\n");
	return StationAccessPoint(ssid,bssid,StringToInteger(channel),StringToInteger(rssi));
}
Ejemplo n.º 5
0
void
Esp8266WiFiPhy::ConfigureSoftAP(SoftAccessPoint sap, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWSAP_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + StringEscape(sap.m_ssid);
	ATCommand += "," + StringEscape(sap.m_password);
	ATCommand += "," + IntegerToString(sap.m_channel);
	ATCommand += "," + IntegerToString(sap.m_encryption);
	ATCommand += "," + IntegerToString(sap.m_maxconnections);
	ATCommand += "," + IntegerToString(sap.m_ssidbroadcast);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWSAP_xxx\r\n");
		return;
	}
	// assign to internal variable
	m_softAP = sap;
	testprintf("Ended!\r\n");
}
Ejemplo n.º 6
0
void
Esp8266WiFiPhy::AutoConnectToStationAtBoot(bool enable){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWAUTOCONN=";
	if (enable){
		ATCommand += "1";
	}
	else{
		ATCommand += "0";
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: AT+CWAUTOCONN! \r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Ejemplo n.º 7
0
void
Esp8266WiFiPhy::ListStationAP(StationAccessPoint sap){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWLAP";
	if (!sap.m_ssid.empty()){
		ATCommand += "=" + StringEscape(sap.m_ssid);
		if (!sap.m_bssidmac.empty()){
			ATCommand += "," + StringEscape(sap.m_bssidmac);
			if (sap.m_channel != -1){
				ATCommand += "," + IntegerToString(sap.m_channel); // not to be escaped, since number!
			}
		}
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWLAP\r\n");
		return;
	}
	dbgprintf("+CWLAP:(<ECN>,<SSID>,<RSSI>,<MAC>,<CH>,<FREQ OFFSET>,<FREQ CALIB>)\r\n");
	testprintf("Ended!\r\n");
}
Ejemplo n.º 8
0
void
Esp8266WiFiPhy::SetWiFiMode(uint8_t mode, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWMODE_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + IntegerToString((int)mode);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWMODE_xxx=\r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Ejemplo n.º 9
0
bool
Esp8266WiFiPhy::DoubleWaitFor(string toCompareOK, string toCompareERR){
	char ch;
	string receivedS;

	Timer t;
	t.start();
	do{
		// if there's anything in the queue picks it up
		if (m_UART->readable()){
			//store into received string
			receivedS += m_UART->getc();
		}

		//until the string is found or the timeout expires
		if (t.read_ms() > TIMEOUT_MS){
			t.stop();
			printf("Timeout expired!! .. %s \r\n", receivedS.c_str());
			return false;
		}

		if (receivedS.find(toCompareERR) != std::string::npos){
			printf("Erroneous Reply!! .. %s \r\n", receivedS.c_str());
			return false;

		}
	} while (receivedS.find(toCompareOK) == std::string::npos);
	dbgprintf("REPLY:\r\n%s\r\n", receivedS.c_str());
	testprintf("%s\r\n", receivedS.c_str());
	m_lastATreply = receivedS;
	return true;
}
Ejemplo n.º 10
0
int main(){
  int count = 0;
  char sysout[1000];
  int sysrc;
  int vdrc;
  double value;
  int w,p;
  static char *format[] = { "%*.*g","%-*.*g","%#*.*g","%+*.*g", "% *.*G",
                            "%*.*e", "%#*.*E", "%*.*f", "%#*.*f", "%*%%*g"};
  int fcnt;
  for(fcnt=0; fcnt<sizeof(format)/sizeof(char*); fcnt++){
   for(w=0; w<=12; w += 3){
    for(p=0; p<=12; p += 3){
      for(value=1.234567890123456789e-32; value<1.3e+32; value *= 1e8 ){
        outidx = 0;
        sprintf(sysout,format[fcnt],w,p,value);
        vdrc = testprintf(format[fcnt],w,p,value);
        sysrc = strlen(sysout);
        outbuf[outidx] = 0;
        count++;
        if( vdrc!=sysrc || !rcmp(outbuf,sysout) ){
          printf("Count=%d  Format=%s  Width=%d  Precision=%d  Value=%.16g\n",
            count,format[fcnt],w,p,value);
          printf("  system:   [%s] returned %d\n",sysout,sysrc);
          printf("  vxprintf: [%s] returned %d\n",outbuf,vdrc);
        }
      }
    }
   }
  }
  printf("Checked %d combinations.\n",count);
  
  return 0;
}
Ejemplo n.º 11
0
void
Esp8266WiFiPhy::QuitStationAP(void){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWQAP\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: AT+CWQAP! \r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Ejemplo n.º 12
0
SoftAccessPoint
Esp8266WiFiPhy::GetConfigurationSoftAP(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWSAP_";
	// store
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWSAP\?\r\n");
		return SoftAccessPoint("","",-1,-1,-1,-1);
	}

	size_t from = 0;
	string ssid = StringUnescape(GetStringBetweenTokens(':',',',m_lastATreply, from));
	string password = StringUnescape(GetStringBetweenTokens(',',',',m_lastATreply, from));
	string channel = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string encryption = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string max_conn = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string ssid_bcast = GetStringBetweenTokens(',','\r',m_lastATreply, from);

	dbgprintf("AccessPoint: <%s>,<%s>,<%s>,<%s>,<%s>,<%s>\r\n", ssid.c_str(), password.c_str(), channel.c_str(), encryption.c_str(), max_conn.c_str(), ssid_bcast.c_str());
	testprintf("Ended!\r\n");
	return SoftAccessPoint(ssid,password,StringToInteger(channel),StringToInteger(encryption),StringToInteger(max_conn),StringToInteger(ssid_bcast));

}
Ejemplo n.º 13
0
bool
Esp8266WiFiPhy::ConnectToStationAP (StationAccessPoint sap, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWJAP_";
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}

	ATCommand += "=" + StringEscape(sap.m_ssid) + ",";
	ATCommand += StringEscape(sap.m_password);
	if (!(sap.m_bssidmac.empty())) {
		ATCommand += "," + StringEscape(sap.m_bssidmac);
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!DoubleWaitFor("OK","FAIL")){
		printf("Error: +CWJAP: Error Code (1<=>4)==(TIMEOUT,WRONG PASSWORD,AP NOT FOUND,FAIL)\r\n");
		return false;
	}
	// assign to internal variable
	m_stationAP = sap;
	testprintf("Ended!\r\n");
	return true;
}
Ejemplo n.º 14
0
void ch2()
{
	printf("==========ch2()\n");
	// float PI3.14159;  // 非法标识符,内含小数点,非数字、字母、下划线,因此非法 
	ch2_1();
	ch2_2();
	ch2_3();
	ch2_4();
	ch2_5();
	ch2_6();
	ch2_7();
	ch2_8();
	floatTest();
	doubleTest();
	testAdd1();
	testAdd2();
	testAdd3();
	testprintf();
	test_and_or();
	expression();
	//getchar();
}
Ejemplo n.º 15
0
int main(){
  int count = 0;
  char sysout[1000];
  int sysrc;
  int vdrc;
  int i;
  int sysx;
  int vdx;
  for(i=0; i<50; i++){
    sprintf(sysout,"%*s%n--%c ho ho ho",i,(i&1)?"xxx":"yyyyyyyy",&sysx,i+'a');
    sysrc = strlen(sysout);
    outidx = 0;
    vdrc = testprintf("%*s%n--%c ho ho ho",i,(i&1)?"xxx":"yyyyyyyy",&vdx,i+'a');
    outbuf[outidx] = 0;
    count++;
    if( vdrc!=sysrc || strcmp(outbuf,sysout)!=0 || sysx!=vdx ){
      printf("  system:   [%s] returned %d with x=%d\n",sysout,sysrc,sysx);
      printf("  vxprintf: [%s] returned %d with x=%d\n",outbuf,vdrc,vdx);
    }
  }
  printf("Checked %d combinations.\n",count);
  
  return 0;
}
Ejemplo n.º 16
0
int main(){
  static char letters[] = "dixXou%";
  static char *flags[] = { "", "-", " ", "+", "#", "-#", "+-", "+#", "# ",
                           "-+#", "# -+", 0 };
  static char *widths[] = { "", "0", "05", "1", "3", "10", "*", 0 };
  static char *precisions[] = { "", ".1", ".3", ".10", ".*", 0 };
  int values[] = { 0, 1, 10, 9999, -1, -10, -9999 };
  char format[100];
  char sysout[1000];
  int longflag;
  int sysrc;
  int vdrc;
  int lcnt;
  int fcnt;
  int wcnt;
  int pcnt;
  int vcnt;
  int v1, v2, v3;
  int count = 0;
  lcnt = fcnt = vcnt = longflag = wcnt = pcnt = v1 = v2 = v3 = 0;
  do{
    sprintf(format,"Ho ho ho %%%s%s%s%s%c hi hi hi",
       flags[fcnt],widths[wcnt],precisions[pcnt],
       longflag?"l":"",letters[lcnt]);
    v1 = values[vcnt];
    if( widths[wcnt][0]=='*' ){
      v2 = v1;
      v1 = 8;
    }
    if( precisions[pcnt][1]=='*' ){
      v3 = v2;
      v2 = v1;
      v1 = 7;
    }
    outidx = 0;
    if( longflag ){
      sprintf(sysout,format,(long)v1,v2,v3);
      vdrc = testprintf(format,(long)v1,v2,v3);
    }else{
      sprintf(sysout,format,v1,v2,v3);
      vdrc = testprintf(format,v1,v2,v3);
    }
    sysrc = strlen(sysout);
    outbuf[outidx] = 0;
    count++;
    if( count%1000==0 ){
      printf("\rChecked thru %d...   ",count);
      fflush(stdout);
    }
    if( vdrc!=sysrc || strcmp(outbuf,sysout)!=0 ){
      printf("Format: [%s]  Arguments: %d, %d, %d\n",format,v1,v2,v3);
      printf("  system:   [%s] returned %d\n",sysout,sysrc);
      printf("  vxprintf: [%s] returned %d\n",outbuf,vdrc);
    }
    vcnt++;
    if( vcnt>=sizeof(values)/sizeof(int) ){ vcnt = 0; lcnt++; }
    if( letters[lcnt]==0 ){ lcnt = 0; longflag++; }
    if( longflag==2 ){ longflag = 0; fcnt++; }
    if( flags[fcnt]==0 ){ fcnt = 0; wcnt++; }
    if( widths[wcnt]==0 ){ wcnt = 0; pcnt++; }
  }while( precisions[pcnt] );
  printf("\nChecked %d combinations.\n",count);
  
  return 0;
}