project(alarmmonitor)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O2")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O0")
# Add the posix targets
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/app )
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION /app)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/alarm_d DESTINATION /app)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/S99_alarmmonitor DESTINATION /etc/init.d)
+install(FILES ${PROJECT_SOURCE_DIR}/ntpd DESTINATION /etc/default/)
install(FILES ${PROJECT_SOURCE_DIR}/log4crc DESTINATION /app)
install(FILES ${PROJECT_SOURCE_DIR}/resolv.conf.head DESTINATION /etc)
case "$1" in
start)
- start
/app/alarm_d start &
;;
stop)
#define PID_FILE "/tmp/alarmmonitor.pid"
+#define CUSTOM_NTP_CONF "/tmp/custom_ntp.conf"
+
#else
//ON BOARD
#define PID_FILE "/var/run/alarmmonitor/alarmmonitor.pid"
+#define CUSTOM_NTP_CONF "/etc/custom_ntp.conf"
+
#endif
typedef struct{
extern am_dev_t g_dev;
+int ntp_update( char *ntp_srv );
#endif //__ALARMMONITOR_H__
--- /dev/null
+#!/bin/sh
+#
+# Network Time Protocol daemon ARGS
+#
+
+if [ -r "/etc/custom_ntp.conf" ]; then
+ NTPD_ARGS="${NTPD_ARGS} -c /etc/custom_ntp.conf"
+fi
+
}
sprintf(buf, "%ld\n", (long)getpid());
- if( write(fd, buf, strlen(buf) + 1)){
+ if( write(fd, buf, strlen(buf) )){
}
//这里不关闭文件, 保持锁定状态
void remote_alarm( int alarm )
{
AM_LOGI( "remote alarm -> %d", alarm );
- alarm_start( &g_dev, alarm );
+ if( alarm >=0 && alarm<=5 ){
+ alarm_start( &g_dev, alarm );
+ }else if( alarm==6 ){
+ //TTS Data, utf8 string
+ printf( "TODO: remote play TTS ....\n" );
+ }else{
+ printf( "invalid remote alarm cmd\n" );
+ }
}
int32_t device_disp_info_update( am_dev_t *dev )
AM_LOGI( "KEYPAD timeout -> Locked" );
}
+extern int ntp_update( char * ntp_srv );
void button_event_cb( button_code_t btn_code, button_event_t btn_event, void* value )
{
int32_t alarm = 0;
}
}
+/*
+/etc/ntp.conf
+server ntp.ntsc.ac.cn iburst
+# Allow only time queries, at a limited rate, sending KoD when in excess.
+# Allow all local queries (IPv4, IPv6)
+restrict default nomodify nopeer noquery limited kod
+restrict 127.0.0.1
+restrict [::1]
+*/
+
+int ntp_update( char *ntp_srv )
+{
+ FILE *fd;
+ printf( "-------------------ntp update srv[%s]\n", ntp_srv );
+
+ char cmd[200];
+ sprintf( cmd, "grep %s %s", ntp_srv, CUSTOM_NTP_CONF );
+
+ if( system( cmd ) == 0 ){
+ AM_LOGI( "ntp conf already exist!\n" );
+ return 0;
+ }
+
+ fd = fopen( CUSTOM_NTP_CONF, "w" );
+ if( fd ){
+ fprintf( fd, "server %s iburst\n" \
+ "restrict default nomodify nopeer noquery limited kod\n" \
+ "restrict 127.0.0.1\n" \
+ "restrict [::1]\n",
+ ntp_srv );
+ fclose(fd );
+ AM_LOGE( "create ntp conf[%s] ... OK!", CUSTOM_NTP_CONF );
+ }else{
+ AM_LOGE( "create ntp conf[%s] ... Fail!", CUSTOM_NTP_CONF );
+ }
+ return 0;
+}
+
void monitor_timer_cb( uv_timer_t *handle )
{
btn_msg_t btn_msg;
{
cJSON *root;
cJSON *idbm;
+ cJSON *ntp;
cJSON *sn;
root = cJSON_Parse( rx_data );
if( root ){
sn = cJSON_GetObjectItem( root, "sn" );
idbm = cJSON_GetObjectItem( root, "idbm" );
+ ntp = cJSON_GetObjectItem( root, "ntp" );
printf( "jsondata[%s],------get idbm:%s, %s\n", rx_data, g_dev.idbm, idbm?idbm->valuestring:"null" );
if( idbm ){
if( g_dev.idbm )
g_dev.idbm = strdup( idbm->valuestring );
printf( "g_dev.idbm->%s\n", g_dev.idbm );
}
+ if( ntp && cJSON_IsString( ntp ) ){
+ printf( "------get ntp srv name:%s\n", ntp->valuestring );
+ ntp_update( ntp->valuestring );
+ }
+ cJSON_Delete(root);
}
}
}
}
}else{
- printf( "tcp write data -- tx_busy->1\n" );
+ printf( "tcp write data[sz:%d] -- tx_busy->1\n",sz );
s_iot.tx_busy = 1;
//uv_write
uv_buf_t uvBuf = uv_buf_init( data, sz );
if( item_ccode && item_devices && item_time && item_type
&& item_devices_device && cJSON_IsString(item_devices_device )
&& item_devices_tagcode && cJSON_IsString(item_devices_tagcode )
- && strcmp( item_type->valuestring, "write")== 0){
+ && strcmp( item_type->valuestring, "write")== 0
+ && item_devices_value && cJSON_IsString(item_devices_value )){
if( strcmp(item_devices_device->valuestring, "gddykz" )==0 ){
//power ctrl
if( strcmp(item_devices_tagcode->valuestring, "jbq" )== 0 ){
}else if( strcmp(item_devices_device->valuestring, "alarm" )==0 ){
//remote alarm
- printf( "\n\n---------alarm:%s\n", item_devices_value->valuestring );
+ printf( "\n\n--------remote -- alarm:%s\n", item_devices_value->valuestring );
resp = wrap_ctrl_resp_json( item_ccode->valuestring, item_devices_device->valuestring, "true", item_devices_tagcode->valuestring, item_devices_value->valuestring, NULL, "write" );
remote_alarm(item_devices_value->valuestring[0]-'0');
}else if( strcmp(item_devices_device->valuestring, "upgrade" )==0 ){
}
resp = wrap_ctrl_resp_json( item_ccode->valuestring, item_devices_device->valuestring, "true", item_devices_tagcode->valuestring, item_devices_value->valuestring, NULL, "write" );
+ }else if( strcmp(item_devices_device->valuestring, "ntp" )==0 ){
+ //remote alarm
+ printf( "\n\n--------remote --set-ntp:[%s]\n", item_devices_value->valuestring );
+ resp = wrap_ctrl_resp_json( item_ccode->valuestring, item_devices_device->valuestring, "true", item_devices_tagcode->valuestring, item_devices_value->valuestring, NULL, "write" );
+ ntp_update( item_devices_value->valuestring );
}
}
//pkcs7
int pad_len = 16-(strlen( item_str )%16);
+ cJSON_Delete( item );
+
plaintext_len = strlen(item_str)+pad_len;
plaintext = malloc( plaintext_len + 1);