#include "mil.h"
#define WINDOW_TITLE MIL_TEXT("Monitoring Application")
#if defined(CONNECT_TO_RTOS)
#define PUBLISH_SYSTEM_NAME MIL_TEXT("dmilshmrt:
#else
#define PUBLISH_SYSTEM_NAME MIL_TEXT("dmilshm:
#endif
int MosMain(void)
{
MIL_ID MilApplication = M_NULL,
MilSystem = M_NULL,
LocalDisplay = M_NULL,
LocalDisplayImage = M_NULL,
LocalOverlayImage = M_NULL;
MIL_ID RemoteDisplayImage = M_NULL,
RemoteOverlayImage = M_NULL,
MilRemoteApplication = M_NULL;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &LocalDisplay, M_NULL, M_NULL);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MappOpenConnection(PUBLISH_SYSTEM_NAME, M_DEFAULT, M_DEFAULT,
&MilRemoteApplication);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
if(MilRemoteApplication == 0)
{
MosPrintf(MIL_TEXT("Cannot open a connection to the remote application.\n"));
MosPrintf(MIL_TEXT("Please make sure the publishing example is running.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n"));
MosGetch();
}
else
{
MappInquireConnection(MilRemoteApplication, M_DMIL_PUBLISHED_NAME,
M_PTR_TO_MIL_INT(MIL_TEXT("DisplayImage")), M_DEFAULT, &RemoteDisplayImage);
MappInquireConnection(MilRemoteApplication, M_DMIL_PUBLISHED_NAME,
M_PTR_TO_MIL_INT(MIL_TEXT("OverlayImage")), M_DEFAULT, &RemoteOverlayImage);
if(RemoteDisplayImage)
{
MbufAllocColor(MilSystem,
MbufInquire(RemoteDisplayImage, M_SIZE_BAND, M_NULL),
MbufInquire(RemoteDisplayImage, M_SIZE_X, M_NULL),
MbufInquire(RemoteDisplayImage, M_SIZE_Y, M_NULL),
MbufInquire(RemoteDisplayImage, M_TYPE, M_NULL),
M_IMAGE+M_DISP,
&LocalDisplayImage);
MbufCopy(RemoteDisplayImage, LocalDisplayImage);
MdispSelect(LocalDisplay, LocalDisplayImage);
MdispControl(LocalDisplay, M_TITLE, M_PTR_TO_DOUBLE(WINDOW_TITLE));
MbufLink(RemoteDisplayImage, LocalDisplayImage, M_LINK, M_DEFAULT);
if(RemoteOverlayImage)
{
MdispControl(LocalDisplay, M_OVERLAY, M_ENABLE);
LocalOverlayImage = (MIL_ID)MdispInquire(LocalDisplay, M_OVERLAY_ID, M_NULL);
MbufCopy(RemoteOverlayImage, LocalOverlayImage);
MbufLink(RemoteOverlayImage, LocalOverlayImage, M_LINK, M_DEFAULT);
}
MosPrintf(MIL_TEXT("DMIL MONITORING (Monitoring):\n"));
MosPrintf(MIL_TEXT("-------------------------------------------\n"));
MosPrintf(MIL_TEXT("The image displayed is the image published by another\n"));
MosPrintf(MIL_TEXT("application for DMIL monitoring.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n"));
MosGetch();
MbufLink(RemoteDisplayImage, LocalDisplayImage, M_UNLINK, M_DEFAULT);
if(RemoteOverlayImage)
MbufLink(RemoteOverlayImage, LocalOverlayImage, M_UNLINK, M_DEFAULT);
}
else
{
MosPrintf(MIL_TEXT("No image to display.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
}
MappCloseConnection(MilRemoteApplication);
}
MappFreeDefault(MilApplication, MilSystem, LocalDisplay, M_NULL, LocalDisplayImage);
}