1.Gps function(eg91 & eg915q).

2.Improve at command read function, do not sleep 200ms.

3.Eg915q usbnet api fixed.
This commit is contained in:
xiaojiazhu 2023-08-08 10:30:39 +08:00
parent 2dedacfb01
commit 4304e4fb4b
6 changed files with 143 additions and 52 deletions

@ -1 +1 @@
Subproject commit 3d822939f4126eba037c4e9e716fba89260c925d Subproject commit face3d634b685baca3afa2a34c16e47f7a0d812e

View File

@ -39,7 +39,10 @@ typedef enum SF_CMD_TYPE_E {
SF_CMD_SYNC_CFG, SF_CMD_SYNC_CFG,
SF_CMD_BUTT SF_CMD_BUTT
} SF_CMD_TYPE_E; } SF_CMD_TYPE_E;
typedef struct sf_gps_param {
int timeout_ms;
int period_ms;
}SF_GPS_PARAM;
SINT32 app_file_upload(SF_FILE_ATTR_S *pstFileAttr, SF_FN_PARAM_S *pfnParam); SINT32 app_file_upload(SF_FILE_ATTR_S *pstFileAttr, SF_FN_PARAM_S *pfnParam);
SF_BOOL app_disconnect_4g_module(void); SF_BOOL app_disconnect_4g_module(void);
SINT32 app_ttyusb_IsOpen(void); SINT32 app_ttyusb_IsOpen(void);
@ -54,6 +57,13 @@ SINT32 sf_module_reboot_reg_net(void);
SINT32 sf_app_to_cardv_hd_ture(void); SINT32 sf_app_to_cardv_hd_ture(void);
int sf_check_eth0(void); int sf_check_eth0(void);
int sf_check_usb0(void); int sf_check_usb0(void);
void serach_gps_onkey_start(void);
void open_gps(void);
int get_gps_location(void);
void keep_get_gps_location(const SF_GPS_PARAM param);
void keep_seraching_gps_location(const int timeout_ms);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }

View File

