Beispiel #1
0
void LogToFile(DataBuffer* myBuf,char annotation, char* fileName) {
	int16_t currentBuf = myBuf->currentReadBuffer;
	//uint8_t write_buf[48];
	UINT bw;

	/* open file */
	if (FAT1_open(&fp, fileName, FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) {
	Err(/*OPEN_FILE_ERROR*/);
	}
	/* move to the end of the file */
	if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) {
	Err(/*END_OF_FILE_ERROR*/);
	}

	/* write data */
	write_buf[0] = '\0';
	//time_t run_time;
	for(int cur_buf_index=0;cur_buf_index<BUFFER_SIZE;++cur_buf_index)
	{
		/** Time Components */
		UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.hour);
		UTIL1_chcat(write_buf, sizeof(write_buf), ':');
		UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.minute);
		UTIL1_chcat(write_buf, sizeof(write_buf), ':');
		UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.second);
		UTIL1_chcat(write_buf, sizeof(write_buf), ':');
		UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.milliBig);
		UTIL1_strcatNum8u(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].time.milliSmall);
		UTIL1_chcat(write_buf, sizeof(write_buf), ',');
;
		/** Accelerometer Components */
		UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].x);
		UTIL1_chcat(write_buf, sizeof(write_buf), ',');
		UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].y);
		UTIL1_chcat(write_buf, sizeof(write_buf), ',');
		UTIL1_strcatNum16s(write_buf, sizeof(write_buf), myBuf->dataBuffer[currentBuf][cur_buf_index].z);
		UTIL1_chcat(write_buf, sizeof(write_buf), ',');

		/** Annotation mode **/
		UTIL1_chcat(write_buf, sizeof(write_buf), annotation);
		UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\n");

		/** Write to file **/
		if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) {
		  (void)FAT1_close(&fp);
		  Err(/*WRITE_ERROR*/);
		  }
		memset(write_buf,'\0',48);
	}
	if(myBuf->currentReadBuffer == currentBuf)
		myBuf->currentReadBuffer=-1;
	/* closing file */
	(void)FAT1_close(&fp);
}
Beispiel #2
0
static void LogToFile(int16_t x, int16_t y, int16_t z) {
  uint8_t write_buf[48];
  UINT bw;
  TIMEREC time;

  /* open file */
  if (FAT1_open(&fp, "./log.txt", FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) {
    Err();
  }
  /* move to the end of the file */
  if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) {
    Err();
  }
  /* get time */
  if (TmDt1_GetTime(&time)!=ERR_OK) {
    Err();
  }
  /* write data */
  write_buf[0] = '\0';
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Hour);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Min);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Sec);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), x);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), y);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), z);
  UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\r\n");
  if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) {
    (void)FAT1_close(&fp);
    Err();
  }
  /* closing file */
  (void)FAT1_close(&fp);
}
Beispiel #3
0
/*!
  \brief This routine is called as callback by the radio driver on reception of a data packet
  \param msg Pointer to the message we received.
 */
