节目和节目单的生成及发送


//==========================================
// API for Program
//==========================================
/*------------------------------------------
Step 1: Create a program object
Step 2: Add play window
Step 3: Add item(text, clock, etc.) to the program
Step 4: Save the program to file
Step 5: Destroy the program object
------------------------------------------*/
CP5200API HOBJECT CALLING_CONV CP5200_Program_Create (WORD width, WORD height, BYTE color);
CP5200API int CALLING_CONV CP5200_Program_Destroy (HOBJECT hObj);
CP5200API int CALLING_CONV CP5200_Program_SetProperty(HOBJECT hObj, int nPropertyValue, int nPropertyID);
CP5200API int CALLING_CONV CP5200_Program_SetBackgndImage(HOBJECT hObj, const BYTE* pImgDat, WORD wImgWidth, WORD wImgHeight, BYTE color, int nMode, int nCompress);
CP5200API int CALLING_CONV CP5200_Program_AddPlayWindow(HOBJECT hObj, WORD x, WORD y, WORD cx, WORD cy);
CP5200API int CALLING_CONV CP5200_Program_SetWindowProperty(HOBJECT hObj, int nWinNo, int nPropertyValue, int nPropertyID);
CP5200API int CALLING_CONV CP5200_Program_SetItemProperty(HOBJECT hObj, int nWinNo, int nItem, int nPropertyValue, int nPropertyID);
CP5200API int CALLING_CONV CP5200_Program_AddText(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nEffect, int nSpeed, int nStay);
CP5200API int CALLING_CONV CP5200_Program_AddText1(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nEffect, int nSpeed, int nStay);
CP5200API int CALLING_CONV CP5200_Program_AddTagText(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nEffect, int nSpeed, int nStay);
CP5200API int CALLING_CONV CP5200_Program_AddTagText1(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nEffect, int nSpeed, int nStay);
CP5200API int CALLING_CONV CP5200_Program_AddFormattedText( HOBJECT hObj, int nWinNo, const char *pText, const char *pFontFaceName, const byte *pFormatData, const byte *pScreenData, int nMode, int nEffect, int nSpeed, int nStay, int nCompress );
CP5200API int CALLING_CONV CP5200_Program_AddFormattedTextW( HOBJECT hObj, int nWinNo, const wchar_t *pText, const char *pFontFaceName, const byte *pFormatData, const byte *pScreenData, int nMode, int nEffect, int nSpeed, int nStay, int nCompress );
CP5200API int CALLING_CONV CP5200_Program_AddPicture(HOBJECT hObj, int nWinNo, const char* pPictFile, int nMode, int nEffect, int nSpeed, int nStay, int nCompress);
CP5200API int CALLING_CONV CP5200_Program_AddImage(HOBJECT hObj, int nWinNo, const BYTE* pImgDat, WORD wImgWidth, WORD wImgHeight, BYTE color, int nMode, int nEffect, int nSpeed, int nStay, int nCompress, int nPageCount);
CP5200API int CALLING_CONV CP5200_Program_AddLafPict(HOBJECT hObj, int nWinNo, const char* pLafFile, int nMode, int nEffect, int nSpeed, int nStay, int nCompress);
CP5200API int CALLING_CONV CP5200_Program_AddLafVideo(HOBJECT hObj, int nWinNo, const char* pLafFile, int nMode, int nRepeat);
CP5200API int CALLING_CONV CP5200_Program_AddAnimator(HOBJECT hObj, int nWinNo, const char* pAniFile, int nMode, int nRepeat);
CP5200API int CALLING_CONV CP5200_Program_AddClock(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nStay, WORD wAttr);
CP5200API int CALLING_CONV CP5200_Program_AddTemperature(HOBJECT hObj, int nWinNo, const char* pText, int nFontSize, COLORREF crColor, int nStay, WORD wAttr);
CP5200API int CALLING_CONV CP5200_Program_AddVariable(HOBJECT hObj, int nWinNo, int nFontSize, COLORREF crColor, int nStay, WORD wAttr);
CP5200API int CALLING_CONV CP5200_Program_AddTimeCounter(HOBJECT hObj, int nWinNo, int nFontSize, COLORREF crColor, int nStay, int nOption, const int *pBaseTime, const char *pContent);
CP5200API int CALLING_CONV CP5200_Program_AddExternalFile(HOBJECT hObj, int nWinNo, const char* pFile, const BYTE *pParamBuf, int nParamLen);
CP5200API int CALLING_CONV CP5200_Program_SaveToFile(HOBJECT hObj, const char* pFilename);

//==========================================
// API for Playbill
//==========================================
/*------------------------------------------
Step 1: Create a playbill object
Step 2: Add program file to the playbill
Step 3: Save the playbill to file
Step 4: Destroy the playbill object
------------------------------------------*/
CP5200API HOBJECT CALLING_CONV CP5200_Playbill_Create (WORD width, WORD height, BYTE color);
CP5200API int CALLING_CONV CP5200_Playbill_Destroy (HOBJECT hObj);
CP5200API int CALLING_CONV CP5200_Playbill_AddFile (HOBJECT hObj, const char* pFilename);
CP5200API int CALLING_CONV CP5200_Playbill_DelFile (HOBJECT hObj, const char* pFilename);
CP5200API int CALLING_CONV CP5200_Playbill_SaveToFile (HOBJECT hObj, const char* pFilename);

CP5200API int CALLING_CONV  CP5200_Net_Connect(); 

 CP5200_Net_IsConnected()


\

CP5200API int CALLING_CONV CP5200_Net_Init(DWORD dwIP, int nIPPort, DWORD dwIDCode, int nTimeOut );
CP5200API int CALLING_CONV CP5200_Net_UploadFile(int nCardID, const char* pSourceFilename, const char *pTargetFilename);
CP5200API int CALLING_CONV CP5200_Net_RestartApp(BYTE nCardID);

