monoZ docs
MZ_Addon_board_CO2.c
Go to the documentation of this file.
1/*
2 * Objectives covered in this Example :
3 * 1. Demonstrate how to create a UART instance, configure and integrate the
4 * UART instance with MonoZ_Lib
5 * 2. Demonstrate how to use UART in interrupt mode for receiving data
6 * 3. Demonstrate how to create a Application Thread using MonoZ_Lib
7 * 4. Demonstrate how to create single-shot and recursive timers, and use them.
8 * 5. Demonstrate how to use lwm2m API's defined in MonoZ_Lib to set
9 * Object/Resource values using mz_set_value_Ob19_X_X API,
10 * Read the new data received from server(in write event) using
11 * mz_read_value_Ob19_X_X API, Send the sensor data using
12 * mz_set_and_notify_Ob19_X_X API.
13 * 6. Demonstrate how to handle post processing event from MonoZ_Lib lwm2m
14 * client.
15 * 7. Demonstrate how to force modem re-initialization.
16 * 8. Demonstrate how to use CLI for printing informations.
17 *
18 * Sources for this example :
19 * MZ_Addon_board_CO2.c - Main Application, UART Driver and sensor Driver
20 * MZ_Addon_board_CO2.h
21 *
22 * [Other Linked files]
23 * MZ_hardware_config.c - Hardware Driver integration file
24 * MZ_modem_config.c - Modem command integration file
25 */
26
27
34/* Include Header Files - START */
35#include "MZ_Addon_board_CO2.h"
36#include "MZ_sys_cmsis_os2.h"
37#include "MZ_error_handler.h"
38#include "MZ_timer.h"
39#include "MZ_print.h"
40#include "MZ_Lwm2m_public.h"
41#include "MZ_type_converter.h"
42#include "MZ_Modem_public.h"
43#include "MZ_uart.h"
44#include "MZ_main.h"
45#include "stdlib.h"
46/* Include Header Files - END */
47
48/* Define some common use MACRO - START */
49#define SERVER_REG_NEED_SET (0)
50#define SERVER_REG_NEED_CLEAR (1)
51#define CO2_READ_TIMER_EXPIRE_SET (1)
52#define CO2_READ_TIMER_EXPIRE_CLEAR (0)
53#define OBSERVE_COMPLETE_SET (1)
54#define OBSERVE_COMPLETE_CLEAR (0)
55#define UART_RECEIVE_COMPLETE_SET (0x00)
56#define UART_RECEIVE_COMPLETE_CLEAR (0xFF)
57#define TIME_180SEC (pdMS_TO_TICKS(180000))
58#define TIME_90SEC (pdMS_TO_TICKS(90000))
59#define TIMER_ID_CLEAR (0)
60/* Define some common use MACRO - END */
61
62/* Thread related MACRO and variables - START */
63#define CO2_APP_STACK_SIZE (512)
65static StaticTask_t co2_cb_mem;
66static StackType_t co2_stack[CO2_APP_STACK_SIZE];
67/* Thread related MACRO and variables - END */
68
69/* Timer related MACRO and variables - START */
70#define LWM2M_SERVER_MONITORING_TIME (TIME_180SEC)
71#define CO2_SENSOR_READ_TIME (TIME_90SEC)
74/* Timer related MACRO and variables - END */
75
76/* CO2 sensor related MACRO and variables - START */
77#define CO2_CMD_ID_21 (0x21)
78#define CO2_CMD_ID_23 (0x23)
79static st_co2_cmd cmd23 = {
80 .sop=0x5B,.ver=0x01,.cmd=0x23,.len=1,.data=0,.crc=0x0A74,.eop=0x5D};
81static st_co2_cmd cmd21 = {
82 .sop=0x5B,.ver=0x01,.cmd=0x21,.len=1,.data=0,.crc=0x8A5F,.eop=0x5D};
85static unsigned char decimal_place = 0;
86static volatile long int co2_raw = 0;
87static volatile long int final_co2_value = 0;
88/* CO2 sensor related MACRO and variables - END */
89
90/* LWM2M related MACRO and variables - START */
93static char payload_string[11] = "";
94/* LWM2M related MACRO and variables - END */
95
101extern void mz_reboot_sequence(void * arg);
102
103/* CRC related MACRO and variables - START */
104#define CRC_TABLE_SIZE 256
105#define CRC16_POLY 0x8005
106#define CRC16_INIT_REM 0x0000
107#define CRC16_FINAL_XOR 0x0000
108extern const unsigned short crc16Table[CRC_TABLE_SIZE];
109/* CRC related MACRO and variables - END */
110
111static mz_error_t co2_uart_init(void);
112static void lwm2m_server_monitoring_timer_cb(TimerHandle_t xTimer);
113static void co2_sensor_read_timer_cb(TimerHandle_t xTimer);
114static void lwm2m_server_reregistration(void);
115static void create_lwm2m_payload(void);
116static void send_payload_to_server(void);
117static void process_resp23(void);
118static void process_resp21(void);
119static void co2_app_thread(void * arg);
120static unsigned short crc16MakeTableMethod( unsigned short crc,
121 const unsigned short *table,
122 unsigned char *pbuffer,
123 unsigned int length);
124/* static function prototypes - END */
125
126/*============================================================================*/
127/* CO2 ADDON board - UART related code - START */
128/*============================================================================*/
129
130/* CO2 UART configuration related MACRO - START */
131#define MZ_ADDONCO2_INSTANCE (LPUART1)
132#define MZ_ADDONCO2_INIT_BAUDRATE (57600)
133#define MZ_ADDONCO2_INIT_WORDLENGTH (UART_WORDLENGTH_8B)
134#define MZ_ADDONCO2_INIT_STOPBITS (UART_STOPBITS_1)
135#define MZ_ADDONCO2_INIT_PARITY (UART_PARITY_NONE)
136#define MZ_ADDONCO2_INIT_MODE (UART_MODE_TX_RX)
137#define MZ_ADDONCO2_INIT_HWFLOWCTL (UART_HWCONTROL_NONE)
138#define MZ_ADDONCO2_INIT_OVERSAMPLING (UART_OVERSAMPLING_16)
139#define MZ_ADDONCO2_INIT_ONEBITSAMPLING (UART_ONE_BIT_SAMPLE_DISABLE)
140#define MZ_ADDONCO2_ADVANCEDINIT_ADVFEATUREINIT (UART_ADVFEATURE_NO_INIT)
141#define MZ_ADDONCO2_UART_INSTANCE (_LPUART1)
142/* CO2 UART configuration related MACRO - START */
143
144/* CO2 UART configuration structure - START */
145/*
146 * This configuration structure is used in MZ_hardware_config.c to initialize
147 * the UART hardware interface.
148 * In this example this Configuration is taken during the Initialization of
149 * the MonoZ_Lib to load the settings prior to Application start.
150 *
151 * NOTE:
152 * In-case Application want to perform UART initialization later after
153 * application start or by itself during runtime, MZ_UART_init() API can be
154 * used.
155 * In such case remove the configuration from MZ_hardware_config.c.
156 */
158{
160 .Init.BaudRate = MZ_ADDONCO2_INIT_BAUDRATE,
161 .Init.WordLength = MZ_ADDONCO2_INIT_WORDLENGTH,
162 .Init.StopBits = MZ_ADDONCO2_INIT_STOPBITS,
163 .Init.Parity = MZ_ADDONCO2_INIT_PARITY,
164 .Init.Mode = MZ_ADDONCO2_INIT_MODE,
165 .Init.HwFlowCtl = MZ_ADDONCO2_INIT_HWFLOWCTL,
166 .Init.OverSampling = MZ_ADDONCO2_INIT_OVERSAMPLING,
167 .Init.OneBitSampling = MZ_ADDONCO2_INIT_ONEBITSAMPLING,
168 .AdvancedInit.AdvFeatureInit = MZ_ADDONCO2_ADVANCEDINIT_ADVFEATUREINIT
169};
170/* CO2 UART configuration structure - END */
171
172/* CO2 UART related variables - START */
174/* CO2 UART related variables - END */
175
181static void co2_lpuart1_rx_intr(void * arg)
182{
183 (void)arg;
184
185 /* Set co2 sensor uart receive complete flag */
187}
188/* CO2 UART related callback - END */
189
197{
198 /*
199 * Register the lpuart1 receive complete callback using
200 * MZ_UART_register_intr_cb_rx() API
201 * When receive is completed on the lpuart interface,
202 * the callback API co2_lpuart1_rx_intr() will be processed.
203 */
206
207 /*
208 * Based on the Application requirement register a transmit callback using
209 * MZ_UART_register_intr_cb_tx() API. Please refer MZ_uart.h for more
210 * details.
211 */
212}
213/* CO2 uart related initialization - END */
214
215/*============================================================================*/
216/* CO2 ADDON board - UART related code - END */
217/*============================================================================*/
218
219/*============================================================================*/
220/* CO2 ADDON board - Co2 sensor read and send to Lwm2m server - START */
221/*============================================================================*/
222
229static void lwm2m_server_monitoring_timer_cb(TimerHandle_t xTimer)
230{
231 /* Check if observe has not started */
233 {
234 /* Then set the server re-registration flag */
236 }
237}
238/* LWM2M server registration monitoring timer callback - END */
239
246static void co2_sensor_read_timer_cb(TimerHandle_t xTimer)
247{
248 /* Set the co2 sensor timer expire flag */
250}
251/* co2 sensor reading timer callback - END */
252
260{
261 /* Clear previous observe receive flag */
263
264 /* Starting the Lwm2m server monitoring one time timer */
266 {
267 mz_puts("Server monitoring timer creation failed\r\n");
268 }
269
270 /* Initiate the server re-registration */
271
273 {
274 /* print the success in the CLI */
275 mz_puts("Server re-reg sequence started\r\n");
276 }
277 else
278 {
279 /* print the fail - It will be again tried on next timer expire */
280 mz_puts("Server re-reg sequence failed\r\n");
281 }
282}
283/* LWM2M server re-registration API - END */
284
290static void create_lwm2m_payload(void)
291{
292 /*
293 * As all the payload is just number, this is a optimized implementation
294 * of converting the final value to ASCII HEX string
295 */
296 payload_string[0] = '\"';
297 payload_string[1] = '3';
298 payload_string[2] = '0' + (final_co2_value % 10000)/1000;
299 payload_string[3] = '3';
300 payload_string[4] = '0' + (final_co2_value % 1000)/100;
301 payload_string[5] = '3';
302 payload_string[6] = '0' + (final_co2_value % 100)/10;
303 payload_string[7] = '3';
304 payload_string[8] = '0' + final_co2_value % 10;
305 payload_string[9] = '\"';
306 payload_string[10] = '\0';
307}
308/* LWM2M Create payload API - END */
309
316static void send_payload_to_server(void)
317{
318 /* Set the Object 19/0/0 Data and send the Notify request to MonoZ_Lib */
320
321 /* Check the status of the request */
322 if(MZ_OK == status)
323 {
324 /* print success on CLI */
325 mz_puts("Notify send to MonoZ_Lib\r\n");
326 }
327 else
328 {
329 /* print of error string on CLI */
330 mz_puts(mz_error_to_str(status));
331 }
332}
333/* LWM2M send payload API - END */
334
344static void process_resp23(void)
345{
346 /* Calculate the crc of received bytes in rsp23 */
347 unsigned short crc16 = crc16MakeTableMethod(CRC16_INIT_REM,
349 (unsigned char *)&resp23,
350 sizeof(resp23)-3);
351
352 /*
353 * If calculated crc matches with received crc value,
354 * data is not corrupted
355 */
356 if(resp23.crc == crc16)
357 {
358 /* Store the decimal place */
360
361 /* Clear the response buffer for next use. */
362 memset(&resp23,0,sizeof(resp23));
363
364 /*
365 * Set the Uart in Interrupt Receiving mode,
366 * set the receiving buffer as resp21
367 */
369 (uint8_t *)&resp21,
370 sizeof(resp21));
371 /* Send the Co2 sensor cmd21 */
373 (uint8_t *)&cmd21,
374 sizeof(cmd21),
375 1000);
376 }
377}
378/* CO2 sensor resp23 processing API - END */
379
391static void process_resp21(void)
392{
393 /* Calculate the crc of received bytes in rsp21 */
394 unsigned short crc16 = crc16MakeTableMethod(CRC16_INIT_REM,
396 (unsigned char *)&resp21,
397 sizeof(resp21)-3);
398 /*
399 * If calculated crc matches with received crc value,
400 * data is not corrupted
401 */
402 if(resp21.crc == crc16)
403 {
404 /* Store the raw co2 value */
405 final_co2_value = resp21.co2_raw;
406
407 /* Clear the response buffer for next use. */
408 memset(&resp21,0,sizeof(resp21));
409
410 /* create final co2 sensor value from raw value and decimal place */
411 while(decimal_place)
412 {
413 /* Divide 10 to the final value to reduce the decimal place */
414 /* Refer to the co2 sensor datasheet for more information */
417 }
418
419 /* Create the payload from the received data */
421 /* send the payload to lwm2m server */
423 }
424}
425/* CO2 sensor resp21 processing API - END */
426
437static void co2_app_thread(void * arg)
438{
439 (void)arg;
440
441 /*
442 * create the Lwm2m server monitoring timer.
443 * As per requirement, We are creating a One-time timer using
444 * mz_tm_create_one() API.
445 * In-case of other type of timer, please refer MZ_timer.h
446 * The expire time for this timer set to LWM2M_SERVER_MONITORING_TIME.
447 * "lwm2m_server_monitoring_timer_cb" is passed as an argument.
448 * When the timer expires, the "lwm2m_server_monitoring_timer_cb" API will
449 * be processed.
450 * Also store the timer id for future use, to restart the timer
451 */
453 mz_tm_create_one("Server monitoring timer",
456 /*
457 * Starting the Lwm2m server monitoring timer.
458 * The response of the API is ignored assuming it is started correctly
459 * without error.
460 * In-case needed please do error management for this API.
461 */
463
464 /* Print on the console about timer start */
465 mz_puts("Server monitoring timer started\r\n");
466
467 /*
468 * create the co2 sensor reading timer.
469 * As per requirement, We are creating a recursive timer using
470 * mz_tm_create_start_recursive() API.
471 * In-case of other type of timer, please refer MZ_timer.h
472 * The expire time for this timer set to CO2_SENSOR_READ_TIME.
473 * "co2_sensor_read_timer_cb" is passed as an argument.
474 * When the timer expires, the "co2_sensor_read_timer_cb" API will be
475 * processed.
476 */
477 if(MZ_OK == mz_tm_create_start_recursive("Uart Read timer",
480 {
481 mz_puts("co2 sensor reading timer started\r\n");
482 }
483
484
485 /*
486 * This is the infinite loop for this thread - the thread will execute this
487 * loop forever and not come outside of this loop
488 */
489 while(1)
490 {
491 /* Need to write the periodic executing logic in this loop block */
492
493 /*
494 * Process the server re-registration based on registration required or
495 * not status - Check if the flag is set
496 */
498 {
499 /* clear the server re-registration flag */
501
502 /* Perform lwm2m server re-registration */
504 }
505
506 /* Process the received co2 sensor data if uart receive has completed */
508 {
509 /* clear the co2 uart receive flag */
511
512 /* Check if the response for cmd23 is received */
513 if(CO2_CMD_ID_23 == resp23.cmd)
514 {
516 }
517
518 /* Check if the response for cmd23 is received */
519 if(CO2_CMD_ID_21 == resp21.cmd)
520 {
522 }
523 }
524
525 /* Check if co2 sensor read timer expired */
527 {
528 /* Process the co2 sensor read timer expire event */
529
530 /*
531 * Set the Uart in Interrupt Receiving mode,
532 * set the receiving buffer as resp23
533 */
535 (uint8_t *)&resp23,
536 sizeof(resp23));
537
538 /* Send the Co2 sensor cmd23 */
540 (uint8_t *)&cmd23,
541 sizeof(cmd23),
542 1000);
543
544 /* clear the flag after processing */
546 }
547
548 /* Put a delay to avoid blocking on this thread */
549 HAL_Delay(10);
550
551
552 }//End of while(1) - Do not place any code after this.
553
554}
555/* CO2 main Application thread. - END */
556
557/*
558 * CO2 Application initialization API. - START
559 *
560 * 1. It call all necessary initializations before application start
561 * 2. It create the main co2 application
562 * 3. It set all variables to its initialization states
563 */
565{
566 mz_error_t _ret = MZ_OK;
567
568 /* Clear Response buffers of co2 */
569 memset(&resp23,0,sizeof(resp23));
570 memset(&resp21,0,sizeof(resp21));
571
572 /* Initialize co2 uart related functions */
573 _ret = co2_uart_init();
574 if(MZ_OK != _ret) goto clean;
575
576 /* Create the Co2 application thread */
578 "co2 Scheduler",
580 NULL,
581 osPriorityNormal,
582 co2_stack,
584 &co2_cb_mem,
585 sizeof(co2_cb_mem)))
586 {
588 }
589
590 /*
591 * Set MonoZ_Lib lwm2m internal resources to default value before
592 * application start.
593 */
594 _ret = mz_set_value_Ob19_0_0("\"30303030\"");
595 if(MZ_OK != _ret) goto clean;
596 _ret = mz_set_value_Ob19_1_0("\"30303030\"");
597 if(MZ_OK != _ret) goto clean;
598
599 clean :
600 return _ret;
601}
602/* CO2 Application initialization API. - END */
603
604/*============================================================================*/
605/* CO2 ADDON board - Co2 sensor read and send to Lwm2m server - END */
606/*============================================================================*/
607
608/*============================================================================*/
609/* CO2 ADDON board - LWM2M event related code - START */
610/*============================================================================*/
623void lwm2m_event_process(void * event)
624{
625 st_lw_event * e = event;
626
627 /* Check post-processing events is send by MonoZ_Lib to user */
628 switch(e->lw_event)
629 {
630 /*
631 * This is a Observe start event. The event has already been processed
632 * and the token is already stored inside MonoZ_Lib. If any user action
633 * need to be taken then it can be performed here.
634 */
635 case LW_EV_OBSERVE:
636 /* print the observe received on CLI */
637 mz_puts("Observe received\r\n");
638 /* Check if observe is started for target Object and resource */
639 if(e->lw_Obj_id == 19 && e->lw_Obj_Ins_id == 0 && e->lw_Res_id == 0)
640 {
641 /* Set the observed received flag */
643 }
644 break;
646 /* print when notify send to server */
647 mz_puts("Notify send to server\r\n");
648 break;
650 /* print when notify acknowledgment is received from server */
651 mz_puts("Notify send acknowledge\r\n");
652 break;
654 /* print when notify failed received from server */
655 mz_puts("Notify send failed\r\n");
656 break;
657 case LW_EV_CLIENT_OFF:
658 /* Set server re-registration flag when received client off */
660 break;
661
662#if 0
663 /* Some other sample cases */
664 case LW_EV_WRITE_DATA:
665 /* Do something */
666 ;
667 break;
668 case LW_EV_EXECUTE:
669 /* Do something */
670 ;
671 break;
672 case LW_EV_READ:
673 /* Do something */
674 ;
675 break;
677 /* Do something */
678 ;
679 break;
680#endif
681
682 default:
683 break;
684 }
685}
686/*============================================================================*/
687/* CO2 ADDON board - LWM2M event related code - END */
688/*============================================================================*/
689
690/*============================================================================*/
691/* CO2 ADDON board - CRC related code - START */
692/*============================================================================*/
693
694/* CRC table - START */
695/*
696 * CRC calculation used in validation of CO2 sensor data.
697 * This information is used directly as it is from the CO2 sensor datasheet.
698 * Please refer the datasheet for more detail information
699 */
700const unsigned short crc16Table[CRC_TABLE_SIZE] = {
701 0x0000, 0x8005, 0x800F, 0x000A,
702 0x801B, 0x001E, 0x0014, 0x8011,
703 0x8033, 0x0036, 0x003C, 0x8039,
704 0x0028, 0x802D, 0x8027, 0x0022,
705 0x8063, 0x0066, 0x006C, 0x8069,
706 0x0078, 0x807D, 0x8077, 0x0072,
707 0x0050, 0x8055, 0x805F, 0x005A,
708 0x804B, 0x004E, 0x0044, 0x8041,
709 0x80C3, 0x00C6, 0x00CC, 0x80C9,
710 0x00D8, 0x80DD, 0x80D7, 0x00D2,
711 0x00F0, 0x80F5, 0x80FF, 0x00FA,
712 0x80EB, 0x00EE, 0x00E4, 0x80E1,
713 0x00A0, 0x80A5, 0x80AF, 0x00AA,
714 0x80BB, 0x00BE, 0x00B4, 0x80B1,
715 0x8093, 0x0096, 0x009C, 0x8099,
716 0x0088, 0x808D, 0x8087, 0x0082,
717 0x8183, 0x0186, 0x018C, 0x8189,
718 0x0198, 0x819D, 0x8197, 0x0192,
719 0x01B0, 0x81B5, 0x81BF, 0x01BA,
720 0x81AB, 0x01AE, 0x01A4, 0x81A1,
721 0x01E0, 0x81E5, 0x81EF, 0x01EA,
722 0x81FB, 0x01FE, 0x01F4, 0x81F1,
723 0x81D3, 0x01D6, 0x01DC, 0x81D9,
724 0x01C8, 0x81CD, 0x81C7, 0x01C2,
725 0x0140, 0x8145, 0x814F, 0x014A,
726 0x815B, 0x015E, 0x0154, 0x8151,
727 0x8173, 0x0176, 0x017C, 0x8179,
728 0x0168, 0x816D, 0x8167, 0x0162,
729 0x8123, 0x0126, 0x012C, 0x8129,
730 0x0138, 0x813D, 0x8137, 0x0132,
731 0x0110, 0x8115, 0x811F, 0x011A,
732 0x810B, 0x010E, 0x0104, 0x8101,
733 0x8303, 0x0306, 0x030C, 0x8309,
734 0x0318, 0x831D, 0x8317, 0x0312,
735 0x0330, 0x8335, 0x833F, 0x033A,
736 0x832B, 0x032E, 0x0324, 0x8321,
737 0x0360, 0x8365, 0x836F, 0x036A,
738 0x837B, 0x037E, 0x0374, 0x8371,
739 0x8353, 0x0356, 0x035C, 0x8359,
740 0x0348, 0x834D, 0x8347, 0x0342,
741 0x03C0, 0x83C5, 0x83CF, 0x03CA,
742 0x83DB, 0x03DE, 0x03D4, 0x83D1,
743 0x83F3, 0x03F6, 0x03FC, 0x83F9,
744 0x03E8, 0x83ED, 0x83E7, 0x03E2,
745 0x83A3, 0x03A6, 0x03AC, 0x83A9,
746 0x03B8, 0x83BD, 0x83B7, 0x03B2,
747 0x0390, 0x8395, 0x839F, 0x039A,
748 0x838B, 0x038E, 0x0384, 0x8381,
749 0x0280, 0x8285, 0x828F, 0x028A,
750 0x829B, 0x029E, 0x0294, 0x8291,
751 0x82B3, 0x02B6, 0x02BC, 0x82B9,
752 0x02A8, 0x82AD, 0x82A7, 0x02A2,
753 0x82E3, 0x02E6, 0x02EC, 0x82E9,
754 0x02F8, 0x82FD, 0x82F7, 0x02F2,
755 0x02D0, 0x82D5, 0x82DF, 0x02DA,
756 0x82CB, 0x02CE, 0x02C4, 0x82C1,
757 0x8243, 0x0246, 0x024C, 0x8249,
758 0x0258, 0x825D, 0x8257, 0x0252,
759 0x0270, 0x8275, 0x827F, 0x027A,
760 0x826B, 0x026E, 0x0264, 0x8261,
761 0x0220, 0x8225, 0x822F, 0x022A,
762 0x823B, 0x023E, 0x0234, 0x8231,
763 0x8213, 0x0216, 0x021C, 0x8219,
764 0x0208, 0x820D, 0x8207, 0x0202
765};
766/* CRC table - END */
767
768/* CRC method - START */
777static unsigned short crc16MakeTableMethod( unsigned short crc,
778 const unsigned short *table,
779 unsigned char *pbuffer,
780 unsigned int length)
781{
782 while(length--)
783 {
784 crc = table[((crc >> 8) ^ *pbuffer++)] ^ (crc << 8); // normal
785 }
786 return(crc ^ CRC16_FINAL_XOR);
787}
788
789/* CRC method - END */
790
791/*============================================================================*/
792/* CO2 ADDON board - CRC related code - END */
793/*============================================================================*/
static void create_lwm2m_payload(void)
LWM2M Create payload API - START This API will be used to create the payload string/buffer from co2 f...
#define CO2_READ_TIMER_EXPIRE_CLEAR
Clear the Timer Expire for CO2 read.
#define MZ_ADDONCO2_INIT_PARITY
Defines the initial parity.
static void process_resp23(void)
CO2 sensor resp23 processing API - START This API will be used to process the response received from ...
#define CO2_CMD_ID_23
Defines cmd23 id.
#define MZ_ADDONCO2_INIT_HWFLOWCTL
Defines initial hardware flow control.
static char lwm2m_server_rereg_flag
const unsigned short crc16Table[CRC_TABLE_SIZE]
static void co2_sensor_read_timer_cb(TimerHandle_t xTimer)
co2 sensor reading timer callback - START This Timer callback will be called after the co2 sensor rea...
static mz_error_t co2_uart_init(void)
CO2 UART related initialization - START This Timer callback will be called after the server monitorin...
#define CO2_SENSOR_READ_TIME
Set 90 seconds timer for read sensor data.
static volatile char co2_uart_recv_complete_flag
MZ_UART_INIT_ST co2_lpuart1_instance
static void lwm2m_server_monitoring_timer_cb(TimerHandle_t xTimer)
LWM2M server registration monitoring timer callback - START This Timer callback will be called after ...
static st_co2_cmd_resp21 resp21
#define MZ_ADDONCO2_INSTANCE
Defines the instance.
#define TIMER_ID_CLEAR
Clear the timer id.
#define MZ_ADDONCO2_INIT_ONEBITSAMPLING
Defines the initial one bit sampling.
static mz_thread_t co2_thread_id
static void process_resp21(void)
CO2 sensor resp21 processing API - START This API will be used to process the response received from ...
#define SERVER_REG_NEED_CLEAR
Clear the server Registration.
static unsigned char decimal_place
static st_co2_cmd cmd23
#define MZ_ADDONCO2_INIT_OVERSAMPLING
Defines the initial oversampling.
#define UART_RECEIVE_COMPLETE_CLEAR
Clear the UART Receive.
#define MZ_ADDONCO2_UART_INSTANCE
Defimes the UART instance.
#define SERVER_REG_NEED_SET
Sets the server registration.
static unsigned short crc16MakeTableMethod(unsigned short crc, const unsigned short *table, unsigned char *pbuffer, unsigned int length)
calculating crc value
static char co2_read_timer_expire_flag
#define CO2_CMD_ID_21
Defines cmd21 id.
void mz_reboot_sequence(void *arg)
This is the function prototype used for sending AT cmds used in server re-registration.
#define OBSERVE_COMPLETE_CLEAR
Clear the Observe Complete.
#define CO2_READ_TIMER_EXPIRE_SET
Set the Timer Expire for CO2 read.
static char observe_receive_flag
#define CRC_TABLE_SIZE
Defines the crc table size.
void lwm2m_event_process(void *event)
LWM2M user defined callback function.
mz_error_t co2_app_init(void)
CO2 Application initialization API.
static st_co2_cmd_resp23 resp23
#define CRC16_INIT_REM
Defines the CRC16_INIT_REM value.
#define CRC16_FINAL_XOR
Defines the CRC16_FINAL_XOR value.
static st_co2_cmd cmd21
static void co2_lpuart1_rx_intr(void *arg)
CO2 UART related callback - START This UART callback will be called after completion of uart receive.
static void send_payload_to_server(void)
LWM2M send payload API - START This API will be used to send the payload string/buffer to MonoZ_Lib.
#define MZ_ADDONCO2_ADVANCEDINIT_ADVFEATUREINIT
Defines the Uart advance features.
#define OBSERVE_COMPLETE_SET
Set the Observe Complete.
static StackType_t co2_stack[CO2_APP_STACK_SIZE]
#define MZ_ADDONCO2_INIT_BAUDRATE
Defines the baud rate.
static volatile long int final_co2_value
#define MZ_ADDONCO2_INIT_MODE
Defines the mode.
#define MZ_ADDONCO2_INIT_STOPBITS
Defines the stop bits.
#define CO2_APP_STACK_SIZE
Stack size for the thread *‍/.
#define MZ_ADDONCO2_INIT_WORDLENGTH
Defines the initial word length.
static void lwm2m_server_reregistration(void)
LWM2M server re-registration API - START This API will be used to start the Server re-registration pr...
static volatile long int co2_raw
static char payload_string[11]
#define UART_RECEIVE_COMPLETE_SET
Sets the UART Receive.
static size_t lwm2m_server_monitoring_timer_id
static void co2_app_thread(void *arg)
CO2 main Application thread.
#define LWM2M_SERVER_MONITORING_TIME
Set 180 seconds timer for server Monitoring.
static StaticTask_t co2_cb_mem
monoZ LWM2M public Protocol
@ LW_EV_READ
@ LW_EV_WRITE_DATA
@ LW_EV_CLIENT_NOTIFY_SEND
@ LW_EV_CLIENT_OFF
@ LW_EV_OBSERVE_CANCEL
@ LW_EV_EXECUTE
@ LW_EV_CLIENT_NOTIFY_SEND_ACK
@ LW_EV_NOTIFY_FAIL
@ LW_EV_OBSERVE
monoZ Modem public Protocol
monoZ Error Handler
mz_error_t
Enumeration of monoZ Error Flags.
@ MZ_THREAD_CREATE_FAIL
@ MZ_OK
monoZ Main file
monoZ Print
monoZ system CMSIS OS2 This is an abstraction layer and includes FreeRTOS configuration,...
osThreadId_t mz_thread_t
mz_thread_t variable of type osThreadId_t
This file contains APIs for create,delete,start and stop of timers. Maximum 5 timers can be created....
monoZ Type Converter This file contains the APIs used to hex to ascii and ascii to hex conversion
This file includes monoZ Uart Related APIs.
const char * mz_error_to_str(mz_error_t e)
This function is used to convert the monoZ error code to corresponding error message.
mz_error_t mz_set_value_Ob19_0_0(char *src)
This function writes 19/0/0 value to internal resource structure.
mz_error_t mz_set_value_Ob19_1_0(char *src)
This function writes 19/1/0 value to internal resource structure.
mz_error_t mz_set_and_notify_Ob19_0_0(char *src)
This function writes 19/0/0 value to internal resource structure and then notify to server.
mz_error_t MZ_modem_config_set(_mz_fp _fp)
This function is used to check modem configuration is set or not set.
int mz_puts(void *__ch)
This function prints the given string.
uint8_t mz_thread_create(mz_thread_t *t, const char *name, mz_fn thread_func, void *const arg, mz_thread_prio_t prio, StackType_t *stack_mem, size_t stack_size, StaticTask_t *cb_mem, uint32_t cb_size)
This function is used to check the message queue object validity Create a thread and add it to Active...
mz_error_t mz_tm_create_start_recursive(char *_name, TickType_t _tick, mz_tm_cb _cb)
Function to Create and Start One Shot Timers.
mz_error_t mz_tm_start(size_t _id)
Function to Start the Timer.
size_t mz_tm_create_one(char *_name, TickType_t _tick, mz_tm_cb _cb)
Function to Create a One Shot Timer.
mz_error_t MZ_UART_Transmit(uint8_t uart_no, uint8_t *pData, uint16_t Size, uint32_t Timeout)
This function is used to transmit data using UART in polling mode.
mz_error_t MZ_UART_register_intr_cb_rx(uint8_t uart_no, _uart_api cb)
This function registers the RX complete callback function for the specific UART.
mz_error_t MZ_UART_Receive_IT(uint8_t uart_no, uint8_t *pData, uint16_t Size)
This function is used to receive data using UART in interrupt mode.
Structure for monoZ UART Initialization parameters.
Definition: MZ_public.h:21
USART_TypeDef * Instance
Definition: MZ_public.h:22
CO2 sensor Receive response structure format for cmd21.
CO2 sensor Receive response structure format for cmd23.
CO2 sensor Transmit cmd structure format.
Structure For LW Events.