static void RADIO_HandleMessage(uint8_t *msg) {
  char buf[32];
  uint8_t i, size;

  if (RADIO_isSniffing && *msg==RADIO_QUEUE_MSG_SNIFF) {
    msg++;
    size = *msg++;
    UTIL1_strcpy(buf, sizeof(buf), "\r\nch #:"); /* use new line at the beginning, as the hex dump at the end might be fill up buffer completely */
    UTIL1_strcatNum16s(buf, sizeof(buf), RADIO_Channel);
    UTIL1_strcat(buf, sizeof(buf), " size:");
    UTIL1_strcatNum16s(buf, sizeof(buf), size);
    UTIL1_strcat(buf, sizeof(buf), " ASCII: ");
    SHELL_SendMessage(buf);
    buf[0] = '\0';
    /* write as string */
    for(i=0;i<size && i<sizeof(buf);i++) {
      UTIL1_chcat(buf, sizeof(buf), msg[i]);
    }
    SHELL_SendMessage(buf);
    /* write as hex */
    buf[0] = '\0';
    UTIL1_strcat(buf, sizeof(buf), " hex: ");
    for(i=0; i<size;i++) {
      UTIL1_strcatNum8Hex(buf, sizeof(buf), msg[i]);
      UTIL1_strcat(buf, sizeof(buf), " ");
    }
    SHELL_SendMessage(buf);
    SHELL_SendMessage("\r\n");
#if PL_HAS_REMOTE && PL_HAS_MOTOR
  /*! \todo Implement handling for your remote control */
  } else if (*msg==RADIO_QUEUE_MSG_ACCEL) {
    msg++;
    size = *msg++;
    REMOTE_ParseMsg((const unsigned char*)msg+sizeof(RADIO_PREFIX_STR)-1, size-sizeof(RADIO_PREFIX_STR)-1);
#endif
  }
}
Beispiel #4
0
static uint8_t PrintStatus(const CLS1_StdIOType *io) {
  unsigned char buf[15];
  int i;

  CLS1_SendStatusStr((unsigned char*)"Reflectance", (unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  led", ledON?(unsigned char*)"on\r\n":(unsigned char*)"off\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  calibrated", isCalibrated?(unsigned char*)"yes\r\n":(unsigned char*)"no\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  raw", (unsigned char*)"", io->stdOut);
  for (i=0;i<NOF_SENSORS;i++) {
    CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorRaw[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  white", (unsigned char*)"", io->stdOut);
  for (i=0;i<NOF_SENSORS;i++) {
    CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorWhite[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  black", (unsigned char*)"", io->stdOut);
  for (i=0;i<NOF_SENSORS;i++) {
    CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorBlack[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  calibrated", (unsigned char*)"", io->stdOut);
  for (i=0;i<NOF_SENSORS;i++) {
    CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorCalibrated[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

  CLS1_SendStatusStr((unsigned char*)"  line", (unsigned char*)"", io->stdOut);
  buf[0] = '\0'; UTIL1_strcatNum16s(buf, sizeof(buf), refLine);
  CLS1_SendStr(buf, io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

  return ERR_OK;
}
Beispiel #5
0
static uint8_t PrintStatus(const CLS1_StdIOType *io) {
  int i;
  uint8_t buf[16], buf2[32];

  CLS1_SendStatusStr((uint8_t*)"Floppy", (uint8_t*)"\r\n", io->stdOut);
  UTIL1_Num32sToStr(buf, sizeof(buf), FLOPPY_NoteOffset);
  UTIL1_strcat(buf, sizeof(buf), (uint8_t*)"\r\n");
  CLS1_SendStatusStr((uint8_t*)"  note offset", buf, io->stdOut);
  for(i=0;i<FLOPPY_NOF_DRIVES;i++) {
    UTIL1_strcpy(buf, sizeof(buf), (uint8_t*)"  drive ");
    UTIL1_strcatNum16u(buf, sizeof(buf), (uint16_t)i);
    UTIL1_chcat(buf, sizeof(buf), ':');
    buf2[0] = '\0';
    if (FLOPPY_Drives[i].forward) {
      UTIL1_strcat(buf2, sizeof(buf2), (uint8_t*)"fw ");
    } else {
      UTIL1_strcat(buf2, sizeof(buf2), (uint8_t*)"bw ");
    }
    UTIL1_strcatNum16s(buf2, sizeof(buf2), FLOPPY_Drives[i].pos);
    UTIL1_strcat(buf2, sizeof(buf2), (uint8_t*)"\r\n");
    CLS1_SendStatusStr(buf, buf2, io->stdOut);
  }
  return ERR_OK;
}
Beispiel #6
0
static uint8_t PrintStatus(const CLS1_StdIOType *io) {
  unsigned char buf[24];
  int i;

  CLS1_SendStatusStr((unsigned char*)"reflectance", (unsigned char*)"\r\n", io->stdOut);
  
  CLS1_SendStatusStr((unsigned char*)"  state", REF_GetStateString(), io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
  UTIL1_strcatNum16Hex(buf, sizeof(buf), REF_MIN_NOISE_VAL);
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
  CLS1_SendStatusStr((unsigned char*)"  min noise", buf, io->stdOut);

  CLS1_SendStatusStr((unsigned char*)"  raw val", (unsigned char*)"", io->stdOut);
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorRaw[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  
  CLS1_SendStatusStr((unsigned char*)"  min val", (unsigned char*)"", io->stdOut);
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorCalibMinMax.minVal[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  max val", (unsigned char*)"", io->stdOut);
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorCalibMinMax.maxVal[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
 
  CLS1_SendStatusStr((unsigned char*)"  calib val", (unsigned char*)"", io->stdOut);
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorCalibrated[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

  CLS1_SendStatusStr((unsigned char*)"  line val", (unsigned char*)"", io->stdOut);
  buf[0] = '\0'; UTIL1_strcatNum16s(buf, sizeof(buf), refCenterLineVal);
  CLS1_SendStr(buf, io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

#if PL_CONFIG_HAS_LINE_FOLLOW
  CLS1_SendStatusStr((unsigned char*)"  line kind", REF_LineKindStr(refLineKind), io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
#endif
return ERR_OK;
}
Beispiel #7
0
static portTASK_FUNCTION(RemoteTask, pvParameters) {
#if PL_HAS_WATCHDOG
    int i;
#endif

    (void)pvParameters;
#if PL_HAS_JOYSTICK
    (void)APP_GetXY(&midPointX, &midPointY, NULL, NULL);
#endif
    for(;;) {
        if (REMOTE_isOn) {
#if PL_HAS_ACCEL
            if (REMOTE_useAccelerometer) {
#if PL_HAS_KEYS
                uint8_t buf[7];
                uint8_t keys;
#else /* PL_HAS_KEYS */
                uint8_t buf[6];
#endif /* PL_HAS_KEYS */
                int16_t x, y, z;

                /* send periodically accelerometer messages */
#if PL_HAS_KEYS
                APP_GetKeys(&keys);
#endif /* PL_HAS_KEYS */
                ACCEL_GetValues(&x, &y, &z);
                buf[0] = (uint8_t)(x&0xFF);
                buf[1] = (uint8_t)(x>>8);
                buf[2] = (uint8_t)(y&0xFF);
                buf[3] = (uint8_t)(y>>8);
                buf[4] = (uint8_t)(z&0xFF);
                buf[5] = (uint8_t)(z>>8);
#if PL_HAS_KEYS
                buf[6] = keys;
#endif /* PL_HAS_KEYS */
                if (REMOTE_isVerbose) {
                    uint8_t txtBuf[48];

                    UTIL1_strcpy(txtBuf, sizeof(txtBuf), (unsigned char*)"TX: x: ");
                    UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), x);
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)" y: ");
                    UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), y);
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)" z: ");
                    UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), z);
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)" to addr 0x");
#if RNWK_SHORT_ADDR_SIZE==1
                    UTIL1_strcatNum8Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#else
                    UTIL1_strcatNum16Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#endif
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)"\r\n");
                    SHELL_SendString(txtBuf);
                }
                (void)RAPP_SendPayloadDataBlock(buf, sizeof(buf), RAPP_MSG_TYPE_ACCEL, RNETA_GetDestAddr(), RPHY_PACKET_FLAGS_REQ_ACK);
                LED1_Neg();
            }
#endif
#if PL_HAS_JOYSTICK
            if (REMOTE_useJoystick) {
#if PL_HAS_KEYS
                uint8_t buf[3];
                uint8_t keys;
#else /* PL_HAS_KEYS */
                uint8_t buf[2];
#endif /* PL_HAS_KEYS */
                int16_t x, y;
                int8_t x8, y8;

                /* send periodically accelerometer messages */
#if PL_HAS_KEYS
                APP_GetKeys(&keys);
#endif /* PL_HAS_KEYS */
                APP_GetXY(&x, &y, &x8, &y8);
                buf[0] = x8;
                buf[1] = y8;
#if PL_HAS_KEYS
                buf[2] = keys;
#endif /* PL_HAS_KEYS */
                if (REMOTE_isVerbose) {
                    uint8_t txtBuf[48];

                    UTIL1_strcpy(txtBuf, sizeof(txtBuf), (unsigned char*)"TX: x: ");
                    UTIL1_strcatNum8s(txtBuf, sizeof(txtBuf), x8);
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)" y: ");
                    UTIL1_strcatNum8s(txtBuf, sizeof(txtBuf), y8);
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)" to addr 0x");
#if RNWK_SHORT_ADDR_SIZE==1
                    UTIL1_strcatNum8Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#else
                    UTIL1_strcatNum16Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#endif
                    UTIL1_strcat(txtBuf, sizeof(txtBuf), (unsigned char*)"\r\n");
                    SHELL_SendString(txtBuf);
                }
                (void)RAPP_SendPayloadDataBlock(buf, sizeof(buf), RAPP_MSG_TYPE_JOYSTICK_XY, RNETA_GetDestAddr(), RPHY_PACKET_FLAGS_REQ_ACK);
                LED1_Neg();
            }
#endif
#if PL_HAS_WATCHDOG
            for(i=0; i<2; i++) { /* do it in smaller steps */
                WDT_IncTaskCntr(WDT_TASK_ID_REMOTE, 100);
                FRTOS1_vTaskDelay(100/portTICK_RATE_MS);
            }
#else
            FRTOS1_vTaskDelay(200/portTICK_RATE_MS);
#endif
        } else {
#if PL_HAS_WATCHDOG
            for(i=0; i<10; i++) { /* do it in smaller steps */
                WDT_IncTaskCntr(WDT_TASK_ID_REMOTE, 100);
                FRTOS1_vTaskDelay(100/portTICK_RATE_MS);
            }
#else
            FRTOS1_vTaskDelay(1000/portTICK_RATE_MS);
#endif
        }
    } /* for */
Beispiel #8
0
static void RemoteTask(void *pvParameters) {
	(void) pvParameters;
#if PL_HAS_JOYSTICK
	(void) APP_GetXY_Joystick(&midPointX, &midPointY, NULL, NULL);
#endif
	FRTOS1_vTaskDelay(1000/portTICK_RATE_MS);
	for (;;) {
		if (REMOTE_isOn) {
#if PL_HAS_ACCEL
			if(REMOTE_useAccel){
				uint8_t buf[6];
				int16_t x, y, z;
				/*send periodically messages*/
				ACCEL_getXYZmg(&x, &y, &z);

				buf[0]=(uint8_t)(x&0xFF);
				buf[1]=(uint8_t)(x>>8);
				buf[2]=(uint8_t)(y&0xFF);
				buf[3]=(uint8_t)(y>>8);
				buf[4]=(uint8_t)(z&0xFF);
				buf[5]=(uint8_t)(z>>8);
				if (REMOTE_isVerbose) {
					uint8_t txtBuf[48];

					UTIL1_strcpy(txtBuf, sizeof(txtBuf),
							(unsigned char*) "TX: x: ");
					UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), x);
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) "\r\n y: ");
					UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), y);
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) "\r\n z: ");
					UTIL1_strcatNum16s(txtBuf, sizeof(txtBuf), z);
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) "\r\n to addr 0x");
#if RNWK_SHORT_ADDR_SIZE==1
					UTIL1_strcatNum8Hex(txtBuf, sizeof(txtBuf),
							RNETA_GetDestAddr());
