Example #1
0
int main(int argc, char *argv[])
{
    log_init(LOG_LEVEL_E, LOG_MODE_PRINT);

    log_v("log level is LOG_LEVEL_E version log\n");
    log_d("log level is LOG_LEVEL_E debug log\n");
    log_e("log level is LOG_LEVEL_E error log\n");

    log_init(LOG_LEVEL_D, LOG_MODE_PRINT);

    log_v("log level is LOG_LEVEL_D version log\n");
    log_d("log level is LOG_LEVEL_D debug log\n");
    log_e("log level is LOG_LEVEL_D error log\n");

    log_init(LOG_LEVEL_V, LOG_MODE_PRINT);

    log_v("log level is LOG_LEVEL_V version log\n");
    log_d("log level is LOG_LEVEL_V debug log\n");
    log_e("log level is LOG_LEVEL_V error log\n");

    log_init(LOG_LEVEL_V, LOG_MODE_FILE);

    log_v("log level is LOG_LEVEL_V version log\n");
    log_d("log level is LOG_LEVEL_V debug log\n");
    log_e("log level is LOG_LEVEL_V error log\n");


    return 0;
}
Example #2
0
bool Config::check_paths()
{
	bool fail = false;

	if(!check_file_readable(share_path+"/extensions/test/init.lua")){
		log_e(MODULE, "Static files don't seem to exist in share_path=\"%s\"",
				cs(share_path));
		fail = true;
	}
	else if(!check_file_readable(share_path+"/client/init.lua")){
		log_e(MODULE, "Static files don't seem to exist in share_path=\"%s\"",
				cs(share_path));
		fail = true;
	}

	if(!check_file_readable(urho3d_path +
			"/Bin/CoreData/Shaders/GLSL/Basic.glsl")){
		log_e(MODULE, "Urho3D doesn't seem to exist in urho3d_path=\"%s\"",
				cs(urho3d_path));
		fail = true;
	}

	auto *fs = interface::getGlobalFilesystem();
	fs->create_directories(cache_path);
	if(!check_file_writable(cache_path+"/write.test")){
		log_e(MODULE, "Cannot write into cache_path=\"%s\"", cs(cache_path));
		fail = true;
	}

	return !fail;
}
Example #3
0
static bool _start_network_event_task(){
    if(!_network_event_group){
        _network_event_group = xEventGroupCreate();
        if(!_network_event_group){
            log_e("Network Event Group Create Failed!");
            return false;
        }
        xEventGroupSetBits(_network_event_group, WIFI_DNS_IDLE_BIT);
    }
    if(!_network_event_queue){
        _network_event_queue = xQueueCreate(32, sizeof(system_event_t *));
        if(!_network_event_queue){
            log_e("Network Event Queue Create Failed!");
            return false;
        }
    }
    if(!_network_event_task_handle){
        xTaskCreatePinnedToCore(_network_event_task, "network_event", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_network_event_task_handle, ARDUINO_RUNNING_CORE);
        if(!_network_event_task_handle){
            log_e("Network Event Task Start Failed!");
            return false;
        }
    }
    return esp_event_loop_init(&_network_event_cb, NULL) == ESP_OK;
}
Example #4
0
bool AsyncClient::connect(IPAddress ip, uint16_t port){
    if (_pcb){
        log_w("already connected, state %d", _pcb->state);
        return false;
    }
    if(!_start_async_task()){
        log_e("failed to start task");
        return false;
    }

    ip_addr_t addr;
    addr.type = IPADDR_TYPE_V4;
    addr.u_addr.ip4.addr = ip;

    tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
    if (!pcb){
        log_e("pcb == NULL");
        return false;
    }

    tcp_arg(pcb, this);
    tcp_err(pcb, &_tcp_error);
    if(_in_lwip_thread){
        tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
    } else {
        _tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
    }
    return true;
}
Example #5
0
static int set_sdl_video_size(unsigned short int w, unsigned short int h)
{
	if (window)
		SDL_DestroyWindow(window);
	if (!w || !h) {
		w = 640;
		h = 480;
		if (flags & SDL_WINDOW_FULLSCREEN) {
			SDL_DisplayMode mode;
			if (!SDL_GetDesktopDisplayMode(0, &mode)) {
				w = mode.w;
				h = mode.h;
			} else
				log_e("SDL_GetDesktopDisplayMode: %s",
				      SDL_GetError());
		}
	}
	log_i("%ux%u", w, h);
	window = SDL_CreateWindow("greedy",
				  SDL_WINDOWPOS_CENTERED,
				  SDL_WINDOWPOS_CENTERED,
				  w, h, flags);
	if (!window)
		log_p("SDL_CreateWindow: %s", SDL_GetError());
	SDL_Delay(50);
	return 0;
}
Example #6
0
unsigned int
shader_create_shader(GLenum type, const char* source)
{
    GLuint shader = glCreateShader(type);
	GLint compiled;
	GLint infoLen;
	char* buf;

    if (shader) {
        glShaderSource(shader, 1, &source, NULL);
        glCompileShader(shader);
        compiled = 0;
        glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
        if (!compiled) {
            infoLen = 0;
            glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
            if (infoLen) {
                buf = (char*) malloc(infoLen);
                if (buf) {
                    glGetShaderInfoLog(shader, infoLen, NULL, buf);
                    log_e("Could not compile shader type %d (%s)\n%s\n",
                            type, buf, source);
                    free(buf);
                }
                glDeleteShader(shader);
                shader = 0;
            }
        }
    }
    return shader;
}
Example #7
0
int8_t AsyncServer::_accept(tcp_pcb* pcb, int8_t err){
    tcp_accepted(_pcb);
    if(_connect_cb){

        if (_noDelay)
            tcp_nagle_disable(pcb);
        else
            tcp_nagle_enable(pcb);

        AsyncClient *c = new AsyncClient(pcb);
        if(c){
            _in_lwip_thread = true;
            c->_in_lwip_thread = true;
            _connect_cb(_connect_cb_arg, c);
            c->_in_lwip_thread = false;
            _in_lwip_thread = false;
            return ERR_OK;
        }
    }
    if(tcp_close(pcb) != ERR_OK){
        tcp_abort(pcb);
    }
    log_e("FAIL");
    return ERR_OK;
}
Example #8
0
/* @stickBreaker 11/2017 fix for ReSTART timeout, ISR
 */
