示例#1
0
bool
tWithWcf( LibTest & tester )
{
  TESTP( tWithWcf01( tester ), true );
  TESTP( tWithWcf02( tester ), true );
  return( true );
}
示例#2
0
void ICACHE_FLASH_ATTR publishAlarm(uint8 alarm, int info) {
	static uint8 last_alarm = 0xff;
	static int last_info = -1;
	if (alarm == last_alarm && info == last_info) {
		TESTP("#");
		return; // Ignore repeated identical alarms
	}
	last_alarm = alarm;
	last_info = info;
	char *topic = (char*) os_zalloc(100);
	char *data = (char*) os_malloc(100);
	if (!checkAlloc(topic, data)) return;

	os_sprintf(topic, (const char*) "/Raw/%s/alarm", sysCfg.device_id);
	os_sprintf(data, (const char*) "{ \"alarm\":%d, \"info\":%d}", alarm, info);
	if (checkClient("publishAlarm")) {
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, 0))
			printMQTTstate();
		TESTP("********");
	} else {
		TESTP("--------");
	}
	TESTP("%s=>%s\n", topic, data);
	checkMinHeap();
	os_free(topic);
	os_free(data);
}
示例#3
0
void ICACHE_FLASH_ATTR publishError(uint8 err, int info) {
	static uint8 last_err = 0xff;
	static int last_info = -1;
	if (err == last_err && info == last_info)
		return; // Ignore repeated errors
	char *topic = (char*) os_malloc(50), *data = (char*) os_malloc(100);
	if (topic == NULL || data == NULL) {
		ERRORP("malloc err %s/%s\n", topic, data);
		startFlash(-1, 50, 50); // fast
		return;
	}
	os_sprintf(topic, (const char*) "/Raw/%s/error", sysCfg.device_id);
	os_sprintf(data, (const char*) "{ \"error\":%d, \"info\":%d}", err, info);
	if (mqttIsConnected()) {
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, 0))
			printMQTTstate();
		TESTP("********");
	} else {
		TESTP("--------");
	}
	TESTP("%s=>%s\n", topic, data);
	checkMinHeap();
	os_free(topic);
	os_free(data);
}
示例#4
0
void ICACHE_FLASH_ATTR printFlows(void) {
	char s0[50], s1[50], s2[50];
	TESTP("fl:%sl/S p:%skW e:%skWS ",
			dtoStr(flow*3600, 6, 3, s0),
			dtoStr(power, 10, 2, s1),
			dtoStr(energy, 12, 2, s2));
	TESTP("tp:%s ts:%s tb:%s\n",
			mappedStrTemperature(MAP_TEMP_PANEL, s0),
			mappedStrTemperature(MAP_TEMP_SUPPLY, s1),
			mappedStrTemperature(MAP_TEMP_TS_BOTTOM, s2));
}
示例#5
0
bool
tDateTime( LibTest & tester )
{
    const char * oldTZ = getenv( "TZ" );

    putenv( (char *)"TZ=CST6CDT" );

    TESTP( tDateTime01( tester ) );
    TESTP( tDateTime02( tester ) );
    TESTP( tDateTime03( tester ) );
    TESTP( tDateTime04( tester ) );
    TESTP( tDateTime05( tester ) );
    TESTP( tDateTime06( tester ) );
    TESTP( tDateTime07( tester ) );
    TESTP( tDateTime08( tester ) );

    if( oldTZ )
    {
        char tzBuf[128];

        sprintf( tzBuf, "TZ=%s", oldTZ );

        putenv( tzBuf );

        DateTime t;
        t.setTimeZone( oldTZ );
    }

    return( true );

}
示例#6
0
文件: io.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR overrideClearOutput(uint8 id) {
	if (id < OUTPUTS) {
		outputOverrides[id] = false;
		easygpio_outputSet(outputMap[id], currentOutputs[id]);
		TESTP("o/p %d(%d)x->%d\n", id, outputMap[id], currentOutputs[id]);
	}
}
示例#7
0
文件: io.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR setLED(enum led_t led) {
	static enum led_t oldLED = DARK;
	if (led != oldLED) {
		TESTP("LED = %d", led);
		oldLED = led;
	}
	switch (led) {
	case DARK:
		setOutput(LED_RED, 0);
		setOutput(LED_GREEN, 0);
		break;
	case RED:
		setOutput(LED_RED, 1);
		setOutput(LED_GREEN, 0);
		break;
	case GREEN:
		setOutput(LED_RED, 0);
		setOutput(LED_GREEN, 1);
		break;
	case YELLOW:
		setOutput(LED_RED, 1);
		setOutput(LED_GREEN, 1);
		break;
	}
}
示例#8
0
bool
tDirectory( LibTest & tester )
{
  TESTP( tDirectory01( tester ) );

  return( true );
}
示例#9
0
文件: io.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR overrideSetOutput(uint8 id, bool set) { // Sets override
	if (id < OUTPUTS) {
		outputOverrides[id] = true;
		easygpio_outputSet(outputMap[id], set);
		TESTP("o/p %d(%d)-->%d\n", id, outputMap[id], set);
	}
}
示例#10
0
文件: http.c 项目: Daven005/ESP8266
static void ICACHE_FLASH_ATTR tcp_receive_cb(void *arg, char *pData, unsigned short len) {
	HttpdConnData c;
	char bfr[100] = { 0 };
	struct espconn *conn = (struct espconn*) arg;

	httpdParseHeader(pData, &c);
	TESTP("URL=%s\n", c.url);
	if (httpSetupMode && os_strncmp(c.url, "/setup", 5) == 0) {
		if (httpdFindArg(c.getArgs, "Action", bfr, sizeof(bfr)) >= 0) {
			TESTP("Action=%s\n", bfr);
			if (os_strncmp(bfr, "Update", 6) == 0) {
				if (httpdFindArg(c.getArgs, "MQTThost", bfr, sizeof(bfr)) >= 0) {
					TESTP("MQTThost=%s\n", bfr);
					if (7 < os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_host)) {
						os_strcpy(sysCfg.mqtt_host, bfr);
					}
				}
				if (httpdFindArg(c.getArgs, "MQTTport", bfr, sizeof(bfr)) >= 0) {
					TESTP("MQTTport=%s\n", bfr);
					if (1 <= os_strlen(bfr) && os_strlen(bfr) <= 4) {
						sysCfg.mqtt_port = atoi(bfr);
					}
				}
				if (httpdFindArg(c.getArgs, "MQTTuser", bfr, sizeof(bfr)) >= 0) {
					TESTP("MQTTuser=%s\n", bfr);
					if (0 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_user)) {
						os_strcpy(sysCfg.mqtt_user, bfr);
					}
				}
				if (httpdFindArg(c.getArgs, "MQTTpass", bfr, sizeof(bfr)) >= 0) {
					TESTP("MQTTpass=%s\n", bfr);
					if (0 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_pass)) {
						os_strcpy(sysCfg.mqtt_pass, bfr);
					}
				}
				if (httpdFindArg(c.getArgs, "DevPrefix", bfr, sizeof(bfr)) >= 0) {
					TESTP("DevPrefix=%s\n", bfr);
					if (2 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.deviceID_prefix)) {
						os_strcpy(sysCfg.deviceID_prefix, bfr);
						os_sprintf(sysCfg.device_id, "%s%lx", sysCfg.deviceID_prefix, system_get_chip_id());
					}
				}
				if (httpdFindArg(c.getArgs, "reboot", bfr, sizeof(bfr)) >= 0) {
					TESTP("reboot=%s\n", bfr);
					if (strcmp(bfr, "yes") == 0) {
						reboot = true;
					}
				}
				CFG_dirty();
			}
		}
		replyOK(conn);
	} else {
		replyFail(conn);
	}
}
示例#11
0
    foreach_set(F, last, p) {
	if (TESTP(p, COVERED)) {
	    RESET(p, ACTIVE);
	    change = TRUE;
	} else {
	    SET(p, ACTIVE);
	    F->active_count++;
	}
    }
