//요청한 실시간 데이터가 수신되면 호출 됩니다. void CGoldenCrossStrategy::OnRealData(LPRECV_REAL_PACKET realpacket) { //선물 체결 실시간 데이터 if( strcmp( realpacket->szTrCode, NAME_FC0 ) == 0 ) { LPFC0_OutBlock pOutBlock = (LPFC0_OutBlock)realpacket->pszData; sltime chetime = GetTime(pOutBlock->chetime); double current = GetDoubleData( pOutBlock->price, sizeof( pOutBlock->price) , 2 ); // 현재가 long curVol = GetLongData( pOutBlock->cvolume , sizeof( pOutBlock->cvolume)); // 체결량 long vol = GetLongData( pOutBlock->volume , sizeof( pOutBlock->volume)); // 누적거래량 CString log; log.Format("선물 시세 수신.. 현재가: %.2f, 체결량 : %d", current, curVol); NormalLog(log); //차트에 데이터를 추가합니다. pFUChart->OnTick(chetime, current, curVol); //캔들의 갯수가 20개를 넘으면 if (pFUChart->GetCandleCount() > 20) { double ma20, ma5; double ma20pre, ma5pre; //마지막 봉의 종가 이평을 구합니다. pFUChart->GetMA(&ma20, CANDLE_PART::close, 20, 0); pFUChart->GetMA(&ma5, CANDLE_PART::close, 5, 0); //하나 이전 봉의 종가이평을 구합니다. pFUChart->GetMA(&ma20pre, CANDLE_PART::close, 20, 1); pFUChart->GetMA(&ma5pre, CANDLE_PART::close, 5, 1); //매수 상태가 아니면 진입 여부를 판단합니다. if (isEntered == FALSE) { //골든 크로스라면 매수합니다. if (ma20pre > ma5pre && ma20 < ma5) { NormalLog("골든 크로스 발생"); FuOrder(JongCode, entryQuantity, 0); isEntered = TRUE; } } else //매수 상태이면 청산 여부를 판단합니다. { //데드 크로스라면 매도합니다. if (ma20pre < ma5pre && ma20 > ma5) { NormalLog("데드 크로스 발생"); FuOrder(JongCode, entryQuantity * -1, 0); isEntered = FALSE; } } } } }
// // Uint32 SCI_Boot - This module is the main SCI boot routine. // It will load code via the SCI-A port. // It will return a entry point address back // to the InitBoot routine which in turn calls // the ExitBoot routine. // Uint32 SCI_Boot(Uint32 BootMode) { statusCode.status = NO_ERROR; statusCode.address = 0x12346578; Uint32 EntryAddr; // // Assign GetWordData to the SCI-A version of the // function. GetWordData is a pointer to a function. // GetWordData = SCIA_GetWordData; // // If the KeyValue was invalid, abort the load // and return the flash entry point. // if (SCIA_GetWordData() != 0x08AA) { statusCode.status = VERIFY_ERROR; statusCode.address = FLASH_ENTRY_POINT; } ReadReservedFn(); //reads and discards 8 reserved words EntryAddr = GetLongData(); CopyData(); Uint16 x = 0; for(x = 0; x < 32676; x++){} for(x = 0; x < 32676; x++){} return EntryAddr; }
Uint32 CAN_Boot() { Uint32 EntryAddr; // If the missing clock detect bit is set, just // loop here. if(SysCtrlRegs.PLLSTS.bit.MCLKSTS == 1) { for(;;); } // Asign GetWordData to the CAN-A version of the // function. GetWordData is a pointer to a function. GetWordData = CAN_GetWordData; CAN_Init(); // If the KeyValue was invalid, abort the load // and return the flash entry point. if (CAN_GetWordData() != 0x08AA) return FLASH_ENTRY_POINT; ReadReservedFn(); EntryAddr = GetLongData(); CopyData(); return EntryAddr; }
Uint32 I2C_Boot(void) { Uint32 EntryAddr; // Assign GetWordData to the I2C-A version of the // function. GetWordData is a pointer to a function. GetWordData = I2C_GetWord; // Init I2C pins, clock, and registers // I2C_Init(); //---------------------------------------------- // Initialize the I2C-A port for communications // with the host. //---------------------------------------------- // Configure I2C pins and turn on I2C clock EALLOW; // GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 2; // Configure as SDA pin // GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 2; // Configure as SCL pin GpioCtrlRegs.GPAMUX2.all |=0x0A000000; // GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0; // Turn SDA pullup on // GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0; // Turn SCL pullup on GpioCtrlRegs.GPAPUD.all &=~0x30000000; // GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3; // Asynch // GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3; // Asynch GpioCtrlRegs.GPAQSEL2.all |=0x0F000000; SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1; // Turn I2C module clock on EDIS; // Initialize I2C in master transmitter mode I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code I2caRegs.I2CPSC.all = 0; // I2C clock should be between 7Mhz-12Mhz I2caRegs.I2CCLKL = 43; // Prescalers set for 100kHz bit rate I2caRegs.I2CCLKH = 43; // at a 10Mhz I2C clock I2caRegs.I2CMDR.all = 0x0620; // Master transmitter // Take I2C out of reset // Stop when suspended I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO I2caRegs.I2CFFRX.all = 0x2000; // Enable RXFIFO // Check for 0x08AA data header, else go to flash if (I2C_CheckKeyVal() == ERROR) { return FLASH_ENTRY_POINT; } // Check for clock and prescaler speed changes and reserved words I2C_ReservedFn(); EDIS; // Get point of entry address after load EntryAddr = GetLongData(); // Receive and copy one or more code sections to destination addresses CopyData(); return EntryAddr; }
Uint32 SCI_Boot() { Uint32 EntryAddr; // Asign GetWordData to the SCI-A version of the // function. GetOnlyWordData is a pointer to a function. // This version doesn't send echo back each character. GetOnlyWordData = SCIA_GetOnlyWordData; SCIA_Init(); SCIA_AutobaudLock(); checksum = 0; // If the KeyValue was invalid, abort the load // and return the flash entry point. if (SCIA_GetOnlyWordData() != 0x08AA) return FLASH_ENTRY_POINT; ReadReservedFn(); EntryAddr = GetLongData(); CopyData(); return EntryAddr; }
void CopyData() { struct HEADER { Uint16 BlockSize; Uint32 DestAddr; Uint32 ProgBuffAddr; } BlockHeader; Uint16 wordData; Uint16 status; Uint16 i,j; //Make sure code security is disabled CsmUnlock(); EALLOW; Flash_CPUScaleFactor = SCALE_FACTOR; Flash_CallbackPtr = NULL; EDIS; status = Flash_Erase((SECTORA | SECTORB | SECTORC | SECTORD), &FlashStatus); if(status != STATUS_SUCCESS) { //TODO fix so that it returns a serial error and reboot device return; } // After Flash Erase, send the checksum to PC program. SendCheckSum(); // Get the size in words of the first block BlockHeader.BlockSize = (*GetOnlyWordData)(); // While the block size is > 0 copy the data // to the DestAddr. There is no error checking // as it is assumed the DestAddr is a valid // memory location while(BlockHeader.BlockSize != (Uint16)0x0000) { if(BlockHeader.BlockSize > PROG_BUFFER_LENGTH){ //Block is to big to fit into our buffer so we must program it in chunks BlockHeader.DestAddr = GetLongData(); //Program as many full buffers as possible for(j = 0; j < (BlockHeader.BlockSize / PROG_BUFFER_LENGTH); j++){ BlockHeader.ProgBuffAddr = (Uint32)progBuf; for(i = 1; i <= PROG_BUFFER_LENGTH; i++) { wordData = (*GetOnlyWordData)(); *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData; } status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, PROG_BUFFER_LENGTH, &FlashStatus); if(status != STATUS_SUCCESS) { return; } BlockHeader.DestAddr += PROG_BUFFER_LENGTH; // After Flash program, send the checksum to PC program. SendCheckSum(); } //Program the leftovers BlockHeader.ProgBuffAddr = (Uint32)progBuf; for(i = 1; i <= (BlockHeader.BlockSize % PROG_BUFFER_LENGTH); i++) { wordData = (*GetOnlyWordData)(); *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData; } status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, (BlockHeader.BlockSize % PROG_BUFFER_LENGTH), &FlashStatus); if(status != STATUS_SUCCESS) { return; } // After Flash program, send the checksum to PC program. SendCheckSum(); }else{ //Block will fit into our buffer so we'll program it all at once BlockHeader.DestAddr = GetLongData(); BlockHeader.ProgBuffAddr = (Uint32)progBuf; for(i = 1; i <= BlockHeader.BlockSize; i++) { wordData = (*GetOnlyWordData)(); *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData; } status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, BlockHeader.BlockSize, &FlashStatus); if(status != STATUS_SUCCESS) { return; } // After Flash program, send the checksum to PC program. SendCheckSum(); } // Get the size of the next block BlockHeader.BlockSize = (*GetOnlyWordData)(); } return; }