o
    ]}}dc                     @   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 )N5https://thingsaccess.com/rfid/index.php/Api/getBundleresponsezbundles/bundle.htmldata_bundlecontext)requestsgetjsonr   )requestr	   	data_sendr
    r   $D:\rfid_django\core\bundles\views.pybundle_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 t	| dS )NPOST
article_IDtag_IDstep_ID
bundleSizestatestatus)r   r   r   r   r   r   z5https://thingsaccess.com/rfid/index.php/Api/addBundler      r   zFailed to add datazbundles/addBundle.html)
methodr   r   r   poststatus_coder   r   errorr   )r   datar	   r   r   r   
Add_bundle   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 )
NZCOM5i        )portZbaudrateZbytesizetimeoutZstopbitsTB   zNumber:)serialr   ZSTOPBITS_ONEreadlinestripprintdecodeindexint
ValueErrorKeyboardInterruptclose)numberZserr"   decoded_dataZnumber_start_indexr   r   r   get_bundle_tag_id(   s8   


r6   c                 C   s,   | j dkrt }d|i}t| t|S d S )NGETr4   )r   r6   r-   r   )r   r4   r	   r   r   r   
get_tag_idB   s   
r8   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   z6https://thingsaccess.com/rfid/index.php/Api/editBundler   r   r   zFailed to edit datazbundles/editBundle.htmlitemr   )r   r   r   r   r   r   r    r   r   r!   r   )r   r:   r	   r   r"   	edit_itemr;   r   r   r   Edit_BundlesK   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:   z8https://thingsaccess.com/rfid/index.php/Api/deleteBundler   r   r   zFailed to delete datazBundle not deleted)r-   r   r   r    r   r   r!   r   )r   r:   data_deleter	   r   r   r   delete_Bundlek   s   
r?   )django.shortcutsr   django.contribr   r   r   django.httpr   r*   timer   r   r   r#   r6   r8   r=   r?   r   r   r   r   <module>   s    	 