uint8_t TwoWire::requestFrom(uint16_t address, uint8_t size, bool sendStop)
{
    //use internal Wire rxBuffer, multiple requestFrom()'s may be pending, try to share rxBuffer
    uint32_t cnt = rxQueued; // currently queued reads, next available position in rxBuffer
    if(cnt < (I2C_BUFFER_LENGTH-1) && (size + cnt) <= I2C_BUFFER_LENGTH) { // any room left in rxBuffer
        rxQueued += size;
    } else { // no room to receive more!
        log_e("rxBuff overflow %d", cnt + size);
        cnt = 0;
        last_error = I2C_ERROR_MEMORY;
        flush();
        return cnt;
    }

    last_error = readTransmission(address, &rxBuffer[cnt], size, sendStop, &cnt);
    rxIndex = 0;
  
    rxLength = cnt;
  
    if( last_error != I2C_ERROR_CONTINUE){ // not a  buffered ReSTART operation
      // so this operation actually moved data, queuing is done.
        rxQueued = 0;
        txQueued = 0; // the SendStop=true will restart all Queueing or error condition
    }
  
    if(last_error != I2C_ERROR_OK){ // ReSTART on read does not return any data
        cnt = 0;
    }
  
    return cnt;
}
Example #9
0
bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
{
    if(sdaPin < 0) { // default param passed
        if(num == 0) {
            if(sda==-1) {
                sdaPin = SDA;    //use Default Pin
            } else {
                sdaPin = sda;    // reuse prior pin
            }
        } else {
            if(sda==-1) {
                log_e("no Default SDA Pin for Second Peripheral");
                return false; //no Default pin for Second Peripheral
            } else {
                sdaPin = sda;    // reuse prior pin
            }
        }
    }

    if(sclPin < 0) { // default param passed
        if(num == 0) {
            if(scl == -1) {
                sclPin = SCL;    // use Default pin
            } else {
                sclPin = scl;    // reuse prior pin
            }
        } else {
            if(scl == -1) {
                log_e("no Default SCL Pin for Second Peripheral");
                return false; //no Default pin for Second Peripheral
            } else {
                sclPin = scl;    // reuse prior pin
            }
        }
    }

    sda = sdaPin;
    scl = sclPin;
    i2c = i2cInit(num, sdaPin, sclPin, frequency);
    if(!i2c) {
        return false;
    }

    flush();
    return true;

}
Example #10
0
static bool check_file_readable(const ss_ &path)
{
	std::ifstream ifs(path);
	bool readable = ifs.good();
	if(!readable)
		log_e(MODULE, "File is not readable: \"%s\"", cs(path));
	return readable;
}
Example #11
0
static bool check_file_writable(const ss_ &path)
{
	std::ofstream ofs(path);
	bool writable = ofs.good();
	if(!writable)
		log_e(MODULE, "File is not writable: \"%s\"", cs(path));
	return writable;
}
Example #12
0
/**
 * Elog demo
 */
