📄 mobilesyncdlg.cpp
字号:
*pDestLen = 0;
return OP_TRUE;
}
//check if the destination buffer length is enough
count = SrcLen / 3;
remainder = SrcLen % 3;
if (remainder == 0)
{
if (count*4 > (OP_UINT16)(*pDestLen))
{
return OP_FALSE;
}
}
else
{
if ((count+1)*4 > (*pDestLen))
{
return OP_FALSE;
}
}
//encode the data
for (i=0; i<count; i++)
{
memcpy(temp8bit, pSrc+3*i, 3);
temp6bit[0] = (temp8bit[0] >> 2) & 0x3f;
temp6asc[0] = base64_asc[temp6bit[0]];
temp6bit[1] = (temp8bit[0]<<4 | temp8bit[1]>>4) & 0x3f;
temp6asc[1] = base64_asc[temp6bit[1]];
temp6bit[2] = (temp8bit[1]<<2 | temp8bit[2]>>6) & 0x3f;
temp6asc[2] = base64_asc[temp6bit[2]];
temp6bit[3] = temp8bit[2] & 0x3f;
temp6asc[3] = base64_asc[temp6bit[3]];
memcpy(pDest+4*i, temp6asc, 4);
}
if (remainder != 0)
{
if (remainder == 1)
{
memcpy(temp8bit, pSrc+3*count, 1);
temp6bit[0] = (temp8bit[0] >> 2) & 0x3f;
temp6asc[0] = base64_asc[temp6bit[0]];
temp6bit[1] = (temp8bit[0] << 4) & 0x3f;
temp6asc[1] = base64_asc[temp6bit[1]];
temp6asc[2] = '=';
temp6asc[3] = '=';
}
else
{
memcpy(temp8bit, pSrc+3*count, 2);
temp6bit[0] = (temp8bit[0] >> 2) & 0x3f;
temp6asc[0] = base64_asc[temp6bit[0]];
temp6bit[1] = (temp8bit[0]<<4 | temp8bit[1]>>4) & 0x3f;
temp6asc[1] = base64_asc[temp6bit[1]];
temp6bit[2] = (temp8bit[1] << 2) & 0x3f;
temp6asc[2] = base64_asc[temp6bit[2]];
temp6asc[3] = '=';
}
memcpy(pDest+4*count, temp6asc, 4);
*pDestLen = 4 * (count + 1);
}
else
{
*pDestLen = 4 * count;
}
return OP_TRUE;
}
OP_UINT16 CMobileSyncDlg::comm_checksum(const OP_UINT8 *pData, OP_UINT16 DataLen)
{
OP_UINT16 i;
OP_UINT16 checksum = 0;
for (i=0; i<DataLen; i++)
{
checksum += *pData++;
}
return checksum;
}
void CMobileSyncDlg::comm_send_error(void)
{
OP_UINT8 errData = 0x7B;
OutText("Send Error Message to PC.\n");
m_comm.SetOutput(COleVariant(errData));
}
void CMobileSyncDlg::comm_send_command(OP_UINT8 *pCmdData, OP_UINT16 CmdLen)
{
WORD checksum;
static OP_UINT8 TxBuffer[2048];
OP_UINT16 DataLen64 = 2047;
CString strOutData;
OP_UINT8 tempBuffer[2048];
//static RxBuffer[2048];
if ((pCmdData != NULL) && (CmdLen > 0))
{
memcpy(tempBuffer, pCmdData, CmdLen);
checksum = comm_checksum(tempBuffer, CmdLen);
memcpy(tempBuffer+CmdLen, &checksum, 2);
memset(TxBuffer, 0x3a, 1);
if (comm_base64_encode(tempBuffer, CmdLen+2, TxBuffer+1, &DataLen64))
{
memset(TxBuffer+DataLen64+1, 0x3b, 1);
memset(TxBuffer+DataLen64+2, 0x00, 1);
strOutData = TxBuffer;
m_comm.SetOutput(COleVariant(strOutData));
OutText("Send Out Data: ");
#ifdef _DISPLAY_DATA_
for (int i=0; i<strOutData.GetLength(); i++)
{
OutText(TxBuffer[i]);
OutText(" ");
}
#endif
//OutText("\"");
//OutText(strOutData);
//OutText("\"\n");
OutText("\n");
}
else
{
comm_send_error();
}
}
}
///////////////////////////////////////////////////////////////////////////////
//Inquire Melody(Picture) file Count
void CMobileSyncDlg::OnCount()
{
this->UpdateData();
OP_UINT8 Cmd[3];
switch (m_nMelodyCmd)
{
case 0: //melody
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x01;
break;
case 1: //picture
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x02;
break;
case 2: //photo
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x03;
break;
case 3:
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x04;
break;
case 4:
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x05;
break;
case 5:
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x06;
break;
case 6:
Cmd[0] = 0x01;
Cmd[1] = 0x01;
Cmd[2] = 0x07;
break;
}
OutText("Send Inquire Count Command.\n");
m_preTime = COleDateTime::GetCurrentTime();
comm_send_command(Cmd, sizeof(Cmd));
}
void CMobileSyncDlg::OnInquire()
{
OP_UINT8 Cmd[7];
this->UpdateData();
switch (m_nMelodyCmd)
{
case 0:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x01;
break;
case 1:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x02;
break;
case 2:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x03;
break;
case 3:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x04;
break;
case 4:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x05;
break;
case 5:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x06;
break;
case 6:
Cmd[0] = 0x01;
Cmd[1] = 0x02;
Cmd[2] = 0x07;
break;
}
OP_UINT16 Index = 0;
OP_UINT16 Count;
m_HeaderList.DeleteAllItems();
if (m_nfCount > 20)
{
Count = 20;
}
else if (m_nfCount > 0)
{
Count = m_nfCount;
}
else
{
MessageBox("Please Inquire File Count First");
return;
}
memcpy(Cmd+3, &Index, 2);
memcpy(Cmd+5, &Count, 2);
OutText("Send Inquire Header Command.\n");
comm_send_command(Cmd, sizeof(Cmd));
}
void CMobileSyncDlg::OnUpload()
{
// upload a file from phone to pc
//OP_UINT8 Cmd[44] = {01, 06}; //melody command
//OP_UINT8 Cmd[44] = {02, 06}; //picture command
OP_UINT8 Cmd[47];
this->UpdateData();
switch (m_nMelodyCmd)
{
case 0:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x01;
break;
case 1:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x02;
break;
case 2:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x03;
break;
case 3:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x04;
break;
case 4:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x05;
break;
case 5:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x06;
break;
case 6:
Cmd[0] = 0x01;
Cmd[1] = 0x06;
Cmd[2] = 0x07;
break;
}
OP_UINT8 fName[44];
OP_UINT8 chSize[10];
WCHAR UniName[22];
POSITION pos = m_HeaderList.GetFirstSelectedItemPosition();
if (pos != NULL)
{
int nItem = m_HeaderList.GetNextSelectedItem(pos);
m_HeaderList.GetItemText(nItem, 0, (LPTSTR)fName, 44);
m_strfName = fName;
m_HeaderList.GetItemText(nItem, 2, (LPTSTR)chSize, 10);
m_nfSize = atoi((char*)chSize);
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)fName, -1, UniName, 44);
memcpy(Cmd+3, UniName, 44);
OutText("Send Upload Header Command.\n");
comm_send_command(Cmd, sizeof(Cmd));
}
else
{
MessageBox("Please Select a File Name.");
return;
}
}
void CMobileSyncDlg::OnDelete()
{
//delete a file in phone
//OP_UINT8 Cmd[44] = {0x01, 0x09}; //melody
//OP_UINT8 Cmd[44] = {0x02, 0x09}; //picture
OP_UINT8 Cmd[47];
this->UpdateData();
switch (m_nMelodyCmd)
{
case 0:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x01;
break;
case 1:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x02;
break;
case 2:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x03;
break;
case 3:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x04;
break;
case 4:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x05;
break;
case 5:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x06;
break;
case 6:
Cmd[0] = 0x01;
Cmd[1] = 0x09;
Cmd[2] = 0x07;
break;
}
OP_UINT8 fileName[44];
WCHAR UniName[22];
POSITION pos = m_HeaderList.GetFirstSelectedItemPosition();
if (pos != NULL)
{
int nItem = m_HeaderList.GetNextSelectedItem(pos);
m_HeaderList.GetItemText(nItem, 0, (LPTSTR)fileName, 44);
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)fileName, -1, UniName, 44);
memcpy(Cmd+3, UniName, 44);
OutText("Send Delete Command.\n");
comm_send_command(Cmd, sizeof(Cmd));
}
else
{
MessageBox("Please Select a File Name.");
return;
}
}
void CMobileSyncDlg::OnDownload()
{
// download a file from pc to phone
OP_UINT8 Cmd[55];
this->UpdateData();
memset(Cmd, 0x00, sizeof(Cmd));
switch (m_nMelodyCmd)
{
case 0:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x01;
break;
case 1:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x02;
break;
case 2:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x03;
break;
case 3:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x04;
break;
case 4:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x05;
break;
case 5:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x06;
break;
case 6:
Cmd[0] = 0x01;
Cmd[1] = 0x03;
Cmd[2] = 0x07;
break;
}
CFileDialog dlg(TRUE);
if (dlg.DoModal() == IDOK)
{
CFile file;
CFileStatus fStat;
CString strfName;
CString strfType;
WCHAR UniName[44];
OP_UINT8* pfTemp;
int n;
strfName = dlg.GetFileTitle();
strfType = dlg.GetFileExt();
if (file.Open(dlg.GetPathName(), CFile::modeRead))
{
file.GetStatus(fStat);
m_nfSize = fStat.m_size;
if (m_pfBuff != NULL) free(m_pfBuff);
if (m_nMelodyCmd == 7) //ebook convert to unicode
{
pfTemp = (OP_UINT8*)malloc(m_nfSize+1);
memset(pfTemp, 0x00, m_nfSize+1);
m_pfBuff = (OP_UINT8*)malloc(m_nfSize*2+2);
memset(m_pfBuff, 0x00, m_nfSize*2+2);
file.Read(pfTemp, m_nfSize);
n = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pfTemp, -1,
(LPWSTR)m_pfBuff, m_nfSize*2);
n = wcslen((LPWSTR)m_pfBuff);
m_nfSize = n*2;
}
else
{
m_pfBuff = (OP_UINT8*)malloc(m_nfSize);
file.Read(m_pfBuff, m_nfSize);
}
m_nOffset = 0;
m_strfName = strfName;
}
else
{
MessageBox("Open File Fail!");
return;
}
n = sizeof(UniName);
memset(UniName, 0x00, 44);
n = MultiByteToWideChar(CP_ACP, 0, strfName, -1, UniName, 44);
n = wcslen(UniName);
memcpy(Cmd+3, UniName, wcslen(UniName)*2);
// memset(Cmd+2+strfName.GetLength(), 0x00, 42-strfName.GetLength());
memcpy(Cmd+47, (LPCTSTR)strfType, 4);
memcpy(Cmd+51, (OP_UINT8*)&m_nfSize, 4);
OutText("Send Download Header Command.\n");
comm_send_command(Cmd, sizeof(Cmd));
}
}
void CMobileSyncDlg::OnPbStatus()
{
// TODO: Add your control notification handler code here
OP_UINT8 Cmd[3] = {0x02, 0x01};
Cmd[2] = 0x02; //device
OutText("Send Inquire Status Command.\n");
comm_send_command(Cmd, sizeof(Cmd));
}
void CMobileSyncDlg::OnPbSave()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -