Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PeMod_ZE08.cpp
00001 #include "SysConfig.h" 00002 00003 #define ZE08_CMD_LEN 9 00004 #define ZE08_DAT_LEN 9 00005 00006 #define uart_ze08 uart_sen 00007 //#define uart_db uart_pc 00008 00009 const uint8_t ZE08_CmdManualMode[ZE08_CMD_LEN] = {0xFF, 0x01, 0x78, 0x41, 0x00, 0x00, 0x00, 0x00, 0x46}; 00010 const uint8_t ZE08_CmdReadCH2O[ZE08_CMD_LEN] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; 00011 00012 int ZE08_Init(void) 00013 { 00014 //Change ZE08 to manual request & reply mode 00015 for(int i=0; i<ZE08_CMD_LEN; i++) 00016 uart_ze08.putc(ZE08_CmdManualMode[i]); 00017 00018 return 0; 00019 } 00020 00021 int ZE08_ReadCH2O(void) 00022 { 00023 int ch2oVol, i, sum = 0; 00024 uint8_t data[ZE08_DAT_LEN]; 00025 00026 for(i=0; i<ZE08_CMD_LEN; i++) 00027 uart_ze08.putc(ZE08_CmdReadCH2O[i]); 00028 00029 #if defined uart_db 00030 uart_db.printf("\n\rZE08 return "); 00031 #endif 00032 00033 for(i=0; i<ZE08_DAT_LEN; i++) 00034 { 00035 while(!uart_ze08.readable()); 00036 data[i] = uart_ze08.getc(); 00037 #if defined uart_db 00038 uart_db.printf("0x%02X ", data[i]); 00039 #endif 00040 } 00041 00042 #if defined uart_db 00043 uart_db.printf(".\n\r"); 00044 #endif 00045 00046 sum = ZE08_CalCheckSum(data); 00047 if(data[ZE08_DAT_LEN - 1] == sum) 00048 { 00049 ch2oVol = data[2] *256 + data[3]; 00050 return ch2oVol; 00051 } 00052 else 00053 { 00054 #if defined uart_db 00055 uart_db.printf("Incorrect checksum 0x%02X, expect 0x%02X.\n\r", sum, data[ZE08_DAT_LEN - 1]); 00056 #endif 00057 return -1; 00058 } 00059 } 00060 00061 uint8_t ZE08_CalCheckSum(uint8_t *packet) 00062 { 00063 uint8_t i, checksum = 0; 00064 for( i = 1; i < 8; i++) 00065 { 00066 checksum += packet[i]; 00067 } 00068 checksum = 0xff - checksum; 00069 checksum += 1; 00070 return checksum; 00071 }
Generated on Fri Jul 15 2022 14:37:21 by
1.7.2