void Packet::Write (const UInt16& value) { WriteData (value); }
// 读取记录 bool CJMYPassPay::ReadRecords(const uint8 *readBuf, const int readLen, string &errcode) { static char temp[BUF_SIZE] = {0}; static uint8 initBuf[BUF_SIZE] = {0}; int initLen = g_readLen; memcpy(initBuf, g_readBuff, g_readLen); // 找出应用文件定位器,tag为94,取出短文件标识符读记录 int i = 0; for (; i < initLen; i++) { if (0X94 == initBuf[i]) { // 找到了短文件标识符,获取短文件标识符的长度 int sfiLen = initBuf[i + 1]; if (0 != sfiLen % 4) { // 短文件标识符长度有错 PrintLog("Find SFI length error!"); return false; } // 把短文件标识符读出 int iStart = i + 2; memset(temp, 0x00, sizeof(temp)); for (int l = 0; l < sfiLen; l++) { sprintf(&temp[l*3], "%02X ", initBuf[iStart++]); } PrintLog("SFI:%s", temp); // 短文件标识符每四个字节为一组,分别是:短文件标示,第一记录编号,最后一条记录编号,存放用于脱机数据认证的数据的连续记录个数 iStart = i + 2; // 指向第一组数据 int iGroup = sfiLen / 4; bool bRead9F74 = false; bool bRead5F25 = false; bool bRead5F24 = false; for (int j = 0; j < iGroup; j++) { // 开始处理一组数据 uint8 sfi = initBuf[iStart + (j * 4)]; // sfi uint8 first = initBuf[iStart + (j * 4) + 1]; // start record uint8 last = initBuf[iStart + (j * 4) + 2]; // end record uint8 otherRec = initBuf[iStart + (j * 4) + 3]; uint8 iReadType = sfi | 0X04; //读指定标识符的记录 0100 int readRecLen = 0; char hexBuf[4] = {0}; string readRecCmd; static uint8 readRecBuff[4096] = {0}; for(int k = first; k <= last; k++) { readRecCmd = "31 00 B2 "; memset(hexBuf,0X00, sizeof(hexBuf)); sprintf(hexBuf, "%02X ", k); // 指定要读取的记录编号 readRecCmd += hexBuf; memset(hexBuf,0X00, sizeof(hexBuf)); sprintf(hexBuf, "%02X ", iReadType); // 指定读取的方式为读取当前记录 readRecCmd += hexBuf; memset(g_readBuff, 0x00, sizeof(g_readBuff)); PrintLog("record cmd:%s", readRecCmd.c_str()); if ( false == WriteData(readRecCmd)) { PrintLog("Send cmd:%s filed", readRecCmd.c_str()); return false; } GetReadRes(); readRecLen = g_readLen; memset(temp, 0x00, sizeof(temp)); for (int i = 0; i < readRecLen; i++) { sprintf(temp + i * 3, "%02X ", g_readBuff[i]); } PrintLog("send cmd:%s\n recv:%s", readRecCmd.c_str(), temp); if (g_readLen > 3) { char sw1sw2[6] = {0}; snprintf(sw1sw2, sizeof(sw1sw2), "%02X%02X", g_readBuff[g_readLen-3], g_readBuff[g_readLen-2]); //PrintLog("************sw1sw = %s************", sw1sw2); //请求的记录不存在,卡片返回 SW1 SW2=“6A83” if(sw1sw2 == NO_RECORD) { PrintLog("命令:%s 读记录失败!", readRecCmd.c_str()); errcode = NO_RECORD; continue; } else if (sw1sw2 != SUCCESS_CODE) { PrintLog("发生了未知的错误:sw1sw2=%s", sw1sw2); errcode = UNKNOW_ERROR; continue; } } // 读取 卡行授权码 if (false == bRead9F74) { bRead9F74 = Get9F74Value(g_readBuff, readLen); } // 读取卡片生效日期 if (false == bRead5F25) { bRead5F25 = GetValidate(g_readBuff, readLen); if(bRead5F25) { int currDateValue = atoi(m_CurrDate.c_str()); // 生效日期检查 if (m_Validate.length() > 0) { int validateValue = atoi(m_Validate.c_str()); PrintLog("生效日期:%d", validateValue); if (validateValue > currDateValue) { PrintLog("卡片未生效"); return false; } } } } // 读取卡片失效日期 if (false == bRead5F24) { bRead5F24 = GetInvalidate(g_readBuff, readLen); if (bRead5F24) { // 失效日期检查 int currDateValue = atoi(m_CurrDate.c_str()); int invalidateValue = atoi(m_Invalidate.c_str()); PrintLog("失效日期:%d", invalidateValue); if (currDateValue > invalidateValue) { PrintLog("卡片已失效"); return false; } } } } } if (false == bRead9F74) { // 所有记录都读完毕了,还没有读9F74则认为是失败 PrintLog("Find tag9F74 value failed!"); return false; } break; } } if (i >= initLen) { PrintLog("读记录时,查找短文件标识符失败"); return false; } return true; }
// 读卡号 bool CJMYPassPay::ReadCardNo(string &cardno, string &sw1sw2) { string cmd; int readLen = 0; static char temp[BUF_SIZE] = {0}; timeval usec1; gettimeofday(&usec1, NULL); //关天线 cmd = "11 00"; if (false == CloseAntenna(cmd)) { sw1sw2 = CLOSE_ANTE_FAILE; return false; } //开天线 cmd = "11 01"; if (false == OpenAntenna(cmd)) { sw1sw2 = OPEN_ANTE_FAILE; return false; } // 寻卡 cmd = "2000"; if (false == FindCard(cmd)) { sw1sw2 = FIND_CARD_FAILE; return false; } // 复位 cmd = "30"; if (false == RestCard(cmd)) { sw1sw2 = CARD_RESET_FAILE; return false; } // 选择PSE string app_id_cmd; cmd = "31 00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31"; if (false == SelectPSE(cmd, app_id_cmd, sw1sw2)) { return false; } // 选应用ID string gpo; if (false == SelectAppId(app_id_cmd, gpo, sw1sw2)) { return false; } // 读取卡号的命令 cmd = "31 00 B2 01 0C"; memset(g_readBuff, 0, sizeof(g_readBuff)); if (false == WriteData(cmd)) { PrintLog("Send cmd:%s failed!", cmd.c_str()); return false; } GetReadRes(); readLen = g_readLen; memset(temp, 0x00, sizeof(temp)); for (int i = 0; i < readLen; i++) { sprintf(temp + i * 2, "%02X", g_readBuff[i]); } PrintLog("Send cmd:%s\n, recv:%s", cmd.c_str(), temp); string str_card = temp; int pos = str_card.find("5712"); if (pos > 0) { cardno = str_card.substr(pos + 4,19); } PrintLog("cardno:%s", cardno.c_str()); sw1sw2 = SUCCESS_CODE; timeval usec2; gettimeofday(&usec2, NULL); int msec = (usec2.tv_sec * 1000 + usec2.tv_usec/1000) - (usec1.tv_sec * 1000 + usec1.tv_usec/1000); PrintLog("***********elapse=%.2f**********", msec/1000.0); return true; }
int main(int argc, char **argv) { if( argc != 2 && argc != 3 ) { printf( "Usage: c64 <command> [filename]\n" ); printf( "Commands:\n" ); printf( " upload <filename> - Uploads CRT image to C64FC\n" ); printf( " download <filename> - Downloads image from C64FC (not implemented)\n"); printf( " reset - Resets the C64\n" ); printf( " clear - Clears the entire C64FC, writes 0x0 to every address\n"); printf( " hexdump - Prints a hexdump of the entire cart\n"); printf( " bootloader - Enters bootloader mode on cart\n"); printf( " ramsize - Prints your EEPROM size\n"); printf( " chardump <fps> - Takes stdout from pipe and dump it on screen\n"); return( 1 ); } if( OpenDevice() ) { printf( "C64FC not found\n" ); return( 1 ); } if( (strcasecmp( argv[1], "reset" ) == 0) && (argc == 2) ) { /* * Issues a Reset of the C64 */ Reset(); } else if( (strcasecmp( argv[1], "bootloader" ) == 0) && (argc == 2) ) { /* * Makes the cart enter bootloader mode, this mode needs a power cycle of the cart to exit from */ EnterBootloader(); } else if( (strcasecmp( argv[1], "upload" ) == 0) && (argc == 3) ) { /* * Uploads data to the cart */ int skip = 0; FILE *fp = fopen( argv[2], "rb" ); if( !fp ) { printf( "Can't open input file for reading\n" ); return( 1 ); } fseek( fp, 0L, SEEK_END ); int len = ftell( fp ); fseek( fp, 0L, SEEK_SET ); unsigned char *array = malloc( len ); fread( array, len, 1, fp ); fclose( fp ); if( array[0] == 'C' && array[1] == '6' && array[2] == '4' ) { skip = 80; } printf( "Sending data (%d bytes)..\n", len-skip ); WriteData( 0, array+skip, len-skip ); if( len-skip >= 8192 ) { Set16KMode(); } else { Set8KMode(); } printf( "Issuing reset..\n" ); Reset(); } else if( (strcasecmp( argv[1], "clear" ) == 0) && (argc == 2) ) { /* * Clears the content of the entire C64FC */ } else if ((strcasecmp( argv[1], "fubar" ) == 0) && (argc == 2)) { /* * Runars test function * Actually.. does nothing more than return fubar in hex to the user... :) */ char buff[10]; int len = getFubar(buff); printf("getFubar: %s(%d)\n", buff, len); hexdump(0, buff, 10); } else if ((strcasecmp( argv[1], "hexdump" ) == 0) && (argc == 2)) { /* * Make a hexdump of the current register in the cart */ char buff[128]; printf("Hexdump of cart:\n"); int i; for (i = 0; i < 0x3FFF; i += 128) { memset(buff, 0x0, 128); int len = getData(i, buff,128); //printf("getData: %d(%d)\n", i, len); hexdump(i, buff, 128); //printf("\n"); } } else if ((strcasecmp( argv[1], "ramsize" ) == 0) && (argc == 2)) { /* * Check if your cart is 8k or 16k.. * .. Thats it.. :) */ unsigned int size = GetRamSize(); printf("Your RAM is a %dkb chip\n", size); } else { /* * Command not understood... yea yea... */ printf( "WHAT? WHAT\n" ); return( 1 ); } CloseDevice(); return( 0 ); }
/* Append all content from ring buffer 'rBuf' to this ring buffer */ bool CRingBuffer::Append(CRingBuffer &rBuf) { return WriteData(rBuf, rBuf.getMaxReadSize()); }
int CFSReg::WriteData(const CFSString &szPath, const CFSData &Data) { return WriteData(szPath, Data.GetData(), Data.GetSize()); }
SQLRETURN MNDBGetStmtAttr(ODBCStmt *stmt, SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER BufferLength, SQLINTEGER *StringLengthPtr) { /* TODO: check parameters: ValuePtr, BufferLength and * StringLengthPtr */ switch (Attribute) { #ifndef STATIC_CODE_ANALYSIS /* Coverity doesn't like the debug print in WriteData, so we * hide this whole thing */ case SQL_ATTR_APP_PARAM_DESC: /* SQLHANDLE */ WriteData(ValuePtr, stmt->ApplParamDescr, SQLHANDLE); return SQL_SUCCESS; case SQL_ATTR_APP_ROW_DESC: /* SQLHANDLE */ WriteData(ValuePtr, stmt->ApplRowDescr, SQLHANDLE); return SQL_SUCCESS; #endif case SQL_ATTR_ASYNC_ENABLE: /* SQLULEN */ /* SQL_ASYNC_ENABLE */ WriteData(ValuePtr, SQL_ASYNC_ENABLE_OFF, SQLULEN); break; case SQL_ATTR_CONCURRENCY: /* SQLULEN */ /* SQL_CONCURRENCY */ WriteData(ValuePtr, SQL_CONCUR_READ_ONLY, SQLULEN); break; case SQL_ATTR_CURSOR_SCROLLABLE: /* SQLULEN */ WriteData(ValuePtr, stmt->cursorScrollable, SQLULEN); break; case SQL_ATTR_CURSOR_SENSITIVITY: /* SQLULEN */ WriteData(ValuePtr, SQL_INSENSITIVE, SQLULEN); break; case SQL_ATTR_CURSOR_TYPE: /* SQLULEN */ /* SQL_CURSOR_TYPE */ WriteData(ValuePtr, stmt->cursorType, SQLULEN); break; #ifndef STATIC_CODE_ANALYSIS /* Coverity doesn't like the debug print in WriteData, so we * hide this whole thing */ case SQL_ATTR_IMP_PARAM_DESC: /* SQLHANDLE */ WriteData(ValuePtr, stmt->ImplParamDescr, SQLHANDLE); return SQL_SUCCESS; case SQL_ATTR_IMP_ROW_DESC: /* SQLHANDLE */ WriteData(ValuePtr, stmt->ImplRowDescr, SQLHANDLE); return SQL_SUCCESS; #endif case SQL_ATTR_MAX_LENGTH: /* SQLULEN */ /* SQL_MAX_LENGTH */ WriteData(ValuePtr, 0, SQLULEN); break; case SQL_ATTR_MAX_ROWS: /* SQLULEN */ /* SQL_MAX_ROWS */ WriteData(ValuePtr, 0, SQLULEN); break; case SQL_ATTR_METADATA_ID: /* SQLULEN */ WriteData(ValuePtr, stmt->Dbc->sql_attr_metadata_id, SQLULEN); break; case SQL_ATTR_NOSCAN: /* SQLULEN */ /* SQL_NOSCAN */ WriteData(ValuePtr, stmt->noScan, SQLULEN); break; case SQL_ATTR_PARAM_BIND_OFFSET_PTR: /* SQLULEN* */ return MNDBGetDescField(stmt->ApplParamDescr, 0, SQL_DESC_BIND_OFFSET_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_PARAM_BIND_TYPE: /* SQLULEN */ /* SQL_BIND_TYPE */ WriteData(ValuePtr, stmt->ApplParamDescr->sql_desc_bind_type, SQLULEN); break; case SQL_ATTR_PARAM_OPERATION_PTR: /* SQLUSMALLINT* */ return MNDBGetDescField(stmt->ApplParamDescr, 0, SQL_DESC_ARRAY_STATUS_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_PARAMSET_SIZE: /* SQLULEN */ return MNDBGetDescField(stmt->ApplParamDescr, 0, SQL_DESC_ARRAY_SIZE, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_PARAMS_PROCESSED_PTR: /* SQLULEN* */ return MNDBGetDescField(stmt->ImplParamDescr, 0, SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_PARAM_STATUS_PTR: /* SQLUSMALLINT* */ return MNDBGetDescField(stmt->ImplParamDescr, 0, SQL_DESC_ARRAY_STATUS_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_RETRIEVE_DATA: /* SQLULEN */ /* SQL_RETRIEVE_DATA */ WriteData(ValuePtr, stmt->retrieveData, SQLULEN); break; case SQL_ATTR_ROW_ARRAY_SIZE: /* SQLULEN */ case SQL_ROWSET_SIZE: return MNDBGetDescField(stmt->ApplRowDescr, 0, SQL_DESC_ARRAY_SIZE, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_ROW_BIND_OFFSET_PTR: /* SQLULEN* */ return MNDBGetDescField(stmt->ApplRowDescr, 0, SQL_DESC_BIND_OFFSET_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_ROW_BIND_TYPE: /* SQLULEN */ WriteData(ValuePtr, stmt->ApplRowDescr->sql_desc_bind_type, SQLULEN); break; case SQL_ATTR_ROW_NUMBER: /* SQLULEN */ if (stmt->State <= EXECUTED1) { /* Invalid cursor state */ addStmtError(stmt, "24000", NULL, 0); return SQL_ERROR; } WriteData(ValuePtr, (SQLULEN) stmt->currentRow, SQLULEN); break; case SQL_ATTR_ROW_OPERATION_PTR: /* SQLUSMALLINT* */ return MNDBGetDescField(stmt->ApplRowDescr, 0, SQL_DESC_ARRAY_STATUS_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_ROW_STATUS_PTR: /* SQLUSMALLINT* */ return MNDBGetDescField(stmt->ImplRowDescr, 0, SQL_DESC_ARRAY_STATUS_PTR, ValuePtr, BufferLength, StringLengthPtr); case SQL_ATTR_ROWS_FETCHED_PTR: /* SQLULEN* */ return MNDBGetDescField(stmt->ImplRowDescr, 0, SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr, BufferLength, StringLengthPtr); /* TODO: implement requested behavior */ #ifdef SQL_ATTR_ASYNC_STMT_EVENT case SQL_ATTR_ASYNC_EVENT: /* SQLPOINTER */ #endif #ifdef SQL_ATTR_ASYNC_STMT_PCALLBACK case SQL_ATTR_ASYNC_PCALLBACK: /* SQLPOINTER */ #endif #ifdef SQL_ATTR_ASYNC_STMT_PCONTEXT case SQL_ATTR_ASYNC_PCONTEXT: /* SQLPOINTER */ #endif case SQL_ATTR_ENABLE_AUTO_IPD: /* SQLULEN */ case SQL_ATTR_FETCH_BOOKMARK_PTR: /* SQLLEN* */ case SQL_ATTR_KEYSET_SIZE: /* SQLULEN */ /* SQL_KEYSET_SIZE */ case SQL_ATTR_QUERY_TIMEOUT: /* SQLULEN */ /* SQL_QUERY_TIMEOUT */ case SQL_ATTR_SIMULATE_CURSOR: /* SQLULEN */ case SQL_ATTR_USE_BOOKMARKS: /* SQLULEN */ /* Optional feature not implemented */ addStmtError(stmt, "HYC00", NULL, 0); return SQL_ERROR; default: /* Invalid attribute/option identifier */ addStmtError(stmt, "HY092", NULL, 0); return SQL_ERROR; } return SQL_SUCCESS; }
void wxsBitmapIconEditorDlg::OnButton1Click(cb_unused wxCommandEvent& event) { WriteData(Data); EndModal(wxID_OK); }
int main(int argc,char* argv[]) { char *str = new char[MAXSIZE],*p; int Port_BDS = atoi(argv[2]); int Port_FC = atoi(argv[3]); sockfd_BDS = Socket(); sockfd_FC = Socket(); struct sockaddr_in servself_addr,client_addr,servBDS_addr; struct hostent *host; int nread; socklen_t len; Bind(sockfd_FC,servself_addr,Port_FC); Listen(sockfd_FC,5); printf("The FS is listening\n"); bzero(&servBDS_addr,sizeof(servBDS_addr)); servBDS_addr.sin_family = AF_INET; host = gethostbyname(argv[1]); memcpy(&servBDS_addr.sin_addr.s_addr,host->h_addr,host->h_length); servBDS_addr.sin_port = htons(Port_BDS); connect(sockfd_BDS,(struct sockaddr*)&servBDS_addr,sizeof(servBDS_addr)); initial(); while (1) { len = sizeof(client_addr); client_sockfd = accept(sockfd_FC,(struct sockaddr *) &client_addr, &len); printf("Connect successfully\n"); bzero(SendToFC,sizeof(SendToFC)); strcat(SendToFC,CurrentInode.Name); strcat(SendToFC," $ "); Write(client_sockfd,SendToFC,strlen(SendToFC)); while (1) { bzero(ReceFromFC,sizeof(ReceFromFC)); int n = Read(client_sockfd,ReceFromFC,MAXSIZE); Write(STDOUT_FILENO,ReceFromFC,strlen(ReceFromFC)); // Show(CurrentInode,CurrentData); strcpy(str,ReceFromFC); p = str; str = strtok(str," \n"); if (0 == strcmp(str,"f")) Format(); else if (0 == strcmp(str,"mk")) /*Create a file*/ { str = strtok(NULL," \n"); Createfile(str,0); } else if (0 == strcmp(str,"mkdir")) /*Create a folder*/ { str = strtok(NULL," \n"); Createfile(str,1); } else if (0 == strcmp(str,"rm")) /*Remove a file*/ { str = strtok(NULL," \n"); Removefile(str,0); } else if (0 == strcmp(str,"cd")) /*Change path*/ { str = strtok(NULL," \n"); Changedir(str); HandleError("cdok!\n"); } else if (0 == strcmp(str,"rmdir")) { str = strtok(NULL," \n"); /*Remove a folder*/ Removefile(str,1); } else if (0 == strcmp(str,"ls")) { str = strtok(NULL," \n"); List(str); } else if (0 == strcmp(str,"cat")) /*Catch a file*/ { str = strtok(NULL," \n"); Catchfile(str); printf("Catch ok!\n"); } else if (0 == strcmp(str,"w")) { str = strtok(NULL,"\n"); WriteData(str); } else if (0 == strcmp(str,"a")) { str = strtok(NULL,"\n"); Append(str); } else if (0 == strcmp(str,"exit")) Exit(); else { HandleError("2:Unavailable command\n"); } bzero(SendToFC,sizeof(SendToFC)); strcat(SendToFC,CurrentInode.Name); strcat(SendToFC," $ "); Write(client_sockfd,SendToFC,strlen(SendToFC)); } Close(client_sockfd); } Close(sockfd_BDS); Close(sockfd_FC); }
void Packet::Write (const String& value) { WriteData (value); }
void Packet::Write (const bool& value) { WriteData (value); }
void Packet::Write (const double& value) { WriteData (value); }
void Packet::Write (const float& value) { WriteData (value); }
void Packet::Write (const uint& value) { WriteData (value); }
void Socket::WriteData(bamboo::protocol::MessageIf* message) { if (!is_open()) return; WriteData(message->Build()); }
void oledWriteChar1x(char letter, unsigned char page, unsigned char column, BOOL invert) { BYTE i; letter -= ' '; // Adjust character to table that starts at 0x20 WriteCommand(page); column += OFFSET; WriteCommand(0x00+(column&0x0F)); WriteCommand(0x10+((column>>4)&0x0F)); if(invert) { WriteData(~g_pucFont[letter][0]); // Write first column WriteData(~g_pucFont[letter][1]); // Write second column WriteData(~g_pucFont[letter][2]); // Write third column WriteData(~g_pucFont[letter][3]); // Write fourth column WriteData(~g_pucFont[letter][4]); // Write fifth column WriteData(~g_pucFont[letter][5]); // Write sixth column } else { WriteData(g_pucFont[letter][0]); // Write first column WriteData(g_pucFont[letter][1]); // Write second column WriteData(g_pucFont[letter][2]); // Write third column WriteData(g_pucFont[letter][3]); // Write fourth column WriteData(g_pucFont[letter][4]); // Write fifth column WriteData(g_pucFont[letter][5]); // Write sixth column } return; }
bool Stream::SetData(const std::string data, int size) //bool SetData(const unsigned char *pData, int size) { char *pData = (char*)data.data(); return WriteData(pData, size, UpdateType::utCopy); }
virtual int run( int checkpoint ) override { test_path = mnt_dir_ ; A_path = mnt_dir_ + "/A"; AC_path = mnt_dir_ + "/A/C"; B_path = mnt_dir_ + "/B"; foo_path = mnt_dir_ + "/foo"; bar_path = mnt_dir_ + "/bar"; Afoo_path = mnt_dir_ + "/A/foo"; Abar_path = mnt_dir_ + "/A/bar"; Bfoo_path = mnt_dir_ + "/B/foo"; Bbar_path = mnt_dir_ + "/B/bar"; ACfoo_path = mnt_dir_ + "/A/C/foo"; ACbar_path = mnt_dir_ + "/A/C/bar"; int local_checkpoint = 0 ; if ( mkdir(A_path.c_str() , 0777) < 0){ return errno; } int fd_Afoo = cm_->CmOpen(Afoo_path.c_str() , O_RDWR|O_CREAT , 0777); if ( fd_Afoo < 0 ) { cm_->CmClose( fd_Afoo); return errno; } if ( WriteData ( fd_Afoo, 0, 32768) < 0){ cm_->CmClose( fd_Afoo); return errno; } if ( fallocate( fd_Afoo , FALLOC_FL_KEEP_SIZE , 0 , 5000) < 0){ cm_->CmClose( fd_Afoo); return errno; } int fd_Abar = cm_->CmOpen(Abar_path.c_str() , O_RDWR|O_CREAT , 0777); if ( fd_Abar < 0 ) { cm_->CmClose( fd_Abar); return errno; } if ( cm_->CmFsync( fd_Abar) < 0){ return errno; } if ( cm_->CmCheckpoint() < 0){ return -1; } local_checkpoint += 1; if (local_checkpoint == checkpoint) { return 1; } if ( cm_->CmClose ( fd_Afoo) < 0){ return errno; } if ( cm_->CmClose ( fd_Abar) < 0){ return errno; } return 0; }
DWORD WINAPI MyThreadProc1(LPVOID lpParameter) { while(true) { WaitForSingleObject(hMutex,INFINITE); int DouNums1; //数据块共有多少个浮点数 unsigned int Length1 = 0; //数据块的长度,总字节数 char * DataBuf1 = new char[DataBlock]; //数据块缓冲区 double * DouBuf1 = new double[MaxSizeDou]; //数据块双精度浮点数数组 char * Buffer1 = new char[MyBufferSize]; while(!(feof(InFile))){ //线程1的读排写 if((Length1 = fread(DataBuf1, sizeof(char), DataBlock - 20, InFile)) < DataBlock - 20){ ReleaseMutex(hMutex); DataBuf1[Length1] = '\0'; DouNums1 = Str2Dou(DataBuf1, DouBuf1); MySort((RadixData*)DouBuf1, DouNums1); if(FileCount == 0){ FILE * OutFile = NULL; OutFile = fopen(OutFileName, "wb"); int LengthTemp, LengthOutPut = 0; for(int i = 0; i < DouNums1; i++){ LengthTemp = Dou2Str(Buffer1 + LengthOutPut, DouBuf1[i]); LengthOutPut += LengthTemp; } fwrite(Buffer1, 1, LengthOutPut, OutFile); //将整块字符串fwrite到输出文件 fclose(OutFile); FileCount++; } else{ char * FileName = TempFileName(FileCount++); FILE *TempFile = fopen(FileName, "wb"); free(FileName); WriteData(TempFile, DouBuf1, DouNums1); fclose(TempFile); } } else{ char * p = DataBuf1 + Length1 - 1; int i = 0; while(*p != '\n' && *p != '\0'){ fread(DataBuf1 + Length1 + i, 1, 1, InFile); p++; i++; } DataBuf1[Length1 + i] = '\0'; DouNums1 = Str2Dou(DataBuf1, DouBuf1); ReleaseMutex(hMutex); MySort((RadixData*)DouBuf1, DouNums1); char * FileName = TempFileName(FileCount++); FILE *TempFile = fopen(FileName, "wb"); free(FileName); WriteData(TempFile, DouBuf1, DouNums1); fclose(TempFile); } } delete []DataBuf1; delete []DouBuf1; delete []Buffer1; break; } flag1 = true; return 0; }
BOOL CMsgPoolBuffer::WriteMsg(TRawMsg *msg) { return WriteData(MSG_DATA(msg), MSG_DATA_LEN(msg)); }
int FFmpegImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) { outTracks.clear(); CreateProgress(); // Remove stream contexts which are not marked for importing and adjust mScs and mNumStreams accordingly const auto scs = mScs->get(); for (int i = 0; i < mNumStreams;) { if (!scs[i]->m_use) { for (int j = i; j < mNumStreams - 1; j++) { scs[j] = std::move(scs[j+1]); } mNumStreams--; } else i++; } mChannels.resize(mNumStreams); int s = -1; for (auto &stream : mChannels) { ++s; auto sc = scs[s].get(); switch (sc->m_stream->codec->sample_fmt) { case AV_SAMPLE_FMT_U8: case AV_SAMPLE_FMT_S16: case AV_SAMPLE_FMT_U8P: case AV_SAMPLE_FMT_S16P: sc->m_osamplesize = sizeof(int16_t); sc->m_osamplefmt = int16Sample; break; default: sc->m_osamplesize = sizeof(float); sc->m_osamplefmt = floatSample; break; } // There is a possibility that number of channels will change over time, but we do not have WaveTracks for NEW channels. Remember the number of channels and stick to it. sc->m_initialchannels = sc->m_stream->codec->channels; stream.resize(sc->m_stream->codec->channels); int c = -1; for (auto &channel : stream) { ++c; channel = trackFactory->NewWaveTrack(sc->m_osamplefmt, sc->m_stream->codec->sample_rate); if (sc->m_stream->codec->channels == 2) { switch (c) { case 0: channel->SetChannel(Track::LeftChannel); channel->SetLinked(true); break; case 1: channel->SetChannel(Track::RightChannel); break; } } else { channel->SetChannel(Track::MonoChannel); } } } // Handles the start_time by creating silence. This may or may not be correct. // There is a possibility that we should ignore first N milliseconds of audio instead. I do not know. /// TODO: Nag FFmpeg devs about start_time until they finally say WHAT is this and HOW to handle it. s = -1; for (auto &stream : mChannels) { ++s; int64_t stream_delay = 0; auto sc = scs[s].get(); if (sc->m_stream->start_time != int64_t(AV_NOPTS_VALUE) && sc->m_stream->start_time > 0) { stream_delay = sc->m_stream->start_time; wxLogDebug(wxT("Stream %d start_time = %lld, that would be %f milliseconds."), s, (long long) sc->m_stream->start_time, double(sc->m_stream->start_time)/AV_TIME_BASE*1000); } if (stream_delay != 0) { int c = -1; for (auto &channel : stream) { ++c; WaveTrack *t = channel.get(); t->InsertSilence(0,double(stream_delay)/AV_TIME_BASE); } } } // This is the heart of the importing process // The result of Import() to be returend. It will be something other than zero if user canceled or some error appears. int res = eProgressSuccess; #ifdef EXPERIMENTAL_OD_FFMPEG mUsingOD = false; gPrefs->Read(wxT("/Library/FFmpegOnDemand"), &mUsingOD); //at this point we know the file is good and that we have to load the number of channels in mScs[s]->m_stream->codec->channels; //so for OD loading we create the tracks and releasee the modal lock after starting the ODTask. if (mUsingOD) { std::vector<ODDecodeFFmpegTask*> tasks; //append blockfiles to each stream and add an individual ODDecodeTask for each one. s = -1; for (const auto &stream : mChannels) { ++s; ODDecodeFFmpegTask* odTask = new ODDecodeFFmpegTask(mScs, ODDecodeFFmpegTask::FromList(mChannels), mFormatContext, s); odTask->CreateFileDecoder(mFilename); //each stream has different duration. We need to know it if seeking is to be allowed. sampleCount sampleDuration = 0; auto sc = scs[s].get(); if (sc->m_stream->duration > 0) sampleDuration = ((sampleCount)sc->m_stream->duration * sc->m_stream->time_base.num), sc->m_stream->codec->sample_rate / sc->m_stream->time_base.den; else sampleDuration = ((sampleCount)mFormatContext->duration *sc->m_stream->codec->sample_rate) / AV_TIME_BASE; // printf(" OD duration samples %qi, sr %d, secs %d\n",sampleDuration, (int)sc->m_stream->codec->sample_rate, (int)sampleDuration/sc->m_stream->codec->sample_rate); //for each wavetrack within the stream add coded blockfiles for (int c = 0; c < sc->m_stream->codec->channels; c++) { WaveTrack *t = stream[c].get(); odTask->AddWaveTrack(t); sampleCount maxBlockSize = t->GetMaxBlockSize(); //use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz) for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) { sampleCount blockLen = maxBlockSize; if (i + blockLen > sampleDuration) blockLen = sampleDuration - i; t->AppendCoded(mFilename, i, blockLen, c, ODTask::eODFFMPEG); // This only works well for single streams since we assume // each stream is of the same duration and channels res = mProgress->Update(i+sampleDuration*c+ sampleDuration*sc->m_stream->codec->channels*s, sampleDuration*sc->m_stream->codec->channels*mNumStreams); if (res != eProgressSuccess) break; } } tasks.push_back(odTask); } //Now we add the tasks and let them run, or DELETE them if the user cancelled for(int i=0; i < (int)tasks.size(); i++) { if(res==eProgressSuccess) ODManager::Instance()->AddNewTask(tasks[i]); else { delete tasks[i]; } } } else { #endif // Read next frame. for (streamContext *sc; (sc = ReadNextFrame()) != NULL && (res == eProgressSuccess);) { // ReadNextFrame returns 1 if stream is not to be imported if (sc != (streamContext*)1) { // Decode frame until it is not possible to decode any further while (sc->m_pktRemainingSiz > 0 && (res == eProgressSuccess || res == eProgressStopped)) { if (DecodeFrame(sc,false) < 0) break; // If something useable was decoded - write it to mChannels if (sc->m_frameValid) res = WriteData(sc); } // Cleanup after frame decoding if (sc->m_pktValid) { av_free_packet(&sc->m_pkt); sc->m_pktValid = 0; } } } // Flush the decoders. if ((mNumStreams != 0) && (res == eProgressSuccess || res == eProgressStopped)) { for (int i = 0; i < mNumStreams; i++) { auto sc = scs[i].get(); if (DecodeFrame(sc, true) == 0) { WriteData(sc); if (sc->m_pktValid) { av_free_packet(&sc->m_pkt); sc->m_pktValid = 0; } } } } #ifdef EXPERIMENTAL_OD_FFMPEG } // else -- !mUsingOD == true #endif //EXPERIMENTAL_OD_FFMPEG // Something bad happened - destroy everything! if (res == eProgressCancelled || res == eProgressFailed) return res; //else if (res == 2), we just stop the decoding as if the file has ended // Copy audio from mChannels to newly created tracks (destroying mChannels elements in process) for (auto &stream : mChannels) { for(auto &channel : stream) { channel->Flush(); outTracks.push_back(std::move(channel)); } } // Save metadata WriteMetadata(tags); return res; }
/* ============ main ============ */ int main (int argc, char **argv) { const char *psrc; void *src, *src2; char filename[1024]; int p, c; unsigned short crc; double start, stop; FILE *f; myargc = argc; myargv = argv; if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help")) { printf(" Compiles progs.dat using progs.src in the current directory\n"); printf(" -src <directory> : Specify source directory\n"); printf(" -dcc : decompile the progs.dat in the current directory\n"); printf(" -dcc -fix : fixes mangled names during decompilation\n"); printf(" -dcc -asm <functionname> : decompile filename to the console\n"); printf(" -dcc -dump -asm <functionname> : same as above but will show\n\t\tinstructions (opcodes and parms) as well\n"); exit(0); } ValidateByteorder (); start = GetTime (); p = CheckParm("-src"); if (p && p < argc-1) { strcpy(sourcedir, argv[p+1]); strcat(sourcedir, "/"); printf("Source directory: %s\n", sourcedir); } else { sourcedir[0] = '\0'; } InitData (); PR_FILE = stdout; p = CheckParm("-dump"); if (p) pr_dumpasm = true; // do a crc of the file p = CheckParm("-crc"); if (p) { CRC_Init (&crc); f = fopen ("progdefs.h", "r"); while ((c = fgetc(f)) != EOF) CRC_ProcessByte (&crc, (byte)c); printf ("#define PROGHEADER_CRC %i %d\n", crc, (int)crc); fclose (f); exit (0); } p = CheckParm("-dcc"); if (p) { DEC_ReadData ("progs.dat"); //fix mangled names if asked p = CheckParm ("-fix"); if (p) FILE_NUM_FOR_NAME = 1; memset(func_headers, 0, MAX_FUNCTIONS * sizeof(char *)); memset(temp_val, 0, MAX_REGS * sizeof(char *)); p = CheckParm("-bbb"); if (p) { /* i= -999; for (p = 0; p < numstatements; p++) if ((statements+p)->op > i) i = (statements+p)->op; printf("largest op %d\n", i); */ FindBuiltinParameters(1); exit (0); } p = CheckParm("-ddd"); if (p) { for (p++ ; p < argc ; p++) { if (argv[p][0] == '-') break; DccFunctionOP (atoi(argv[p])); } exit (0); } p = CheckParm("-info2"); if (p) { printf("\n=======================\n"); printf("fields\n"); printf("=======================\n"); PrintFields (); printf("\n=======================\n"); printf("globals\n"); printf("=======================\n"); PrintGlobals (); exit (0); } p = CheckParm("-info"); if (p) { printf("\n=======================\n"); printf("strings\n"); printf("=======================\n"); PrintStrings (); printf("\n=======================\n"); printf("functions"); printf("\n=======================\n"); PrintFunctions (); printf("\n=======================\n"); printf("fields\n"); printf("=======================\n"); PrintFields (); printf("\n=======================\n"); printf("globals\n"); printf("=======================\n"); PrintGlobals (); printf("\n=======================\n"); printf("pr_globals\n"); printf("=======================\n"); PrintPRGlobals (); printf("\n=======================\n"); printf("statements\n"); printf("=======================\n"); Printstatements(); exit (0); } p = CheckParm("-asm"); if (p) { for (p++; p < argc; p++) { if (argv[p][0] == '-') break; PR_PrintFunction(argv[p]); } } else { Dcc_Functions (); stop = GetTime (); printf("\n%d seconds elapsed.\n", (int)(stop-start)); } exit (0); } sprintf(filename, "%sprogs.src", sourcedir); LoadFile(filename, &src); psrc = (char *) src; psrc = COM_Parse(psrc); if (!psrc) { Error("No destination filename. HCC -help for info.\n"); } strcpy(destfile, com_token); printf("outputfile: %s\n", destfile); pr_dumpasm = false; PR_BeginCompilation(); // compile all the files do { psrc = COM_Parse(psrc); if (!psrc) break; sprintf (filename, "%s%s", sourcedir, com_token); printf ("compiling %s\n", filename); LoadFile (filename, &src2); if (!PR_CompileFile((char *)src2, filename)) exit (1); } while (1); if (!PR_FinishCompilation()) { Error ("compilation errors"); } p = CheckParm("-asm"); if (p) { for (p++; p < argc; p++) { if (argv[p][0] == '-') { break; } PrintFunction(argv[p]); } } // write progdefs.h crc = PR_WriteProgdefs("progdefs.h"); // crc = 14046; // FIXME: cheap hack for now!!!!!!!!!!!!! // write data file WriteData(crc); // write files.dat WriteFiles(); stop = GetTime (); printf("\n%d seconds elapsed.\n", (int)(stop-start)); exit (0); }
static int DataPut( byte data, unsigned long wait ) { dbgrtn( "\r\n-DataPut-" ); switch( CableType ) { case WATCOM_VAL: while( Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } WriteData( data ); /* write the data */ RaiseCtl1(); /* tell him the data's there */ while( Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } LowerCtl1(); /* clear control line */ break; case FMR_VAL: /* We're talking to the FMR which can RaiseCtl2/LowerCtl2 */ while( Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } WriteData( data ); /* write the data */ RaiseCtl1(); /* tell him the data's there */ while( Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } LowerCtl1(); /* clear control line */ break; case LAPLINK_VAL: /* send low nibble */ while( LL_Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } LL_WriteData( data & 0x0f ); /* write the data */ /* and tell him the data's there */ while( LL_Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } LL_LowerCtl1(); /* clear control line */ /* send high nibble */ while( LL_Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } LL_WriteData( data >> 4 ); /* write the data */ /* and tell him the data's there */ while( LL_Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } LL_LowerCtl1(); /* clear control line */ break; case DUTCHMAN_VAL: /* send low nibble */ while( FD_Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } FD_WriteData( data & 0x0f ); /* write the data */ FD_RaiseCtl1(); /* tell him the data's there */ while( FD_Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } FD_LowerCtl1(); /* clear control line */ /* send high nibble */ while( FD_Ctl2Lo() ) { /* wait till he's ready to read */ TWIDDLE_THUMBS; } FD_WriteData( data >> 4 ); /* write the data */ FD_RaiseCtl1(); /* tell him the data's there */ while( FD_Ctl2Hi() ) { /* wait till he got the bits */ TWIDDLE_THUMBS; } FD_LowerCtl1(); /* clear control line */ break; } return( 0 ); }
// Write the core dump file: // ELF header // Single section header (Shdr) for 64 bit program header count // Phdr for the PT_NOTE // PT_LOAD // PT_NOTEs // process info (prpsinfo_t) // NT_FILE entries // threads // alignment // memory blocks bool DumpWriter::WriteDump() { // Write the ELF header Ehdr ehdr; memset(&ehdr, 0, sizeof(Ehdr)); ehdr.e_ident[0] = ELFMAG0; ehdr.e_ident[1] = ELFMAG1; ehdr.e_ident[2] = ELFMAG2; ehdr.e_ident[3] = ELFMAG3; ehdr.e_ident[4] = ELF_CLASS; // Note: The sex is the current system running minidump-2-core // Big or Little endian. This means you have to create // the core (minidump-2-core) on the system that matches // your intent to debug properly. ehdr.e_ident[5] = sex() ? ELFDATA2MSB : ELFDATA2LSB; ehdr.e_ident[6] = EV_CURRENT; ehdr.e_ident[EI_OSABI] = ELFOSABI_LINUX; ehdr.e_type = ET_CORE; ehdr.e_machine = ELF_ARCH; ehdr.e_version = EV_CURRENT; ehdr.e_shoff = sizeof(Ehdr); ehdr.e_phoff = sizeof(Ehdr) + sizeof(Shdr); ehdr.e_ehsize = sizeof(Ehdr); ehdr.e_phentsize = sizeof(Phdr); ehdr.e_shentsize = sizeof(Shdr); // The ELF header only allows UINT16 for the number of program // headers. In a core dump this equates to PT_NODE and PT_LOAD. // // When more program headers than 65534 the first section entry // is used to store the actual program header count. // PT_NOTE + number of memory regions uint64_t phnum = 1 + m_crashInfo.MemoryRegions().size(); if (phnum < PH_HDR_CANARY) { ehdr.e_phnum = phnum; } else { ehdr.e_phnum = PH_HDR_CANARY; } if (!WriteData(&ehdr, sizeof(Ehdr))) { return false; } size_t offset = sizeof(Ehdr) + sizeof(Shdr) + (phnum * sizeof(Phdr)); size_t filesz = GetProcessInfoSize() + GetAuxvInfoSize() + GetThreadInfoSize() + GetNTFileInfoSize(); // Add single section containing the actual count // of the program headers to be written. Shdr shdr; memset(&shdr, 0, sizeof(shdr)); shdr.sh_info = phnum; // When section header offset is present but ehdr section num = 0 // then is is expected that the sh_size indicates the size of the // section array or 1 in our case. shdr.sh_size = 1; if (!WriteData(&shdr, sizeof(shdr))) { return false; } // PT_NOTE header Phdr phdr; memset(&phdr, 0, sizeof(Phdr)); phdr.p_type = PT_NOTE; phdr.p_offset = offset; phdr.p_filesz = filesz; if (!WriteData(&phdr, sizeof(phdr))) { return false; } // PT_NOTE sections must end on 4 byte boundary // We output the NT_FILE, AUX and Thread entries // AUX is aligned, NT_FILE is aligned and then we // check to pad end of the thread list phdr.p_type = PT_LOAD; phdr.p_align = 4096; size_t finalNoteAlignment = phdr.p_align - ((offset + filesz) % phdr.p_align); if (finalNoteAlignment == phdr.p_align) { finalNoteAlignment = 0; } offset += finalNoteAlignment; TRACE("Writing memory region headers to core file\n"); // Write memory region note headers for (const MemoryRegion& memoryRegion : m_crashInfo.MemoryRegions()) { phdr.p_flags = memoryRegion.Permissions(); phdr.p_vaddr = memoryRegion.StartAddress(); phdr.p_memsz = memoryRegion.Size(); offset += filesz; phdr.p_filesz = filesz = memoryRegion.Size(); phdr.p_offset = offset; if (!WriteData(&phdr, sizeof(phdr))) { return false; } } // Write process info data to core file if (!WriteProcessInfo()) { return false; } // Write auxv data to core file if (!WriteAuxv()) { return false; } // Write NT_FILE entries to the core file if (!WriteNTFileInfo()) { return false; } TRACE("Writing %ld thread entries to core file\n", m_crashInfo.Threads().size()); // Write all the thread's state and registers for (const ThreadInfo* thread : m_crashInfo.Threads()) { if (!WriteThread(*thread, SIGABRT)) { return false; } } // Zero out the end of the PT_NOTE section to the boundary // and then laydown the memory blocks if (finalNoteAlignment > 0) { assert(finalNoteAlignment < sizeof(m_tempBuffer)); memset(m_tempBuffer, 0, finalNoteAlignment); if (!WriteData(m_tempBuffer, finalNoteAlignment)) { return false; } } TRACE("Writing %ld memory regions to core file\n", m_crashInfo.MemoryRegions().size()); // Read from target process and write memory regions to core uint64_t total = 0; for (const MemoryRegion& memoryRegion : m_crashInfo.MemoryRegions()) { uint32_t size = memoryRegion.Size(); uint64_t address = memoryRegion.StartAddress(); total += size; while (size > 0) { uint32_t bytesToRead = std::min(size, (uint32_t)sizeof(m_tempBuffer)); uint32_t read = 0; if (FAILED(m_crashInfo.DataTarget()->ReadVirtual(address, m_tempBuffer, bytesToRead, &read))) { fprintf(stderr, "ReadVirtual(%016lx, %08x) FAILED\n", address, bytesToRead); return false; } if (!WriteData(m_tempBuffer, read)) { return false; } address += read; size -= read; } } printf("Written %ld bytes (%ld pages) to core file\n", total, total >> PAGE_SHIFT); return true; }
/********************************************** Lcd初始化函数 ***********************************************/ void Lcd_Initialize(void) { LCD_GPIO_Config(); LCD_FSMC_Config(); LCD_Rst(); //************* Start Initial Sequence **********// WriteComm(0xFF); // EXTC Command Set enable register WriteData(0xFF); WriteData(0x98); WriteData(0x06); WriteComm(0xBA); // SPI Interface Setting WriteData(0xE0); WriteComm(0xBC); // GIP 1 WriteData(0x03); WriteData(0x0F); WriteData(0x63); WriteData(0x69); WriteData(0x01); WriteData(0x01); WriteData(0x1B); WriteData(0x11); WriteData(0x70); WriteData(0x73); WriteData(0xFF); WriteData(0xFF); WriteData(0x08); WriteData(0x09); WriteData(0x05); WriteData(0x00); WriteData(0xEE); WriteData(0xE2); WriteData(0x01); WriteData(0x00); WriteData(0xC1); WriteComm(0xBD); // GIP 2 WriteData(0x01); WriteData(0x23); WriteData(0x45); WriteData(0x67); WriteData(0x01); WriteData(0x23); WriteData(0x45); WriteData(0x67); WriteComm(0xBE); // GIP 3 WriteData(0x00); WriteData(0x22); WriteData(0x27); WriteData(0x6A); WriteData(0xBC); WriteData(0xD8); WriteData(0x92); WriteData(0x22); WriteData(0x22); WriteComm(0xC7); // Vcom WriteData(0x1E); WriteComm(0xED); // EN_volt_reg WriteData(0x7F); WriteData(0x0F); WriteData(0x00); WriteComm(0xC0); // Power Control 1 WriteData(0xE3); WriteData(0x0B); WriteData(0x00); WriteComm(0xFC); WriteData(0x08); WriteComm(0xDF); // Engineering Setting WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteData(0x02); WriteComm(0xF3); // DVDD Voltage Setting WriteData(0x74); WriteComm(0xB4); // Display Inversion Control WriteData(0x00); WriteData(0x00); WriteData(0x00); WriteComm(0xF7); // 480x854 WriteData(0x81); WriteComm(0xB1); // Frame Rate WriteData(0x00); WriteData(0x10); WriteData(0x14); WriteComm(0xF1); // Panel Timing Control WriteData(0x29); WriteData(0x8A); WriteData(0x07); WriteComm(0xF2); //Panel Timing Control WriteData(0x40); WriteData(0xD2); WriteData(0x50); WriteData(0x28); WriteComm(0xC1); // Power Control 2 WriteData(0x17); WriteData(0X85); WriteData(0x85); WriteData(0x20); WriteComm(0xE0); WriteData(0x00); //P1 WriteData(0x0C); //P2 WriteData(0x15); //P3 WriteData(0x0D); //P4 WriteData(0x0F); //P5 WriteData(0x0C); //P6 WriteData(0x07); //P7 WriteData(0x05); //P8 WriteData(0x07); //P9 WriteData(0x0B); //P10 WriteData(0x10); //P11 WriteData(0x10); //P12 WriteData(0x0D); //P13 WriteData(0x17); //P14 WriteData(0x0F); //P15 WriteData(0x00); //P16 WriteComm(0xE1); WriteData(0x00); //P1 WriteData(0x0D); //P2 WriteData(0x15); //P3 WriteData(0x0E); //P4 WriteData(0x10); //P5 WriteData(0x0D); //P6 WriteData(0x08); //P7 WriteData(0x06); //P8 WriteData(0x07); //P9 WriteData(0x0C); //P10 WriteData(0x11); //P11 WriteData(0x11); //P12 WriteData(0x0E); //P13 WriteData(0x17); //P14 WriteData(0x0F); //P15 WriteData(0x00); //P16 WriteComm(0x35); //Tearing Effect ON WriteData(0x00); WriteComm(0x36); WriteData(0x60); WriteComm(0x3A); WriteData(0x55); WriteComm(0x11); //Exit Sleep LCD_delay(120); WriteComm(0x29); // Display On LCD_delay(10); Lcd_Light_ON; WriteComm(0x3A); WriteData(0x55); WriteComm(0x36); WriteData(0xA8); Lcd_ColorBox(0,0,800,480,YELLOW); // LCD_Fill_Pic(80,160,320,480, gImage_MM_T035); // BlockWrite(0,0,799,479); }
void NIBWriter::WriteObjects() { XIBObject *nibRoot = new XIBArray(); nibRoot->_className = "NSObject"; nibRoot->_members.clear(); nibRoot->AddMember("UINibTopLevelObjectsKey", _topObjects); nibRoot->AddMember("UINibObjectsKey", _allUIObjects); nibRoot->AddMember("UINibConnectionsKey", _connections); nibRoot->AddMember("UINibVisibleWindowsKey", _visibleWindows); nibRoot->AddMember("UINibAccessibilityConfigurationsKey", _accessibilityObjects); nibRoot->AddMember("UINibKeyValuePairsKey", new XIBArray()); AddOutputObject(nibRoot); // Sort connection records alphabetically using stable, uh, bubble sort for ( ;; ) { bool didSwap = false; for ( memberList::iterator cur = _connections->_outputMembers.begin(); cur != _connections->_outputMembers.end(); cur ++ ) { if ( (cur + 1) == _connections->_outputMembers.end() ) break; XIBMember *curMember = (*cur); XIBMember *nextMember = (*(cur + 1)); if ( strcmp(curMember->_name, "UINibEncoderEmptyKey") != 0 ) continue; // Event connections first if ( strcmp(curMember->_obj->_className, "UIRuntimeOutletConnection") == 0 && strcmp(nextMember->_obj->_className, "UIRuntimeEventConnection") == 0 ) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; continue; } if ( strcmp(curMember->_obj->_className, nextMember->_obj->_className) == 0 ) { const char *label1, *label2; if ( strcmp(curMember->_obj->_className, "UIRuntimeEventConnection") == 0 ) { UIRuntimeEventConnection *conn1 = (UIRuntimeEventConnection *) curMember->_obj; UIRuntimeEventConnection *conn2 = (UIRuntimeEventConnection *) nextMember->_obj; label1 = conn1->_label; label2 = conn2->_label; } else { UIRuntimeOutletConnection *conn1 = (UIRuntimeOutletConnection *) curMember->_obj; UIRuntimeOutletConnection *conn2 = (UIRuntimeOutletConnection *) nextMember->_obj; label1 = conn1->_label; label2 = conn2->_label; } if ( strcmp(label1, label2) > 0 ) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; } } } if ( !didSwap ) break; } WriteData(); }
bool CJMYPassPay::QueryBalance(string &balance, string &sw1sw2) { int readLen = 0; string cmd; static char temp[BUF_SIZE] = {0}; //关天线 cmd = "11 00"; if (false == CloseAntenna(cmd)) { sw1sw2 = CLOSE_ANTE_FAILE; return false; } //开天线 cmd = "11 01"; if (false == OpenAntenna(cmd)) { sw1sw2 = OPEN_ANTE_FAILE; return false; } // 寻卡 cmd = "2000"; if (false == FindCard(cmd)) { return false; } // 复位 cmd = "30"; if (false == RestCard(cmd)) { return false; } // 选择PSE string app_id_cmd; cmd = "31 00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31"; if (false == SelectPSE(cmd, app_id_cmd, sw1sw2)) { return false; } // 选应用ID string gpo; if (false == SelectAppId(app_id_cmd, gpo, sw1sw2)) { return false; } // 查询余额 cmd = "31 80CA9F79"; memset(g_readBuff, 0X00, sizeof(g_readBuff)); if (false == WriteData(cmd)) { PrintLog("send cmd:%s failed", cmd.c_str()); return false; } GetReadRes(); readLen = g_readLen; memset(temp, 0x00, sizeof(temp)); for (int i = 0; i < readLen; i++) { sprintf(temp + i * 3, "%02X ", g_readBuff[i]); } PrintLog("send cmd:%s\n recv:%s", cmd.c_str(), temp); for (int i = 0; i < readLen; i++) { if (0X9F == g_readBuff[i] && 0X79 == g_readBuff[i+1]) { int money_len = g_readBuff[i+2]; int start = i + 3; memset(temp, 0x00, sizeof(temp)); for (int j = 0; j < money_len; j++) { sprintf(temp + j * 2, "%02X ", g_readBuff[start++]); } balance = temp; break; } } sw1sw2 = SUCCESS_CODE; return true; }
void XMLWriter::WriteData(const wxChar *value) { WriteData(wxString(value)); }
// 选择支付环境(PSE) bool CJMYPassPay::SelectPSE(string &cmd, string &appidcmd, string &errcode) { static uint8 readBuf[BUF_SIZE] = {0}; int readLen = 0; static char temp[BUF_SIZE] = {0}; if (false == IsOpenPort()) { PrintLog("Serial port was closed"); errcode = PORT_NOT_OPEN; return false; } if (false == WriteData(cmd)) { PrintLog("send cmd:%s failed", cmd.c_str()); errcode = SEND_CMD_FAILE; return false; } GetReadRes(); readLen = g_readLen; memset(temp, 0x00, sizeof(temp)); for (int i = 0; i < readLen; i++) { sprintf(temp + i * 3, "%02X ", g_readBuff[i]); } PrintLog("send cmd:%s\n recv:%s", cmd.c_str(), temp); // 判断PSE选择是否成功 if (readLen > 3) { char sw1sw2[6] = {0}; snprintf(sw1sw2, sizeof(sw1sw2), "%02X%02X", g_readBuff[readLen-3], g_readBuff[readLen-2]); if (sw1sw2 == CARD_LOCK) { //如果卡片锁定或者选择(SELECT)命令不支持,卡片响应 SW1 SW2=“6A81” PrintLog("卡片锁定或者选择(SELECT)命令不支持,cmd:%s", cmd.c_str()); errcode = CARD_LOCK; return false; } else if(sw1sw2 == NO_PSE) { //如果卡片中没有 PSE,卡片响应选择(SELECT)命令指出文件不存在(SW1 SW2=“6A82”); PrintLog("卡片中没有 PSE: cmd:%s", cmd.c_str()); errcode = NO_PSE; return false; } else if(sw1sw2 == PSE_LOCK) { //如果 PSE 锁定,卡片响应“6283”; PrintLog("PSE 锁定,cmd:%s", cmd.c_str()); errcode = PSE_LOCK; return false; } else if (sw1sw2 != SUCCESS_CODE) { // 只有返回9000才为PSE选择成功 PrintLog("PSE选择失败,cmd:%s", cmd.c_str()); errcode = UNKNOW_ERROR; return false; } } // 寻找DF名称,在4F后面,即下一步要选择的应用ID int i = 0; for(; i < readLen; i++) { if (0X4F == g_readBuff[i]) { char app_id[256] = {0}; int len = g_readBuff[i + 1]; // ID的长度 int startPos = i + 1; for (int j = 0; j <= len; j++) { sprintf(&app_id[j * 3], "%02X ", g_readBuff[startPos + j]); } // 删除最后一个空格 app_id[strlen(app_id) - 1] = 0; appidcmd = app_id; break; } } if (i >= readLen) { PrintLog("Get appId failed"); errcode = GET_AID_FAILE; return false; } return true; }
void Packet::Write (const uchar& value) { WriteData (value); }