static void test_elog(void) {
    log_a("Hello EasyLogger!");
    log_e("Hello EasyLogger!");
    log_w("Hello EasyLogger!");
    log_i("Hello EasyLogger!");
    log_d("Hello EasyLogger!");
    log_v("Hello EasyLogger!");
    //elog_raw("Hello EasyLogger!");
}
Example #13
0
/**
 * EasyLogger demo
 */
void test_elog(void) {
    /* test log output for all level */
    log_a("Hello EasyLogger!");
    log_e("Hello EasyLogger!");
    log_w("Hello EasyLogger!");
    log_i("Hello EasyLogger!");
    log_d("Hello EasyLogger!");
    log_v("Hello EasyLogger!");
//    elog_raw("Hello EasyLogger!");
}
Example #14
0
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms)
{
    if(0 > _uart_nr || _uart_nr > 2) {
        log_e("Serial number is invalid, please use 0, 1 or 2");
        return;
    }
    if(_uart) {
        end();
    }
    if(_uart_nr == 0 && rxPin < 0 && txPin < 0) {
        rxPin = 3;
        txPin = 1;
    }
    if(_uart_nr == 1 && rxPin < 0 && txPin < 0) {
        rxPin = RX1;
        txPin = TX1;
    }
    if(_uart_nr == 2 && rxPin < 0 && txPin < 0) {
        rxPin = RX2;
        txPin = TX2;
    }

    _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);

    if(!baud) {
        time_t startMillis = millis();
        unsigned long detectedBaudRate = 0;
        while(millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) {
            yield();
        }

        end();

        if(detectedBaudRate) {
            delay(100); // Give some time...
            _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert);
        } else {
            log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
            _uart = NULL;
        }
    }
}
Example #15
0
QStringList rpnoc::Profile::readXml( const QString &iUsername )
{
	QString oUser, oPass, oAddr, oPort;
	QString oUserName = iUsername.toLower();
	QFile oFile("profiles/" + oUserName + "/" + oUserName + ".xml");

	if( !oFile.open( QIODevice::ReadOnly ) ) {
		log_e( "Failed to open file '" + oFile.errorString() + "' for reading." );
	}

	QXmlStreamReader oReader;
	oReader.setDevice( &oFile );

	oReader.readNext();
	while(!oReader.atEnd()){
		if(oReader.isStartElement()){
			if(oReader.name() == "personalia"){
				oReader.readNext();
				while(!oReader.atEnd()){
					if(oReader.isEndElement()){
						oReader.readNext();
					}
					if(oReader.isStartElement()){
						if(oReader.name() == "user"){
							oUser = oReader.attributes().value("username").toString();
							oReader.readNext();
						}else if(oReader.name() == "pass"){
							oPass = oReader.attributes().value("password").toString();
							oReader.readNext();
						}else if(oReader.name() == "addr"){
							oAddr = oReader.attributes().value("address").toString();
							oReader.readNext();
						}else if(oReader.name() == "port"){
							oPort = oReader.attributes().value("portnr").toString();
							oReader.readNext();
						}
					}else{
						oReader.readNext();
					}
				}
			}else{
				oReader.raiseError(QObject::tr("Not a user file"));
			}
		}else{
			oReader.readNext();
		}
	}

	oFile.close();

	QStringList oStringList;
	oStringList << oUser << oPass << oAddr << oPort;
	return oStringList;
}
Example #16
0
static int initialize_sdl()
{
	int error = 0;
	if (sdl_count++)
		return 0;
	if ((error = SDL_Init(0))) {
		log_e("SDL_Init: %s\n.", SDL_GetError());
		sdl_count = 0;
	}
	return error;
}
Example #17
0
bool AsyncClient::connect(const char* host, uint16_t port){
    ip_addr_t addr;
    err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_s_dns_found, this);
    if(err == ERR_OK) {
        return connect(IPAddress(addr.u_addr.ip4.addr), port);
    } else if(err == ERR_INPROGRESS) {
        _connect_port = port;
        return true;
    }
    log_e("error: %d", err);
    return false;
}
Example #18
0
void AsyncClient::_dns_found(ip_addr_t *ipaddr){
    _in_lwip_thread = true;
    if(ipaddr){
        connect(IPAddress(ipaddr->u_addr.ip4.addr), _connect_port);
    } else {
        log_e("dns fail");
        if(_error_cb)
            _error_cb(_error_cb_arg, this, -55);
        if(_discard_cb)
            _discard_cb(_discard_cb_arg, this);
    }
    _in_lwip_thread = false;
}
Example #19
0
bool rpnoc::Profile::writeXml( const QString &iFilename, QStringList *iItem )
{
	QString oFileName = iFilename.toLower();
	QFile oFile( oFileName );
	if( !oFile.open( QFile::ReadWrite | QFile::Text ) ) {
		log_e( "Failed to open file '" + iFilename + "'." + log_endl + oFile.errorString() );
		return false;
	}

	QXmlStreamWriter oWriter( &oFile );
	oWriter.setAutoFormatting( true );
	oWriter.writeStartDocument();
	oWriter.writeStartElement( "Profile" );
	writeIndexEntry( &oWriter, iItem );
	oWriter.writeEndDocument();
	
	oFile.close();
	if( oFile.error() ) {
		log_e( "Failed to close file '" + iFilename + "'." + log_endl + oFile.errorString() );
		return false;
	}
	return true;
}
Example #20
0
/**
 * Elog demo
 */
