@@ -78,6 +78,9 @@ public enum LastDataTransferReplySentFromBS
7878 public ushort PayloadIndex { get ; set ; }
7979 public int ? PreviouslyWrittenPayloadIndex { get ; set ; } = - 1 ;
8080 public string binFileFolderDir { get ; set ; }
81+ public string sensorLogFileName { get ; set ; }
82+ public string sensorLogFilePath { get ; set ; }
83+ public string sensorLogFolderDir { get ; set ; }
8184
8285 #endregion
8386
@@ -533,9 +536,13 @@ void HandleCommonResponse()
533536 case 0x39 : // read event log
534537 var logEventsData = new LogEventsPayload ( ) ;
535538 var logEventsResult = logEventsData . ProcessPayload ( ResponseBuffer ) ;
539+ createSensorLogFile ( false ) ;
540+ SaveVlogFileToDB ( ) ;
536541 if ( logEventsResult )
537542 {
538543 LogEvents = logEventsData ;
544+ WriteSensorLogToFile ( ( ( LogEventsPayload ) logEventsData ) . LogEventsBytes ) ;
545+ //logEventsData.WriteLogEventsToFile(sensorLogFilePath);
539546 if ( ShimmerBLEEvent != null )
540547 {
541548 ShimmerBLEEvent . Invoke ( null , new ShimmerBLEEventData { ASMID = Asm_uuid . ToString ( ) , CurrentEvent = VerisenseBLEEvent . RequestResponse , ObjMsg = RequestType . ReadEventLog } ) ;
@@ -996,6 +1003,15 @@ protected virtual void SaveBinFileToDB()
9961003 //
9971004 }
9981005
1006+
1007+ /// <summary>
1008+ /// For advance applications, to have the option to keep the location of the vlog file in the DB
1009+ /// </summary>
1010+ protected virtual void SaveVlogFileToDB ( )
1011+ {
1012+ //
1013+ }
1014+
9991015 /// <summary>
10001016 /// Get Sensor ID
10011017 /// </summary>
@@ -1610,6 +1626,52 @@ protected virtual void createBinFile(bool crcError)
16101626 }
16111627 }
16121628
1629+ protected virtual void createSensorLogFile ( bool crcError )
1630+ {
1631+ try
1632+ {
1633+ String sensorID = Asm_uuid . ToString ( ) ;
1634+ try
1635+ {
1636+ sensorID = GetSensorID ( ) ;
1637+ }
1638+ catch ( Exception ex ) // if production config wasnt read default to the UUID
1639+ {
1640+ sensorID = Asm_uuid . ToString ( ) ;
1641+ AdvanceLog ( ex . Message , "Defaulting to UUID" , sensorLogFileName , ASMName ) ;
1642+ }
1643+
1644+ sensorLogFolderDir = string . Format ( "{0}/{1}/{2}/SensorLogs" , GetTrialName ( ) , GetParticipantID ( ) , sensorID ) ;
1645+ //sensorLogFolderDir = String.Format("SensorLog");
1646+
1647+ //need to check how data bin file is being uploaded (so that no all bin file is being uploaded to the BinaryFiles folder)
1648+ //or use a different path
1649+ var folder = Path . Combine ( DependencyService . Get < ILocalFolderService > ( ) . GetAppLocalFolder ( ) , sensorLogFolderDir ) ;
1650+
1651+ if ( ! Directory . Exists ( folder ) )
1652+ {
1653+ Directory . CreateDirectory ( folder ) ;
1654+ }
1655+ if ( crcError )
1656+ {
1657+ sensorLogFileName = string . Format ( "{0}_{1}_{2}.vlog" , DateTime . Now . ToString ( "yyMMdd_HHmmss" ) , "DebugLog" , BadCRC ) ;
1658+ }
1659+ else
1660+ {
1661+ sensorLogFileName = string . Format ( "{0}_{1}.vlog" , DateTime . Now . ToString ( "yyMMdd_HHmmss" ) , "DebugLog" ) ;
1662+ }
1663+
1664+ AdvanceLog ( LogObject , "SensorLogFileNameCreated" , sensorLogFileName , ASMName ) ;
1665+ sensorLogFilePath = Path . Combine ( folder , sensorLogFileName ) ;
1666+
1667+ AdvanceLog ( LogObject , "SensorLogFileCreated" , sensorLogFilePath , ASMName ) ;
1668+ }
1669+ catch ( Exception ex )
1670+ {
1671+ AdvanceLog ( LogObject , "SensorLogFileCreatedException" , ex , ASMName ) ;
1672+ }
1673+ }
1674+
16131675 void DeleteLastPayloadFromBinFile ( )
16141676 {
16151677 AdvanceLog ( LogObject , "DeleteLastPayloadFromBinFile" , FinalChunkLogMsgForNack , ASMName ) ;
@@ -1666,6 +1728,32 @@ void WritePayloadToBinFile()
16661728 AdvanceLog ( LogObject , "WritePayloadToBinFile" , "Same Payload Index = " + PayloadIndex . ToString ( ) , ASMName ) ;
16671729 }
16681730 }
1731+
1732+ void WriteSensorLogToFile ( byte [ ] payload )
1733+ {
1734+ if ( PreviouslyWrittenPayloadIndex != PayloadIndex )
1735+ {
1736+ try
1737+ {
1738+ System . Console . WriteLine ( "Write Sensor Log To File!" ) ;
1739+ using ( var stream = new FileStream ( sensorLogFilePath , FileMode . Append ) )
1740+ {
1741+ stream . Write ( payload , 0 , payload . Length ) ;
1742+ }
1743+ IsFileLocked ( sensorLogFilePath ) ;
1744+ }
1745+ catch ( Exception ex )
1746+ {
1747+ AdvanceLog ( LogObject , "SensorLogFileAppendException" , ex , ASMName ) ;
1748+ throw ex ;
1749+ }
1750+ }
1751+ else
1752+ {
1753+ AdvanceLog ( LogObject , "WriteSensorLogToFile" , "Same Payload Index = " + PayloadIndex . ToString ( ) , ASMName ) ;
1754+ }
1755+ }
1756+
16691757 protected virtual bool IsFileLocked ( string filepath )
16701758 {
16711759 try
0 commit comments