| /* |
| * Copyright (C) 2022 ASR Microelectronic Ltd. |
| * |
| * Author: Shuo Dai <shuodai@asrmicro.com> |
| * |
| * This file contains proprietary information. |
| * No dissemination allowed without prior written permission from |
| * ASR Microelectronic Ltd. |
| * |
| * File Description: |
| * |
| * This file implements eCall demo application |
| */ |
| |
| #include <stdint.h> |
| #include <string.h> |
| #include <stddef.h> |
| #include <stdlib.h> |
| #include <stdio.h> |
| #include "include/log.h" |
| #include "ecall_app.h" |
| #if ECALL_EXTERNAL_GPS_MODE == 0 |
| #include "gps_hub.h" |
| #include "gps.h" |
| |
| static int latlong2milliarcsec(double data) { |
| double ddata = (data < 0 ? -data : data); |
| int d = (int)(ddata); |
| int m = (int)((ddata- d) * 60); |
| double s = (double)(((ddata- d) * 60 - m) * 60); |
| int milliarcsec = (int)((d * 3600 + m * 60 + s) * 1000); |
| return milliarcsec; |
| } |
| |
| static void updateGPS2MSD(void) { |
| char buf[100] = { 0 }; |
| GPS_HUB_LOCATION_DATA current_gps = { 0 }; |
| |
| RDBGMSG("%s: enter\n", __FUNCTION__); |
| gps_hub_read(¤t_gps); |
| RDBGMSG("%s: flags:0x%lx\n", __FUNCTION__, current_gps.flags ); |
| if (current_gps.flags & GPS_LOCATION_HAS_LAT_LONG) { |
| int latitude = latlong2milliarcsec(current_gps.latitude); |
| int longitude = latlong2milliarcsec(current_gps.longitude); |
| RDBGMSG("%s: latitude %f to %d, longitude %f to %d\n", __FUNCTION__, current_gps.latitude, latitude, current_gps.longitude, longitude); |
| sprintf(buf, "AT*ECALLMSDCFG=6,\"%d, %d\",0\r", latitude, longitude); |
| ecallApp_SendAtCmd(buf, 0); |
| } |
| else { |
| sprintf(buf, "AT*ECALLMSDCFG=6,\"%d, %d\",0\r", INT32_MAX, INT32_MAX); |
| ecallApp_SendAtCmd(buf, 0); |
| } |
| |
| if (current_gps.flags & GPS_LOCATION_HAS_BEARING) { |
| char buf_bearing[100] = { 0 }; |
| int bearing = (int)(current_gps.bearing / 2); |
| sprintf(buf_bearing, "AT*ECALLMSDCFG=7,\"%d\",0\r", bearing); |
| ecallApp_SendAtCmd(buf_bearing, 0); |
| } |
| else { |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=7,\"255\",0\r", 0); |
| } |
| ecallApp_SendAtCmd("AT*ECALLMSDGEN\r", 0); |
| RDBGMSG("%s: leave\n", __FUNCTION__); |
| } |
| #endif |
| |
| /* OEM should rewrite to customize MSD content for automatically initiated eCall*/ |
| //ICAT EXPORTED FUNCTION - Audio,ECALL_APP,HandleCrashEvent |
| int HandleCrashEvent(void) { |
| #if ECALL_EXTERNAL_GPS_MODE == 1 |
| ecallApp_SendAtCmd("AT*ECALLMSD=0220040695F3997CE65F39959F3997CE6567FCC0002958F000000530000005200020\r", 0); |
| #else |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=2,\"1,0,1,6,\",0\r", 0);//control type |
| updateGPS2MSD(); |
| #endif |
| ecallApp_SendAtCmd("AT+CECALL=3\r", 0); |
| ecallApp_SendAtCmd("AT*ECALLPUSH\r", 0); |
| return 0; |
| } |
| |
| /* OEM should rewrite to customize MSD content for manually initiated eCall*/ |
| //ICAT EXPORTED FUNCTION - Audio,ECALL_APP,HandleButtonEvent |
| int HandleButtonEvent(void) { |
| #if ECALL_EXTERNAL_GPS_MODE == 1 |
| ecallApp_SendAtCmd("AT*ECALLMSD=0220040495F3997CE65F39959F3997CE6567FCC000290AB00000055000000545A040\r", 0); |
| #else |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=2,\"0,0,1,6,\",0\r", 0);//control type |
| updateGPS2MSD(); |
| #endif |
| ecallApp_SendAtCmd("AT+CECALL=2\r", 0); |
| ecallApp_SendAtCmd("AT*ECALLPUSH\r", 0); |
| return 0; |
| } |
| |
| /* OEM should rewrite to customize MSD content when PULL requested from PSAP*/ |
| //ICAT EXPORTED FUNCTION - Audio,ECALL_APP,HandleResendRequest |
| int HandleResendRequest(void) { |
| #if ECALL_EXTERNAL_GPS_MODE == 1 |
| ecallApp_SendAtCmd("AT*ECALLMSD=54321\r", 0); |
| #else |
| updateGPS2MSD(); |
| #endif |
| return 0; |
| } |
| |
| /* OEM should rewrite to customize MSD content when PUSH requested from PSAP*/ |
| int HandleSendRequest(int type) { |
| //According to GOST 33467: 6.19 'Checking transfer of SMS command for initiation of emergency call', when IVS receives PSAP SMS to initiate eCall, IVS should make an emergency call and transmit the MSD via in-band modem. In this case, eCall application should monitor URC (*ECALLDATA: 32, urc_data), collect MSD information and initiate eCall with call type=urc_data |
| if (type == 2) { |
| //manually initiated |
| HandleButtonEvent(); |
| } |
| else if (type == 3) { |
| //automatically initiated |
| HandleCrashEvent(); |
| } |
| //According to GOST 33467: 6.20 'Checking transfer of SMS command for MSD retransmission', when IVS receives PSAP SMS to retransmit MSD, IVS should update MSDand transmit the MSD using SMS.In this case, eCall application should monitor URC(*ECALLDATA: 32, urc_data), collect MSD informationand send MSD via SMS |
| else if (type == 20) { |
| ecallApp_SendAtCmd("AT*ECALLMSD=0220040495F3997CE65F39959F3997CE6567FCC000290AB00000055000000545A040\r", 0); |
| ecallApp_SendAtCmd("AT*ECALLSMS=0\r", 0); |
| } |
| else { |
| return -1; |
| } |
| return 0; |
| } |
| |
| int HandleInitEvent(void) { |
| #if ECALL_EXTERNAL_GPS_MODE == 0 |
| //pre-configure MSD fixed fileds |
| //messageIdentifier(1) & timestamp(5) are maintained by ASR eCall solution internally |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=2,\"0,0,1,6,\",0\r", 0);//control type |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=3,\"YES,YESYES,N,YESYESN\",1\r", 0);//vin |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=4,\"1,1,0,0,1,1\",1\r", 0);//vehiclePropulsionStorageType |
| ecallApp_SendAtCmd("AT*ECALLMSDCFG=10,\"2\",1\r", 0);//numberOfPassengers(optional) |
| #endif |
| return 0; |
| } |
| |
| /* OEM should rewrite to customize behaviour when MO dialing to 112*/ |
| int HandleDialEvent(void) |
| { |
| //According to GOST 33464 7.5.3.5 'While the common emergency number 112 is being dialled in Emergency Call mode, the IVDS shall notify the persons present in the vehicle cabin on such dialling, either using the IVDS status indicator (see 8.8.2), or by playback of a relevant sound signal or voice message.' |
| char* file_name = "/NVM/33464_7535.wav"; |
| if (access(file_name, F_OK) == 0) { |
| return ecallApp_ControlPlayback(file_name, 1); |
| } |
| return -1; |
| } |
| |
| /* OEM should rewrite to customize behaviour when MSD transfer start*/ |
| int HandleMSDTransferStartEvent(void) |
| { |
| //According to GOST 33464 7.5.3.6 'While the MSD is being transmitted in Emergency Call mode, the IVDS shall report that to the persons present in the vehicle cabin, either using the IVDS status indicator, or by playback of a relevant sound signal or voice message.' |
| char* file_name = "/NVM/33464_7536.wav"; |
| if (access(file_name, F_OK) == 0) { |
| return ecallApp_ControlPlayback(file_name, 1); |
| } |
| return -1; |
| } |
| |
| /* OEM should rewrite to customize behaviour when MSD transfer stop*/ |
| int HandleMSDTransferStopEvent(void) |
| { |
| //According to GOST 33464 7.5.3.7 'Once the MSD has been transmitted before the voice channel connection, the IVDS shall notify the persons present in the vehicle compartment (cabin) that the voice channel connection is about to be established, by playback of a relevant sound signal or voice message.' |
| char* file_name = "/NVM/33464_7537.wav"; |
| if (access(file_name, F_OK) == 0) { |
| return ecallApp_ControlPlayback(file_name, 1); |
| } |
| return -1; |
| } |
| |
| /* OEM should rewrite to customize behaviour when voice channel establish*/ |
| int HandleVoiceChannelEstablishEvent(void) |
| { |
| //According to GOST 33464 7.5.3.8 'Once the voice channel connection has been established, the IVDS shall report that to the persons present in the vehicle compartment (cabin) using the IVDS status indicator.' |
| char* file_name = "/NVM/33464_7538.wav"; |
| if (access(file_name, F_OK) == 0) { |
| return ecallApp_ControlPlayback(file_name, 1); |
| } |
| return -1; |
| } |
| |
| int ecallApp_Init(void) { |
| #if ECALL_EXTERNAL_GPS_MODE == 0 |
| //init ASR GPS module if not whole MSD mode |
| gps_hub_init(); |
| gps_hub_open(); |
| #endif |
| HandleInitEvent(); |
| return 0; |
| } |