#else
					UTIL1_strcatNum16Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#endif
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) "\r\n");
					SHELL_SendString(txtBuf);
				}
				(void) RAPP_SendPayloadDataBlock(buf, sizeof(buf),
						RAPP_MSG_TYPE_ACCEL, RNETA_GetDestAddr(),
						RPHY_PACKET_FLAGS_REQ_ACK);
				LED1_Neg();

			}
#endif
#if PL_HAS_JOYSTICK
			if (REMOTE_useJoystick) {
				uint8_t buf[2];
				int16_t x, y;
				int8_t x8, y8;

				/* send periodically messages */
				APP_GetXY_Joystick(&x, &y, &x8, &y8);
				buf[0] = x8;
				buf[1] = y8;
				if (REMOTE_isVerbose) {
					uint8_t txtBuf[48];

					UTIL1_strcpy(txtBuf, sizeof(txtBuf),
							(unsigned char*) "TX: x: ");
					UTIL1_strcatNum8s(txtBuf, sizeof(txtBuf), x8);
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) " y: ");
					UTIL1_strcatNum8s(txtBuf, sizeof(txtBuf), y8);
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) " to addr 0x");
#if RNWK_SHORT_ADDR_SIZE==1
					UTIL1_strcatNum8Hex(txtBuf, sizeof(txtBuf),
							RNETA_GetDestAddr());
#else
					UTIL1_strcatNum16Hex(txtBuf, sizeof(txtBuf), RNETA_GetDestAddr());
#endif
					UTIL1_strcat(txtBuf, sizeof(txtBuf),
							(unsigned char*) "\r\n");
					SHELL_SendString(txtBuf);
				}
				(void) RAPP_SendPayloadDataBlock(buf, sizeof(buf),
						RAPP_MSG_TYPE_JOYSTICK_XY, RNETA_GetDestAddr(),
						RPHY_PACKET_FLAGS_REQ_ACK);
				LED1_Neg();
			}
#endif
			FRTOS1_vTaskDelay(200/portTICK_RATE_MS);
		} else {
			FRTOS1_vTaskDelay(1000/portTICK_RATE_MS);
		}
	} /* for */
Beispiel #9
0
void RAPP_SniffPacket(RPHY_PacketDesc *packet, bool isTx) {
  uint8_t buf[32];
  const CLS1_StdIOType *io;
  int i;
  uint8_t dataSize;
  RNWK_ShortAddrType addr;
  
  io = CLS1_GetStdio();
  if (isTx) {
    CLS1_SendStr((unsigned char*)"Packet Tx ", io->stdOut);
  } else {
    CLS1_SendStr((unsigned char*)"Packet Rx ", io->stdOut);
  }
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"flags: ");
  UTIL1_strcatNum16s(buf, sizeof(buf), packet->flags);
  CLS1_SendStr(buf, io->stdOut);
  if (packet->flags!=RPHY_PACKET_FLAGS_NONE) {
    CLS1_SendStr((unsigned char*)"(", io->stdOut);
    if (packet->flags&RPHY_PACKET_FLAGS_IS_ACK) {
      CLS1_SendStr((unsigned char*)"IS_ACK,", io->stdOut);
    }
    if (packet->flags&RPHY_PACKET_FLAGS_REQ_ACK) {
      CLS1_SendStr((unsigned char*)"REQ_ACK", io->stdOut);
    }
    CLS1_SendStr((unsigned char*)")", io->stdOut);
  }
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" size: ");
  UTIL1_strcatNum16s(buf, sizeof(buf), packet->phySize);
  CLS1_SendStr(buf, io->stdOut);
  /* PHY */
  CLS1_SendStr((unsigned char*)" PHY data: ", io->stdOut);
  dataSize = RPHY_BUF_SIZE(packet->phyData);
  for(i=0; i<dataSize+RPHY_HEADER_SIZE;i++) {
    buf[0] = '\0';
    UTIL1_strcatNum8Hex(buf, sizeof(buf), packet->phyData[i]);
    UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" ");
    CLS1_SendStr(buf, io->stdOut);
  }
  /* MAC */
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" MAC size:");
  UTIL1_strcatNum8u(buf, sizeof(buf), dataSize);
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" type:");
  UTIL1_strcatNum8Hex(buf, sizeof(buf), RMAC_BUF_TYPE(packet->phyData));
  CLS1_SendStr(buf, io->stdOut);
  RMAC_DecodeType(buf, sizeof(buf), packet);
  CLS1_SendStr(buf, io->stdOut);
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" s#:");
  UTIL1_strcatNum8Hex(buf, sizeof(buf), RMAC_BUF_SEQN(packet->phyData));
  CLS1_SendStr(buf, io->stdOut);
  /* NWK */
  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" NWK src:");
  addr = RNWK_BUF_GET_SRC_ADDR(packet->phyData);
