Init Project for PSM

Committer:
AustinKim
Date:
Wed Sep 11 07:34:38 2019 +0000
Revision:
0:739a04e1daf4
Init Project for PSM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AustinKim 0:739a04e1daf4 1 /* WIZnet IoT Shield Cat.M1 Sample code for Arm MBED
AustinKim 0:739a04e1daf4 2 * Copyright (c) 2019 WIZnet Co., Ltd.
AustinKim 0:739a04e1daf4 3 * SPDX-License-Identifier: Apache-2.0
AustinKim 0:739a04e1daf4 4 */
AustinKim 0:739a04e1daf4 5
AustinKim 0:739a04e1daf4 6 /*
AustinKim 0:739a04e1daf4 7 * Licensed under the Apache License, Version 2.0 (the "License");
AustinKim 0:739a04e1daf4 8 * you may not use this file except in compliance with the License.
AustinKim 0:739a04e1daf4 9 * You may obtain a copy of the License at
AustinKim 0:739a04e1daf4 10 *
AustinKim 0:739a04e1daf4 11 * http://www.apache.org/licenses/LICENSE-2.0
AustinKim 0:739a04e1daf4 12 *
AustinKim 0:739a04e1daf4 13 * Unless required by applicable law or agreed to in writing, software
AustinKim 0:739a04e1daf4 14 * distributed under the License is distributed on an "AS IS" BASIS,
AustinKim 0:739a04e1daf4 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AustinKim 0:739a04e1daf4 16 *
AustinKim 0:739a04e1daf4 17 * See the License for the specific language governing permissions and
AustinKim 0:739a04e1daf4 18 * limitations under the License.
AustinKim 0:739a04e1daf4 19 *
AustinKim 0:739a04e1daf4 20 */
AustinKim 0:739a04e1daf4 21
AustinKim 0:739a04e1daf4 22 #include "mbed.h"
AustinKim 0:739a04e1daf4 23
AustinKim 0:739a04e1daf4 24 #include <string>
AustinKim 0:739a04e1daf4 25
AustinKim 0:739a04e1daf4 26 #define RET_OK 1
AustinKim 0:739a04e1daf4 27 #define RET_NOK -1
AustinKim 0:739a04e1daf4 28 #define DEBUG_ENABLE 1
AustinKim 0:739a04e1daf4 29 #define DEBUG_DISABLE 0
AustinKim 0:739a04e1daf4 30 #define ON 1
AustinKim 0:739a04e1daf4 31 #define OFF 0
AustinKim 0:739a04e1daf4 32
AustinKim 0:739a04e1daf4 33 #define MAX_BUF_SIZE 1024
AustinKim 0:739a04e1daf4 34
AustinKim 0:739a04e1daf4 35 #define WM01_APN_PROTOCOL_IPv4 1
AustinKim 0:739a04e1daf4 36 #define WM01_APN_PROTOCOL_IPv6 2
AustinKim 0:739a04e1daf4 37 #define WM01_DEFAULT_TIMEOUT 1000
AustinKim 0:739a04e1daf4 38 #define WM01_CONNECT_TIMEOUT 15000
AustinKim 0:739a04e1daf4 39 #define WM01_SEND_TIMEOUT 500
AustinKim 0:739a04e1daf4 40 #define WM01_RECV_TIMEOUT 500
AustinKim 0:739a04e1daf4 41 #define WM01_BOOTING_TIME 15000
AustinKim 0:739a04e1daf4 42
AustinKim 0:739a04e1daf4 43 #define WM01_APN_PROTOCOL WM01_APN_PROTOCOL_IPv6
AustinKim 0:739a04e1daf4 44 #define WM01_DEFAULT_BAUD_RATE 115200
AustinKim 0:739a04e1daf4 45 #define WM01_PARSER_DELIMITER "\r\n"
AustinKim 0:739a04e1daf4 46
AustinKim 0:739a04e1daf4 47 #define CATM1_APN_SKT "lte-internet.sktelecom.com"
AustinKim 0:739a04e1daf4 48
AustinKim 0:739a04e1daf4 49 #define CATM1_DEVICE_NAME_WM01 "WM01"
AustinKim 0:739a04e1daf4 50 #define DEVNAME CATM1_DEVICE_NAME_WM01
AustinKim 0:739a04e1daf4 51
AustinKim 0:739a04e1daf4 52 #define devlog(f_, ...) if(CATM1_DEVICE_DEBUG == DEBUG_ENABLE) { pc.printf("\r\n[%s] ", DEVNAME); pc.printf((f_), ##__VA_ARGS__); }
AustinKim 0:739a04e1daf4 53 #define myprintf(f_, ...) {pc.printf("\r\n[MAIN] "); pc.printf((f_), ##__VA_ARGS__);}
AustinKim 0:739a04e1daf4 54
AustinKim 0:739a04e1daf4 55 /* Pin configuraiton */
AustinKim 0:739a04e1daf4 56 // Cat.M1
AustinKim 0:739a04e1daf4 57 #define MBED_CONF_IOTSHIELD_CATM1_TX D8
AustinKim 0:739a04e1daf4 58 #define MBED_CONF_IOTSHIELD_CATM1_RX D2
AustinKim 0:739a04e1daf4 59 #define MBED_CONF_IOTSHIELD_CATM1_RESET D7
AustinKim 0:739a04e1daf4 60 #define MBED_CONF_IOTSHIELD_CATM1_PWRKEY D9
AustinKim 0:739a04e1daf4 61
AustinKim 0:739a04e1daf4 62 // Sensors
AustinKim 0:739a04e1daf4 63 #define MBED_CONF_IOTSHIELD_SENSOR_CDS A0
AustinKim 0:739a04e1daf4 64 #define MBED_CONF_IOTSHIELD_SENSOR_TEMP A1
AustinKim 0:739a04e1daf4 65
AustinKim 0:739a04e1daf4 66 /* Debug message settings */
AustinKim 0:739a04e1daf4 67 #define WM01_PARSER_DEBUG DEBUG_DISABLE
AustinKim 0:739a04e1daf4 68 #define CATM1_DEVICE_DEBUG DEBUG_ENABLE
AustinKim 0:739a04e1daf4 69
AustinKim 0:739a04e1daf4 70 char periodic_tau[] = "10100001"; // (60s * 1) + (3s ~ 4s) = 63s ~ 64s
AustinKim 0:739a04e1daf4 71 char active_time[] = "00000001"; // (2s * 1) + (24s ~ 27s) = 26s ~ 29s
AustinKim 0:739a04e1daf4 72
AustinKim 0:739a04e1daf4 73 // Functions: Print information
AustinKim 0:739a04e1daf4 74 void printInfo(void);
AustinKim 0:739a04e1daf4 75
AustinKim 0:739a04e1daf4 76 // Functions: Module Status
AustinKim 0:739a04e1daf4 77 void waitCatM1Ready(void);
AustinKim 0:739a04e1daf4 78 int8_t setEchoStatus_WM01(bool onoff);
AustinKim 0:739a04e1daf4 79 int8_t getUsimStatus_WM01(void);
AustinKim 0:739a04e1daf4 80 int8_t getNetworkStatus_WM01(void);
AustinKim 0:739a04e1daf4 81
AustinKim 0:739a04e1daf4 82 // Functions: PSM (Power Saving Mode)
AustinKim 0:739a04e1daf4 83 int8_t setPsmActivate_WM01(char *Requested_Periodic_TAU, char *Requested_Active_Time);
AustinKim 0:739a04e1daf4 84 int8_t setPsmDeactivate_WM01(void);
AustinKim 0:739a04e1daf4 85
AustinKim 0:739a04e1daf4 86 // Functions: Network time
AustinKim 0:739a04e1daf4 87 int8_t getNetworkTimeLocal_WM01(char *time);
AustinKim 0:739a04e1daf4 88 void setFlagGettime(void);
AustinKim 0:739a04e1daf4 89 void clearFlagGettime(void);
AustinKim 0:739a04e1daf4 90
AustinKim 0:739a04e1daf4 91 Serial pc(USBTX, USBRX); // USB debug
AustinKim 0:739a04e1daf4 92
AustinKim 0:739a04e1daf4 93 UARTSerial *_serial; // Cat.M1 module
AustinKim 0:739a04e1daf4 94 ATCmdParser *_parser;
AustinKim 0:739a04e1daf4 95
AustinKim 0:739a04e1daf4 96 DigitalOut _RESET_WM01(MBED_CONF_IOTSHIELD_CATM1_RESET);
AustinKim 0:739a04e1daf4 97 DigitalOut _PWRKEY_WM01(MBED_CONF_IOTSHIELD_CATM1_PWRKEY);
AustinKim 0:739a04e1daf4 98
AustinKim 0:739a04e1daf4 99 Ticker flip;
AustinKim 0:739a04e1daf4 100
AustinKim 0:739a04e1daf4 101 bool flag_gettime = false;
AustinKim 0:739a04e1daf4 102
AustinKim 0:739a04e1daf4 103 void serialPcInit(void)
AustinKim 0:739a04e1daf4 104 {
AustinKim 0:739a04e1daf4 105 pc.baud(115200);
AustinKim 0:739a04e1daf4 106 pc.format(8, Serial::None, 1);
AustinKim 0:739a04e1daf4 107 }
AustinKim 0:739a04e1daf4 108
AustinKim 0:739a04e1daf4 109 void serialDeviceInit(PinName tx, PinName rx, int baudrate)
AustinKim 0:739a04e1daf4 110 {
AustinKim 0:739a04e1daf4 111 _serial = new UARTSerial(tx, rx, baudrate);
AustinKim 0:739a04e1daf4 112 }
AustinKim 0:739a04e1daf4 113
AustinKim 0:739a04e1daf4 114 void serialAtParserInit(const char *delimiter, bool debug_en)
AustinKim 0:739a04e1daf4 115 {
AustinKim 0:739a04e1daf4 116 _parser = new ATCmdParser(_serial);
AustinKim 0:739a04e1daf4 117 _parser->debug_on(debug_en);
AustinKim 0:739a04e1daf4 118 _parser->set_delimiter(delimiter);
AustinKim 0:739a04e1daf4 119 _parser->set_timeout(WM01_DEFAULT_TIMEOUT);
AustinKim 0:739a04e1daf4 120 }
AustinKim 0:739a04e1daf4 121
AustinKim 0:739a04e1daf4 122 void catm1DeviceInit(void)
AustinKim 0:739a04e1daf4 123 {
AustinKim 0:739a04e1daf4 124 serialDeviceInit( MBED_CONF_IOTSHIELD_CATM1_TX,
AustinKim 0:739a04e1daf4 125 MBED_CONF_IOTSHIELD_CATM1_RX,
AustinKim 0:739a04e1daf4 126 WM01_DEFAULT_BAUD_RATE);
AustinKim 0:739a04e1daf4 127
AustinKim 0:739a04e1daf4 128 serialAtParserInit( WM01_PARSER_DELIMITER,
AustinKim 0:739a04e1daf4 129 WM01_PARSER_DEBUG);
AustinKim 0:739a04e1daf4 130 }
AustinKim 0:739a04e1daf4 131
AustinKim 0:739a04e1daf4 132 void catm1DeviceReset_WM01(void)
AustinKim 0:739a04e1daf4 133 {
AustinKim 0:739a04e1daf4 134 _RESET_WM01 = 1;
AustinKim 0:739a04e1daf4 135 _PWRKEY_WM01 = 1;
AustinKim 0:739a04e1daf4 136 wait_ms(300);
AustinKim 0:739a04e1daf4 137
AustinKim 0:739a04e1daf4 138 _RESET_WM01 = 0;
AustinKim 0:739a04e1daf4 139 _PWRKEY_WM01 = 0;
AustinKim 0:739a04e1daf4 140 wait_ms(400);
AustinKim 0:739a04e1daf4 141
AustinKim 0:739a04e1daf4 142 _RESET_WM01 = 1;
AustinKim 0:739a04e1daf4 143 wait_ms(1000);
AustinKim 0:739a04e1daf4 144 }
AustinKim 0:739a04e1daf4 145
AustinKim 0:739a04e1daf4 146 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 147 // Main routine
AustinKim 0:739a04e1daf4 148 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 149
AustinKim 0:739a04e1daf4 150 int main()
AustinKim 0:739a04e1daf4 151 {
AustinKim 0:739a04e1daf4 152 bool psm_en = false;
AustinKim 0:739a04e1daf4 153 char time[30] = {0, };
AustinKim 0:739a04e1daf4 154 float elapsed_time_sec = 0;
AustinKim 0:739a04e1daf4 155
AustinKim 0:739a04e1daf4 156 Timer t;
AustinKim 0:739a04e1daf4 157
AustinKim 0:739a04e1daf4 158 serialPcInit();
AustinKim 0:739a04e1daf4 159 catm1DeviceInit();
AustinKim 0:739a04e1daf4 160
AustinKim 0:739a04e1daf4 161 myprintf("Waiting for Cat.M1 Module Ready...\r\n");
AustinKim 0:739a04e1daf4 162
AustinKim 0:739a04e1daf4 163 catm1DeviceReset_WM01();
AustinKim 0:739a04e1daf4 164
AustinKim 0:739a04e1daf4 165 waitCatM1Ready();
AustinKim 0:739a04e1daf4 166
AustinKim 0:739a04e1daf4 167 wait_ms(5000);
AustinKim 0:739a04e1daf4 168
AustinKim 0:739a04e1daf4 169 myprintf("System Init Complete\r\n");
AustinKim 0:739a04e1daf4 170
AustinKim 0:739a04e1daf4 171 printInfo();
AustinKim 0:739a04e1daf4 172
AustinKim 0:739a04e1daf4 173 setEchoStatus_WM01(OFF);
AustinKim 0:739a04e1daf4 174
AustinKim 0:739a04e1daf4 175 getUsimStatus_WM01();
AustinKim 0:739a04e1daf4 176
AustinKim 0:739a04e1daf4 177 getNetworkStatus_WM01();
AustinKim 0:739a04e1daf4 178
AustinKim 0:739a04e1daf4 179 #if 0
AustinKim 0:739a04e1daf4 180 // PSM disable
AustinKim 0:739a04e1daf4 181 setPsmDeactivate_WM01();
AustinKim 0:739a04e1daf4 182 #endif
AustinKim 0:739a04e1daf4 183
AustinKim 0:739a04e1daf4 184 if(psm_en != true)
AustinKim 0:739a04e1daf4 185 {
AustinKim 0:739a04e1daf4 186 if(setPsmActivate_WM01(periodic_tau, active_time) == RET_OK)
AustinKim 0:739a04e1daf4 187 {
AustinKim 0:739a04e1daf4 188 myprintf("Cat.M1 PSM enable, Device reboot\r\n");
AustinKim 0:739a04e1daf4 189
AustinKim 0:739a04e1daf4 190 // Cat.M1 reboot
AustinKim 0:739a04e1daf4 191 catm1DeviceReset_WM01();
AustinKim 0:739a04e1daf4 192
AustinKim 0:739a04e1daf4 193 waitCatM1Ready();
AustinKim 0:739a04e1daf4 194 }
AustinKim 0:739a04e1daf4 195 else
AustinKim 0:739a04e1daf4 196 {
AustinKim 0:739a04e1daf4 197 myprintf("Cat.M1 PSM enable failed\r\n");
AustinKim 0:739a04e1daf4 198 }
AustinKim 0:739a04e1daf4 199 }
AustinKim 0:739a04e1daf4 200
AustinKim 0:739a04e1daf4 201 // Timer event callback
AustinKim 0:739a04e1daf4 202 flip.attach(callback(&setFlagGettime), 1.0);
AustinKim 0:739a04e1daf4 203
AustinKim 0:739a04e1daf4 204 while(1)
AustinKim 0:739a04e1daf4 205 {
AustinKim 0:739a04e1daf4 206 if(flag_gettime)
AustinKim 0:739a04e1daf4 207 {
AustinKim 0:739a04e1daf4 208 if(getNetworkTimeLocal_WM01(time) == RET_OK)
AustinKim 0:739a04e1daf4 209 {
AustinKim 0:739a04e1daf4 210 if(elapsed_time_sec > 0)
AustinKim 0:739a04e1daf4 211 {
AustinKim 0:739a04e1daf4 212 t.stop();
AustinKim 0:739a04e1daf4 213
AustinKim 0:739a04e1daf4 214 myprintf("Cat.M1 Active, Sleep time: %.2fsec", elapsed_time_sec);
AustinKim 0:739a04e1daf4 215
AustinKim 0:739a04e1daf4 216 elapsed_time_sec = 0;
AustinKim 0:739a04e1daf4 217 }
AustinKim 0:739a04e1daf4 218
AustinKim 0:739a04e1daf4 219 myprintf("%s", time);
AustinKim 0:739a04e1daf4 220 }
AustinKim 0:739a04e1daf4 221 else
AustinKim 0:739a04e1daf4 222 {
AustinKim 0:739a04e1daf4 223 if(elapsed_time_sec == 0)
AustinKim 0:739a04e1daf4 224 {
AustinKim 0:739a04e1daf4 225 t.reset();
AustinKim 0:739a04e1daf4 226 t.start();
AustinKim 0:739a04e1daf4 227
AustinKim 0:739a04e1daf4 228 myprintf("%s", "PSM Power Down Start");
AustinKim 0:739a04e1daf4 229 }
AustinKim 0:739a04e1daf4 230
AustinKim 0:739a04e1daf4 231 elapsed_time_sec = t.read();
AustinKim 0:739a04e1daf4 232
AustinKim 0:739a04e1daf4 233 myprintf("Cat.M1 PSM, %.2f", elapsed_time_sec);
AustinKim 0:739a04e1daf4 234 }
AustinKim 0:739a04e1daf4 235
AustinKim 0:739a04e1daf4 236 clearFlagGettime();
AustinKim 0:739a04e1daf4 237 }
AustinKim 0:739a04e1daf4 238 }
AustinKim 0:739a04e1daf4 239 }
AustinKim 0:739a04e1daf4 240
AustinKim 0:739a04e1daf4 241 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 242 // Functions: Print information
AustinKim 0:739a04e1daf4 243 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 244
AustinKim 0:739a04e1daf4 245 void printInfo(void)
AustinKim 0:739a04e1daf4 246 {
AustinKim 0:739a04e1daf4 247 myprintf("WIZnet IoT Shield for Arm MBED");
AustinKim 0:739a04e1daf4 248 myprintf("LTE Cat.M1 Version");
AustinKim 0:739a04e1daf4 249 myprintf("=================================================");
AustinKim 0:739a04e1daf4 250 myprintf(">> Target Board: WIoT-WM01 (Woorinet WM-N400MSE)");
AustinKim 0:739a04e1daf4 251 myprintf(">> Sample Code: PSM Test");
AustinKim 0:739a04e1daf4 252 myprintf("=================================================\r\n");
AustinKim 0:739a04e1daf4 253 }
AustinKim 0:739a04e1daf4 254
AustinKim 0:739a04e1daf4 255 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 256 // Functions: Cat.M1 Status
AustinKim 0:739a04e1daf4 257 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 258
AustinKim 0:739a04e1daf4 259 void waitCatM1Ready(void)
AustinKim 0:739a04e1daf4 260 {
AustinKim 0:739a04e1daf4 261 while(1)
AustinKim 0:739a04e1daf4 262 {
AustinKim 0:739a04e1daf4 263 if(_parser->send("AT") && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 264 {
AustinKim 0:739a04e1daf4 265 myprintf("WM01 is Available\r\n");
AustinKim 0:739a04e1daf4 266
AustinKim 0:739a04e1daf4 267 return;
AustinKim 0:739a04e1daf4 268 }
AustinKim 0:739a04e1daf4 269 }
AustinKim 0:739a04e1daf4 270 }
AustinKim 0:739a04e1daf4 271
AustinKim 0:739a04e1daf4 272 int8_t setEchoStatus_WM01(bool onoff)
AustinKim 0:739a04e1daf4 273 {
AustinKim 0:739a04e1daf4 274 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 275 char _buf[10];
AustinKim 0:739a04e1daf4 276
AustinKim 0:739a04e1daf4 277 sprintf((char *)_buf, "ATE%d", onoff);
AustinKim 0:739a04e1daf4 278
AustinKim 0:739a04e1daf4 279 if(_parser->send(_buf) && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 280 {
AustinKim 0:739a04e1daf4 281 devlog("Turn Echo %s : success\r\n", onoff ? "ON" : "OFF");
AustinKim 0:739a04e1daf4 282
AustinKim 0:739a04e1daf4 283 ret = RET_OK;
AustinKim 0:739a04e1daf4 284 }
AustinKim 0:739a04e1daf4 285 else
AustinKim 0:739a04e1daf4 286 {
AustinKim 0:739a04e1daf4 287 devlog("Turn Echo %s : failed\r\n", onoff ? "ON" : "OFF");
AustinKim 0:739a04e1daf4 288 }
AustinKim 0:739a04e1daf4 289
AustinKim 0:739a04e1daf4 290 return ret;
AustinKim 0:739a04e1daf4 291 }
AustinKim 0:739a04e1daf4 292
AustinKim 0:739a04e1daf4 293 int8_t getUsimStatus_WM01(void)
AustinKim 0:739a04e1daf4 294 {
AustinKim 0:739a04e1daf4 295 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 296
AustinKim 0:739a04e1daf4 297 if(_parser->send("AT$$STAT?") && _parser->recv("$$STAT:READY") && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 298 {
AustinKim 0:739a04e1daf4 299 devlog("USIM Status : READY\r\n");
AustinKim 0:739a04e1daf4 300
AustinKim 0:739a04e1daf4 301 ret = RET_OK;
AustinKim 0:739a04e1daf4 302 }
AustinKim 0:739a04e1daf4 303 else
AustinKim 0:739a04e1daf4 304 {
AustinKim 0:739a04e1daf4 305 devlog("Retrieving USIM Status failed\r\n");
AustinKim 0:739a04e1daf4 306 }
AustinKim 0:739a04e1daf4 307
AustinKim 0:739a04e1daf4 308 return ret;
AustinKim 0:739a04e1daf4 309 }
AustinKim 0:739a04e1daf4 310
AustinKim 0:739a04e1daf4 311 int8_t getNetworkStatus_WM01(void)
AustinKim 0:739a04e1daf4 312 {
AustinKim 0:739a04e1daf4 313 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 314 int val, stat;
AustinKim 0:739a04e1daf4 315
AustinKim 0:739a04e1daf4 316 if(_parser->send("AT+CEREG?") && _parser->recv("+CEREG: %d,%d", &val, &stat) && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 317 {
AustinKim 0:739a04e1daf4 318 if((val == 0) && (stat == 1))
AustinKim 0:739a04e1daf4 319 {
AustinKim 0:739a04e1daf4 320 devlog("Network Status : attached\r\n");
AustinKim 0:739a04e1daf4 321
AustinKim 0:739a04e1daf4 322 ret = RET_OK;
AustinKim 0:739a04e1daf4 323 }
AustinKim 0:739a04e1daf4 324 else
AustinKim 0:739a04e1daf4 325 {
AustinKim 0:739a04e1daf4 326 devlog("Network Status : %d, %d\r\n", val, stat);
AustinKim 0:739a04e1daf4 327 }
AustinKim 0:739a04e1daf4 328 }
AustinKim 0:739a04e1daf4 329 else
AustinKim 0:739a04e1daf4 330 {
AustinKim 0:739a04e1daf4 331 devlog("Network Status : Error\r\n");
AustinKim 0:739a04e1daf4 332 }
AustinKim 0:739a04e1daf4 333
AustinKim 0:739a04e1daf4 334 return ret;
AustinKim 0:739a04e1daf4 335 }
AustinKim 0:739a04e1daf4 336
AustinKim 0:739a04e1daf4 337 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 338 // Functions: Cat.M1 PSM activate / deactivate
AustinKim 0:739a04e1daf4 339 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 340
AustinKim 0:739a04e1daf4 341 int8_t setPsmActivate_WM01(char *Requested_Periodic_TAU, char *Requested_Active_Time)
AustinKim 0:739a04e1daf4 342 {
AustinKim 0:739a04e1daf4 343 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 344
AustinKim 0:739a04e1daf4 345 if(_parser->send("AT+CPSMS=1,,,\"%s\",\"%s\"", Requested_Periodic_TAU, Requested_Active_Time) && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 346 {
AustinKim 0:739a04e1daf4 347 devlog("PSM activate : success\r\n");
AustinKim 0:739a04e1daf4 348
AustinKim 0:739a04e1daf4 349 ret = RET_OK;
AustinKim 0:739a04e1daf4 350 }
AustinKim 0:739a04e1daf4 351 else
AustinKim 0:739a04e1daf4 352 {
AustinKim 0:739a04e1daf4 353 devlog("PSM activate : failed\r\n");
AustinKim 0:739a04e1daf4 354 }
AustinKim 0:739a04e1daf4 355
AustinKim 0:739a04e1daf4 356 return ret;
AustinKim 0:739a04e1daf4 357 }
AustinKim 0:739a04e1daf4 358
AustinKim 0:739a04e1daf4 359 int8_t setPsmDeactivate_WM01(void)
AustinKim 0:739a04e1daf4 360 {
AustinKim 0:739a04e1daf4 361 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 362
AustinKim 0:739a04e1daf4 363 if(_parser->send("AT+CPSMS=0") && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 364 {
AustinKim 0:739a04e1daf4 365 devlog("PSM deactivate : success\r\n");
AustinKim 0:739a04e1daf4 366 }
AustinKim 0:739a04e1daf4 367 else
AustinKim 0:739a04e1daf4 368 {
AustinKim 0:739a04e1daf4 369 devlog("PSM deactivate : failed\r\n");
AustinKim 0:739a04e1daf4 370 }
AustinKim 0:739a04e1daf4 371
AustinKim 0:739a04e1daf4 372 return ret;
AustinKim 0:739a04e1daf4 373 }
AustinKim 0:739a04e1daf4 374
AustinKim 0:739a04e1daf4 375 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 376 // Functions: Cat.M1 Network time
AustinKim 0:739a04e1daf4 377 // ----------------------------------------------------------------
AustinKim 0:739a04e1daf4 378
AustinKim 0:739a04e1daf4 379 int8_t getNetworkTimeLocal_WM01(char *time)
AustinKim 0:739a04e1daf4 380 {
AustinKim 0:739a04e1daf4 381 int8_t ret = RET_NOK;
AustinKim 0:739a04e1daf4 382
AustinKim 0:739a04e1daf4 383 if(_parser->send("AT$$MSTIME?") && _parser->recv("$$MSTIME:%s\n", time) && _parser->recv("OK"))
AustinKim 0:739a04e1daf4 384 {
AustinKim 0:739a04e1daf4 385 //devlog("Get current local time success\r\n");
AustinKim 0:739a04e1daf4 386
AustinKim 0:739a04e1daf4 387 ret = RET_OK;
AustinKim 0:739a04e1daf4 388 }
AustinKim 0:739a04e1daf4 389
AustinKim 0:739a04e1daf4 390 return ret;
AustinKim 0:739a04e1daf4 391 }
AustinKim 0:739a04e1daf4 392
AustinKim 0:739a04e1daf4 393 void setFlagGettime(void)
AustinKim 0:739a04e1daf4 394 {
AustinKim 0:739a04e1daf4 395 flag_gettime = true;
AustinKim 0:739a04e1daf4 396 }
AustinKim 0:739a04e1daf4 397
AustinKim 0:739a04e1daf4 398 void clearFlagGettime(void)
AustinKim 0:739a04e1daf4 399 {
AustinKim 0:739a04e1daf4 400 flag_gettime = false;
AustinKim 0:739a04e1daf4 401 }