Skip to content
Snippets Groups Projects
Commit 71f90a58 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Further.

parent da2b152e
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -106,13 +106,13 @@ const (
cmdGetSerial = "<GETSERIAL>>"
cmdGetVersion = "<GETVER>>"
cmdGetVoltage = "<GETVOLT>>"
cmdGetCpm = "<GETCPM>>"
cmdGetCps = "<GETCPS>>"
cmdGetCPM = "<GETCPM>>"
cmdGetCPS = "<GETCPS>>"
cmdGetCfg = "<GETCFG>>"
cmdEraseCfg = "<ECFG>>"
cmdUpdateCfg = "<CFGUPDATE>>"
cmdTurnOnCps = "<HEARTBEAT1>>"
cmdTurnOffCps = "<HEARTBEAT0>>"
cmdTurnOnCPS = "<HEARTBEAT1>>"
cmdTurnOffCPS = "<HEARTBEAT0>>"
cmdTurnOffPwr = "<POWEROFF>>"
)
......@@ -192,14 +192,13 @@ func (gc *GQGMCCounter) SerialNum() (string, error) {
// GetCPM returns CPM
func (gc *GQGMCCounter) GetCPM() (uint16, error) {
//uint32_t cpmsize = 2; // 2 bytes of returned data
//communicate(get_cpm_cmd, cpm_char, cpmsize);
// 1st byte is MSB, but note that upper two bits are reserved bits.
// Note that shifting and bitmasking performed in uP register, so
// endianess is irrevelant.
//cpm_int |= ((uint16_t(cpm_char[0]) << 8) & 0x3f00);
//cpm_int |= (uint16_t(cpm_char[1]) & 0x00ff);
return 0, nil
buf, err := gc.communicate([]byte(cmdGetCPM), 2)
if err != nil {
return 0, err
}
cpm := ((uint16(buf[0]) << 8) & 0x3f00)
cpm |= (uint16(buf[1]) & 0x00ff)
return cpm, nil
}
// GetCPS returns CPS
......@@ -344,19 +343,22 @@ func (gc *GQGMCCounter) SetTime(time string) {
}
func (gc *GQGMCCounter) communicate(cmd []byte, length uint32) ([]byte, error) {
//clearUSB();
//if (cmd.size() > 0) sendCmd(cmd);
//if (retbytes > 0) readCmdReturn(retdata, retbytes);
gc.Clear()
if len(cmd) > 0 {
gc.sendCmd(cmd)
}
if length != 0 {
return gc.readCmd(length)
}
return nil, nil
}
func (gc *GQGMCCounter) sendCmd(cmd []byte) {
// The port write thing
gc.port.Write(cmd)
return
}
func (gc *GQGMCCounter) readCmdReturn(length uint32) ([]byte, error) {
func (gc *GQGMCCounter) readCmd(length uint32) ([]byte, error) {
buf := make([]byte, length)
n, err := gc.port.Read(buf)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment