21
21
22
22
from pathlib import Path
23
23
import os
24
+ import stat
24
25
import sys
25
26
import errno
26
27
import threading
@@ -82,13 +83,15 @@ def is_valid_gen_info(self, gen_info):
82
83
self .is_valid_poe_cfg_ver (gen_info [POE_CFG_VER ])
83
84
84
85
def is_increasing_time_sequence (self , t1 , t2 ):
85
- tDelta = datetime .strptime (t2 , TIME_FMT ) - \
86
- datetime .strptime (t1 , TIME_FMT )
87
- result1 = (tDelta .days > 0 or tDelta .seconds > 0 )
88
- result2 = (tDelta .days * tDelta .seconds ) >= 0
89
- # print_stderr("is_increasing_time_sequence(self, t1, t2): result1={0},result2={1} ".format(str(result1),
90
- # str(result2)))
91
- return result1 and result2
86
+ unixtime1 = time .mktime (datetime .strptime (t1 , TIME_FMT ).timetuple ())
87
+ unixtime2 = time .mktime (datetime .strptime (t2 , TIME_FMT ).timetuple ())
88
+ unixtime_diff = unixtime2 - unixtime1
89
+ # print_stderr(
90
+ # "unixtime diff: {0}-{1}={2}".format(unixtime2, unixtime1, (unixtime2-unixtime1)))
91
+ if unixtime_diff >= 0 :
92
+ return True
93
+ else :
94
+ return False
92
95
def is_valid_timestamp (self , timestamp ):
93
96
last_save_time = timestamp [LAST_SAVE_TIME ]
94
97
last_set_time = timestamp [LAST_SET_TIME ]
@@ -312,6 +315,7 @@ def save_curerent_runtime(self):
312
315
copyfile (self .runtime_cfg .path (),
313
316
self .permanent_cfg .path ())
314
317
318
+
315
319
def autosave_main (self ):
316
320
global thread_flag
317
321
self .log .info ("Start autosave thread" )
@@ -320,6 +324,7 @@ def autosave_main(self):
320
324
while thread_flag is True :
321
325
try :
322
326
if self .rt_counter >= self .cfg_update_intvl_rt :
327
+ # print_stderr("Load chip state")
323
328
cfg_data = self .collect_running_state ()
324
329
if self .failsafe_flag == False :
325
330
if self .save_poe_cfg (self .runtime_cfg , cfg_data ) == True :
@@ -414,6 +419,9 @@ def get_poe_agent_stae(self):
414
419
415
420
def create_poe_set_ipc (self ):
416
421
try :
422
+ if stat .S_ISFIFO (os .stat (POE_IPC_EVT ).st_mode ) == False :
423
+ #Remove non-namedpipe file
424
+ remove_file (POE_IPC_EVT )
417
425
os .mkfifo (POE_IPC_EVT )
418
426
except OSError as oe :
419
427
if oe .errno != errno .EEXIST :
@@ -504,10 +512,10 @@ def main(argv):
504
512
if data == POECLI_SET :
505
513
pa .update_set_time ()
506
514
pa .log .info ("Receive a set event from poecli!" )
507
- if pa .rt_counter < pa .cfg_update_intvl_rt :
508
- pa .log .info ("Reset rt_counter timing: {0}" .format (
509
- str (pa .cfg_update_intvl_rt )))
510
- pa .rt_counter = pa .cfg_update_intvl_rt
515
+ # if pa.rt_counter <pa.cfg_update_intvl_rt:
516
+ pa .log .info ("Reset rt_counter timing: {0}" .format (
517
+ str (pa .cfg_update_intvl_rt - 1 )))
518
+ pa .rt_counter = pa .cfg_update_intvl_rt - 1
511
519
break
512
520
elif data == POECLI_CFG :
513
521
pa .log .info ("Receive a cfg event from poecli!" )
@@ -524,6 +532,15 @@ def main(argv):
524
532
apply = data_list [3 ]
525
533
pa .log .info ("CFG Apply: {0}" .format (apply ))
526
534
if action == POED_SAVE_ACTION :
535
+ touch_file (POED_BUSY_FLAG )
536
+ pa .rt_counter = 0
537
+ cfg_data = pa .collect_running_state ()
538
+ if pa .save_poe_cfg (pa .runtime_cfg , cfg_data ) == True :
539
+ pa .log .info (
540
+ "Load chip state to runtime completed." )
541
+ else :
542
+ pa .log .warn (
543
+ "Failed to save cfg data in autosave routine!" )
527
544
if file == None :
528
545
pa .log .info (
529
546
"CFG Save: Save runtime setting to persistent file" )
@@ -533,16 +550,19 @@ def main(argv):
533
550
file )
534
551
pa .log .info (
535
552
"CFG Save: Save runtime setting to {0}" .format (file ))
536
- elif action == POED_LOAD_ACTION :
553
+ remove_file (POED_BUSY_FLAG )
554
+ elif action == POED_LOAD_ACTION :
537
555
if file == None :
538
556
pa .log .info (
539
557
"CFG Load: Load persistent file" )
540
558
result = pa .load_poe_cfg (pa .permanent_cfg )
559
+ remove_file (POED_BUSY_FLAG )
541
560
else :
542
561
pa .log .info (
543
562
"CFG Load: Load cfg file from {0}" .format (file ))
544
563
temp_cfg = PoeConfig (file , pa .plat_name )
545
564
result = pa .load_poe_cfg (temp_cfg )
565
+ remove_file (POED_BUSY_FLAG )
546
566
if result == True :
547
567
pa .update_set_time ()
548
568
break
0 commit comments