Hi,
I have written a program for STM32xx and x86 Linux for testing.
This is just a portion of C++ code; I need to document it, so I'll provide a link to a zip file."
#ifndef __ISYS_S700_H__
#define __ISYS_S700_H__
#include <isys/main.h>
#include <isys/hash/hash.h>
#include <isys/time/time.h>
enum {
S700_RX_ELAPSE_TIME = 2000,
S700_IC_ELAPSE_TIME = 4000
};
enum S700_ERR { // S700 DISPLAY THIS ERROR
LOW_BAT = 0x08, // 00006
MOTOR_ERROR = 0x40, // 00007
THROTTLE_ERROR = 0x20, // 00008
CONTROLLER_ERROR = 0x30, // 00009
};
typedef struct { // OFFS DESCRIPTOPN
uint8_t _00; // 0. 0x01
uint8_t size; // 1. 0x14 size
uint8_t _02; // 2. 0x01
uint8_t drivingMode; // 3. P10 (0=assist, 1=throttle, 2=both)
uint8_t PAS; // 4. P05 (0=3=0x05, 1=5=0x03, 2=9=0x01 assist levels)
uint8_t nonZeorStart; // 5. P09 (0=0xA0, 1=0xE0)
uint8_t speedSensorMagnetCount; // 6. P07 (1 - 100)
uint8_t _07; // 7. 0x01
uint8_t wheelSize; // 8. P06 (xx ^ 128) + 128 = (256 for 25.6", 260 for 26" ...)
uint8_t PAS_sensitivity; // 9. P11 (1 - 24)
uint8_t PAS_starting_power; // 10. P12 (0 - 5)
uint16_t speedLimit; // 11. P08 (0 - 100) BIG ENDIAN!
uint8_t currentLimit; // 13. P14 (1A - 50A)
uint8_t reserved[4]; // 14. ?
uint8_t PAS_type; // 18. P13 (5, 8, 12)
uint8_t csum; // 19. CHECKSUM XOR
inline double get_wheelSize(void) {
return (double)(128 + (wheelSize ^ 128)) / 10;
}
} __attribute__((packed)) S700_RX_t;
typedef struct {
uint8_t _00; // 0. 0x01
uint8_t size; // 1. 0x0E size
uint8_t _02; // 2. 0x01
uint8_t ERR; // 3. S700 ERR
uint8_t COM_ERR; // 4. COM ERR
uint8_t reserved0[3]; // 5. ?
uint16_t pulseTime; // 6. BIG ENDIAN!
uint8_t reserved1[3]; // 10. ?
uint8_t csum; // 13. CHECKSUM XOR
inline void set_pulseTime(uint16_t pt) {
pulseTime = pt > 0 ? (pt >> 8) | (pt << 8) : 0xFFFF;
}
inline void set_csum() {
csum = hash::XOR8(this, sizeof(*this) - 1);
}
} __attribute__((packed)) S700_TX_t;
#endif