Exemplo n.º 1
0
void RS485::setup(int32_t userID, int32_t groupID)
{
	try
	{
		setDevicePermission(userID, groupID);
		if(_settings->gpio.find(1) != _settings->gpio.end())
		{
			exportGPIO(1);
			setGPIOPermission(1, userID, groupID, false);
			setGPIODirection(1, GPIODirection::OUT);
		}
		if(_settings->gpio.find(2) != _settings->gpio.end())
		{
			exportGPIO(2);
			setGPIOPermission(2, userID, groupID, false);
			setGPIODirection(2, GPIODirection::OUT);
		}
	}
    catch(const std::exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(BaseLib::Exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
Exemplo n.º 2
0
int main(void){

	int ret = -1;
	/*Init Led port*/
	if((ret = exportGPIOPin(led0.pin)) == -1){
		printf("exportGPIO(%d)failed\n", led0.pin);
	}
	if((ret = setGPIODirection(led0.pin, GPIO_OUT)) == -1){
		
		printf("setGPIODirection(%d)failed\n", led0.pin);
	}



	if((sockfd = socket(AF_INET, SOCK_STREAM,0))==-1){
	perror("socket");
	exit(1);	
	};

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(SERV_PORT);

	if(bind(sockfd, (struct sockaddr *)&servaddr,sizeof(servaddr)) == -1){
		perror("bind error");
		exit(1);
	}
	if(listen(sockfd,10)<0){  
		perror("listen");  
		exit(1);  
	}
	do_echo(sockfd);
	return 0;
}
Exemplo n.º 3
0
void TICC1100::setup(int32_t userID, int32_t groupID)
{
	try
	{
		_out.printDebug("Debug: CC1100: Setting device permissions");
		setDevicePermission(userID, groupID);
		_out.printDebug("Debug: CC1100: Exporting GPIO");
		exportGPIO(1);
		_out.printDebug("Debug: CC1100: Setting GPIO permissions");
		setGPIOPermission(1, userID, groupID, true);
		_out.printDebug("Debug: CC1100: Setting GPIO direction");
		setGPIODirection(1, GPIODirection::IN);
		_out.printDebug("Debug: CC1100: Settings GPIO edge");
		setGPIOEdge(1, GPIOEdge::BOTH);
	}
    catch(const std::exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(BaseLib::Exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
Exemplo n.º 4
0
void TICC1100::initDevice()
{
	try
	{
		openDevice();
		if(!_fileDescriptor || _fileDescriptor->descriptor == -1) return;

		initChip();
		_out.printDebug("Debug: CC1100: Setting GPIO direction");
		setGPIODirection(1, GPIODirection::IN);
		_out.printDebug("Debug: CC1100: Setting GPIO edge");
		setGPIOEdge(1, GPIOEdge::BOTH);
		openGPIO(1, true);
		if(!_gpioDescriptors[1] || _gpioDescriptors[1]->descriptor == -1) throw(BaseLib::Exception("Couldn't listen to rf device, because the gpio pointer is not valid: " + _settings->device));
		if(gpioDefined(2)) //Enable high gain mode
		{
			openGPIO(2, false);
			if(!getGPIO(2)) setGPIO(2, true);
			closeGPIO(2);
		}
	}
    catch(const std::exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(BaseLib::Exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
Exemplo n.º 5
0
void TICC1100::setup(int32_t userID, int32_t groupID)
{
	try
	{
		_out.printDebug("Debug: CC1100: Setting device permissions");
		setDevicePermission(userID, groupID);
		_out.printDebug("Debug: CC1100: Exporting GPIO");
		exportGPIO(1);
		if(gpioDefined(2)) exportGPIO(2);
		_out.printDebug("Debug: CC1100: Setting GPIO permissions");
		setGPIOPermission(1, userID, groupID, false);
		if(gpioDefined(2)) setGPIOPermission(2, userID, groupID, false);
		if(gpioDefined(2)) setGPIODirection(2, GPIODirection::OUT);
	}
    catch(const std::exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(BaseLib::Exception& ex)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
        _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
int THmonitoring_init() {
	//LED	
	if ((exportGPIOPin(LEDpin)) == -1) {   
	        printf("exportGPIOPin(%d) failed\n", LEDpin);
		return -1;
	}
        if ((setGPIODirection(LEDpin, GPIO_OUT)) == -1) {
        	printf("setGPIODirection(%d) failed\n", LEDpin);
		return -1;
    	}
	//LCD
        if ((devFD_LCD = LCD1602Init()) == -1) {
        	printf("Fail to init LCD1602\n");
        	return -1;
        }
	if (LCD1602Clear(devFD_LCD) == -1) {
		printf("Fail to Clear\n");
		return -1;
	}
	//dht11
	if ((devFD_DHT11 = dht11Init(DHT11pin)) == -1) {
        	printf("Fail to init dht11\n");
        	return -1;
        }
	return 0;
}
Exemplo n.º 7
0
int main(int argc, char ** argv)
{
    char *status = "off";
    if (argc != 2) {
        printf("Set relay on\n");
    } else {
        status = argv[1];
        printf("Set relay %s\n", argv[1]);
    }

    int pin = GPIO_PIN(7);
    int ret = -1;
    boardInit();
    if ((ret = exportGPIOPin(pin)) == -1) {	
        printf("exportGPIOPin(%d) failed!", pin);
    }
    if ((ret = setGPIODirection(pin, GPIO_OUT)) != 0) {
        printf("setGPIODirection(%d) failed", pin);
    }

    if (strcmp(status, "on") == 0) {
        ret = setGPIOValue(pin, GPIO_HIGH);
    } else if (strcmp(status, "off") == 0) {
        ret = setGPIOValue(pin, GPIO_LOW);
    }
    return ret;
}
Exemplo n.º 8
0
int doorbell_init() {
    //sensor init
    if ((devFD = sensorInit(sensor_dev, ARRAY_SIZE(sensor_dev))) == -1) {
        printf("Fail to init sensor sound\n");
        return -1;
    }

    //LED init
    if ((exportGPIOPin(LEDpin)) == -1) {
        printf("exportGPIOPin(%d) failed\n", LEDpin);
        return -1;
    }
    if ((setGPIODirection(LEDpin, GPIO_OUT)) == -1) {
        printf("setGPIODirection(%d) failed\n", LEDpin);
        return -1;
    }
    return 0;
}
Exemplo n.º 9
0
int main(int argc, char ** argv) 
{
    int pin = GPIO_PIN(7); 
    int i, value, board;
    int ret = -1;
    
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
    if (board == BOARD_NANOPC_T2 || board == BOARD_NANOPC_T3)
        pin = GPIO_PIN(15);
    
    if (argc == 2)
        pin = GPIO_PIN(atoi(argv[1]));
    if ((ret = exportGPIOPin(pin)) == -1) {   
        printf("exportGPIOPin(%d) failed\n", pin);
    }
    if ((ret = setGPIODirection(pin, GPIO_OUT)) == -1) {
        printf("setGPIODirection(%d) failed\n", pin);
    }
    for (i = 0; i < STATUS_CHANGE_TIMES; i++) {
        if (i % 2) {
            value = GPIO_HIGH;
        } else {
            value = GPIO_LOW;
        }
        if ((ret = setGPIOValue(pin, value)) > 0) {
            printf("%d: GPIO_PIN(%d) value is %d\n", i+1, pin, value);
        } else {
            printf("setGPIOValue(%d) failed\n", pin);
        }
        sleep(1);
    }
    unexportGPIOPin(pin);
    return 0;
}
Exemplo n.º 10
0
int main(void){

	int ret = -1;
	int i = 0;
	pthread_t pt_1 = 0;
	size_t len =  sizeof(struct sockaddr);;
	/*Init Led port*/
	if((ret = exportGPIOPin(led0.pin)) == -1){
		printf("exportGPIO(%d)failed\n", led0.pin);
	}
	if((ret = setGPIODirection(led0.pin, GPIO_OUT)) == -1){
		
		printf("setGPIODirection(%d)failed\n", led0.pin);
	}


	//Initialize socket
	if((sockfd = socket(AF_INET, SOCK_STREAM,0))==-1){
	perror("socket");
	exit(1);	
	};

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(SERV_PORT);

	if(bind(sockfd, (struct sockaddr *)&servaddr,sizeof(servaddr)) == -1){
		perror("bind error");
		exit(1);
	}
	if(listen(sockfd,10)<0){  
		perror("listen");  
		exit(1);  
	}
	//Initalize UART2
	if((uartfd=open_port(uartfd,4)) < 0)//打开串口 1
	{
		perror("open_port error1\n");
		exit(1);
	}
	if((i=set_opt(uartfd,9600,8,'N',1)) < 0)//设置串口 9600 8 N 1
	{
		perror("set_opt error1\n");
		exit(1);
	}

	clifd = accept(sockfd, (struct sockaddr *)&cliaddr, (int *)&len);
	if(clifd < 0){
		perror("error accept\n");
	}
	//Create Thread to send CMD from uart to wifi
	ret = pthread_create (&pt_1, NULL, pthread_UART2WiFi, NULL);
	if (ret != 0)
	{
	 perror ("pthread_1_create");
	}
	//Receive data from wifi to uart
	wifi2uart(sockfd);

	//wait pthread
	pthread_join (pt_1, NULL);
	close(clifd);
	close(sockfd);
	return 0;
}