diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go index 43dccdc6fec19c0fe67eb017cb390353c1110faf..07b1031de74d540537012dcbf32a9ff805bd3d5b 100644 --- a/devices/geiger/gqgmc.go +++ b/devices/geiger/gqgmc.go @@ -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 {