Commit e170692d authored by 张泽仁's avatar 张泽仁

develop version 2023.11.3 back from suihua

parent 4c35b5cf
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <stdint.h>
#include <wiringPi.h>
#include <string.h>
int main()
{
int fileuart;
if ((fileuart = serialOpen("/dev/ttyAMA0", 9600)) < 0)
{
printf("/dev/ttyAMA0 Open Faild\r\n");
// return 0;
}
printf("/dev/ttyAMA0 Open success\r\n");
char message[9] = {0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x2b, 0x58};
write(fileuart, message, 9);
char buf[100] = {0};
int recbytenum = serialDataAvail(filedevid);
for (int i = 0; i < recbytenum; i++)
{
buf[i] = serialGetchar(filedevid);
}
for (int i = 0; i < recbytenum; i++)
{
printf("%x ", buf[i]);
}
printf("\n");
int angle = (buf[7] << 24) | (buf[8] << 16) | (buf[9] << 8) | buf[10];
printf("angle = %d\n", angle);
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
// crc
uint16_t CrcValueCalc(uint8_t *cpucData, uint16_t usLength) // changed
{
uint16_t crcValue = 0xffff;
int i;
while (usLength--)
{
crcValue ^= *cpucData++;
for (i = 8 - 1; i >= 0; i--)
{
if (crcValue & 0x0001)
{
crcValue = (crcValue >> 1) ^ 0xa001;
}
else
{
crcValue = crcValue >> 1;
}
}
}
return crcValue;
}
int main()
{ //a 10 b11 c12 d13
unsigned char mess[13] = {0x40, 0x38, 0x0b, 0x06, 0x00, 0x02, 0x01, 0xff, 0xff, 0xff, 0xa6, 0x00, 0x00};
uint16_t crc = CrcValueCalc(mess, 11);
mess[11] = crc & 0xff;
mess[12] = (crc >> 8) & 0xff;
for (int i = 0; i < 13; i++)
{
printf("0x%x, ", mess[i]);
}
printf("\n");
return 0;
}
// 120 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x4, 0xb0, 0x1e, 0x7c,
// 0 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1d, 0x8,
// 60 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x2, 0x58, 0x1d, 0x92,
// 90 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x8, 0x84, 0x1a, 0xab,
// 150 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x5, 0xdc, 0x1f, 0xc1,
// 30 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x1, 0x2c, 0x1d, 0x45,
// 85 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x3, 0x52, 0x9c, 0x5
// -25 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0xff, 0xff, 0xff, 0xe7, 0x1c, 0x96,
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment