LONG operator()(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2) { static const TCHAR *CPL_TYPE[] = { _T("****"), _T("CPL_INIT"), _T("CPL_GETCOUNT"), _T("CPL_INQUIRE"), _T("CPL_SELECT"), _T("CPL_DBLCLK"), _T("CPL_STOP"), _T("CPL_EXIT"), _T("CPL_NEWINQUIRE"), }; // TRACE(_T("%S(%p,%s(%u),%d,%d)\n"), __FUNCTION__, hwndCPl, CPL_TYPE[uMsg % 9], uMsg, lParam1, lParam2); switch(uMsg) { case CPL_INIT: return Init() ? TRUE : FALSE; case CPL_GETCOUNT: return GetCount(); case CPL_INQUIRE: Inquire(LONG(lParam1), (LPCPLINFO)lParam2); break; // case CPL_SELECT: // is not used // break; case CPL_DBLCLK: Dblclk(LONG(lParam1), (LONG_PTR)lParam2); break; case CPL_STOP: Stop(LONG(lParam1), (LONG_PTR)lParam2); break; case CPL_EXIT: Exit(); break; case CPL_NEWINQUIRE: NewInquire(LONG(lParam1), (LPCPLINFO)lParam2); break; default: return FALSE; } return TRUE; }
void maintask ( void ) { static unsigned char checknum = 0xff, checked = 0; ModuLenNumStruct *p_modu; p_modu = &ModuTemp; if ( AdcTimeTask >= AdcTimeTaskFlg ) { ModuCheckFlg += 1; AdcTimeTask = 0; AdcTask(); #ifdef vhe01 if ( P40 ) { P40 = 0; } else { P40 = 1; } #else if ( P15 ) { P15 = 0; } else { P15 = 1; } #endif } if ( Uart1TimeTask >= Uart1TimeTaskFlg ) { Uart1TimeTask = 0; if ( indexmk > 0x0a ) { indexmk = 0x01; } Inquire ( indexmk ); *p_modu = I2cSwitchModu ( indexmk ); if ( UartRcvFrame.len == 0 && p_modu->Online == 1 ) //ʧ°Ü { checknum = indexmk; checked++; if ( checked > 3 ) { p_modu->Online = 0; MainModu.Inserted &= ~ ( 0x01 << ( indexmk - 1 ) ); checked = 0; checknum = 0xff; indexmk++; } } else { if ( checknum == indexmk ) { checked = 0; } indexmk++; } } if ( I2cTimeTask >= I2cTimeTaskFlg ) { _SYS_RESET_CPU(); I2cTimeTask = 0; } }
/************************************************************* *函数名称:void I2cFramePro(I2CRcvFrame *frame) *函数功能:接收帧处理 *参 数:数据帧 *返 回:null *************************************************************/ void I2cFramePro ( void ) { unsigned char MODUDATACS = 0; ModuLenNumStruct *p_modu; unsigned char i = 0; p_modu = &ModuTemp; /*检查是否是升级命令*/ if ( I2Cuse[0] == 0x55 && I2Cuse[2] == 0x04 && I2Cuse[5] == 0xaa ) { I2Csend[0] = 0x55; I2Csend[1] = 0x00; I2Csend[2] = 0x06; I2Csend[3] = 0x40; I2Csend[4] = 0x13; I2Csend[5] = 0xaa; ClearDim ( I2Cuse, sizeof ( I2Cuse ) / sizeof ( char ) ); return; } if ( I2Cuse[0] == 0x55 && I2Cuse[5] == 0xAA && I2Cuse[2] == 0x00 ) { SYS_UnlockReg(); FMC->ISPCON = FMC_ISPCON_BS_LDROM; _SYS_RESET_CPU();//从LD 启动 } if ( I2Cuse[0] != FRAME_HEAD1 || I2Cuse[I2Cuse[2] - 1] != FRAME_REAR ) //针头和针尾 { g_I2Cupdate = 0; return; } I2Cchkxor = 0; for ( i = 0; i < I2Cuse[2] - 2; i++ ) //cs 为针头到CS前的异或校验 { I2Cchkxor ^= I2Cuse[i]; } if ( I2Cchkxor != I2Cuse[I2Cuse[2] - 2] ) { I2Cchkxor = 0; return; } I2Cchksum = 0; for ( i = 0; i < I2Cuse[2] - 2; i++ ) //cs 为针头到CS前的异或校验 { I2Cchksum += I2Cuse[i]; } if ( I2Cuse[2] != 0x05 ) //设置模块任务 { I2Cuse[I2Cuse[2] - 2] = I2Cchksum; RS485_Send ( I2Cuse, I2Cuse[2] ); DelayMs ( 10 ); Inquire ( I2Cuse[1] ); DelayMs ( 10 ); ClearDim ( I2Cuse, ( sizeof ( I2Cuse ) / sizeof ( char ) ) ); } else if ( I2Cuse[2] == 5 ) //选择模块(0-10) { I2Cchoosed_M = I2Cuse[1]; *p_modu = I2cSwitchModu ( I2Cchoosed_M ); if ( I2Cchoosed_M != 0x00 ) { I2Csend[0] = 0xf5; I2Csend[1] = I2Cchoosed_M; I2Csend[2] = 6 + p_modu ->DataLen; I2Csend[3] = p_modu->ModuType; for ( i = 0; i < p_modu->DataLen; i++ ) { I2Csend[4 + i] = p_modu->ModuData[i]; } I2Csend[4 + p_modu->DataLen] = 0; for ( i = 0; i < 4 + p_modu->DataLen; i++ ) { MODUDATACS ^= I2Csend[i]; } I2Csend[4 + p_modu->DataLen] = MODUDATACS; I2Csend[5 + p_modu->DataLen] = 0XAA; } else { I2Csend[0] = 0xf5; //主模块 I2Csend[1] = 0x00; I2Csend[2] = 11; MainModu.POWERA = ADC_CH ( FourDataAdc ( ADCtempA ) ); MainModu.POWERB = ADC_CH ( FourDataAdc ( ADCtempB ) ); I2Csend[5] = MainModu.POWERA >> 8; I2Csend[6] = MainModu.POWERA; I2Csend[3] = MainModu.POWERB >> 8; I2Csend[4] = MainModu.POWERB; I2Csend[7] = MainModu.Inserted >> 8; I2Csend[8] = MainModu.Inserted; I2Csend[9] = 0; for ( i = 0; i < 9; i++ ) { I2Csend[9] ^= I2Csend[i]; } I2Csend[10] = 0xAA; } ClearDim ( I2Cuse, ( sizeof ( I2Cuse ) / sizeof ( char ) ) ); }