#if RNWK_SHORT_ADDR_SIZE==1
  UTIL1_strcatNum8Hex(buf, sizeof(buf), addr);
#else
  UTIL1_strcatNum16Hex(buf, sizeof(buf), addr);
#endif
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" dst:");
  addr = RNWK_BUF_GET_DST_ADDR(packet->phyData);
#if RNWK_SHORT_ADDR_SIZE==1
  UTIL1_strcatNum8Hex(buf, sizeof(buf), addr);
#else
  UTIL1_strcatNum16Hex(buf, sizeof(buf), addr);
#endif
  CLS1_SendStr(buf, io->stdOut);
  /* APP */
  if (dataSize>RMAC_HEADER_SIZE+RNWK_HEADER_SIZE) { /* there is application data */
    UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)" APP type:");
    UTIL1_strcatNum8Hex(buf, sizeof(buf), RAPP_BUF_TYPE(packet->phyData));
    UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" size:");
    UTIL1_strcatNum8Hex(buf, sizeof(buf), RAPP_BUF_SIZE(packet->phyData));
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
}
static portTASK_FUNCTION(TaskAccelDemo, pvParameters) {
    int16_t x,y,z;
    ACCEL_WindowDesc *ui = (ACCEL_WindowDesc*)pvParameters;
    unsigned char buf[sizeof("X: 123")];
    UIG1_DataPoint data[3], prevData[3];

    appWp = ui;
#if PL_APP_MODE_I2C_LCD
    I2C_ClearBuffers();
#endif
    data[0].color = UI1_COLOR_RED;
    data[0].data = 0;
    data[1].color = UI1_COLOR_BLUE;
    data[1].data = 0;
    data[2].color = UI1_COLOR_DARK_GREEN;
    data[3].data = 0;
    prevData[0].color = UI1_COLOR_RED;
    prevData[0].data = 0;
    prevData[1].color = UI1_COLOR_BLUE;
    prevData[1].data = 0;
    prevData[2].color = UI1_COLOR_DARK_GREEN;
    prevData[2].data = 0;
    for (;;) {
        /* we are getting the values in milli-g (means: around -1200 to +1200 */
#if PL_HAS_AUTO_DEMO && PL_HAS_HW_ACCELEROMETER
        /* for demo, make values more interesting */
        x = ACCEL1_GetX();
        y = ACCEL1_GetY();
        z = ACCEL1_GetZ();
        while (z>900) { /* put in range */
            z /= 2;
        }
#else
        x = ACCEL_GetX();
        y = ACCEL_GetY();
        z = ACCEL_GetZ();
#endif
        /* cap to -100..+100 */
        x /= 11; /* little bit more than 10, just to have 1g not always hitting the limit of 100% */
        y /= 11;
        z /= 11;
        /* make sure it is in the -100..+100 range */
        if (x>100) {
            x = 100;
        }
        else if (x<-100) {
            x = -100;
        }
        if (y>100) {
            y = 100;
        }
        else if (y<-100) {
            y = -100;
        }
        if (z>100) {
            z = 100;
        }
        else if (z<-100) {
            z = -100;
        }
        /* midpoint of graph is at 50% */
        x = 50+(x/2); /* scale between 0..100% */
        y = 50+(y/2); /* scale between 0..100% */
        z = 50+(z/2); /* scale between 0..100% */
        UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"X: ");
        UTIL1_strcatNum16s(buf, sizeof(buf), x);
        UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtX, sizeof(ui->txtBufX), buf);
        UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"Y: ");
        UTIL1_strcatNum16s(buf, sizeof(buf), y);
        UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtY, sizeof(ui->txtBufY), buf);
        UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"Z: ");
        UTIL1_strcatNum16s(buf, sizeof(buf), z);
        UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtZ, sizeof(ui->txtBufZ), buf);
        (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 0, (uint8_t)x);
        (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 1, (uint8_t)y);
        (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 2, (uint8_t)z);
        /* graph */
        data[0].data = (uint8_t)x;
        data[1].data = (uint8_t)y;
        data[2].data = (uint8_t)z;
        (void)UIG1_AddDataLine((UI1_Element *)&ui->graph, &prevData[0], &data[0], 3);
        prevData[0].data = data[0].data;
        prevData[1].data = data[1].data;
        prevData[2].data = data[2].data;
        if (EVNT1_GetEvent(EVNT1_APP_MODE_CHANGE)) { /* request to close application */
            EVNT1_ClearEvent(EVNT1_APP_MODE_CHANGE); /* reset event flag */
            FRTOS1_vTaskDelete(NULL); /* kill ourself */
        }
        FRTOS1_vTaskDelay(25/portTICK_RATE_MS);
    } /* for */
}
Beispiel #11
0
static uint8_t PrintStatus(const CLS1_StdIOType *io) {
  unsigned char buf[24];
  int i;

  CLS1_SendStatusStr((unsigned char*)"reflectance", (unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  IR led on", ledON?(unsigned char*)"yes\r\n":(unsigned char*)"no\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  calibrating", doMinMaxCalibration?(unsigned char*)"yes\r\n":(unsigned char*)"no\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  calibrated", isCalibrated?(unsigned char*)"yes\r\n":(unsigned char*)"no\r\n", io->stdOut);

  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
  UTIL1_strcatNum16Hex(buf, sizeof(buf), REF_MIN_NOISE_VAL);
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
  CLS1_SendStatusStr((unsigned char*)"  min noise", buf, io->stdOut);

  UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"0x");
  UTIL1_strcatNum16Hex(buf, sizeof(buf), REF_MIN_LINE_VAL);
  UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
  CLS1_SendStatusStr((unsigned char*)"  min line", buf, io->stdOut);

  CLS1_SendStatusStr((unsigned char*)"  raw val", (unsigned char*)"", io->stdOut);
#if REF_SENSOR1_IS_LEFT
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
#else
  for (i=REF_NOF_SENSORS-1;i>=0;i--) {
    if (i==REF_NOF_SENSORS-1) {
#endif
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorRaw[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  min val", (unsigned char*)"", io->stdOut);
#if REF_SENSOR1_IS_LEFT
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
#else
  for (i=REF_NOF_SENSORS-1;i>=0;i--) {
    if (i==REF_NOF_SENSORS-1) {
#endif
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorMin[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  max val", (unsigned char*)"", io->stdOut);
#if REF_SENSOR1_IS_LEFT
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
#else
  for (i=REF_NOF_SENSORS-1;i>=0;i--) {
    if (i==REF_NOF_SENSORS-1) {
#endif
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorMax[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  CLS1_SendStatusStr((unsigned char*)"  calib val", (unsigned char*)"", io->stdOut);
#if REF_SENSOR1_IS_LEFT
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
#else
  for (i=REF_NOF_SENSORS-1;i>=0;i--) {
    if (i==REF_NOF_SENSORS-1) {
#endif
      CLS1_SendStr((unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorCalibrated[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

  CLS1_SendStatusStr((unsigned char*)"  line val", (unsigned char*)"", io->stdOut);
  buf[0] = '\0'; UTIL1_strcatNum16s(buf, sizeof(buf), refCenterLineVal);
  CLS1_SendStr(buf, io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);

#if PL_APP_LINE_MAZE
#if REF_SENSOR1_IS_LEFT
  for (i=0;i<REF_NOF_SENSORS;i++) {
    if (i==0) {
#else
  for (i=REF_NOF_SENSORS-1;i>=0;i--) {
    if (i==REF_NOF_SENSORS-1) {
#endif
      CLS1_SendStatusStr((unsigned char*)"  history", (unsigned char*)"0x", io->stdOut);
    } else {
      CLS1_SendStr((unsigned char*)" 0x", io->stdOut);
    }
    buf[0] = '\0'; UTIL1_strcatNum16Hex(buf, sizeof(buf), SensorHistory[i]);
    CLS1_SendStr(buf, io->stdOut);
  }
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
#endif
  
  CLS1_SendStatusStr((unsigned char*)"  line kind", REF_LineKindStr(refLineKind), io->stdOut);
  CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
  return ERR_OK;
}

byte REF_ParseCommand(const unsigned char *cmd, bool *handled, const CLS1_StdIOType *io) {
  if (UTIL1_strcmp((char*)cmd, CLS1_CMD_HELP)==0 || UTIL1_strcmp((char*)cmd, "ref help")==0) {
    *handled = TRUE;
    return PrintHelp(io);
  } else if ((UTIL1_strcmp((char*)cmd, CLS1_CMD_STATUS)==0) || (UTIL1_strcmp((char*)cmd, "ref status")==0)) {
    *handled = TRUE;
    return PrintStatus(io);
  } else if (UTIL1_strcmp((char*)cmd, "ref calib on")==0) {
    APP_StateStartCalibrate();
    *handled = TRUE;
    return ERR_OK;  
  } else if (UTIL1_strcmp((char*)cmd, "ref calib off")==0) {
    APP_StateStopCalibrate();
    *handled = TRUE;
    return ERR_OK;
  } else if (UTIL1_strcmp((char*)cmd, "ref led on")==0) {
    ledON = TRUE;
    *handled = TRUE;
    return ERR_OK;
  } else if (UTIL1_strcmp((char*)cmd, "ref led off")==0) {
    ledON = FALSE;
    *handled = TRUE;
    return ERR_OK;
  }
  return ERR_OK;
}

uint16_t REF_GetLineValue(bool *onLine) {
  *onLine = refCenterLineVal>0 && refCenterLineVal<REF_MAX_LINE_VALUE;
  return refCenterLineVal;
}

static portTASK_FUNCTION(ReflTask, pvParameters) {
  (void)pvParameters; /* not used */
  for(;;) {
    if (doMinMaxCalibration) {
      REF_CalibrateMinMax(SensorMin, SensorMax, SensorRaw);
#if PL_HAS_BUZZER
      BUZ_Beep(300, 50);
#endif
    } else {
      REF_Measure();
    }
    FRTOS1_vTaskDelay(10/portTICK_RATE_MS);
  }
}

void REF_Init(void) {
  refLineKind = REF_LINE_NONE;
  refCenterLineVal = 0;
  mutexHandle = FRTOS1_xSemaphoreCreateMutex();
  if (mutexHandle==NULL) {
    for(;;);
  }
  timerHandle = RefCnt_Init(NULL);
  REF_InitSensorValues();
  if (FRTOS1_xTaskCreate(ReflTask, (signed portCHAR *)"Refl", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1+2, NULL) != pdPASS) {
    for(;;){} /* error */
  }
}