@ -151,31 +151,12 @@ SINT32 sf_USB_net_init(void) {
SF_CHAR cmdStr[128] = {0}; SF_CHAR cmdStr[128] = {0};
char cmdtmp[20] = {0}; char cmdtmp[20] = {0};
UINT8 i = 0; UINT8 i = 0;
int ret = SF_FAILURE; int ret = SF_SUCCESS;
UIMenuStoreInfo *puiPara = sf_app_ui_para_get(); UIMenuStoreInfo *puiPara = sf_app_ui_para_get();
if(strncmp(puiPara->ModuleVer, GPRS_MODULE_TYPE_EG915Q, 6) == 0){
sprintf(cmdStr, "/usr/bin/quectel-CM-EG915Q -n %d&",A_PDP_INDEX);
sprintf(cmdtmp, "/dev/ttyUSB3");
}else {
sprintf(cmdStr, "/usr/bin/quectel-CM-EG91 -n %d&",A_PDP_INDEX);
sprintf(cmdtmp, "/dev/qcqmi0");
}
for (i = 0; i < 40; i++) {
if (access(cmdtmp, F_OK) == SF_SUCCESS) {
ret = SF_SUCCESS;
printf("usb net ko exist!\r\n");
break;
} else {
usleep(100 * 1000);
}
}
if (ret == SF_SUCCESS) { if (ret == SF_SUCCESS) {
ret = system(cmdStr); if(AT_MANAGER_SUCCEED != at_usbnet_init()){
if(SUCCESS != ret){ MLOGE("usb net err %d\n", AT_MANAGER_SUCCEED);
MLOGE("usb net err %d\n",ret);
}else { }else {
for (i = 0; i < 40; i++) { for (i = 0; i < 40; i++) {
if(strncmp(puiPara->ModuleVer, GPRS_MODULE_TYPE_EG915Q, 6) == 0){ if(strncmp(puiPara->ModuleVer, GPRS_MODULE_TYPE_EG915Q, 6) == 0){
@ -1296,26 +1277,12 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) {
break; break;
#endif #endif
s32ret = sf_get_utc(); s32ret = sf_get_utc();
if ((s32ret == SF_SIM_ERROR_UTC) || (SF_ON == pCustomerParam->GpsSwitch)) {
SF_PARA_TIME_S current_time = { 0, 0, 0, 0, 0, 0};
s32ret = sf_get_ntp(s32ret, &current_time);
#define NTP_TIME_LENGTH 32
char ntp_time[NTP_TIME_LENGTH] = {0};
snprintf(ntp_time, NTP_TIME_LENGTH, "%04d/%02d/%02d,%02d:%02d:%02d",
current_time.Year, current_time.Mon, current_time.Day,
current_time.Hour, current_time.Min, current_time.Sec);
gps_map_update(pCustomerParam->Sim4gApn, pCustomerParam->Sim4gUsr, pCustomerParam->Sim4gPwd, ntp_time);
gps_open(ntp_time);
//while(1)
//{
//GpsLocation location = gps_get_location();
//LogInfo("location.latitude = %s\n", location.latitude);
//LogInfo("location.longitude = %s\n", location.longitude);
//}
}
sf_4G_usb_net_apn_cfg(pfnParam); sf_4G_usb_net_apn_cfg(pfnParam);
sf_USB_net_init(); sf_USB_net_init();
if ((SF_ON == pCustomerParam->GpsSwitch)) {
serach_gps_onkey_start();
}
if(sf_get_signal_ready()){ if(sf_get_signal_ready()){
if(SUCCESS != sf_connect_ftps_server()){ if(SUCCESS != sf_connect_ftps_server()){
@ -1437,9 +1404,8 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) {
sf_USB_net_init(); sf_USB_net_init();
s32ret = sf_get_utc(); s32ret = sf_get_utc();
if ((s32ret == SF_SIM_ERROR_UTC) || (SF_ON == pCustomerParam->GpsSwitch)) { if ((SF_ON == pCustomerParam->GpsSwitch)) {
SF_PARA_TIME_S current_time = { 0, 0, 0, 0, 0, 0}; open_gps();
s32ret = sf_get_ntp(s32ret, &current_time);
} }
if (1 == pCustomerParam->NeedTimeSyncStartUp) { if (1 == pCustomerParam->NeedTimeSyncStartUp) {
printf("[%s:%d]8 between A and B,no reg net again,no reset time sync.\n", printf("[%s:%d]8 between A and B,no reg net again,no reset time sync.\n",
@ -1481,9 +1447,8 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) {
sf_USB_net_init(); sf_USB_net_init();
s32ret = sf_get_utc(); s32ret = sf_get_utc();
if ((s32ret == SF_SIM_ERROR_UTC) || (SF_ON == pCustomerParam->GpsSwitch)) { if ((SF_ON == pCustomerParam->GpsSwitch)) {
SF_PARA_TIME_S current_time = { 0, 0, 0, 0, 0, 0}; open_gps();
s32ret = sf_get_ntp(s32ret, &current_time);
} }
if (0 != sf_get_cq_signal()) { if (0 != sf_get_cq_signal()) {
pCustomerParam->GpsSendFlag = 1; pCustomerParam->GpsSendFlag = 1;
@ -1519,6 +1484,18 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) {
sf_4G_usb_net_apn_cfg(pfnParam); sf_4G_usb_net_apn_cfg(pfnParam);
sf_USB_net_init(); sf_USB_net_init();
if ((SF_ON == pCustomerParam->GpsSwitch)) {
const int KEEP_SERACHING_TIMEOUT_MS = 2000;
const int KEEP_SERACHING_PERIOD_MS = 200;
// keep_seraching_gps_location(KEEP_SERACHING_TIMEOUT_S);
SF_GPS_PARAM gps_param = {
.timeout_ms = KEEP_SERACHING_TIMEOUT_MS,
.period_ms = KEEP_SERACHING_PERIOD_MS,
};
keep_get_gps_location(gps_param);
gps_close();
}
s32ret = sf_read_message(); s32ret = sf_read_message();
SF_APPCOMM_CHECK_RETURN(s32ret, SF_APP_ERROR_REQUEST); SF_APPCOMM_CHECK_RETURN(s32ret, SF_APP_ERROR_REQUEST);
@ -1752,6 +1729,107 @@ int sf_check_usb0(void)
free(output); free(output);
return 0; return 0;
} }
void open_gps(void)
{
UIMenuStoreInfo *pCustomerParam = sf_app_ui_para_get();
SINT32 s32ret = 0;
SF_PARA_TIME_S current_time = { 0, 0, 0, 0, 0, 0};
s32ret = sf_get_ntp(s32ret, &current_time);
#define NTP_TIME_LENGTH 32
char ntp_time[NTP_TIME_LENGTH] = {0};
snprintf(ntp_time, NTP_TIME_LENGTH, "%04d/%02d/%02d,%02d:%02d:%02d",
current_time.Year, current_time.Mon, current_time.Day,
current_time.Hour, current_time.Min, current_time.Sec);
gps_map_update(pCustomerParam->Sim4gApn, pCustomerParam->Sim4gUsr, pCustomerParam->Sim4gPwd, ntp_time);
gps_open(ntp_time);
}
#define GPS_GET_SUCCEED 0
#define GPS_GET_FAILED -1
int get_gps_location(void)
{
UIMenuStoreInfo *pCustomerParam = sf_app_ui_para_get();
GpsLocation location;
memset(&location, 0, sizeof(GpsLocation));
location = gps_get_location();
if (strlen(location.latitude) > 0 && strlen(location.longitude) > 0)
{
LogInfo("Get gps location!\n");
memset(pCustomerParam->Longitude, 0, sizeof(pCustomerParam->Longitude));
memset(pCustomerParam->Latitude, 0, sizeof(pCustomerParam->Latitude));
strcpy(pCustomerParam->Longitude, location.longitude);
strcpy(pCustomerParam->Latitude, location.latitude);
LogInfo("location.Longitude = %s\n", pCustomerParam->Longitude);
LogInfo("location.Latitude = %s\n", pCustomerParam->Latitude);
return GPS_GET_SUCCEED;
}
return GPS_GET_FAILED;
}
void keep_get_gps_location(const SF_GPS_PARAM param)
{
int seraching = 0;
while(seraching < param.timeout_ms)
{
// const int SERACHING_ONCE_MS = 200;
if (GPS_GET_SUCCEED == get_gps_location())
{
break;
}
usleep(param.period_ms * 1000);
seraching += param.period_ms;
}
return;
}
static void *keep_get_gps_location_thread(void *param)
{
SF_GPS_PARAM *gps_param = (SF_GPS_PARAM *)param;
keep_get_gps_location(*gps_param);
return NULL;
}
void keep_seraching_gps_location(const int timeout_ms)
{
static SF_GPS_PARAM gps_param;
const int KEEP_SERACHING_PERIOD_MS = 200;
gps_param.timeout_ms = timeout_ms;
gps_param.period_ms = KEEP_SERACHING_PERIOD_MS;
pthread_t pthid;
int ret = -1;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ret = pthread_create(&pthid, &attr, keep_get_gps_location_thread, &gps_param);
if (ret != 0)
{
LogError("keep_seraching_gps_location failed.\n");
}
pthread_attr_destroy(&attr);
}
static void *serach_gps_onkey_thread(void *param)
{
const int SERACH_GPS_TIMEOUT_MS = 90 * 1000;
const int SERACH_PERIOD_MS = 1000 * 15;
SF_GPS_PARAM gps_param;
gps_param.timeout_ms = SERACH_GPS_TIMEOUT_MS;
gps_param.period_ms = SERACH_PERIOD_MS;
open_gps();
keep_get_gps_location(gps_param);
return NULL;
}
void serach_gps_onkey_start(void)
{
pthread_t pthid;
int ret = -1;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ret = pthread_create(&pthid, &attr, serach_gps_onkey_thread, NULL);
if (ret != 0)
{
LogError("serach_gps_onkey_start failed.\n");
}
pthread_attr_destroy(&attr);
}
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }

View File

@ -960,7 +960,10 @@ unsigned char sf_commu_parse_mcu_data(unsigned char * src, unsigned int len)
sf_com_message_send_to_cardv(&stMessageBuf); sf_com_message_send_to_cardv(&stMessageBuf);
} }
else if(0 == stMessageBuf.arg3) //ON->OFF else if(0 == stMessageBuf.arg3) //ON->OFF
{ {
UIMenuStoreInfo *pCustomerParam = sf_app_ui_para_get();
memset(pCustomerParam->Longitude, 0, sizeof(pCustomerParam->Longitude));
memset(pCustomerParam->Latitude, 0, sizeof(pCustomerParam->Latitude));
sf_set_module_sleep_flag(0); sf_set_module_sleep_flag(0);
sf_com_message_send_to_cardv(&stMessageBuf); sf_com_message_send_to_cardv(&stMessageBuf);
sf_sys_status_led_set(SF_LED_SYS_STATE_POWER_OFF); sf_sys_status_led_set(SF_LED_SYS_STATE_POWER_OFF);

View File

@ -94,7 +94,7 @@ UINT8 sf_mcu_write_multi(UINT8 reg[], UINT8 data[], UINT32 num)
{ {
for(i = 0; i < num; i++) for(i = 0; i < num; i++)
{ {
printf("W_addr[%d]=0x%02x\n", reg[i], data[i]); printf("W_addr multi[%d]=0x%02x\n", reg[i], data[i]);
} }
return SUCCESS; return SUCCESS;
} }
@ -1269,7 +1269,7 @@ void sf_dailyReport_refresh(void)
} }
else else
{ {
puiPara->DailyReportTime2.Hour = (preRtcTime.Hour + (preRtcTime.Min + 30) / 60) % 24; puiPara->DailyReportTime2.Hour = (preRtcTime.Hour + (preRtcTime.Min + 5) / 60) % 24;
puiPara->DailyReportTime2.Min = (preRtcTime.Min + 5) % 60; puiPara->DailyReportTime2.Min = (preRtcTime.Min + 5) % 60;
} }
} }

View File

@ -249,8 +249,8 @@ static SINT32 hal_ttyusb_read(SINT32 fd, SF_CHAR *recvBuf, SINT32 waitTime)
SINT32 s32ret = 0; SINT32 s32ret = 0;
fd_set read_fds; fd_set read_fds;
struct timeval TimeoutVal; struct timeval TimeoutVal;
if(waitTime > 0) // if(waitTime > 0)
sf_sleep_ms(waitTime); // sf_sleep_ms(waitTime);
while(waitTime--){ while(waitTime--){