实现对控制卡的操作。
注意:控制卡启动时只查找节目单文件”playbill.lpp”,若生成数据时保存为其它文件名,在将节目单文件(“.lpp”)发送到卡上的时候,需要改文件名为”playbill.lpp”。

1.创建节目
HOBJECT hProgram= CP5200_Program_Create (progData.GetLPictAreaW()+progData.GetRPictAreaW()+progData.GetTextAreaW()
1.1 如果节目句柄hProgram不为空,就添加播放窗口到节目,一帧就是一个节目,帧有几个播放窗口就添加多少窗口到节目,一个节目生成一个节目文件;
int nWindowFirst= CP5200_Program_AddPlayWindow(hProgram, 0, 0,progData.GetLPictAreaW() , progData.GetLPictAreaH());
nWindowSecond=CP5200_Program_AddPlayWindow(hProgram, progData.GetLPictAreaW(), 0,progData.GetTextAreaW(),progData.GetLPictAreaH());
int nWindowThird= CP5200_Program_AddPlayWindow(hProgram, progData.GetLPictAreaW() + progData.GetTextAreaW() , 0,progData.GetRPictAreaW() , progData.GetLPictAreaH());
1.2 添加图片或者文字到节目对应的播放窗口;

for (i=0 ; i< MAX_PICT_NUM ; i++)
{ //把左边区域的图片添加进去,有很多张图片;
CString strLname = progData.GetLeftPictItemPath( k ,i );
if (!strLname.IsEmpty())
{
nRet = CP5200_Program_AddPicture(hProgram, nWindowFirst, strLname, 1, 0, 0, progData.GetLeftPictItemStaytime(k,i) , 0) ;
if (nRet < 0)
return ;
}

//把右边区域的图片添加进去,有很多张图片;
CString strRname = progData.GetRightPictItemPath(k,i);
if (!strRname.IsEmpty())
{
nRet= CP5200_Program_AddPicture(hProgram, nWindowThird, strRname, 1, 0, 0, progData.GetRightPictItemStaytime(k,i) , 0) ;
if ( nRet < 0 )
return;
}
}
//1.4、添加文字内容
CString str=_T("");
for(j =0 ; j< progData.GetRowCnt() ;j++)
{
//把中间区域的字添加到窗口
CString StrLine;
for (int n = 0 ; n <progData.GetColCnt() ; n++ )
{
StrLine.Format(_T("%c"), progData.GetWordItem(k,j,n));
str+=StrLine;
}

str+="\r\n";
}

nRet = CP5200_Program_AddText(hProgram, nWindowSecond, str,progData.GetFontHigh(), progData.GetColorFont(), 0, 0, progData.GetTextStayTime(k));
if ( nRet <0 )
return ;

1.3 保存节目导节目内容,一个节目生成一个文件;
CString strProgramPath;
strProgramPath = GetModulePath();
strProgramPath.Format( _T("%s%08d.lpb"), GetModulePath(), k );
nRet = CP5200_Program_SaveToFile(hProgram, strProgramPath );
if( 0 <= nRet )
{
strFilePathToUpload.AddTail( strProgramPath );
}
else
{
ASSERT( FALSE );
}
CP5200_Program_Destroy(hProgram);
}

2.生成节目单文件,很多节目就只有一个节目单
2.1 创建节目单
HOBJECT hPlaybill = CP5200_Playbill_Create (WidthShow, HeigtShow,progData.GetFontType());
2.2 添加所有节目文件到节目单
if(hPlaybill )
{
POSITION pos = strFilePathToUpload.GetHeadPosition();
while( pos )
{
//strFilePathToUpload是一个数组,装生成的节目名字;
CString strProgramPath = strFilePathToUpload.GetNext( pos );
nRet = CP5200_Playbill_AddFile(hPlaybill, strProgramPath );
if ( nRet <0)
{
CP5200_Program_Destroy( hPlaybill );
return;
}
}
}

//保存节目单文件
CString strPlaybill;
strPlaybill = GetModulePath() + PLAYBILL_FILENAME;

nRet = CP5200_Playbill_SaveToFile( hPlaybill, strPlaybill );//保存节目单;
if( 0 == nRet )
{

strFilePathToUpload.AddTail( strPlaybill );;//把节目单也添加到数组中,因为后面要把节目和节目单上传 到CP5200_Net_UploadFile(),信号卡上;
}
else //节目单生成失败,不上传文件
{
strFilePathToUpload.RemoveAll();
}


发送所有文件

bRet = !strFilePathToUpload.IsEmpty();
//TODO暂时不处理发送
return bRet;


//发送所有文件

if( bRet )

 {

  int nRet;

  bRet = FALSE;

  nRet = CP5200_Net_Init( IPStringToValue( sign.GetIP() ), 5200,  IPStringToValue( _T("255.255.255.255")), 600);

  nRet = CP5200_Net_Connect();   if( CP5200_Net_IsConnected() )

  {    POSITION pos = strFilePathToUpload.GetHeadPosition();   

 while( pos )   

 {   

  CString strSrcName, strDestName;

    strSrcName = strFilePathToUpload.GetNext( pos );

    strDestName = GetPathFileName( strSrcName );    

 nRet =CP5200_Net_UploadFile(0xff , strSrcName, strDestName );  

   if(0 !=nRet)

    {     

 break;

    }  

  }  

  bRet = !pos;   

 //重启app  

  nRet = CP5200_Net_RestartApp(0xff);  

  CP5200_Net_Disconnect();  

 }  

}

 return bRet;

原文地址:https://www.cnblogs.com/chenzuoyou/p/3085017.html