static void test_elog(void) {
    /* output all saved log from flash */
    elog_flash_output_all();
    /* test log output for all level */
    log_a("Hello EasyLogger!");
    log_e("Hello EasyLogger!");
    log_w("Hello EasyLogger!");
    log_i("Hello EasyLogger!");
    log_d("Hello EasyLogger!");
    log_v("Hello EasyLogger!");
    elog_raw("Hello EasyLogger!");
    /* trigger assert. Now will run elog_user_assert_hook. All log information will save to flash. */
    ELOG_ASSERT(0);
}
Example #21
0
static bool espWiFiStop(){
    esp_err_t err;
    if(!_esp_wifi_started){
        return true;
    }
    _esp_wifi_started = false;
    err = esp_wifi_stop();
    if(err){
        log_e("Could not stop WiFi! %u", err);
        _esp_wifi_started = true;
        return false;
    }
    return wifiLowLevelDeinit();
}
Example #22
0
void AsyncServer::begin(){
    if(_pcb)
        return;

    if(!_start_async_task()){
        log_e("failed to start task");
        return;
    }
    int8_t err;
    _pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
    if (!_pcb){
        log_e("_pcb == NULL");
        return;
    }

    ip_addr_t local_addr;
    local_addr.type = IPADDR_TYPE_V4;
    local_addr.u_addr.ip4.addr = (uint32_t) _addr;
    err = _tcp_bind(_pcb, &local_addr, _port);

    if (err != ERR_OK) {
        _tcp_close(_pcb);
        log_e("bind error: %d", err);
        return;
    }

    static uint8_t backlog = 5;
    _pcb = _tcp_listen_with_backlog(_pcb, backlog);
    //_pcb = _tcp_listen(_pcb);
    if (!_pcb) {
        log_e("listen_pcb == NULL");
        return;
    }
    tcp_arg(_pcb, (void*) this);
    tcp_accept(_pcb, &_s_accept);
}
Example #23
0
bool init_mutex()
{
    if (pthread_cond_init(&file_cond, NULL)) {
        log_e("A condition variable for file finding was not able to initialize.");
        return false;
    }

    if (pthread_cond_init(&print_cond, NULL)) {
        log_e("A condition variable for print result was not able to initialize.");
        return false;
    }

    if (pthread_mutex_init(&file_mutex, NULL)) {
        log_e("A mutex for file finding was not able to initialize.");
        return false;
    }

    if (pthread_mutex_init(&print_mutex, NULL)) {
        log_e("A mutex for print result was not able to initialize.");
        return false;
    }

    return true;
}
Example #24
0
static int initialize_sdl_video()
{
	if (initialize_sdl())
		return -1;
	if (SDL_InitSubSystem(SDL_INIT_VIDEO)) {
		log_e("%s", SDL_GetError());
		return -1;
	}
	if (get_console_fullscreen()) {
		SDL_ShowCursor(SDL_DISABLE);
		flags |= SDL_WINDOW_FULLSCREEN;
	} else
		flags &= ~SDL_WINDOW_FULLSCREEN;
	return 0;
}
Example #25
0
static bool wifiLowLevelInit(bool persistent){
    if(!lowLevelInitDone){
        tcpipInit();
        wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
        esp_err_t err = esp_wifi_init(&cfg);
        if(err){
            log_e("esp_wifi_init %d", err);
            return false;
        }
        if(!persistent){
          esp_wifi_set_storage(WIFI_STORAGE_RAM);
        }
        lowLevelInitDone = true;
    }
    return true;
}
Example #26
0
static void recover_ghosts_den(struct level *self, struct layout *layout)
{
	int xs, ys, xd, yd;
	struct level_iterator iter;
	struct place *closest_place = NULL;
	unsigned int distance, min_distance = LEVEL_WIDTH + LEVEL_HEIGHT;
	if (!self->ghosts_home)
		return;
	place_location(self, self->ghosts_home, &xs, &ys);
	if (is_place_clear(layout, xs, ys))
		return;
	log_i("recovering from non-accessible ghosts den.");
	initialize_level_iterator(&iter, self);
	while (level_iterator_has_next(&iter)) {
		struct place *place = level_iterator_next(&iter);
		place_location(self, place, &xd, &yd);
		distance = (xs > xd ? xs - xd : xd - xs) +
			(ys > yd ? ys - yd : yd - ys);
		if (distance && distance < min_distance) {
			closest_place = place;
			min_distance = distance;
		}
	}
	if (!closest_place) {
		log_e("could not find the closest place to ghost den.");
		return;
	}
	if (min_distance > ghost_den_recovery_radius) {
		log_w("could not find a place close enough to ghost den "
		      "(%u > %u).", min_distance, ghost_den_recovery_radius);
		return;
	}
	place_location(self, closest_place, &xd, &yd);
	while (--min_distance) {
		if (xs < xd)
			xs += 1;
		else if (xs > xd)
			xs -= 1;
		else if (ys < yd)
			ys += 1;
		else if (ys > yd)
			ys -= 1;
		__get_place(self, xs, ys)->item = clone_empty(self->items);
	}
}
Example #27
0
/** Loads configuration string in app_config_buffer. */
static int8_t
_app_config_load_microSD()
{
  int fd;

  // And open it
  fd = cfs_open("inga.cfg", CFS_READ);

  // In case something goes wrong, we cannot save this file
  if (fd == -1) {
    log_e("Failed opening config file\n");
    return -1;
  }


  // do nothing if modification timestamp of file is older/equal than stored
#if CONF_FILE_TIMESTAMP_CHECK
  log_i("Checking config file timestamp...\n");
  if ((cfs_fat_get_last_date(fd) <= system_config._mod_date)
          && (cfs_fat_get_last_time(fd) <= system_config._mod_time)) {
    log_i("Config file is older than stored config, will not be loaded\n");
    cfs_close(fd);
    return -1;
  }
#endif

  // update modification timestamps
  system_config._mod_date = cfs_fat_get_last_date(fd);
  system_config._mod_time = cfs_fat_get_last_time(fd);


  int size = cfs_read(fd, app_config_buffer, MAX_FILE_SIZE);
  app_config_buffer[size] = '\0'; // string null terminator
  log_v("actually read: %d\n", size);
  log_i("Loaded data from microSD card\n");

  cfs_close(fd);

  parse_ini(app_config_buffer, &inga_conf_file);

  app_config_update();

  return 0;
}
Example #28
0
/**
 * Resolve the given hostname to an IP address.
 * @param aHostname     Name to be resolved
 * @param aResult       IPAddress structure to store the returned IP address
 * @return 1 if aIPAddrString was successfully converted to an IP address,
 *          else error code
 */
