-
Notifications
You must be signed in to change notification settings - Fork 4
/
file.py
78 lines (63 loc) · 1.91 KB
/
file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Module for including file functions of PicoLTE module.
"""
from pico_lte.utils.status import Status
class File:
"""
Class for inculding functions of file operations of PicoLTE module.
"""
CTRL_Z = "\x1A"
def __init__(self, atcom):
"""
Initialization of the class.
"""
self.atcom = atcom
def get_file_list(self, path="*"):
"""
Function for getting file list
Parameters
----------
path : str, default: "*"
Path to the directory
Returns
-------
dict
Result that includes "status" and "response" keys
"""
command = f'AT+QFLST="{path}"'
return self.atcom.send_at_comm(command)
def delete_file_from_modem(self, file_name):
"""
Function for deleting file from modem UFS storage
Parameters
----------
file_path : str
Path to the file
Returns
-------
dict
Result that includes "status" and "response" keys
"""
command = f'AT+QFDEL="{file_name}"'
return self.atcom.send_at_comm(command)
def upload_file_to_modem(self, filename, file, timeout=5000):
"""
Function for uploading file to modem
Parameters
----------
file : str
Path to the file
timeout : int, default: 5000
Timeout for the command
Returns
-------
dict
Result that includes "status" and "response" keys
"""
len_file = len(file)
command = f'AT+QFUPL="{filename}",{len_file},{timeout}'
result = self.atcom.send_at_comm(command, "CONNECT", urc=True)
if result["status"] == Status.SUCCESS:
self.atcom.send_at_comm_once(file) # send ca cert
return self.atcom.send_at_comm(self.CTRL_Z) # send end char -> CTRL_Z
return result