void Cmd_Set_Intensity(void) { unsigned int i=0; unsigned char data=0; _printf("Set Intensity Cmd : "); if (QueueStatus()) // some news? op_status=PullQueue(&data); else return; _printf("%c",data); if ((data >= '0') && (data <= '2') ) // Protect from unexpected data Led_intensity=Intensity_Table[data-'0']; op_status=PullQueue(&data); // Get terminator and discard _printf("\n"); }
void Cmd_Set_Color(void) { unsigned int i=0; unsigned char data=0; _printf("Set Color Cmd : "); if (QueueStatus()) // some news? op_status=PullQueue(&data); else return; _printf("%c",data); if ((data >= '0') && (data <= '7') ) // Protect from unexpected data color=Led_Colors[data-'0']; op_status=PullQueue(&data); // Get terminator and discard _printf("\n"); }
void Cmd_Set_Party(void) { unsigned int i=0; unsigned char data=0; _printf("Set Party Cmd : "); if (QueueStatus()) // some news? op_status=PullQueue(&data); else return; _printf("%c",data); if ((data >= '0') && (data <= '1') ) // Protect from unexpected data { if (data == '1') Set_Party_Mode_On(); if (data == '0') Set_Party_Mode_Off(); } op_status=PullQueue(&data); // Get terminator and discard _printf("\n"); }
void Cmd_Rd_Battery(void) { unsigned char data=0; _printf("Rd_Battery Cmd : "); if (QueueStatus()) // some news? op_status=PullQueue(&data); // Get terminator and discard else return; // send STX data ETX data is Battery Status sendsci(STX); // sendsci('N'); // Mando estado de bateria adcval=atd_getsample(); sendsci(Batt_Status(adcval)); sendsci(ETX); }
void Cqtestbench(void) // queue Test bench { unsigned char data; unsigned char status; QueueInit(); // initialize queue status= PushQueue(1); // Push something into the queue status= PushQueue(2); status= PushQueue(3); if(PushQueue(4)==QFULL) { _printf( "Queue Overflowed \n"); return; } while (QueueStatus()) // some news? { status=PullQueue(&data); // if yes then get data from queue _printf( "Data pulled: %d , Remaining: %d \n",data,QueueStatus()); } }
void Cmd_Set_Text(void) { ///#define MAX_TEXT_LEN 200 ///char textBuf[MAX_TEXT_LEN]; unsigned int i=0; unsigned char data=0; _printf("Set Text Cmd : "); do { if (QueueStatus()) // some news? op_status=PullQueue(&data); else return; //_printf("%c",data); // _printf("*(%c)-[%.2X]* ",data,data); textBuf[i++]=data; if(i > MAX_TEXT_LEN-1) // Prevent overwiting { textBuf[i]=0; return; } } while (data); textBuf[i]=data; LEDscreen_setActualMSJ(textBuf); _printf("\n"); }
unsigned char command_parser(CMD_STR *p2cmd) { unsigned char cmd; if(QueueStatus()) { op_status=PullQueue(&cmd); _printf("$(%c)-[%.2X]$",cmd,cmd); while (p2cmd->command!= END_OF_LIST && p2cmd->command!=cmd) p2cmd++; (p2cmd->exec)(); return(OK); } return(QEMPTY); // Error queue is empty }
void LEDtest3(void) { LEDSTR *p2Matrix=NULL; unsigned char temp; // unsigned char show_led=0; // LEDscreen_setShiftEnded_voidCallback(timetoshift); LEDscreen_setActualMSJ("**C5N**"); for (;;) { adcval=atd_getsample(); _printf("ADC;%d \n",adcval); ///// putcspi0(show_led++); p2Matrix=LEDscreen_getScreenAddress(); PORTA |= 0x01; LEDscreen_ShiftMSJ(); // shift msg one colum left if( Get_End_Of_Shift_Status() == TRUE) //Ckeck if the whole msg was sent { //_printf("Hallo Welt \n "); end_of_transmision = FALSE; Reset_FSM(); QueueInit(); Sci1_Putchar(XON); // HC05 Bluetooth //////// rti_start(); // Non Blocking W/hardware Timer Set_Timer_ms(3000); // 3 seconds window /* TIMER TEST _printf("Timer in \n"); while(1){ if( Get_Timer_ms_Status()) { _printf("Timer\n"); Set_Timer_ms(1000); } } TIMER TEST END*/ //// _printf("-(%c)[%.2X]-",ch,ch); do { if(messages_count()) _printf("Remaining mess %d\n",messages_count()); if(new_messages()) op_status=command_parser(commands); // Process the cmd } while ((endsts=(end_of_transmision == FALSE)) && (timsts=(Get_Timer_ms_Status()!=TIME_OUT))); if(!endsts) _printf("end_of_trans EOT\n"); if(!timsts) _printf("timeout EOT\n"); ////////////// rti_stop(); while(QueueStatus()) /// cleanup op_status=PullQueue(&temp); } Matrix2Vector(p2Matrix); // Convert Matrix to Vector Set_Color(color); Set_Intensity(Led_intensity); WS2812B_Init(); WS2812B_Set_Data_pointer((unsigned char *)DestLedScreen); WS2812B_Set_Data_Length(32*8*sizeof(LEDSTR)); WS2812B_Send_data(); PORTA &= 0xFE; //21.3 ms /// Set_Timer_ms(24); // 24 ms esto es normal velocidad posta Set_Timer_ms(speed); while (Get_Timer_ms_Status()!=TIME_OUT) ; // test_delay(100); //24.8 ms (OLD) _asm nop; _asm nop; _asm nop; _asm nop; } }
AMUInt32 SenderRunner(void* lpParam) #endif #endif { Event* pEvent = NULL; AMInt32 isExit = 0; PcNetworkConfig* pConfig = NULL; ProtocolEngine* pProtocolEngine = ((PacketConnection*)lpParam)->pProtocolEngine; PacketConnection* pPacketConnection; AMInt32 iBarkTime = 0, iNowTime = 0, iMissCount = 0; PcHealthCheckConfig hcConfig = {0, NULL}; Event* pHealthCheckEvent = NULL; Event* pHealthCheckSelfEvent = NULL; PcClearVarInd* pClearVarInd = NULL; while(1) { //get Request EVENT from sender queue. PullQueue(pProtocolEngine->pPCCore->pSenderQueue, &pEvent, 1); if(pEvent != NULL) { pPacketConnection = (PacketConnection*)pEvent->hPCHandle; switch(pEvent->id) { case PC_SHUTDOWN_IND: //关闭当前模块 #ifdef AMOS_DEBUG AMPrintf("noble:exit sender thread....\n"); #endif isExit = 1; break; case PC_CLEAR_VAR_IND: #ifdef AMOS_DEBUG AMPrintf("noble:sender PC_CLEAR_VAR_IND....\n"); #endif //network need to close if(pPacketConnection && pPacketConnection->pNetwork && pPacketConnection->pNetwork->fd>0) PCContextGetInstance()->socketClose(&pPacketConnection->pNetwork->fd); pClearVarInd = (PcClearVarInd*)pEvent->pContent; pProtocolEngine->pPCContext->semaphoreSignal(pClearVarInd->pSemaphore); break; case PC_SET_HEALTH_CHECK_CONFIG: if(iBarkTime == 0) memcpy(&hcConfig, (PcHealthCheckConfig*)pEvent->pContent, sizeof(hcConfig)); if( IsPCNetworkReady(pProtocolEngine->pPCCore) > 0 && IsPCNeedHealthCheck(pProtocolEngine->pPCCore) > 0 ) { iNowTime = AMGetUTCTime(AMNULL); if( iBarkTime+hcConfig.second < iNowTime || iNowTime < iBarkTime) { if(hcConfig.pMaker != NULL) { hcConfig.pMaker(pEvent->hPCHandle, &pHealthCheckEvent, pPacketConnection->pReference); SenderPacket(pHealthCheckEvent); EventDestory(&pHealthCheckEvent); iBarkTime = iNowTime; } iMissCount = 0; } } //send PC_SET_HEALTH_CHECK_CONFIG to self. EventCreate(pEvent->hPCHandle, &pHealthCheckSelfEvent, PC_SET_HEALTH_CHECK_CONFIG, (void*)&hcConfig, sizeof(hcConfig)); PCPostMessage(pHealthCheckSelfEvent, pProtocolEngine->pPCCore->pSenderQueue); pProtocolEngine->pPCContext->sleep(HEALTH_CHECK_SLEEP_TIME); break; case PC_SET_NETWORK_CONFIG: //预处理网络连接 pConfig = (PcNetworkConfig*)pEvent->pContent; if(pConfig->nCount <= 1) { #ifdef AMOS_DEBUG AMPrintf("noble:sender socket create. ip = %s:%d\n", pConfig->ip, pConfig->port); #endif pProtocolEngine->pPCCore->socketFd = pProtocolEngine->pPCContext->socketCreate( pConfig->ip, pConfig->port #ifdef AMOS #ifdef SOCKET_ASYNC , (AMInt32)pIMnet, AMSocketIAPGet(), SocketConnectionCallback, SocketSenderCallback, SocketReaderCallback #endif #endif ); #ifdef AMOS_DEBUG AMPrintf("noble:sender socket create over %d \n", pProtocolEngine->pPCCore->socketFd); #endif } if(pPacketConnection->pNetwork != NULL) pPacketConnection->pNetwork->fd = pProtocolEngine->pPCCore->socketFd; if(pConfig->sync) { //tell pcmgr PacketConnectionOpen pPacketConnection->pProtocolEngine->pPCContext->semaphoreSignal(&(pPacketConnection->semaphore)); } else { #ifdef SOCKET_ASYNC if(pProtocolEngine->pPCCore->socketFd <= 0) #endif { SendNetworkConnectedMsg(pPacketConnection, pProtocolEngine->pPCCore->socketFd); } } break; default: SenderPacket(pEvent); break; } } //destory EVENT if(pEvent != NULL) EventDestory(&pEvent); if(isExit == 1) goto SenderEnd; } SenderEnd: pProtocolEngine->pPCContext->semaphoreSignal(&pProtocolEngine->pPCCore->pSenderLooper->semaphore); #ifdef AMOS return (AMPVoid)isExit; #else #ifdef WIN32 return isExit; #endif #endif }
PCRetCode ReaderEventHandler(ProtocolEngine* pProtocolEngine, AMInt32 sync #ifdef SOCKET_ASYNC , AMInt32* pIndType #endif ) { PCRetCode retCode = eOK; Event* pEvent = NULL; PcClearVarInd* pClearVarInd = NULL; PacketConnection* pPacketConnection = NULL; AMAssert(NULL != pProtocolEngine && NULL != pProtocolEngine->pPCCore); //get Request EVENT from reader queue. PullQueue(pProtocolEngine->pPCCore->pReaderQueue, &pEvent, sync); if(pEvent != NULL) { switch(pEvent->id) { case PC_SHUTDOWN_IND: #ifdef AMOS_DEBUG AMPrintf("noble:exit reader thread....\n"); #endif retCode = eJumpWhile; break; #ifdef SOCKET_ASYNC case PC_SOCKET_IND: *pIndType = ((ImSocketInd*)pEvent->pContent)->indType; break; #endif case PC_CLEAR_VAR_IND: #ifdef AMOS_DEBUG AMPrintf("noble:ReaderEventHandler PC_CLEAR_VAR_IND.\n"); #endif pPacketConnection = (PacketConnection*)pEvent->hPCHandle; //network need to close if(pPacketConnection && pPacketConnection->pNetwork && pPacketConnection->pNetwork->fd>0) PCContextGetInstance()->socketClose(&pPacketConnection->pNetwork->fd); pClearVarInd = (PcClearVarInd*)pEvent->pContent; PCContextGetInstance()->semaphoreSignal(pClearVarInd->pSemaphore); break; default: #ifdef AMOS_DEBUG AMPrintf("noble:ReaderEventHandler default.\n"); #endif break; } //destory EVENT EventDestory(&pEvent); #ifdef AMOS_DEBUG AMPrintf("noble:ReaderEventHandler after EventDestory.\n"); #endif } return retCode; }
AMUInt32 CallbackRunner(void* lpParam) #endif #endif { Event* pEvent = NULL; AMInt32 isExit = 0; ProtocolEngine* pProtocolEngine = ((PacketConnection*)lpParam)->pProtocolEngine; PacketConnection* pPacketConnection; PcClearVarInd* pClearVarInd = NULL; while(1) { //get Request EVENT from callback queue. PullQueue(pProtocolEngine->pPCCore->pCallbackQueue, &pEvent, 1); if(pEvent != NULL) { pPacketConnection = (PacketConnection*)pEvent->hPCHandle; switch(pEvent->id) { case PC_SHUTDOWN_IND: #ifdef AMOS_DEBUG AMPrintf("noble:exit callback thread....\n"); #endif isExit = 1; break; case PC_CLEAR_VAR_IND: #ifdef AMOS_DEBUG AMPrintf("noble:callback PC_CLEAR_VAR_IND....\n"); #endif //network need to close if(pPacketConnection && pPacketConnection->pNetwork && pPacketConnection->pNetwork->fd>0) PCContextGetInstance()->socketClose(&pPacketConnection->pNetwork->fd); pClearVarInd = (PcClearVarInd*)pEvent->pContent; PCContextGetInstance()->semaphoreSignal(pClearVarInd->pSemaphore); break; default: #ifdef AMOS_DEBUG AMPrintf("noble:callback event <<<<< 0x%x... start\n", pEvent->id); #endif if(pEvent->id == PC_RECV_EXCEPTION_IND) ProtocolNetworkDestory(pEvent->hPCHandle, 1); if(pPacketConnection && pPacketConnection->pReceiver) pPacketConnection->pReceiver(pPacketConnection, pEvent, pPacketConnection->pReference); #ifdef AMOS_DEBUG AMPrintf("noble:callback event >>>>> 0x%x end \n", pEvent->id); #endif break; } //destory EVENT EventDestory(&pEvent); if(isExit == 1) goto CallbackEnd; } } CallbackEnd: PCContextGetInstance()->semaphoreSignal(&pProtocolEngine->pPCCore->pCallbackLooper->semaphore); #ifdef AMOS return (AMPVoid)isExit; #else #ifdef WIN32 return isExit; #endif #endif }