o
    ~}d                     @   s   d dl mZ d dlmZ d dl mZ d dlZd dlmZ d dlZd dl	Z	d dlm
Z
 d dlmZ dd	 Zd
d Zdd Zdd Zdd Zdd ZdS )    )render)messages)redirectN)HttpResponse)Serial)JsonResponsec                 C   s,   t d}| }|d }t| dd|idS )N7https://thingsaccess.com/rfid/index.php/Api/getOperatorresponsezoperators/operator.htmldata_operatorcontext)requestsgetjsonr   )requestr	   	data_sendr
    r   &D:\rfid_django\core\operators\views.pyoperator_page   s   
r   c                 C   s~   | j dkr:| jd| jd| jd| jd| jd| jdd}tjd	|d
}|jdkr6tdS tdS t| dS )NPOSTNamecniccelladdressskilltag_id)r   r   r   r   r   r   z7https://thingsaccess.com/rfid/index.php/Api/addOperatorr      r   zOperator not addedzoperators/addOperator.html)	methodr   r   r   poststatus_coder   r   r   )r   datar	   r   r   r   Add_operator   s   








r"   c              	   C   s   t d}| }|d }d }|D ]}|d |kr|} nq|r]| jdkr]|| jd| jd| jd| jd| jd	| jd
d}t jd|d}|jdkrWtdS t	| d t
| dd|idS )Nr   r	   IDr   r   r   r   r   r   r   )idr   r   r   r   r   r   z8https://thingsaccess.com/rfid/index.php/Api/editOperatorr   r   r   zFailed to edit datazoperators/editOperator.htmlitemr   )r   r   r   r   r   r   r    r   r   errorr   )r   r$   r	   r   r!   	edit_itemr%   r   r   r   Edit_Operator(   s0   







	
r(   c                 C   sD   d|i}t | tjd|d}|jdkrtdS t| d tdS )Nr$   z:https://thingsaccess.com/rfid/index.php/Api/deleteOperatorr   r   r   zFailed to delete datazOperator not deleted)printr   r   r    r   r   r&   r   )r   r$   data_deleter	   r   r   r   delete_OperatorH   s   
r+   c                  C   s   d } t jddddt jd}zLz4	 |  }|r@t| z| }|dd }t||d  } td	|  W n
 t	y?   Y nw qW n	 t
yK   Y nw W |  | S W |  | S |  w )
NCOM5i        )portbaudratebytesizetimeoutstopbitsTO   zNumber:)serialr   STOPBITS_ONEreadlinestripr)   decodeindexint
ValueErrorKeyboardInterruptclose)numberserr!   decoded_datanumber_start_indexr   r   r   get_operator_tag_idW   s8   


rD   c                 C   s,   | j dkrt }d|i}t| t|S d S )NGETr@   )r   rD   r)   r   )r   r@   r	   r   r   r   tag_id_operatorq   s   
rF   )django.shortcutsr   django.contribr   r   r   django.httpr   r6   timer   r   r   r"   r(   r+   rD   rF   r   r   r   r   <module>   s    