示例#12
0
文件: config.c 项目: Daven005/ESP8266
static void ICACHE_FLASH_ATTR checkLazyWrite(void) {
	if (dirtyCount == 0)
		return;
	if (!checkSum()) { // data has changed
		saveSum();
		CFG_Save();
		TESTP("sysCfg updated\n");
	}
}
示例#13
0
    /* Try to expand each nonprime and noncovered cube */
    foreach_set(F, last, p) {
	/* do not expand if PRIME or if covered by previous expansion */
	if (! TESTP(p, PRIME) && ! TESTP(p, COVERED)) {

	    /* expand the cube p, result is RAISE */
	    expand1(R, F, RAISE, FREESET, OVEREXPANDED_CUBE, SUPER_CUBE,
		INIT_LOWER, &num_covered, p);
	    if (debug & EXPAND)
		printf("EXPAND: %s (covered %d)\n", pc1(p), num_covered);
	    (void) set_copy(p, RAISE);
	    SET(p, PRIME);
	    RESET(p, COVERED);		/* not really necessary */

	    /* See if we generated an inessential prime */
	    if (num_covered == 0 && ! setp_equal(p, OVEREXPANDED_CUBE)) {
		SET(p, NONESSEN);
	    }
	}
    }
示例#14
0
static void ICACHE_FLASH_ATTR startUp() {
	TESTP("\n%s ( %s - %s ) starting ...\n", "MQTT Bridge", wifi_station_get_hostname(), version);
	INFOP("wifi_get_phy_mode = %d\n", wifi_get_phy_mode());

//	os_timer_disarm(&uartTimer);
//	os_timer_setfn(&uartTimer, (os_timer_func_t *) uartTimerCb, (void *) 0);
//	os_timer_arm(&uartTimer, 10 * 1000, true);

	if ( !system_os_task(backgroundTask, USER_TASK_PRIO_1, taskQueue, QUEUE_SIZE))
		ERRORP("Can't set up background task\n");
	lastAction = INIT_DONE;
}
示例#15
0
static void ICACHE_FLASH_ATTR initDone_cb() {
	TESTP("Start test\n");
	easygpio_pinMode(LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_outputEnable(LED, 0);
	easygpio_pinMode(XMIT, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_outputEnable(XMIT, 0);
	os_timer_disarm(&xmit_timer);
	os_timer_setfn(&xmit_timer, (os_timer_func_t *) xmitWordCb, NULL);
	os_timer_arm(&xmit_timer, 2000, true); // repeat every 2S

    hw_timer_init(FRC1_SOURCE, 1);
    hw_timer_set_func(hw_timer_cb);
    hw_timer_arm(PULSE_WIDTH);
}
示例#16
0
文件: flash.c 项目: Daven005/ESP8266
void startMultiFlash(int pCount, uint8 fCount, unsigned int flashTime, unsigned int offTime) {
	TESTP("Start Flash %d (*%d) %d/%d\n", pCount, fCount, flashTime, offTime);
	easygpio_pinMode(LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_outputEnable(LED, LED_ON);
	patternRepeatCount = pCount;
	flashCounter = flashCount = fCount;
	flashOnTime = flashTime;
	patternOffTime = offTime;
	flashFinishedCb = NULL;
	flashState = FLASHING_ON;
	os_timer_disarm(&flash_timer);
	os_timer_setfn(&flash_timer, (os_timer_func_t *) flashCb, (void *) 0);
	os_timer_arm(&flash_timer, flashOnTime, false);
}
示例#17
0
bool
tSubStr( LibTest & tester )
{
  TESTP( tSubStr01( tester ) );
  TESTP( tSubStr02( tester ) );
  TESTP( tSubStr03( tester ) );
  TESTP( tSubStr04( tester ) );
  TESTP( tSubStr05( tester ) );
  TESTP( tSubStr06( tester ) );
  TESTP( tSubStr07( tester ) );

  return( true );
}
示例#18
0
文件: io.c 项目: Daven005/ESP8266
static void setPirLightActive(enum pir_t pir) {
	if (PIR1 <= pir && pir <= PIR2) {
		pirLightStatus[pir] = true;
		if (pirLightStatus[pir] != oldPirLightstatus[pir]) {
			TESTP("PIR Lt:%d ", pir);
			publishSensorData(SENSOR_LIGHT_PIR_ACTIVE1 - 1 + pir, "PIR LIGHT ON", "1");
			oldPirLightstatus[pir] = true;
		}
		os_timer_disarm(&pirLightTmer[pir]);
		os_timer_setfn(&pirLightTmer[pir], (os_timer_func_t *) pirLightTimeoutCb, pir);
		os_timer_arm(&pirLightTmer[pir], sysCfg.settings[SETTING_LIGHT_PIR1_ON_TIME-1+pir]*1000*60, false); // Minutes
	} else  {
		ERRORP("Bad PIR # %d", pir);
	}
}
示例#19
0
文件: io.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR setPirFanActive(enum pir_t pir) {
	if (PIR1 <= pir && pir <= PIR2) {
		pirFanStatus[pir] = true;
		if (pirFanStatus[pir] != oldPirFanstatus[pir]) {
			TESTP("PIR Fan:%d ", pir);
			publishSensorData(SENSOR_FAN_PIR_ACTIVE1 - 1 + pir, "PIR FAN ON", "1");
			oldPirFanstatus[pir] = true;
		}
		os_timer_disarm(&pirFanTmer[pir]);
		os_timer_setfn(&pirFanTmer[pir], (os_timer_func_t *) pirFanTimeoutCb, pir);
		os_timer_arm(&pirFanTmer[pir], sysCfg.settings[SETTING_FAN_PIR1_ON_TIME-1+pir]*1000*60, false); // Minutes
	} else  {
		ERRORP("Bad PIR # %d", pir);
	}
}
示例#20
0
文件: pump.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR setPump_Manual(void) { // Pump On/OFF
	sounderClear();
	startCheckIsFlowing();
	switch (pumpState()) {
	case AUTO_OFF:
	case AUTO_ON:
	case MANUAL_OFF:
		startCheckIsFlowing();
		pumpState_OnManual();
		break;
	case MANUAL_ON:
		pumpState_OffManual();
		break;
	}
	TESTP("Pump->%d\n", pumpState());
	processPump();
}
示例#21
0
void ICACHE_FLASH_ATTR publishAnalogue(uint16 val) {

	if (checkClient("publishAnalogue")) {
		char *topic = (char*) os_malloc(100), *data = (char*) os_malloc(100);
		if (!checkAlloc(topic, data)) return;

		os_sprintf(topic, (const char*) "/Raw/%s/A1/info", sysCfg.device_id);
		os_sprintf(data, (const char*) "{ \"Type\":\"Level\", \"Value\":%d}", val);
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, 0))
			printMQTTstate();
		TESTP("%s=>%s\n", topic, data);

		checkMinHeap();
		os_free(topic);
		os_free(data);
	}
}
示例#22
0
void ICACHE_FLASH_ATTR publishOverride(void) {

	if (checkClient("publishOverride")) {
		char *topic = (char*) os_malloc(100), *data = (char*) os_malloc(100);
		if (!checkAlloc(topic, data)) return;

		os_sprintf(topic, (const char*) "/Raw/%s/Override/info", sysCfg.device_id);
		os_sprintf(data, (const char*) "{ \"Temp\":%d, \"Hour\":%d, \"Minute\":%d}",
				sysCfg.overrideTemp, sysCfg.overrideHour, sysCfg.overrideMinute);
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, 0))
			printMQTTstate();
		TESTP("%s=>%s\n", topic, data);

		checkMinHeap();
		os_free(topic);
		os_free(data);
	}
}
示例#23
0
文件: config.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR CFG_Load() {
	os_printf("\nload (%x/%x)...\n", sizeof(sysCfg), SPI_FLASH_SEC_SIZE);
	spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE,
				   (uint32 *)&saveFlag, sizeof(SAVE_FLAG));
	if (saveFlag.flag == 0) {
		spi_flash_read((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE,
					   (uint32 *)&sysCfg, sizeof(SYSCFG));
	} else {
		spi_flash_read((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE,
					   (uint32 *)&sysCfg, sizeof(SYSCFG));
	}
	if(sysCfg.cfg_holder != CFG_HOLDER || !checkSum()){
		TESTP("Reinitialising sgsCFG\n");
		initSysCfg();
		saveSum();
		CFG_Save();
	}
}
示例#24
0
文件: http.c 项目: Daven005/ESP8266
static int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen) {
	char *p, *e;
	if (line==NULL) return 0;
	p = line;
	while(p!=NULL && *p!='\n' && *p!='\r' && *p!=0) {
		INFOP("findArg: %s\n", p);
		if (os_strncmp(p, arg, os_strlen(arg))==0 && p[os_strlen(arg)]=='=') {
			p += os_strlen(arg)+1; //move p to start of value
			e = (char*)os_strstr(p, "&");
			if (e==NULL) e = p+os_strlen(p);
			INFOP("findArg: val %s len %d\n", p, (e-p));
			return httpdUrlDecode(p, (e-p), buff, buffLen);
		}
		p = (char*)os_strstr(p, "&");
		if (p!=NULL) p += 1;
	}
	TESTP("Finding %s in %s: Not found\n", arg, line);
	return -1; //not found
}
示例#25
0
void ICACHE_FLASH_ATTR publishDeviceReset(char *version, int lastAction) {
	if (checkClient("publishDeviceReset")) {
		int idx;
		char *topic = (char *) os_zalloc(100);
		char *data = (char *) os_zalloc(200);
		if (!checkAlloc(topic, data)) return;

		os_sprintf(topic, "/Raw/%10s/reset", sysCfg.device_id);
		os_sprintf(data,
				"{\"Name\":\"%s\", \"Location\":\"%s\", \"Version\":\"%s\", \"Reason\":%d, \"LastAction\":%d}",
				sysCfg.deviceName, sysCfg.deviceLocation, version, system_get_rst_info()->reason,
				lastAction);
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, false))
			printMQTTstate();
		TESTP("%s=>%s\n", topic, data);
		checkMinHeap();
		os_free(topic);
		os_free(data);
	}
}
示例#26
0
文件: io.c 项目: Daven005/ESP8266
void ICACHE_FLASH_ATTR setSpeed(enum speedSelect speed) {
	if (speed != oldSpeed) {
		TESTP("relay:%d\n", speed);
		oldSpeed = speed;
	}
	switch (speed) {
	case STOP:
		setOutput(RELAY1, 0);
		setOutput(RELAY2, 0);
		break;
	case SLOW:
		setOutput(RELAY1, 1);
		setOutput(RELAY2, 0);
		break;
	case FAST:
		setOutput(RELAY1, 1);
		setOutput(RELAY2, 1);
		break;
	}
}
示例#27
0
static int test_errtable_match_OStable(void)
{
   logcontext_t lc = logcontext_FREE;
   TEST(0 == init_logcontext(&lc));

   // !! this works currently only for KONFIG_LANG set to en !!
   setlocale(LC_MESSAGES, "C");
   for (unsigned i=0; i<=maxsyserrno_logcontext(); ++i) {
      const char* expect = strerror((int)i); // error description returned by OS
      const char* errstr = (const char*) errstr_logcontext(&lc, i);
      TESTP(0 == strcmp(expect, errstr), "i:%d", i);
   }

   // reset
   TEST(0 == free_logcontext(&lc));

   return 0;
ONERR:
   free_logcontext(&lc);
   return EINVAL;
}
示例#28
0
文件: http.c 项目: Daven005/ESP8266
static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
	int i;
	char first_line = false;

	if (os_strncmp(h, "GET ", 4)==0) {
		conn->requestType = HTTPD_METHOD_GET;
		first_line = true;
	} else if (os_strncmp(h, "Host:", 5)==0) {
		i=5;
		while (h[i]==' ') i++;
		conn->hostName=&h[i];
	} else if (os_strncmp(h, "POST ", 5)==0) {
		conn->requestType = HTTPD_METHOD_POST;
		first_line = true;
	}

	if (first_line) {
		char *e;

		//Skip past the space after POST/GET
		i=0;
		while (h[i]!=' ') i++;
		conn->url=h+i+1;

		//Figure out end of url.
		e=(char*)os_strstr(conn->url, " ");
		if (e==NULL) return; // ?
		*e=0; //terminate url part

		//Parse out the URL part before the GET parameters.
		conn->getArgs=(char*)os_strstr(conn->url, "?");
		if (conn->getArgs!=0) {
			*conn->getArgs=0;
			conn->getArgs++;
			TESTP("GET args = %s\n", conn->getArgs);
		} else {
			conn->getArgs=NULL;
		}
	}
}
示例#29
0
文件: http.c 项目: Daven005/ESP8266
bool ICACHE_FLASH_ATTR tcp_listen(unsigned int port) {
	int ret;

	httpConn.type = ESPCONN_TCP;
	httpConn.state = ESPCONN_NONE;
	httpConn.proto.tcp = &httpTcp;
	httpConn.proto.tcp->local_port = port;

	espconn_regist_connectcb(&httpConn, tcp_connect_cb);
	espconn_regist_reconcb(&httpConn, tcp_reconnect_cb);
	espconn_regist_disconcb(&httpConn, tcp_disconnect_cb);

	ret = espconn_accept(&httpConn);
	espconn_regist_time(&httpConn, 15, 0); //timeout

	if (ret != ESPCONN_OK) {
		TESTP("Error when starting the listener: %d.\n", ret);
		ets_delay_us(2000);
		return false;
	}
	return true;
}
示例#30
0
static int compare_iotask( volatile iotask_t* iotask,
   int err, size_t bytesrw, iostate_e state,
   ioop_e op, iochannel_t ioc, off_t off,
   void* bufaddr, size_t bufsize, eventcount_t* counter)
{
   TEST(iotask->iolist_next == 0);
   if (err) {
   TEST(iotask->err        == err);
   } else {
   TESTP(iotask->bytesrw   == bytesrw, "expect:%zu read:%zu", bytesrw, iotask->bytesrw);
   }
   TEST(iotask->state      == state);
   TEST(iotask->op         == op);
   TEST(iotask->ioc        == ioc);
   TEST(iotask->offset     == off);
   TEST(iotask->bufaddr    == bufaddr);
   TEST(iotask->bufsize    == bufsize);
   TEST(iotask->readycount == counter);

   return 0;
ONERR:
   return EINVAL;
}