diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-16 17:48:16 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-09-16 17:48:16 +0300 |
| commit | 161fe6f6d2b29ba3deb641cdc049ad0d8f58004e (patch) | |
| tree | 20318bb7ea4a243b8c2e9757e4635e8d5f5cb728 /Software/Embedded_SW/Embedded/Common | |
| parent | 30fcfa4100a9d00e887c6e17e32e427b05296ce7 (diff) | |
| parent | b674a2e7751daa80c0d74207968bf8e3d18d7faf (diff) | |
| download | Tango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.tar.gz Tango-161fe6f6d2b29ba3deb641cdc049ad0d8f58004e.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Common')
15 files changed, 419 insertions, 58 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c index 5a77a013d..4396f6da1 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c @@ -35,6 +35,7 @@ #include "third_party/fatfs/src/diskio.h" #include "drivers/Flash_Memory/Flash_Memory.h" #include "drivers/Flash_Memory/fatfs/ff.h" +#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h" #include "third_party/fatfs/src/ffconf.h" @@ -52,7 +53,7 @@ FIL *UploadFileHandle = 0; //the system supports a single active file FIL *DownloadFileHandle = 0; //the system supports a single active file char FileHandleChar[5]; char ErrorMsg[100]; -#define MAX_CHUNK_LENGTH 4000 +#define MAX_CHUNK_LENGTH 5500 int32_t FileLength = 0; int32_t FileReceivedLength = 0; int32_t FileSentLength = 0; @@ -61,6 +62,7 @@ uint32_t WrittenBytes = 0; uint32_t ReadBytes = 0; Task_Handle CommRxTaskHandle; +extern Semaphore_Handle FFS_Sem; ErrorCode getErrorCode(FRESULT Fresult) { @@ -72,6 +74,7 @@ bool isDirectory(FileAttribute FileAtt) return true; return false; } +bool FileDone = false; uint32_t FileUploadRequestFunc(MessageContainer* requestContainer) { @@ -95,6 +98,7 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer) Fresult = FR_DENIED; else { + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_open(UploadFileHandle,request->path,FA_READ | FA_WRITE | FA_OPEN_ALWAYS | FA_CREATE_ALWAYS); if (Fresult == FR_OK) { @@ -105,17 +109,20 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer) response.maxchunklength = MAX_CHUNK_LENGTH; strcpy(FileHandleChar, "1234"); response.uploadid = FileHandleChar; //supporting only single file at each time. + FileDone = false; } else { - free (UploadFileHandle); + my_free (UploadFileHandle); UploadFileHandle = 0; + Semaphore_post(FFS_Sem); } } } CommRxTaskHandle = Task_self(); Task_setPri(CommRxTaskHandle, 4); + // Report("Task_setPri", __FILE__, __LINE__, 4, RpWarning, (int)CommRxTaskHandle, 0); responseContainer = createContainer(MESSAGE_TYPE__FileUploadResponse, requestContainer->token, false, &response, &file_upload_response__pack, &file_upload_response__get_packed_size); @@ -133,11 +140,11 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer) return OK; } +FRESULT lFresult = FR_OK; uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer) { //uint32_t status = OK; FRESULT Fresult = FR_OK; - bool FileDone = false; MessageContainer responseContainer; @@ -153,8 +160,11 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer) // memcpy (&ReceivedFileHandle,request->uploadid,sizeof(ReceivedFileHandle)); //if (ReceivedFileHandle == FileHandle) //{ - KeepAliveOneSecondCounter = 0; + Control_WD(ENABLE,55); //activate heaters/dispenser watchdog, 0.5 seconds + GeneralHwReady = false; + KeepAliveOneSecondCounter = 0; Fresult = f_write(ReceivedFileHandle,request->buffer.data,request->buffer.len,&WrittenBytes ); + lFresult = Fresult; if(Fresult != FR_OK) { LOG_ERROR (Fresult,"f_write error"); @@ -168,7 +178,8 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer) { REPORT_MSG (FileReceivedLength,"file upload ended successfully"); f_close(ReceivedFileHandle); - free (UploadFileHandle); + my_free (UploadFileHandle); + UploadFileHandle = 0; FileReceivedLength = 0; FileDone = true; } @@ -178,7 +189,8 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer) { REPORT_MSG (FileReceivedLength,"file upload too much data!"); f_close(ReceivedFileHandle); - free (UploadFileHandle); + my_free (UploadFileHandle); + UploadFileHandle = 0; FileReceivedLength = 0; FileDone = true; } @@ -202,12 +214,17 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer) responseContainer.continuous = false; uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); + //my_free(request->buffer.data); file_chunk_upload_request__free_unpacked(request,NULL); my_free(responseContainer.data.data); - SendChars(container_buffer, container_size); + SendCharsWithType(container_buffer, container_size,MESSAGE_TYPE__FileChunkUploadResponse); if (FileDone == true) + { Task_setPri(CommRxTaskHandle, 9); - + GeneralHwReady = true; + Semaphore_post(FFS_Sem); + //Report("Task_setPri", __FILE__, __LINE__, 9, RpWarning, (int)CommRxTaskHandle, 0); + } return OK; } uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer) @@ -239,6 +256,7 @@ uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer) Fresult = FR_DENIED; else { + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_open(DownloadFileHandle,request->filename,FA_READ ); if (Fresult == FR_OK) { @@ -277,7 +295,7 @@ uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer) FIL *SentFileHandle; //the system supports a single active file SentFileHandle = DownloadFileHandle; - char *Buffer = 0; + uint8_t *Buffer = 0; Buffer = my_malloc (MAX_CHUNK_LENGTH); if (Buffer != NULL) { @@ -296,7 +314,8 @@ uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer) { REPORT_MSG (FileSentLength,"file download ended successfully"); f_close(SentFileHandle); - free (DownloadFileHandle); + Semaphore_post(FFS_Sem); + my_free (DownloadFileHandle); FileSentLength = 0; } else @@ -305,7 +324,8 @@ uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer) { REPORT_MSG (FileSentLength,"file download too much data!"); f_close(SentFileHandle); - free (DownloadFileHandle); + Semaphore_post(FFS_Sem); + my_free (DownloadFileHandle); FileSentLength = 0; } } @@ -401,6 +421,7 @@ uint32_t CreateRequestFunc(MessageContainer* requestContainer) Fresult = FR_DENIED; else { + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_open(UploadFileHandle,request->path,FA_CREATE_NEW); if (Fresult == FR_OK) { @@ -409,6 +430,7 @@ uint32_t CreateRequestFunc(MessageContainer* requestContainer) Fresult = FR_LOCKED; } } + Semaphore_post(FFS_Sem); } } if (Fresult != FR_OK) @@ -448,7 +470,9 @@ uint32_t DeleteRequestFunc(MessageContainer* requestContainer) //int NumOfFiles = 0; FRESULT Fresult = FR_OK; + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_unlink(request->path); + Semaphore_post(FFS_Sem); REPORT_MSG(Fresult, "File Delete"); responseContainer = createContainer(MESSAGE_TYPE__DeleteResponse, requestContainer->token, false, &response, &delete_response__pack, &delete_response__get_packed_size); @@ -523,16 +547,18 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer) GetFilesResponse response = GET_FILES_RESPONSE__INIT; - #define MAX_NUM_OF_FILES 10 + #define MAX_NUM_OF_FILES 20 DIR dir; FILINFO* fno[MAX_NUM_OF_FILES]; - char FullPath[MAX_NUM_OF_FILES][100]; + char FullPath[MAX_NUM_OF_FILES][60]; int i,NumOfFiles = 0; FRESULT Fresult = FR_OK; + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult |= f_opendir(&dir, g_cCwdBuf); if(Fresult != FR_OK) { + Semaphore_post(FFS_Sem); return(Fresult); } @@ -561,6 +587,7 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer) } } } + Semaphore_post(FFS_Sem); if ((Fresult == FR_OK)&&(NumOfFiles)) { @@ -573,7 +600,9 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer) Data[i].name = fno[i]->fname; Data[i].has_length = true; Data[i].length = fno[i]->fsize; + Data[i].has_lastmodifieddate = true; Data[i].lastmodifieddate = fno[i]->fdate; + Data[i].has_lastmodifiedtime = true; Data[i].lastmodifiedtime = fno[i]->ftime; if (i==0) usnprintf(&FullPath[i], 50, "%s", request->path); @@ -617,7 +646,7 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer) } return Fresult; } -FRESULT FileWrite(void * buffer, uint16_t size,char *path) +FRESULT FileWrite(void * buffer, uint16_t size,char *path, uint32_t timeout) { FRESULT Fresult = FR_OK; FIL *FileHandle = 0; //the system supports a single active file @@ -630,6 +659,12 @@ FRESULT FileWrite(void * buffer, uint16_t size,char *path) Fresult = FR_DENIED; else { + if (Semaphore_pend(FFS_Sem, timeout) == false) + { + LOG_ERROR (false,"file system busy error"); + return FR_TIMEOUT; + } + Fresult = f_open(FileHandle,path,FA_WRITE | FA_OPEN_ALWAYS); if (Fresult == FR_OK) { @@ -644,6 +679,7 @@ FRESULT FileWrite(void * buffer, uint16_t size,char *path) { LOG_ERROR (Fresult,"fopen error"); } + Semaphore_post(FFS_Sem); my_free(FileHandle); } } @@ -673,6 +709,7 @@ FRESULT FileRead(char *path, uint32_t *Size, void **Buffer) Fresult = FR_DENIED; else { + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_open(FileHandle,path,FA_READ); if (Fresult == FR_OK) { @@ -688,6 +725,7 @@ FRESULT FileRead(char *path, uint32_t *Size, void **Buffer) my_free (buffer); } f_close(FileHandle); + Semaphore_post(FFS_Sem); } else { @@ -726,6 +764,7 @@ FRESULT FileOpen(char *path, uint32_t *Size, FIL *FileHandle) if (FileHandle == 0) Fresult = FR_DENIED; else + Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER); Fresult = f_open(FileHandle,path,FA_READ); } else diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.h b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.h index 605b4a475..0f6fd9d5d 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.h +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.h @@ -22,7 +22,7 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer); uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer); uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer); -FRESULT FileWrite(void * buffer, uint16_t size,char *path); +FRESULT FileWrite(void * buffer, uint16_t size,char *path, uint32_t timeout); FRESULT FileRead(char *path, uint32_t *Size, void **Buffer); FRESULT FileOpen(char *path, uint32_t *Size, FIL *FileHandle); diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c index 01a30c21a..8818d51e5 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.c @@ -28,6 +28,9 @@ #include "Common/SWUpdate/FileSystem.h" #include "Modules/Control/Control.h" +#include "Modules/AlarmHandling/AlarmHandling.h" + +extern Semaphore_Handle FFS_Sem; int NumberOfFiles = 0,CurrentRunningFile; int CurrentFileSize = 0; @@ -41,41 +44,52 @@ bool SwUpgradeActive(void) { if (ActivateVersionControlId != 0xFF) { - Reboot = false; + //Reboot = false; return true; } return false; } uint32_t ActivateVersionCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { - //ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT; - //MessageContainer responseContainer; + ActivateVersionResponse response = ACTIVATE_VERSION_RESPONSE__INIT; + MessageContainer responseContainer; usnprintf(activateString, 1000, "file %d of %d bytes %d of %d",CurrentRunningFile,NumberOfFiles,vme_index,CurrentFileSize); Report(activateString,__FILE__,__LINE__,(int)CurrentRunningFile,RpWarning,CurrentFileSize,0); if (CurrentRunningFile<NumberOfFiles) + { + responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, ActivateToken, false, &response, &activate_version_response__pack, &activate_version_response__get_packed_size); + responseContainer.continuous = true; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars(container_buffer, container_size); return OK; - if (SafeRemoveControlCallback(ActivateVersionControlId, ActivateVersionCallBackFunction )==OK) - ActivateVersionControlId = 0xFF; - else - LOG_ERROR(255,"ActivateVersionCallBackFunction"); - return OK; - - /* - responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, ActivateToken, false, &response, &activate_version_response__pack, &activate_version_response__get_packed_size); + } + responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, ActivateToken, true, &response, &activate_version_response__pack, &activate_version_response__get_packed_size); responseContainer.continuous = true; uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); my_free(responseContainer.data.data); SendChars(container_buffer, container_size); + if (SafeRemoveControlCallback(ActivateVersionControlId, ActivateVersionCallBackFunction )==OK) + ActivateVersionControlId = 0xFF; + else + LOG_ERROR(255,"ActivateVersionCallBackFunction"); + if (Reboot == true) { + LOG_ERROR(255,"Update successful, Rebooting in 5 seconds"); + Task_sleep (120000000*5); Power_Reset(); } -*/ + return OK; + + + } int File_i = 0; @@ -102,7 +116,8 @@ uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer) ustrncpy (ActivateToken, requestContainer->token,36); - strcpy (SWUpgradePath,request->path); + strncpy (SWUpgradePath,request->path,99); + SWUpgradePath[99] = NULL; strcat(SWUpgradePath,"/package.cfg"); Fresult = FileRead(SWUpgradePath, &Bytes, &buffer); @@ -119,9 +134,8 @@ uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer) } for (File_i = 0;File_i<VersionPackage->n_filedescriptors;File_i++) { - CurrentRunningFile = 0; CurrentFileSize = -1; - vme_index = 0; + //vme_index = 0; switch(VersionPackage->filedescriptors[File_i]->destination) { case VERSION_FILE_DESTINATION__MCU: @@ -142,21 +156,27 @@ uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer) usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename); Fresult = f_unlink("//SYSINFO//EMBPARAM.CFG"); Fresult |= f_rename (FullPath, "//SYSINFO//EMBPARAM.CFG"); + LoadConfigurationParamsFromFile(); + CurrentRunningFile++; break; case VERSION_FILE_DESTINATION__ProcessParams: usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename); Fresult = f_unlink("//SYSINFO//PROCESSP.CFG"); Fresult |= f_rename (FullPath, "//SYSINFO//PROCESSP.CFG"); + CurrentRunningFile++; break; case VERSION_FILE_DESTINATION__AlarmParams: usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename); Fresult = f_unlink("//SYSINFO//ALARMPRM.CFG"); Fresult |= f_rename (FullPath, "//SYSINFO//ALARMPRM.CFG"); + AlarmHandlingLoadFile(); + CurrentRunningFile++; break; case VERSION_FILE_DESTINATION__GeneralHWConfigParams: usnprintf(FullPath, 50, "%s%s%s", request->path,"/", VersionPackage->filedescriptors[File_i]->filename); Fresult = f_unlink("//SYSINFO//GENHWCFG.CFG"); Fresult |= f_rename (FullPath, "//SYSINFO//GENHWCFG.CFG"); + CurrentRunningFile++; break; default: LOG_ERROR (VersionPackage->filedescriptors[File_i]->destination,"wrong file update Destination"); @@ -166,22 +186,20 @@ uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer) } } responseContainer = createContainer(MESSAGE_TYPE__ActivateVersionResponse, requestContainer->token, false, &response, &activate_version_response__pack, &activate_version_response__get_packed_size); + responseContainer.continuous = true; if (Fresult!= OK) { responseContainer.error = FileError_to_ErrorCode[Fresult]; responseContainer.errormessage = "Activate Version Request error"; + responseContainer.continuous = false; } - responseContainer.continuous = false; + responseContainer.continuous = true; uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); my_free(responseContainer.data.data); activate_version_request__free_unpacked(request,NULL); SendChars(container_buffer, container_size); - if (Reboot == true) - { - Power_Reset(); - } return OK; } diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h index 6f817fe90..2b0a9bff9 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FirmwareUpgrade.h @@ -8,6 +8,8 @@ #ifndef COMMON_SWUPDATE_FIRMWAREUPGRADE_H_ #define COMMON_SWUPDATE_FIRMWAREUPGRADE_H_ +extern int CurrentFileSize; +extern int CurrentRunningFile; uint32_t ActivateVersionRequestFunc(MessageContainer* requestContainer); uint32_t ValidateVersionRequestFunc(MessageContainer* requestContainer); diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index 6705148e3..833b8b66c 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -20,7 +20,7 @@ typedef struct } TangoVersion_t; -TangoVersion_t _gTangoVersion = {1,3,10,2}; +TangoVersion_t _gTangoVersion = {1,4,4,8};//remove AUTO_HOME_DISPENSERS + midtank pressure new calculation #define BUILD_DATE __DATE__ char Dat[50] = BUILD_DATE; char _gTangoName [MAX_STRING_LEN] = "Tango01 ";//d @@ -43,14 +43,14 @@ uint16_t GetTangoVersion(uint8_t* _buffer) memcpy(currPtr,_gTangoName,size); currPtr+= size; - char time[50]; + char ttime[50]; int len; - len = usnprintf(time, 50, "%s %s",__DATE__, __TIME__); + len = usnprintf(ttime, 50, "%s %s",__DATE__, __TIME__); //++len; // added \0 //memcpy(currPtr,&len,2); //currPtr+= 1; //--len; // actual string len - memcpy (currPtr,time,len); + memcpy (currPtr,ttime,len); currPtr += len; size = (currPtr - _buffer) + size; //_buffer[size++] = '\0'; diff --git a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c index bd9336db3..93ce6cf51 100644 --- a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c +++ b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c @@ -123,6 +123,7 @@ PinoutSet(void) MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOS); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOT); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); // // Configure the GPIO Pin Mux for PD1 diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/RFIDTagHandling.c b/Software/Embedded_SW/Embedded/Common/Utilities/RFIDTagHandling.c new file mode 100644 index 000000000..f1e354743 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/Utilities/RFIDTagHandling.c @@ -0,0 +1,208 @@ +/* + * RFIDTagHandling.c + * + * Created on: Sep 8, 2019 + * Author: shlomo + */ +#include "include.h" + +#include "Modules/Waste/Waste.h" +#include "Modules/IFS/ifs.h" +#include "Modules/AlarmHandling/AlarmHandling.h" +#include "PMR/Diagnostics/CartridgeValidationRequest.pb-c.h" +#include "PMR/Diagnostics/CartridgeValidationResponse.pb-c.h" +#include "PMR/Diagnostics/CartridgeTagContent.pb-c.h" +#include <PMR/Diagnostics/EventType.pb-c.h> +#include <Utilities/RfidTagContent.h> +#include "drivers/Valves/Valve.h" +#include "Modules/Waste/Waste.h" +#include "CartridgeSlot.pb-c.h" +#include "CartridgeTagContent.pb-c.h" +#include "Cartridge.pb-c.h" + +/* + typedef struct +{ + uint32_t UniqueId; + char SerialNumber[16]; + char FactoryId[3]; + int32_t FillingSystemId; + char ColorName[12]; + int32_t ColorCategory; + int32_t ColorTypeRevision; + int32_t CartridgeSize; + int32_t FilledInkVolume; + char InkBatchNum[10]; + char InkMFGDate[6]; + char InkEOLDate[6]; + char CartridgeFillingDate[6]; + char WasteFilledDate[6]; + int32_t PlugInCounter; + bool Inkfill; + bool InkUsed; + bool InkEmpty; + bool WasteEmpty; + bool WasteFilling; + bool WasteFull; + bool Blocked; + bool Fail; + int32_t WasteCounter; + char MachineIdInkUsed[16]; + char MachineIdWasteUsed[16]; +}RfidTagContent; + struct _CartridgeTagContent +{ + ProtobufCMessage base; + protobuf_c_boolean has_uniqueid; + uint32_t uniqueid; + char *serialnumber; + char *factoryid; + protobuf_c_boolean has_fillingsystemid; + int32_t fillingsystemid; + char *colorname; + protobuf_c_boolean has_colorcategory; + int32_t colorcategory; + protobuf_c_boolean has_colortyperevision; + int32_t colortyperevision; + protobuf_c_boolean has_cartridgesize; + int32_t cartridgesize; + protobuf_c_boolean has_filledinkvolume; + int32_t filledinkvolume; + char *inkbatchnum; + char *inkmfgdate; + char *inkeoldate; + char *cartridgefillingdate; + char *wastefilleddate; + protobuf_c_boolean has_plugincounter; + int32_t plugincounter; + protobuf_c_boolean has_inkfill; + protobuf_c_boolean inkfill; + protobuf_c_boolean has_inkused; + protobuf_c_boolean inkused; + protobuf_c_boolean has_inkempty; + protobuf_c_boolean inkempty; + protobuf_c_boolean has_wasteempty; + protobuf_c_boolean wasteempty; + protobuf_c_boolean has_wastefilling; + protobuf_c_boolean wastefilling; + protobuf_c_boolean has_wastefull; + protobuf_c_boolean wastefull; + protobuf_c_boolean has_blocked; + protobuf_c_boolean blocked; + protobuf_c_boolean has_fail; + protobuf_c_boolean fail; + protobuf_c_boolean has_wastecounter; + int32_t wastecounter; + char *machineidinkused; + char *machineidwasteused; +}; + */ +CartridgeTagContent * RFID_Tag2PPC(RfidTagContent *Tag) +{ + CartridgeTagContent *PpcTag = my_malloc(sizeof(CartridgeTagContent)); + + if (PpcTag == NULL) + return NULL; + + + cartridge_Tag_content__init(PpcTag); + PpcTag->has_uniqueid = true; + PpcTag->uniqueid = Tag->uniqueid; + PpcTag->serialnumber = Tag->serialnumber; + PpcTag->factoryid = Tag->factoryid; + + PpcTag->has_fillingsystemid = true; + PpcTag->fillingsystemid = Tag->fillingsystemid; + PpcTag->colorname = Tag->colorname; + PpcTag->has_colorcategory = true; + PpcTag->colorcategory = Tag->colorcategory; + PpcTag->has_colortyperevision = true; + PpcTag->colortyperevision = Tag->colortyperevision; + PpcTag->has_cartridgesize = true; + PpcTag->cartridgesize = Tag->cartridgesize; + PpcTag->has_filledinkvolume = true; + PpcTag->filledinkvolume = Tag->filledinkvolume; + PpcTag->inkbatchnum = Tag->inkbatchnum; + PpcTag->inkmfgdate = Tag->inkmfgdate; + PpcTag->inkeoldate = Tag->inkeoldate; + PpcTag->cartridgefillingdate = Tag->cartridgefillingdate; + PpcTag->wastefilleddate = Tag->wastefilleddate; + PpcTag->has_plugincounter = true; + PpcTag->plugincounter = Tag->plugincounter; + PpcTag->has_inkfill = true; + PpcTag->inkfill = Tag->inkfill; + PpcTag->has_inkused = true; + PpcTag->inkused = Tag->inkused; + PpcTag->has_inkempty = true; + PpcTag->inkempty = Tag->inkempty; + PpcTag->has_wasteempty = true; + PpcTag->wasteempty = Tag->wasteempty; + PpcTag->has_wastefilling; + PpcTag->wastefilling = Tag->wastefilling; + PpcTag->has_wastefull = true; + PpcTag->wastefull = Tag->wastefull; + PpcTag->has_blocked = true; + PpcTag->blocked = Tag->blocked; + PpcTag->has_fail = true; + PpcTag->fail = Tag->fail; + PpcTag->has_wastecounter = true; + PpcTag->wastecounter = Tag->wastecounter; + PpcTag->machineidinkused = Tag->machineidinkused; + PpcTag->machineidwasteused = Tag->machineidwasteused; + + return PpcTag; +} +RfidTagContent * RFID_PPC2Tag( CartridgeTagContent *PpcTag) +{ + RfidTagContent *Tag = my_malloc(sizeof(RfidTagContent)); + if (Tag == NULL) + return NULL; + memset (Tag,0,sizeof(Tag)); + + if (PpcTag->has_uniqueid == true) + Tag->uniqueid = PpcTag->uniqueid; + memcpy(Tag->serialnumber , PpcTag->serialnumber,sizeof(Tag->serialnumber)); + memcpy(Tag->factoryid , PpcTag->factoryid,sizeof(Tag->factoryid)); + + if (PpcTag->has_fillingsystemid == true) + Tag->fillingsystemid = PpcTag->fillingsystemid; + memcpy(Tag->colorname , PpcTag->colorname,sizeof(Tag->colorname)); + if (PpcTag->has_colorcategory == true) + Tag->colorcategory = PpcTag->colorcategory; + if (PpcTag->has_colortyperevision == true) + Tag->colortyperevision = PpcTag->colortyperevision; + if (PpcTag->has_cartridgesize == true) + Tag->cartridgesize = PpcTag->cartridgesize; + if (PpcTag->has_filledinkvolume == true) + Tag->filledinkvolume = PpcTag->filledinkvolume; + memcpy(Tag->inkbatchnum , PpcTag->inkbatchnum,sizeof(Tag->inkbatchnum)); + memcpy(Tag->inkmfgdate , PpcTag->inkmfgdate,sizeof(Tag->inkmfgdate)); + memcpy(Tag->inkeoldate , PpcTag->inkeoldate,sizeof(Tag->inkeoldate)); + memcpy(Tag->cartridgefillingdate , PpcTag->cartridgefillingdate,sizeof(Tag->cartridgefillingdate)); + memcpy(Tag->wastefilleddate , PpcTag->wastefilleddate,sizeof(Tag->wastefilleddate)); + if (PpcTag->has_plugincounter == true) + Tag->plugincounter = PpcTag->plugincounter; + if (PpcTag->has_inkfill == true) + Tag->inkfill = PpcTag->inkfill; + if (PpcTag->has_inkused == true) + Tag->inkused = PpcTag->inkused; + if (PpcTag->has_inkempty == true) + Tag->inkempty = PpcTag->inkempty; + if (PpcTag->has_wasteempty == true) + Tag->wasteempty = PpcTag->wasteempty; + if (PpcTag->has_wastefilling == true) + Tag->wastefilling = PpcTag->wastefilling; + if (PpcTag->has_wastefull == true) + Tag->wastefull = PpcTag->wastefull; + if (PpcTag->has_blocked == true) + Tag->blocked = PpcTag->blocked; + if (PpcTag->has_fail == true) + Tag->fail = PpcTag->fail; + if (PpcTag->has_wastecounter == true) + Tag->wastecounter = PpcTag->wastecounter; + memcpy(Tag->machineidinkused , PpcTag->machineidinkused,sizeof(Tag->machineidinkused)); + memcpy(Tag->machineidwasteused , PpcTag->machineidwasteused,sizeof(Tag->machineidwasteused)); + + return Tag; + +} diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/RfidTagContent.h b/Software/Embedded_SW/Embedded/Common/Utilities/RfidTagContent.h new file mode 100644 index 000000000..e94392e49 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/Utilities/RfidTagContent.h @@ -0,0 +1,51 @@ +/* + * RfidTagContent.h + * + * Created on: Jul 8, 2019 + * Author: shlomo + */ + +#ifndef MODULES_IFS_RFIDTAGCONTENT_H_ +#define MODULES_IFS_RFIDTAGCONTENT_H_ + +#include "PMR/Diagnostics/CartridgeSlot.pb-c.h" +#include "PMR/Diagnostics/CartridgeTagContent.pb-c.h" + +#include <DataDef.h> +#include "include.h" + + +#define MAX_CARTRIDGES (CARTRIDGE_SLOT__WasteLower+1) +typedef struct +{ + uint32_t uniqueid; + char serialnumber[16]; + char factoryid[3]; + int32_t fillingsystemid; + char colorname[12]; + int32_t colorcategory; + int32_t colortyperevision; + int32_t cartridgesize; + int32_t filledinkvolume; + char inkbatchnum[10]; + char inkmfgdate[6]; + char inkeoldate[6]; + char cartridgefillingdate[6]; + char wastefilleddate[6]; + int32_t plugincounter; + bool inkfill; + bool inkused; + bool inkempty; + bool wasteempty; + bool wastefilling; + bool wastefull; + bool blocked; + bool fail; + int32_t wastecounter; + char machineidinkused[16]; + char machineidwasteused[16]; +}RfidTagContent; + + + +#endif /* MODULES_IFS_RFIDTAGCONTENT_H_ */ diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/Update.c b/Software/Embedded_SW/Embedded/Common/Utilities/Update.c index 422c1632b..460334b15 100644 --- a/Software/Embedded_SW/Embedded/Common/Utilities/Update.c +++ b/Software/Embedded_SW/Embedded/Common/Utilities/Update.c @@ -13,6 +13,9 @@ #include <inc/hw_types.h> #include <inc/hw_memmap.h> +#include "Modules/Control/control.h" +#include "Modules/Control/MillisecTask.h" +#include "Modules/Heaters/Heaters_ex.h" #include "Drivers/USB_Communication/USBCDCD.h" @@ -31,6 +34,14 @@ void UpdateUsb(void) // Disable all interrupts. // ROM_IntMasterDisable(); +#ifdef WATCHDOG + ROM_WatchdogResetDisable(WATCHDOG0_BASE); + uint32_t timeout = 0xFFFFFFFFU; + ROM_WatchdogReloadSet(WATCHDOG0_BASE, timeout); +#endif + ControlStop(); + MillisecStop(); + HeatersEnd(); // // Disable SysTick and its interrupt. diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/Utils.c b/Software/Embedded_SW/Embedded/Common/Utilities/Utils.c index 341a43704..d1143ada2 100644 --- a/Software/Embedded_SW/Embedded/Common/Utilities/Utils.c +++ b/Software/Embedded_SW/Embedded/Common/Utilities/Utils.c @@ -12,15 +12,16 @@ //#include <driverlib/systick.h> #include "driverlib/hibernate.h" #include <driverlib/Watchdog.h> +#include <ti/sysbios/hal/Seconds.h> //***************************************************************************** -#define MAX_MEM_LOG 100 +/*#define MAX_MEM_LOG 100 int freeIndex=0,malloc_index=0; uint32_t malloc_size[MAX_MEM_LOG+1]; uint32_t malloc_time[MAX_MEM_LOG+1]; void * malloc_addr[MAX_MEM_LOG+1]; -void * free_addr[MAX_MEM_LOG+1]; +void * free_addr[MAX_MEM_LOG+1];*/ //uint32_t total_allocated = 0; void *my_malloc(size_t _size) { @@ -43,14 +44,14 @@ void *my_malloc(size_t _size) malloc_time[malloc_index] = msec_millisecondCounter; } */ - if ((addr)&&(_size>400)) + /*if ((addr)&&(_size>400)) { malloc_addr[malloc_index] = addr; malloc_size[malloc_index] = _size; malloc_time[malloc_index] = msec_millisecondCounter; if (malloc_index++>=MAX_MEM_LOG) malloc_index = 0; - } + }*/ return addr; } int allocated_size = 0; @@ -80,9 +81,9 @@ void my_free(void *_ptr) // allocated_size+=malloc_size[i]; * */ - free_addr[freeIndex] = _ptr; - if (freeIndex++>=MAX_MEM_LOG) - freeIndex = 0; +// free_addr[freeIndex] = _ptr; +// if (freeIndex++>=MAX_MEM_LOG) +// freeIndex = 0; } } @@ -97,6 +98,7 @@ void InitWatchdog(uint32_t clock) // // Enable the watchdog interrupt. // +#ifdef WATCHDOG MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0); ROM_WatchdogIntClear(WATCHDOG0_BASE); ROM_WatchdogIntTypeSet(WATCHDOG0_BASE,0); //interrupt, not NMI @@ -116,6 +118,7 @@ void InitWatchdog(uint32_t clock) // Enable the watchdog timer. // ROM_WatchdogEnable(WATCHDOG0_BASE); +#endif } void utilsInit(uint32_t ui32SysClock) { @@ -136,9 +139,14 @@ void utilsInit(uint32_t ui32SysClock) // Configure the hibernate module counter to RTC counter mode. HibernateCounterMode(HIBERNATE_COUNTER_RTC); +#define STARTTIME 1564403262 + Seconds_set(STARTTIME); } - +void utilsUpdateDateTime(uint32_t StartTime) +{ + Seconds_set(StartTime); +} uint32_t UsersysTickGet (void) { uint32_t tick = 0; diff --git a/Software/Embedded_SW/Embedded/Common/Utilities/Utils.h b/Software/Embedded_SW/Embedded/Common/Utilities/Utils.h index 37eade5c4..b54453e2c 100644 --- a/Software/Embedded_SW/Embedded/Common/Utilities/Utils.h +++ b/Software/Embedded_SW/Embedded/Common/Utilities/Utils.h @@ -22,6 +22,7 @@ typedef enum void utilsInit(uint32_t ui32SysClock); +void utilsUpdateDateTime(uint32_t StartTime); uint32_t UsersysTickGet (void); bool DanserCheckPosition(uint16_t position , Danser_t danser, bool test); void InitWatchdog(uint32_t clock); diff --git a/Software/Embedded_SW/Embedded/Common/report/distributor.c b/Software/Embedded_SW/Embedded/Common/report/distributor.c index e4ab5fa36..d485abb70 100644 --- a/Software/Embedded_SW/Embedded/Common/report/distributor.c +++ b/Software/Embedded_SW/Embedded/Common/report/distributor.c @@ -728,7 +728,8 @@ static void messageDistribute(char *msg, Dist_Table[DistTableEntry].dest[index].function(msg,FileName,LineNumber,errorCode,parameter1,parameter2); } */ - strcpy (reportmsg,msg); + strncpy (reportmsg,msg,250); + reportmsg[251] = NULL; if (ReportFunc1 != NULL) ReportFunc1(reportmsg, FileName,LineNumber,errorCode,Severity, parameter); diff --git a/Software/Embedded_SW/Embedded/Common/report/filter.c b/Software/Embedded_SW/Embedded/Common/report/filter.c index b922e53bc..febc1ea8c 100644 --- a/Software/Embedded_SW/Embedded/Common/report/filter.c +++ b/Software/Embedded_SW/Embedded/Common/report/filter.c @@ -145,7 +145,7 @@ int ReportFilterPackage(const char *filterName, uint8_t SwitchAddRemove) return -1; /* nothing to remove */ } strcpy(packageFilterTable[filterNumOfCurrentEntries].filterName,filterName); - packageFilterTable[filterNumOfCurrentEntries].filterDontUse = true; + packageFilterTable[filterNumOfCurrentEntries].filterDontUse = false; filterNumOfCurrentEntries++; return (filterNumOfCurrentEntries-1); } diff --git a/Software/Embedded_SW/Embedded/Common/report/report.h b/Software/Embedded_SW/Embedded/Common/report/report.h index 349bdb733..093481081 100644 --- a/Software/Embedded_SW/Embedded/Common/report/report.h +++ b/Software/Embedded_SW/Embedded/Common/report/report.h @@ -228,7 +228,7 @@ extern STATUS ReportMessage2Dist(DistributorHandle distributor, const char *mess * Return value: OK; or Report's return code **************************************************************************/ #define REPORT_IF_ERROR(condition, msg, error, severity, par1, par2) \ - ((condition) ? Report(REPORT_LINE(msg), error, severity, par1, par2) : OK) + ((condition) ? Report(msg, __FILE__,__LINE__, error, severity, par1, par2) : OK) /*----------------------------------------------------------------------------*/ /*---------------------- Report Tracing and Exceptions -----------------------*/ diff --git a/Software/Embedded_SW/Embedded/Common/report/reportInit.c b/Software/Embedded_SW/Embedded/Common/report/reportInit.c index bc3cbe20b..d633ffc00 100644 --- a/Software/Embedded_SW/Embedded/Common/report/reportInit.c +++ b/Software/Embedded_SW/Embedded/Common/report/reportInit.c @@ -38,7 +38,9 @@ #include "PMR/debugging/StartDebugLogResponse.pb-c.h" #include "PMR/debugging/StopDebugLogResponse.pb-c.h" -/*PackageHandle ControlFilter; +#include "modules/General/process.h" + +PackageHandle ControlFilter; PackageHandle HeatersFilter; PackageHandle JobFilter ; PackageHandle WasteFilter ; @@ -51,7 +53,7 @@ PackageHandle CommFilter; PackageHandle FPGAFilter; PackageHandle LoadFilter; PackageHandle InitFilter; -PackageHandle MaintFilter;*/ +PackageHandle MaintFilter; char protobufToken[36+1] = {0}; @@ -99,7 +101,7 @@ int ReportResponseFunc(char *message, /* The formatted message response.message = message; responseContainer = /*Report*/createContainer(MESSAGE_TYPE__StartDebugLogResponse, protobufToken, false, &response, &start_debug_log_response__pack, &start_debug_log_response__get_packed_size); responseContainer.continuous = true; - if (responseContainer.data.data) + //if (responseContainer.data.data) { uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); if (container_buffer) @@ -109,13 +111,13 @@ int ReportResponseFunc(char *message, /* The formatted message if (SendCharsWithType(container_buffer, container_size,MESSAGE_TYPE__StartDebugLogResponse) == false) //comm tx mailbox full { //CommunicationMailboxFlush(); - //protobufToken[0] = 0; + protobufToken[0] = 0; my_free(container_buffer); } } my_free(responseContainer.data.data); } - + //Task_sleep(5); return OK; } @@ -145,8 +147,27 @@ uint32_t ReportInitMessage(MessageContainer* requestContainer) #define SYSCTL_CAUSE_EXT 0x00000001 // External reset */ uint32_t RESC = SysCtlResetCauseGet (); - LOG_ERROR(RESC,"Reset Reason Register"); + char ResetMessage[200] = "Reset Reason Register"; + if (RESC & SYSCTL_CAUSE_HSRVREQ) strcat (ResetMessage,", Service Req"); + if (RESC & SYSCTL_CAUSE_HIB) strcat (ResetMessage,", Hibernate"); + if (RESC & SYSCTL_CAUSE_WDOG1) strcat (ResetMessage,", Watchdog 1"); + if (RESC & SYSCTL_CAUSE_SW) strcat (ResetMessage,", Software"); + if (RESC & SYSCTL_CAUSE_WDOG0) strcat (ResetMessage,", Watchdog 0"); + if (RESC & SYSCTL_CAUSE_BOR) strcat (ResetMessage,", Brown-out"); + if (RESC & SYSCTL_CAUSE_POR) strcat (ResetMessage,", Power on"); + if (RESC & SYSCTL_CAUSE_EXT) strcat (ResetMessage,", External"); + Report(ResetMessage,__FILE__,__LINE__,RESC,RpWarning,status,0); + Task_sleep (100); + /*SysCtlResetCauseClear(RESC);*/ +#ifdef TEST_PID_THREAD + Task_sleep(1000); + dyeingspeed = 50; + ThreadJoggingFunc(50); + ThreadPreSegmentState(NULL,0); + Task_sleep(2000); + ThreadAbortJoggingFunc(); +#endif return status; } uint32_t StopReportInitMessage(MessageContainer* requestContainer) @@ -216,7 +237,7 @@ STATUS ReportInit(ReportInitParams InitParams) status = filterTableInit(MaxNumOfFilterNames); if (status == OK) initialized = true; -/* ControlFilter = ReportAddFilterPackage("Control"); + ControlFilter = ReportAddFilterPackage("Control"); HeatersFilter = ReportAddFilterPackage("Heaters"); JobFilter = ReportAddFilterPackage("Job"); WasteFilter = ReportAddFilterPackage("Waste"); @@ -229,7 +250,7 @@ STATUS ReportInit(ReportInitParams InitParams) FPGAFilter = ReportAddFilterPackage("FPGA"); LoadFilter = ReportAddFilterPackage("Load"); InitFilter = ReportAddFilterPackage("Init"); - MaintFilter = ReportAddFilterPackage("Maint");*/ + MaintFilter = ReportAddFilterPackage("Maint"); // Filter = ReportAddFilterPackage(""); return status; |
