diff --git a/docs/sbs/en/thread/code/event_message_test.py b/docs/sbs/en/thread/code/event_message_test.py new file mode 100644 index 0000000000000000000000000000000000000000..5c3a7ae3ae5baf8e0783b21907e5fb3446beddaa --- /dev/null +++ b/docs/sbs/en/thread/code/event_message_test.py @@ -0,0 +1,67 @@ +from event_message import Event +import utime +""" +1. Initialize event +2. Initialize event manager +3. Register event to event manager +4. Start event manager +5. Add event manager +6. Dispatch data +""" +from event_message import Event, EventManager +# Initialize event and event manager +event = Event("test") +event_manager = EventManager() +# Register event +event_manager.register_event(event) +# Start event manager +event_manager.start() +# Add event manager, you can comment different event types by patches. +@event.add_handler_via() +def handler(**kwargs): + em = kwargs["event_message"] + """ + The first way to get data + kwargs:{ + "event_message":EventMessageObject + } + Four attributes are invloved in EventMessageObject + event_name + msg + event + callback + It provides the method to get by itself and by combination. As for getting by combination, following methods are available, the model_to_dict()will get the dictionary of combination. + { + 'name': 'test', + 'event': event_object, + 'msg': '1111', + 'callback': None + } + """ + + print("handler1 {}".format(kwargs)) + """ + 1. Method to get the first attribute + # Get the event name + event_name = em.event_name + # Get the event message + msg = em.msg + # Get the original event + ev = em.event + # None Get the transmitted callback, it is None by default if there is no transmission. + cb = em.callback + """ + """ + 2. The way to get the second attribute value(Recommended) + data_map = em.model_to_dict() + { + 'name': 'test', + 'event': event_object, + 'msg': '1111', + 'callback': None + } + """ +# Asynchronous dispatch data instead of block +while True: + event.post(message="1111") + utime.sleep(2) \ No newline at end of file diff --git a/docs/sbs/en/thread/code/queue_test.py b/docs/sbs/en/thread/code/queue_test.py new file mode 100644 index 0000000000000000000000000000000000000000..11a5d1741b5ebb35f6e9ef2f05ca5b97e43479cc --- /dev/null +++ b/docs/sbs/en/thread/code/queue_test.py @@ -0,0 +1,18 @@ +import _thread +from queue import Queue +import utime +# Initialize queue +q = Queue(maxsize=100) +def get(): + while True: +# The q.get will wait until get the message. Whenever the q.put is executed, the q.get will delete block and carry on if influenced by relevant signal. + item = q.get() + print(item) +# Start the thread and wait for message in which place. +_thread.start_new_thread(get,()) +# put the message to queue +q.put(1) +utime.sleep(2) +q.put(2) +utime.sleep(2) +q.put(3) \ No newline at end of file diff --git a/docs/sbs/en/thread/code/sys_bus_test.py b/docs/sbs/en/thread/code/sys_bus_test.py new file mode 100644 index 0000000000000000000000000000000000000000..7da5ba938d3036db221a262c6357c4705aa5551c --- /dev/null +++ b/docs/sbs/en/thread/code/sys_bus_test.py @@ -0,0 +1,31 @@ +import sys_bus +import utime +def cb_callback(topic, msg): + print(topic, msg) +# Support registering multiple subscription functions by one topic. +sys_bus.subscribe("topic1", cb_callback) +sys_bus.subscribe("topic2", cb_callback) +sys_bus.subscribe("topic3", cb_callback) + + +" The subscriber will receive message after publishing" +sys_bus.publish("topic1", " What printed here is the message published by topic 1") +utime.sleep(2) +sys_bus.publish("topic2", " What printed here is the message published by topic 2") +utime.sleep(2) +sys_bus.publish("topic3", " What printed here is the message published by topic 3") +utime.sleep(2) + +print(sys_bus.sub_table()) +# Return {"topic1": set(cb_callback...)} +utime.sleep(2) +print(sys_bus.sub_table("topic1")) +# Return set(cb_callback...) + +sys_bus.unsubscribe("topic1", cb_callback) +# As suscribing callback has been cancelled above, the following publication won' t slide into the former callback. That means: the subscribed message can still be received, however, there is no callback. +sys_bus.publish("topic1", "What printed here is the message published by topic 1") + +sys_bus.unsubscribe("topic1") +# As the subscription of topic 1 has been cancelled, the following publication won't receive any message. +sys_bus.publish("topic1", " What printed here is the message published by topic 1") \ No newline at end of file diff --git a/docs/sbs/en/thread/media/_thread_02.jpg b/docs/sbs/en/thread/media/_thread_02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d50abe2079ba8312718b8e4d231dac33c1de9582 Binary files /dev/null and b/docs/sbs/en/thread/media/_thread_02.jpg differ diff --git a/docs/sbs/en/thread/media/_thread_02.png b/docs/sbs/en/thread/media/_thread_02.png deleted file mode 100644 index 7e383ac56a31aace1d39e8894a2dfab26016da6b..0000000000000000000000000000000000000000 Binary files a/docs/sbs/en/thread/media/_thread_02.png and /dev/null differ diff --git a/docs/sbs/en/thread/media/_thread_03.png b/docs/sbs/en/thread/media/_thread_03.png index 1926877555c918027285bccf412612a9f1bd4436..7bbf1d4c9ba825d9b2ecb7268c7f6972eaba532a 100644 Binary files a/docs/sbs/en/thread/media/_thread_03.png and b/docs/sbs/en/thread/media/_thread_03.png differ diff --git a/docs/sbs/en/thread/media/queue_01.jpg b/docs/sbs/en/thread/media/queue_01.jpg index b4bde78cb23f9ca65c837a50178dd9db7c3fa528..e30794d6b7601ab2bcea3ca0d42db8a8b91763a9 100644 Binary files a/docs/sbs/en/thread/media/queue_01.jpg and b/docs/sbs/en/thread/media/queue_01.jpg differ diff --git a/docs/sbs/en/thread/media/queue_02.jpg b/docs/sbs/en/thread/media/queue_02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0eb2560a4382131a083c7b927032e33b94aae564 Binary files /dev/null and b/docs/sbs/en/thread/media/queue_02.jpg differ diff --git a/docs/sbs/en/thread/media/queue_02.png b/docs/sbs/en/thread/media/queue_02.png deleted file mode 100644 index f0ee9345c8614cb06319c9d59aea13a440b2eeaa..0000000000000000000000000000000000000000 Binary files a/docs/sbs/en/thread/media/queue_02.png and /dev/null differ diff --git a/docs/sbs/en/thread/media/queue_03.jpg b/docs/sbs/en/thread/media/queue_03.jpg index d13f3da79e93b444d1a3750fba52cf6f73e7c633..0242e48384b8577ad1c4759d21b7a49ceff2ec27 100644 Binary files a/docs/sbs/en/thread/media/queue_03.jpg and b/docs/sbs/en/thread/media/queue_03.jpg differ diff --git a/docs/sbs/en/thread/media/queue_04.jpg b/docs/sbs/en/thread/media/queue_04.jpg index f02398bc20c5f5a3ee05d8ef4d44433ce4dfe54a..b80bab9928a2fdddc16131686abddf61dc4225ba 100644 Binary files a/docs/sbs/en/thread/media/queue_04.jpg and b/docs/sbs/en/thread/media/queue_04.jpg differ diff --git a/docs/sbs/en/thread/queue.md b/docs/sbs/en/thread/queue.md index a683e0033fa44ffae2028c2e20e1fcd29aced21d..e1a0af72d9d36306349ce987481b3a7e6f5e5f17 100644 --- a/docs/sbs/en/thread/queue.md +++ b/docs/sbs/en/thread/queue.md @@ -1,8 +1,9 @@ ## Revision History -| Version | Date | Author | Description | -| ------- | ---------- | ---------- | --------------- | -| 1.0 | 2021-09-30 | David.Tang | Initial version | +| Version | Date | Author | Description | +| ------- | ---------- | ---------- | ------------------------------------ | +| 1.0 | 2021-09-30 | David.Tang | Initial version | +| 1.1 | 2022-02-16 | David.Tang | Translate Chinese operation pictures | ## Foreword @@ -56,7 +57,7 @@ sys_bus.publish("topic1", " What printed here is the message published by topic Here is the result. -![queue_02](media/queue_02.png) +![queue_02](media/queue_02.jpg) Explanation @@ -87,7 +88,9 @@ utime.sleep(2) q.put(3) ``` -Here shows the result. ![queue_03](media/queue_03.jpg) +Here shows the result. + + ![queue_03](media/queue_03.jpg) Explanation diff --git a/docs/sbs/en/thread/thread.md b/docs/sbs/en/thread/thread.md index 899569f2aff3e936d972daf4f954157731a017b8..dcbe1b63c545840bd8abce000cfedd030d77747f 100644 --- a/docs/sbs/en/thread/thread.md +++ b/docs/sbs/en/thread/thread.md @@ -1,8 +1,9 @@ ## Revision history -| Version | Date | Author | Description | -| ------- | ---------- | ---------- | --------------- | -| 1.0 | 2021-09-16 | David.Tang | Initial version | +| Version | Date | Author | Description | +| ------- | ---------- | ---------- | ------------------------------------ | +| 1.0 | 2021-09-16 | David.Tang | Initial version | +| 1.1 | 2022-02-16 | David.Tang | Translate Chinese operation pictures | ## Foreword @@ -14,11 +15,11 @@ Thread is the function implementation on software level; as for the hardware, e ## SW design -The function of thread module is to provide the method to make new thread and mutex. For more details, please refer to the link: [thread](https://python.quectel.com/wiki/#/zh-cn/api/pythonStdlib?id=_thread-%e5%a4%9a%e7%ba%bf%e7%a8%8b). +The function of thread module is to provide the method to make new thread and mutex. For more details, please refer to the link: [thread](https://python.quectel.com/wiki/#/en-us/api/pythonStdlib?id=_thread-multithreading-support). ## Interaction -Interact with EC600S-CN via QPYcom. Please refer to the screen-shot for more details +Interact with EC600U-EU via QPYcom. Please refer to the screen-shot for more details ```python >>> import _thread @@ -38,8 +39,9 @@ False Note: -3. The reason to execute command ”import_thread'' is to make the ***_thread*** visible in current space. -4. Only execute "import_thread" command in module can the function and variate in ***_thread*** be used. +​ 1.The reason to execute command ”import_thread'' is to make the ***_thread*** visible in current space. + +​ 2.Only execute "import_thread" command in module can the function and variate in ***_thread*** be used. ## Download and verify @@ -122,7 +124,7 @@ The figure displayed HW connection: (1)Run *example_thread_file.py* in QPYcom . -![thread_02(E)](media\thread_02(E).png) +![_thread_02](media/_thread_02.jpg) (2)Since two threads are conducted simultaneously, when writing data via UART, it is available to transmit data to EC600U-CN serial interface. (The following figure just displays that writing and reading are conducted simultaneously; however, the detailed outputting sequence of log is decided by manual transmission time.) As the next figure implies, during the third and fourth interval when writing data to EC600U-CN, it transmits "QuecPython" to EC600U-CN via TTL-to-USB.