21
OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI Bitwise operators in Web applications and its use for home automation applications with Raspberry Pi Autores: MsC. Henry Raúl González Brito, MsC.Dainys Gainza Reyes Universidad de las Ciencias Informáticas email: [email protected]

OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Embed Size (px)

Citation preview

Page 1: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

OPERADORES A NIVEL DE BITS EN

APLICACIONES WEB Y SU

UTILIZACIÓN EN LA DOMÓTICA CON

RASPBERRY PI

Bitwise operators in Web applications and its use for

home automation applications with Raspberry Pi

Autores:

MsC. Henry Raúl González Brito, MsC.Dainys Gainza Reyes

Universidad de las Ciencias Informáticas

email: [email protected]

Page 2: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Domótica

Agrupan un conjunto de tecnologías en la creación de

sistemas para automatizar las operaciones de recintos

cerrados como oficinas, viviendas o un auto.

• Gestión energética

• Seguridad

• Accesibilidad

• Confort

• Gestión de diferentes parámetros de funcionamientos de manera

remota, tanto desde el interior como desde el exterior

Page 3: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Internet de las Cosas

• La interconexión a través de internet de dispositivos como

electrodomésticos, maquinarias, sensores.

• Producción de Datos y su aplicación inteligente por los

dispositivos.

• Interrelaciones:

• Dispositivo – Dispositivo

• Persona – Dispositivo

• Dispositivo - Persona

Page 4: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Internet de las Cosas

Nevera realizando compras a través de

internet, sugiriendo platos a preparar y

chateando con el dueño a través de LINE.

Autos que se controlan a través de

Internet e informan de sus parámetros de

funcionamiento.

Red de sensores en un bosque, avisando

por Twitter a los guardabosques si hay un

incendio.

Page 5: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Características importantes

• Hardware (Bajo Costo, Consumo de Energía

Discreto, Inteligente, Dimensiones reducidas)

• Datos (Producción continua de datos, Big Data, uso

de estos)

• Velocidad de respuesta (Percepción del usuario)

• Interfaz de Usuario(Simple y Directa)

Page 6: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Raspberry Pi

• Computador de bajo Costo Creado para estimular el

aprendizaje de la programación desde edades tempranas

en el Reino Unido.

• CPU 700 MHz, RAM 512 MB, no trae Almacenamiento

Interno ni Fuente de Alimentación.

• O.S Linux Raspbian(Debian), RISC OS 5, Arch Linux

ARM, Pidora, entre otros.

Page 7: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Puertos

USB

(MOUSE Y

TECLADO)

Salida VGA

(Monitor TV)

Puerto SD Card Almacenamiento (SD 8 GB)

Puerto de

Alimentación 5V

Micro USB

Puerto de

Red RJ-45

GPIO

Page 8: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

GPIO (General Purpose Input/Output)

Configurados para ser de entrada o de salida.

Pueden activarse o desactivarse.

Leer valores de entrada y salida.

Page 9: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Capa de Presentación

Javascript/AJAX

Page 10: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Capa de Lógica de Negocio

PHP 5.4

RPi.GPIO

Page 12: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

• Actúan sobre los bits individuales de la representación

binaria de un número entero sin signo.

• Operaciones soportadas directamente por el CPU por lo

que son operaciones muy rápidas.

Posición

Operadores a nivel de bits

Operaciones bit a bit

Operaciones de Desplazamiento

Operaciones de Rotación

7 6 5 4 3 2 1 0

0 0 0 1 0 0 0 0

Valor

Page 13: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Aplicaciones en la Domótica

• Compresión de datos.

• Incremento en la velocidad de las operaciones.

• Codificación más simple.

7 6 5 4 3 2 1 0

0 0 0 1 0 0 0 0

Encendido/Apagado Abierto/cerrado 0-31 ºC

Page 14: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Operadores a nivel de bits en los

Lenguajes de Programación

Lenguaje de Programación AND OR NOT XOR

Python & | ~ ^

JavaScript & | ~ ^

PHP & | ~ ^

Page 15: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Aplicación del operador AND

Comprobar el

estado de un bit.

7 6 5 4 3 2 1 0

0 0 0 1 0 0 0 0

Bit de Interés

0 0 0 0 0 1 0 0

0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0Apagado de bits.

Extracción de bit.

Page 16: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Aplicación del operador XOR

Invertir selectivamente

los bits de un número

entero

7 6 5 4 3 2 1 0

0 0 0 1 0 0 0 0

Bit de Interés

0 0 0 0 0 1 0 0

Page 17: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Ejemplo XOR

00000110 (6)

XOR 00000010 (2)

---------------------

00000100 (4)

Lámpara L en la Posición 1:

Máscara de la Lámpara L:

00000100

00000010 (2)

00000100 (4)

XOR 00000010 (2)

----------------------

00000110 (6)

A

B C

Page 18: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Cambio de estado con XOR

1.<input id="LAMP1" type=image src="ON.ico“ onclick="set_state(2)">

CAPA DE PRESENTACIÓN

CAPA DE LÓGICA DE NEGOCIO

3.$datumToWrite = $statusDatum ^ $datum;

2.xmlhttp.open ("GET","actualizador.php?st="+st);

Lámpara Máscara

L0 00000001

L1 00000010

L3 00000100

Page 19: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Actualización de estado con AND

5. stateNumberLEDTmp = stateDatum & 2;

if (stateNumberLEDTmp==0){

document.getElementById("LAMP1").src="OFF.ICO";

}else{

document.getElementById("LAMP1").src="ON.ICO";

}

4. GPIO.output(4, ((statusdatum&2)>0))

CAPA DE LÓGICA DE NEGOCIO

CAPA DE PRESENTACIÓN

Page 20: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

Conclusiones

• Incremento en las aplicaciones de domótica y para la

Internet de las Cosas.

• La utilización de los operadores a nivel de bit en

aplicaciones Web de domótica puede contribuir a

disminuir código, simplificar las operaciones, disminuir el

volumen de datos y aumentar la velocidad de respuesta

en aplicaciones de domótica.

Page 21: OPERADORES A NIVEL DE BITS EN APLICACIONES WEB Y SU UTILIZACIÓN EN LA DOMÓTICA CON RASPBERRY PI - Using of Operators Bitwise in Web Applications of Home Automation with Raspberry

OPERADORES A NIVEL DE BITS EN

APLICACIONES WEB Y SU

UTILIZACIÓN EN LA DOMÓTICA CON

RASPBERRY PI

Bitwise operators in Web applications and its use for

home automation applications with Raspberry Pi

Autores:

MsC. Henry Raúl González Brito, MsC.Dainys Gainza Reyes

Universidad de las Ciencias Informáticas

email: [email protected]