int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult)
{
    ip_addr_t addr;
    aResult = static_cast<uint32_t>(0);
    waitStatusBits(WIFI_DNS_IDLE_BIT, 5000);
    clearStatusBits(WIFI_DNS_IDLE_BIT);
    err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
    if(err == ERR_OK && addr.u_addr.ip4.addr) {
        aResult = addr.u_addr.ip4.addr;
    } else if(err == ERR_INPROGRESS) {
        waitStatusBits(WIFI_DNS_DONE_BIT, 4000);
        clearStatusBits(WIFI_DNS_DONE_BIT);
    }
    setStatusBits(WIFI_DNS_IDLE_BIT);
    if((uint32_t)aResult == 0){
        log_e("DNS Failed for %s", aHostname);
    }
    return (uint32_t)aResult != 0;
}
Example #29
0
static void crash_pad(int signum)
{
	switch (signum) {
	case SIGINT:  log_e(_s("interruption")); break;
	case SIGTERM: log_e(_s("termination request")); break;
	case SIGABRT: log_e(_s("aborting")); break;
	case SIGFPE:  log_e(_s("floating point exception")); break;
	case SIGILL:  log_e(_s("illegal instruction")); break;
	case SIGSEGV: log_e(_s("segmentation fault")); break;
	default:
		logf_e("caught signal #%d", signum);
	}
	exit(EXIT_FAILURE);
}
Example #30
0
static bool espWiFiStart(bool persistent){
    if(_esp_wifi_started){
        return true;
    }
    if(!wifiLowLevelInit(persistent)){
        return false;
    }
    esp_err_t err = esp_wifi_start();
    if (err != ESP_OK) {
        log_e("esp_wifi_start %d", err);
        wifiLowLevelDeinit();
        return false;
    }
    _esp_wifi_started = true;
    system_event_t event;
    event.event_id = SYSTEM_EVENT_WIFI_READY;
    WiFiGenericClass::_eventCallback(nullptr, &event);

    return true;
}