Пример #1
0
// Reads configuration file
func (g *GSM) SetConfig(config string) (err error) {
	path := C.CString(config)
	defer C.free(unsafe.Pointer(path))

	var cfg *C.INI_Section
	defer C.INI_Free(cfg)

	// find configuration file
	e := C.GSM_FindGammuRC(&cfg, path)
	if e != ERR_NONE {
		err = errors.New(errorString(int(e)))
		return
	}

	// read it
	e = C.GSM_ReadConfig(cfg, C.GSM_GetConfig(g.sm, 0), 0)
	if e != ERR_NONE {
		err = errors.New(errorString(int(e)))
		return
	}

	// we have one valid configuration
	C.GSM_SetConfigNum(g.sm, 1)
	return
}
Пример #2
0
// Creates new state maschine using cf configuration file or default
// configuration file if cf == "".
func NewStateMachine(cf string) (*StateMachine, error) {
	//C.setDebug()
	var config *C.INI_Section
	if cf != "" {
		cs := C.CString(cf)
		defer C.free(unsafe.Pointer(cs))
		if e := C.GSM_FindGammuRC(&config, cs); e != C.ERR_NONE {
			return nil, Error{"FindGammuRC", e}
		}
	} else {
		if e := C.GSM_FindGammuRC(&config, nil); e != C.ERR_NONE {
			return nil, Error{"FindGammuRC", e}
		}
	}
	defer C.INI_Free(config)

	sm := new(StateMachine)
	sm.g = C.GSM_AllocStateMachine()
	if sm.g == nil {
		panic("out of memory")
	}

	if e := C.GSM_ReadConfig(config, C.GSM_GetConfig(sm.g, 0), 0); e != C.ERR_NONE {
		sm.free()
		return nil, Error{"ReadConfig", e}
	}
	C.GSM_SetConfigNum(sm.g, 1)
	sm.Timeout = 15 * time.Second

	runtime.SetFinalizer(sm, (*StateMachine).free)
	return sm, nil
}
Пример #3
0
// Callback for message sending
//export sendSMSCallback
func sendSMSCallback(sm *C.GSM_StateMachine, status C.int, messageReference C.int, user_data unsafe.Pointer) {
	t := fmt.Sprintf("Sent SMS on device %s - ", C.GoString(C.GSM_GetConfig(sm, -1).Device))
	if int(status) == 0 {
		log.Printf(t + "OK\n")
		smsSendStatus = ERR_NONE
	} else {
		log.Printf(t+"ERROR %d\n", int(status))
		smsSendStatus = ERR_UNKNOWN
	}
}